1

I have a few shapefiles in one folder with different coordinate systems but would like to use one of them as a template dataset. Is there a way to use python to filter out the shapefiles already in the required projection in the same folder?

I have been looking at the ListFeatureClasses and somehow using a wildcard, but not sure if that's the right way to go.

  • This is a near duplicate of gis.stackexchange.com/questions/141351/… - the only difference seems to be the use of a file geodatabase instead of a folder of shapefiles. – PolyGeo Apr 7 '15 at 10:18
  • Oh sorry, thanks for pointing out PolyGeo, I will try. – John H Apr 7 '15 at 10:26
  • Is there a way to filter out the shapefiles already in the required projection in the same folder? – John H Apr 7 '15 at 10:48
  • You should probably research/ask that as a new question but the way I would try is to use arcpy.Describe(). – PolyGeo Apr 7 '15 at 10:58
3

You can use the Describe function to get information about your spatial references. Then simply use logic to screen out the spatial reference you do not want.

import arcpy

arcpy.env.workspace = r'C:\path\to\your\fgdb.gdb'

fcs = arcpy.ListFeatureClasses()

for fc in fcs:
    sr = arcpy.Describe(fc).spatialReference.name
    # Note that you can add multiple spatial references in a list ["sr1", "sr2"...]
    if sr not in ["NAD_1983_UTM_Zone_15N"]:
        # Do something
        print sr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.