Last active
June 14, 2018 17:59
-
-
Save andygarfield/83525ee5a7a11aee43fa to your computer and use it in GitHub Desktop.
ArcPy Project tool
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from arcpy import CreateFeatureclass_management, os, da, ListFields, Describe | |
def project_better(in_dataset, out_dataset, spatial_reference): | |
# Script borrowed from http://joshwerts.com/blog/2015/09/10/arcpy-dot-project-in-memory-featureclass/ | |
# Can project a dataset and create the output in an 'in_memory' workspace | |
path, name = os.path.split(out_dataset) | |
CreateFeatureclass_management( | |
path, | |
name, | |
Describe(in_dataset).shapeType, | |
template=in_dataset, | |
spatial_reference=spatial_reference, | |
) | |
fields = ["Shape@"] + [f.name for f in ListFields(in_dataset) if not f.required] | |
with da.SearchCursor(in_dataset, fields, spatial_reference=spatial_reference) as source_curs, \ | |
da.InsertCursor(out_dataset, fields) as ins_curs: | |
for row in source_curs: | |
ins_curs.insertRow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment