Wednesday, 2 September 2015

arcgis 10.0 - Checking whether feature class has selection using ArcPy?



In a sentence, how do you test in Arcpy whether a feature class has any selected records or not? More info below to explain:


I am doing a batch process in which a sampling layer (10km grids) is used to select polygon records (of which there are about 100,000 in total). My script returns the list of polygon IDs that intersect each 10km grid square. I then do some further processing/summarizing using that list of polygon IDs.


In instances where there are polygons within the sample square, ArcGIS performs a selection on the polygons, and it's relatively easy to iterate through those records using a searchcursor. Note I'm using v10.0.



But in instances where there are no selected records (ie there are no polygons intersecting my 10km sample square), the searchcursor would return ALL records in the database. So what's the most robust way to test programatically whether a feature class has a selection or not?


I know you can use arcpy.GetCount_management to return a number that tells you how many records are selected, and if that number = the number of records in the entire layer then you can infer that either none, or all are selected.


But that's not the same as determining if there is a selection or not. What's the best way to do that in Arcpy?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...