Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#603 closed defect (fixed)

shp2pgsql: "-w" produces invalid WKT for MULTI* objects

Reported by: Mike Taves Owned by: pramsey
Priority: medium Milestone: PostGIS 1.5.2
Component: postgis Version: master
Keywords: shp2pgsql Cc:


When using the "-w" option for WKT output on MULTILINESTRING/MULTIPOLYGON shapefiles, the output is invalid.
For example, using a two feature shapefile where the first is a single polygon and the second is a two-piece multipolygon:

$ shp2pgsql -s 4326 -w foopoly.shp
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
INSERT INTO "foopoly" ("fooname",the_geom) VALUES ('triangle',GeomFromText('SRID=4326;MULTIPOLYGON(SRID=4326;((-0.573744292237443 0.445890410958904,-0.436301369863014 0.257305936073059,-0.660045662100457 0.209360730593607,-0.573744292237443 0.445890410958904)))', 4326));
INSERT INTO "foopoly" ("fooname",the_geom) VALUES ('split shape',GeomFromText('SRID=4326;MULTIPOLYGON(SRID=4326;((-0.100684931506849 0.365981735159817,-0.0335616438356166 0.199771689497717,-0.209360730593607 0.225342465753425,-0.100684931506849 0.365981735159817)),SRID=4326;((-0.212557077625571 0.190182648401827,-0.0367579908675799 0.161415525114155,-0.167808219178082 0.0463470319634702,-0.212557077625571 0.190182648401827)))', 4326));

Attachments (2) (1.7 KB ) - added by Mike Taves 14 years ago.
multipolygon example
postgis-shp2pgsql-wkt.patch (1.1 KB ) - added by mcayland 14 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 by mcayland, 14 years ago

Hi Mike,

Can you attach your example shapefile so I can take a look at this?


by Mike Taves, 14 years ago

Attachment: added

multipolygon example

comment:2 by Mike Taves, 14 years ago

I've tested with several other shapefiles, and I've confirmed this happens with any simple line and polygon shapefiles. (But it does not apply to point shapefiles).

The only possible way to avoid this bug and produce valid WKT is if the polygon or line files are not multi- objects, and the "-S" flag is used (this won't work with "foopoly" since it uses multi- objects).

comment:3 by pramsey, 14 years ago

HWGEOM support is only required to load into pre-1.0 versions of PostGIS… are you testing this for completeness or for your own use? I'm willing to fix it in 1.5 if someone has a legitimate use for it, but for 2.0+ it must be removed :)

by mcayland, 14 years ago

Attachment: postgis-shp2pgsql-wkt.patch added

comment:4 by mcayland, 14 years ago

Already beat you to it ;)

Mike, please can you try the attached branch against 1.5? It's reasonably safe to apply as it's small and only does anything when -w is specified.

comment:5 by Mike Taves, 14 years ago

The patch works to produce usable SQL that is successfully loaded into postgres.

INSERT INTO "foopoly" ("fooname",the_geom) VALUES ('triangle',GeomFromText('SRID=26910;MULTIPOLYGON(((-0.573744292237443 0.445890410958904,-0.436301369863014 0.257305936073059,-0.660045662100457 0.209360730593607,-0.573744292237443 0.445890410958904)))', 26910));
INSERT INTO "foopoly" ("fooname",the_geom) VALUES ('split shape',GeomFromText('SRID=26910;MULTIPOLYGON(((-0.100684931506849 0.365981735159817,-0.0335616438356166 0.199771689497717,-0.209360730593607 0.225342465753425,-0.100684931506849 0.365981735159817)),((-0.212557077625571 0.190182648401827,-0.0367579908675799 0.161415525114155,-0.167808219178082 0.0463470319634702,-0.212557077625571 0.190182648401827)))', 26910));

However I get this warning for each feature (twice for :

WARNING:  OGC WKT expected, EWKT provided - use GeomFromEWKT() for this

I think a better patch would set SRID = -1 for all geometries (not just inner). But a warning is fine at this stage.

Regarding the future of this feature: I don't rely on it, but I've found it helpful for some debugging. I won't miss it if it is removed for v2.0.

comment:6 by mcayland, 14 years ago

Resolution: fixed
Status: newclosed

Yeah, that's because the old 0.9 installations don't have the separate EWKT/EWKB functions.

I've committed the patch to 1.5 branch at r5989 and trunk at r5990. Paul, I'll leave it you to remove this functionality later as a separate task on trunk, although I also have used it on occasions to debug shapefile content. Maybe we should just bring it up to date, i.e. using the correct EWKT functions, since the code overhead from this now really small given that liblwgeom does all the magic.

comment:7 by robe, 14 years ago

Milestone: PostGIS 2.0.0PostGIS 1.5.2
Note: See TracTickets for help on using tickets.