I had to build a rather complex fixing script as the problems are quite varied. Some could be fixed with a simple st_buffer(geom,0) while others required more advanced cleaning. Below is an incomplete list of problems I found while sorting through the data:<div>
<br></div><div><ul><li>Figure eights or as I like to call them, Loop-di-dos |><|</li><li>Self-Intersections at river heads due to the rather simplistic boundary simplification algorithms used.</li><li>Boundaries that back tracked along themselves.</li>
<li>Boundaries that contained a line off the boundary that represented a peninsula or pier that had zero area.</li><li>Overlapping borders that had to be cleaned for my data set so that no single point could belong in two countries.</li>
<li>There were also a few inconsistencies with naming conventions that had to be manually corrected based upon some research (thank you wikipedia).</li><li>Missing state/province and/or county/muncipality borders that left a few holes at the sub-country level in a few areas.</li>
<li>Some of my missing data and inconsistencies may have been corrected since I pulled the data a year or so ago.</li></ul><div>I'd offer to send you my cleaned up data set but unfortunately it has been updated with some proprietary data for Canada and Mexico.</div>
--<br>Nathan Gerber<br>
<br><br><div class="gmail_quote">On Thu, Dec 30, 2010 at 7:03 PM, David Blackman <span dir="ltr"><<a href="mailto:david@whizziwig.com">david@whizziwig.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi all--<br>
<br>
I'm trying to import the 10m-admin-1 data from<br>
<a href="http://www.naturalearthdata.com/" target="_blank">http://www.naturalearthdata.com/</a> to postgis 1.5.2. It's generating a<br>
lot of invalid geometry that I don't know how to fix.<br>
<br>
My import command looks like this:<br>
<br>
shp2pgsql -W LATIN1 -I 10m-admin-1-states-provinces-shp ><br>
10m-admin-1-states-provinces-shp.sql<br>
(note, in postgis2, this entirely fails on invalid input characters,<br>
none of the character sets I tried worked)<br>
<br>
and of the import, 148 rows have invalid geometry, with errors like:<br>
blackmad=# select fips_1 FROM<br>
public."10m-admin-1-states-provinces-shp" WHERE ST_IsValid(the_geom) =<br>
false;<br>
NOTICE: Holes are nested at or near point 101.662 3.04074<br>
NOTICE: Self-intersection at or near point 120.185 22.9625<br>
NOTICE: IllegalArgumentException: Invalid number of points in<br>
LinearRing found 2 - must be 0 or >= 4<br>
NOTICE: Ring Self-intersection at or near point -47.3025 -16.0401<br>
NOTICE: Too few points in geometry component at or near point -65.458 -22.1012<br>
<br>
This cleangeometry.sql script @<br>
<a href="http://www.sogis1.so.ch/sogis/dl/postgis/cleanGeometry.sql" target="_blank">http://www.sogis1.so.ch/sogis/dl/postgis/cleanGeometry.sql</a> fixes most,<br>
but the LinearRing errors cause the script to choke.<br>
<br>
Can someone advise me on how to fix these errors, or where the problem<br>
lies (in the data or the import tool)?<br>
<br>
thanks<br>
--dave<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</blockquote></div><br></div>