I've picked up a copy of the super-wicked book 'Python Geospatial Development' by Erik Westra (Amazon link), and I'm working through it. Currently, it's teaching me to load GSHHS coastline data from a shapefile into a PostGIS database, in preparation for building a geospatial web app.
My problem is this: when I try to import the GSHHS data into PostGIS, it is rejected due to the coastline polygons not being considered 'valid'. Specifically, I am given an error message described some (but not all) of the coastline polygons as being 'non-closed rings'.
I understand that this error is trying to tell me that the first and last points of the polygon are not the same. However, this is simply not true. I have examined the WKT representation of many of the polygons, and they are correct. They definately begin and end with the same co-ordinate.
The polygons are extracted from the shapefiles using the OGR library, and exporting each polygon feature to WKT. I've tried reconstituting the polygon via Shapely, and experimented with WKB, but to no avail. I have been able to load the same data into PostGIS as a MULTIPOLYGON table, using the shp2pgsql loader.
I was wondering if anybody out there had:
(a) perhaps used the same book, got stuck at the same problem, and has the answer for me?
(b) has encountered a similar problem, and found a solution?
(c) failing that, has some 'best practice' advice for ensuring valid geometry before loading into PostGIS?
UPDATE: a colleague has suggested that the 'non-closed rings' problem may just be a symptom of another problem. It is possible that my PostGIS/PostgreSQL configuration has size limits (on insert transactions, packets received, text strings, etc).
As I'm using very long WKT polygons as input, PostGIS may be cutting them too early to allow each polygon to complete. I will test it out tomorrow, but it does sound likely. My insert of country borders was only accepting some records and not others. From memory, the accepted geometries were for small island nations like Antigua (and so probably had short WKT representations).
So this could end up being more of a PostGIS database admin thread, rather than an invalid geometry thread.