Opened 20 years ago

Last modified 20 years ago

#646 closed defect (fixed)

patch to tigerpoly.py to eliminate certain kinds of inconsistent/invalid geometry errors

Reported by: schuyler@… Owned by: warmerdam
Priority: high Milestone:
Component: OGR_SF Version: unspecified
Severity: minor Keywords:
Cc:

Description

--- pymod/samples/tigerpoly.py  2003-07-11 07:52:13.000000000 -0700
+++ ../tigerpoly.py     2004-10-28 01:18:09.258400951 -0700
@@ -166,6 +166,11 @@
     lpoly_id = feat.GetField( lpoly_field )
     rpoly_id = feat.GetField( rpoly_field )
 
+    if lpoly_id == rpoly_id:
+       feat.Destroy()
+       feat = link_layer.GetNextFeature()
+       continue
+
     try:
         module.poly_line_links[lpoly_id].append( tlid )
     except:
@@ -192,6 +197,7 @@
 polyid_field = feat.GetFieldIndex( 'POLYID' )
 
 poly_count = 0
+degenerate_count = 0
 
 while feat is not None:
     module = modules_hash[feat.GetField( tile_ref_field )]
@@ -207,6 +213,13 @@
     try:
         poly = ogr.BuildPolygonFromEdges( link_coll )
 
+        if poly.GetGeometryRef(0).GetPointCount() < 4:
+           degenerate_count = degenerate_count + 1
+           poly.Destroy()
+           feat.Destroy()
+           feat = poly_layer.GetNextFeature()
+           continue
+
         #print poly.ExportToWkt()
         #feat.SetGeometryDirectly( poly )
 
@@ -228,6 +241,9 @@
 
     feat = poly_layer.GetNextFeature()
 
+if degenerate_count: 
+    print 'Discarded %d degenerate polygons.' % degenerate_count
+
 print 'Built %d polygons.' % poly_count
 
 #############################################################################

Change History (1)

comment:1 by warmerdam, 20 years ago

I have applied the patch in CVS, though I wasn't able to find any datasets
amoung the 5 or 6 I tried that reported any discarded shapes. 

Note: See TracTickets for help on using tickets.