Skip to content

Instantly share code, notes, and snippets.

@andygarfield
Last active June 14, 2018 17:59
Show Gist options
  • Save andygarfield/83525ee5a7a11aee43fa to your computer and use it in GitHub Desktop.
Save andygarfield/83525ee5a7a11aee43fa to your computer and use it in GitHub Desktop.
ArcPy Project tool
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