POST
|
Yes, I developed something similar that creates a unique string representation of area, centroid X, and centroid Y. It is imperfect, as different datasets may require tweaking of the decimal tolerances, but it works alright the way it is. def repGeomString(shp):
return str(round(shp.area)) + '|' + str(round(shp.centroid.X, 2)) + '|' + str(round(shp.centroid.Y, 2)) I call this in a search cursor loop and add it to a dictionary with the OID as key, much in the same way you did it. I have experienced finding polygons with mysterious null centroids, but if you account for them somehow that's the only trip-up. This wouldn't be necessary if FindIdentical worked on large datasets. I wish the internal tolerances of this tool were exposed so we could improve these imperfect geometry estimators. I've included a sample function I've wrote that returns a dictionary relating each OID to its overlapping OIDs, based on if repGeomString is equal. Buffering often leads to small changes in shapes that should be identical, and therefore this function gets thrown off sometimes, but usually works quite well. def fasterFindID(fc):
"""Records geometrical attributes of all features, then returns a dictionary:
overlapDict: key = OID; value = identical overlap OIDs. The parameter fc
is assumed to be the product of an overlap operation like Union or Intersect."""
# this creates a representation of a geometry string by concatenating various attributes to create a "unique" identifier
def repGeomString(shp):
return str(round(shp.area)) + '|' + str(round(shp.centroid.X, 2)) + '|' + str(round(shp.centroid.Y, 2))
# two dictionaries to keep track of duplicate geometries and their OIDs
geomDictByOID = {} # key = OID; value = represented geometry string
uniqueGeoms = {} # key = represented geometry string; value = list of OIDs with same geometry
oidFieldName = arcpy.Describe(fc).oidFieldName
nullCentroids = []
# gather geometries, and if centroid null, append to list
with arcpy.da.SearchCursor(fc, ("OID@", "SHAPE@")) as cursor:
for row in cursor:
try:
# get full k,v pair of OID and geometries
geomDictByOID[row[0]] = repGeomString(row[1])
# initialize empty list as value of unique geometry key
uniqueGeoms[repGeomString(row[1])] = []
except:
nullCentroids.append(row[0])
# if null centroids exist, convert features to point and reread centroids
# post-conversion, centroids will exist... for some reason
if len(nullCentroids) > 0:
# Format to string tuple for SQL query, and remove trailing comma for len = 1
if len(nullCentroids) > 1:
nullCentroidsFormat = str(tuple(nullCentroids))
else:
nullCentroidsFormat = str(tuple(nullCentroids)).replace(',', '')
arcpy.MakeFeatureLayer_management(fc, 'nLyr', '"{0}" IN {1}'.format(oidFieldName, nullCentroidsFormat))
nullCentroidsPts = arcpy.FeatureToPoint_management('nLyr', arcpy.Describe(fc).name + 'NullCentroids')
# loop through null centroid features and read new centroids
with arcpy.da.SearchCursor(nullCentroidsPts, ("OID@", "SHAPE@")) as cursor:
for row in cursor:
# get full k,v pair of OID and geometries
geomDictByOID[row[0]] = repGeomString(row[1])
# initialize empty list as value of unique geometry key
uniqueGeoms[repGeomString(row[1])] = []
# for each geometry key in uniqueGeoms, append all OIDs that match
for oid, g in geomDictByOID.iteritems():
uniqueGeoms .append(oid)
# create dictionary that relates each oid to its overlaps
overlapDict = {}
for oid, g in geomDictByOID.iteritems():
if len(uniqueGeoms ) > 1:
overlapDict[oid] = [k for k in uniqueGeoms if k != oid]
# Delete potentially large dicts
del geomDictByOID
del uniqueGeoms
return overlapDict
... View more
06-13-2013
09:27 AM
|
0
|
0
|
562
|
POST
|
No, they are still different, although the string length difference has changed from 4 to 1. (???) I am running this on a buffer product, and likely these true curves are the culprit. My question is: how does FindIdentical do it? I just need to replicate that without the bells and whistles that slow it down so much. All I'm really interested in is which shapes are identical to each other after a union operation on buffers.
... View more
06-11-2013
10:50 AM
|
0
|
0
|
562
|
POST
|
The string lengths of the WKT values differ, and although the differences are slight, any difference renders them unequal. The FindIdentical tool obviously has some internal geometry tolerance that allows it to overlook these slight differences, and I wonder if we can simulate this in some way by altering the WKT values. I am trying to explore geometries this way because running FindIdentical on large features (>100,000) often crashes or takes forever to run.
... View more
06-11-2013
09:03 AM
|
0
|
0
|
562
|
POST
|
The results of arcpy.FindIdentical() with "Shape" selected as field option show two features in my dataset to be identical in geometry, yet when I run a search cursor through it, and append the WKT of the two geometries into a list, these two strings are not equal (they even have different lengths). I thought the WKT was a representation of the geometry in string form. The JSON representation is also unequal.
... View more
06-11-2013
08:07 AM
|
0
|
7
|
775
|
POST
|
I apologize, but it turns out this is a repeat of a previous issue: http://forums.arcgis.com/threads/69714-Debug-Python-Toolbox Again, a syntax error, this time in a dictionary comprehension, foiled my Python Toolbox. Since it was a syntax error in Python, I figured the debugger should be able to inform me of it. Why does it pick up some errors and ignore others?
... View more
05-15-2013
01:30 PM
|
0
|
0
|
655
|
POST
|
There are over a thousand lines, plus 6 other .py files that get called with close to 500 lines each, so it's not feasible to publish the whole thing. Plus, it's proprietary =D I suppose I'd need someone at ESRI to take a look at it.
... View more
05-15-2013
09:35 AM
|
0
|
0
|
655
|
POST
|
Now having an identical error, yet no GitHub merge conflict text. Even turned on SublimeLinter in SublimeText2 to try and find errors, and came up with nothing. If these are not syntax errors, and are in fact logic errors, why does the .pyt shut down completely and not let me run through the logic of the tool and experience the error myself? Currently, the .pyt has a big red X and tells me "no syntax errors". Any help?
... View more
05-14-2013
04:10 PM
|
0
|
0
|
655
|
POST
|
UPDATE: this error is only thrown for the Union operation, while Identity and Intersect work just fine.
... View more
05-14-2013
01:52 PM
|
0
|
0
|
195
|
POST
|
I am unioning a fc with ~45k features, and am getting this error, even after repairing and checking geometry until no errors are found. I know this error has come up before, but doesn't seem to ever get addressed with any seriousness. Polygons with under 100k features are not so big that I'd expect machine failure, and if the error is not geometrical, why does it say it is? How do I fix this "duplicate segment", and what does it mean? In short, PLEASE alter these error messages so that they are not maddeningly cryptic and actually can point me to a solution. Thank you.
... View more
05-14-2013
12:49 PM
|
0
|
1
|
409
|
POST
|
Let me clarify -- my .pyt calls other custom modules, and if there is a syntax error in one of these modules, a red X appears (rendering the toolbox unusable) and the message is "no syntax errors" even though there is one, though not in the .pyt. Shouldn't the debugger be able to point me to the file with the error? My particular syntax error arose because I am using GitHub and had a merge conflict, which wrote a bunch of lines like "<<<<<<HEAD" as guidance for manual edits. Since one of the custom module scripts had the error, compiling the .pyt worked fine, but as the module is imported, opening the toolbox in ArcGIS won't work. Could there be more direction to errors in imported modules? Otherwise, debugging becomes difficult.
... View more
05-09-2013
10:31 AM
|
0
|
0
|
655
|
POST
|
I make many small changes to the code in my Python Toolbox on a daily basis, and therefore often refresh the toolbox to solidify the changes before running the tool. Usually when I have a syntax error, I am notified when I right-click of the location of the error. However, and I've noticed this a number of times, the message will be "no syntax errors" while the red X remains. In these cases, I am forced to find the part of the code ArcGIS doesn't like. This error does not always translate to a Python syntax error, so compiling to find errors quickly does not work all the time. If a red X is present and my tool is not accessible, the Python Toolbox should be able to notify me where the error is all the time. Has anyone else found this issue?
... View more
05-08-2013
01:52 PM
|
0
|
6
|
883
|
POST
|
I found that if you don't specify a search radius, the tool won't split properly, or not at all.
... View more
04-03-2013
03:31 PM
|
0
|
0
|
217
|
POST
|
Just solved it. I never had this issue before, but perhaps this is a new limitation in 10.1? The input parameter to Union must be a list, at least in my case. I put the single input into a list, i.e. arcpy.Union_analysis([input], output) and my tool runs smoothly. If this is a hard rule, it should be emphasized in the tool help.
... View more
04-03-2013
09:22 AM
|
3
|
2
|
987
|
POST
|
I am getting the exact same error, but my input is just one feature class (in order to find overlapping regions). It is called within a Python Toolbox workflow, and consistently throws this error. When I run it outside the tool run session, it works fine. Maddening. Any clues as to what might be going on?
... View more
04-02-2013
03:01 PM
|
0
|
0
|
987
|
POST
|
The current documentation for 10.1 says that Python version 2.7 is compatible with ArcGIS, but does that mean 2.7.x? Wondering because I am thinking of installing the current version of GeanyPy, a Python plug-in for Geany -- text editor similar to PyScripter but with code folding =0, however missing interpreter functionality, hence GeanyPy. This plug-in requires the installation of Python 2.7.3, and will likely upgrade to 2.7.4 in the future (if it comes out). I need to know if ArcGIS 10.1 will like these newer flavors of 2.7 before I mess everything up. Thanks.
... View more
04-01-2013
02:48 PM
|
0
|
1
|
642
|
Title | Kudos | Posted |
---|---|---|
4 | 10-07-2011 01:14 PM | |
1 | 05-29-2012 01:15 PM | |
3 | 10-27-2011 04:46 PM | |
3 | 04-03-2013 09:22 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|