Monday, 21 September 2015

arcmap - How to determine if all points on a map are identical in arcpy?


My eventual goal is to automate kernel density calculations for a large corpus of point data; however, if all points are identical (for example, if there are 7 points all stacked on top of one another because they have the same long/lat values), the kernel density function in arcpy will not work. It will result in the following error:


"Error 010246: All input points are identical A valid window must be specified"


Since this will be an automated process, I need a way to check the points in the current input to be sure they aren't all the same using python/arcpy. Is there a way to do that?


EDIT: I specified a grid size and an extent, so a lot of the errors are fixed; however, identical points still give me the "valid window must be specified." I have tried to use the FindIdentical function to look for identical points, but this returns a DBF file, that I cannot read in the script. Is there some way to read a DBF easily in python, or can I find if all points are identical in another way?



Answer



Well, I found a decent way to find if all points are identical that suits my needs. I used the getExtent() function from the Layer class to find the extent of the points in the current dataset layer. If the extent's XMin == XMax and YMin == YMax, that means that the data points are all the same, since the extent is a single point.


By inserting a check with a simple if statement, I was able to choose not to perform the kernel density calculation if all the points were the same. If the points are not the same, I am able to correctly set an extent and cell size for each dataset, and the kernel density calculation moves ahead with no problems.


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...