I've created a polygon from a raster dataset:

arcpy.RasterToPolygon_conversion(RasterInt, "C:/arc/poly_int.shp", "NO_SIMPLIFY", "Value")

The 'value' field has numbers 1-37, which map to the ID field in the output polygon shapefile feature class.

Now I would like to select points that lay within certain polygons (e.g. delineated by ID). Using the SelectLayerByLocation_management tool only selects points inside all the polygons. How to a define a criteria?

Alternative approach: How do I create multiple polygons from the main polygon, using the ID field?

I'm looking for solutions in Python -- not necessarily using arcpy but I do have it.


You should be able to do a SelectLayerByAttribute on your polygons (from raster) prior to using SelectLayerByLocation.

The Select_analysis tool could be useful to your alternative approach.

  • I'm new with arcpy, are you saying I could do something along the lines of: arcpy.SelectLayerByLocation_management("MaalestDnmiSF", "WITHIN", arcpy.SelectLayerByAttribute(..."test")) – John Jan 18 '13 at 13:19
  • It works! arcpy.SelectLayerByLocation_management("stations", "WITHIN", arcpy.SelectLayerByAttribute_management("test", "NEW_SELECTION", '"ID" = 21')) – John Jan 18 '13 at 13:24

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.