[1138] Project conversion and shapefile to JSON file based on arcpy
Refer to the following scripts:
import os, arcpy
arcpy.env.overwriteOutput = True
# Change the feature's project
def atlas_project_conversion(in_fc, out_fc):
# Change the project to:102100 Web Mercator
sr_webmerc = arcpy.SpatialReference(102100)
arcpy.Project_management(
in_dataset=in_fc,
out_dataset=out_fc,
out_coor_system=sr_webmerc
)
# Convert the feature to json file
def atlas_feature_to_json(in_shp, out_json):
arcpy.conversion.FeaturesToJSON(
in_features=in_shp,
out_json_file=out_json,
format_json="NOT_FORMATTED",
include_z_values="NO_Z_VALUES",
include_m_values="NO_M_VALUES",
geoJSON="GEOJSON",
outputToWGS84="KEEP_INPUT_SR",
use_field_alias="USE_FIELD_NAME"
)
# find the root directory
root_dir = __file__[:__file__.find("\\Working\\GIS\\Data\\Models")]
excel_dir = root_dir + "\\Working\\GIS\\Data\\Models\\Automation\\Reports\\Excel Results"
data_dir = root_dir + "\\Working\\GIS\\Data"
project_in_shp = os.path.join(data_dir, "Boundaries", "siteboundary.shp")
project_out_shp = os.path.join(data_dir, "Boundaries", "siteboundary_atlas.shp")
json_out_json = os.path.join(data_dir, "Boundaries", "siteboundary_atlas.geojson")
# Change the feature's project
funcs.atlas_project_conversion(project_in_shp, project_out_shp)
# Convert the feature to json file
funcs.atlas_feature_to_json(project_out_shp, json_out_json)
浙公网安备 33010602011771号