2

I have point layer in ArcGIS 10.4 with attribute EPSG codes. I want to iterate feature selection with EPSG code, and value with EPSG code use like output coordinate system to function define projection, but there is no possible connect value to output coordinate system value. Maybe it is possible in Python script but I don't know how.

attribute in point layer point in zones

3

This sort of iteration is fairly easy in python using a search cursor on your polygons then make feature layer with a definition query to clip by. There is an environment variable called output coordinate system which controls the spatial reference of the output, so it's not a big deal to get the zone for the row, calculate the EPSG, turn the code into an Esri spatial reference with the constructor then define the output coordinate system; much easier than clipping to a temp feature class then projecting.

import os, sys, arcpy

arcpy.env.overwriteOutput = True

InDataToBeClipped = sys.argv[1]
InZonePolygons    = sys.argv[2]
InZoneField       = sys.argv[3] # I'm assuming the zone field is an integer type
OutWorkspace      = sys.argv[4]

with arcpy.da.SearchCursor(InZonePolygons,InZoneField) as sCur:
    # this is how to iterate over the features in the zone polygons
    for row in sCur:
        outZone  = row[0]                                # get the zone for this row, assuming an int type
        outEPSG  = 32600 + outZone                       # make the zone into EPSG for WGS84 UTM Zone XX North
        outSR    = arcpy.SpatialReference(outEPSG)       # create an Esri spatial reference from the EPSG code

        defQuery = '{} = {}'.format(InZoneField,outZone) # define just this zone
        arcpy.AddMessage("Clipping Zone {}".format(outZone))

        arcpy.MakeFeatureLayer_management(InZonePolygons,"ClipPoly",defQuery)
        arcpy.env.outputCoordinateSystem = outSR         # set the spatial reference for the output features

        outFeatureClass = os.path.join(OutWorkspace,'Clipped_Zone{}'.format(outZone))
        arcpy.Clip_analysis(InDataToBeClipped,"ClipPoly",outFeatureClass)
        arcpy.Delete_management("ClipPoly")              # get rid of the temp layer

        # remove empty results
        cnt = arcpy.GetCount_management(outFeatureClass)
        if int(cnt.getOutput(0)) == 0:
            arcpy.AddWarning("No features in output")
            arcpy.Delete_management(outFeatureClass)

If you're new to python have a read of Adding a script tool and Define script tool parameters. This tool has 4 parameters, in order: feature class or layer, feature class or layer, field and workspace. The zone field should be derived from the 2nd feature class or layer.

  • Thanks, it works. This is what i want :-) Now i need the same for aster gdem raster. Clip parts of raster in zone a project coordinate system. It is the same but no imput points but raster. – komy May 29 '17 at 10:49
  • You should be able to use clip_management resources.arcgis.com/en/help/main/10.2/index.html#//… but the tricky part is getting the xmin, ymin, xmax, ymax from the polygon. That would be worth another question. – Michael Stimson May 29 '17 at 21:25

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.