I have had similar problems with data where we had multiple vertices "stacked" at close to the same x,y pt in polylines and polygons. If you are using ArcGIS Arcmap (32 bit) ESRI products with python 2.7, I wrote a script to identify and clean those issues. In my script, I'm always saving the beginning and ending vertex of a polyline.
import arcpy
import math
#path
fc = arcpy.mapping.Layer('D:/Folder/Errors/HIGHWAYS.shp')
#UpdateCursor up, then down
with arcpy.da.UpdateCursor(fc,["shape@", "OID@"]) as cursor:
for row in cursor:
# loop through parts
for part in row[0]:
counter = 0
compX = 000000.1
compY = 000000.1
#print "Beginning OID = " + str(row[1])
for pnt in part:
#--NOTE--if you want 2 places with ceil, multi and divide by 100
if (math.ceil(pnt.X*10)/10 < compX + 0.2 and math.ceil(pnt.X*10)/10 >
compX - 0.2) and (math.ceil(pnt.Y*10)/10 < compY + 0.2 and
math.ceil(pnt.Y*10)/10 > compY - 0.2):
print "##########################################################"
#print str(compX) + "," + str(compY)
print "OID = " + str(row[1])
arr = row[0].getPart(0)
if arr.count == 3:
print "arr.count = 3"
arr.remove(1)
newLine = arcpy.Polyline(arr)
row[0] = newLine
print("Removing Malcolm in the Middle vertex " + "{0},
{1}".format(pnt.X, pnt.Y))
cursor.updateRow(row)
print "-----------------------------------------"
elif arr.count <= 2:
print "no beuno---very small line---probably a sliver"
else:
print "arrcount = " + str(arr.count)
print "counter = " + str(counter)
if arr.count == (counter + 1):
arr.remove(arr.count - 2)
newLine = arcpy.Polyline(arr)
row[0] = newLine
print("Removing vertex " + "{0}, {1}".format(pnt.X, pnt.Y))
print "Saved Original Endpoint"
cursor.updateRow(row)
print "----------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
else:
arr.remove(counter - 1)
newLine = arcpy.Polyline(arr)
row[0] = newLine
print("Removing vertex " + "{0}, {1}".format(pnt.X, pnt.Y))
cursor.updateRow(row)
print "-----------------------------------------"
else:
compX = math.ceil(pnt.X*10)/10
compY = math.ceil(pnt.Y*10)/10
counter = counter + 1
print ("Done")
If you are using something like Oracle Spatial.....
select * from (
SELECT id_number, id_2, SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT(c.geometry,
0.2) val
FROM highway c )
where val <> 'TRUE';
Fixed the data using:
update highway set geometry = sdo_util.rectify_geometry(GEOMETRY,0.2) where
id_number = 'somenumber1' ;
u_cur.updateRow(row)
. updateRow is a method of UpdateCursor not of the row object! – fatih_dur Jan 31 '17 at 16:32