[postgis-devel] [PostGIS] #492: shp2pgsql behaving differently with -w and without

PostGIS trac at osgeo.org
Wed Apr 7 08:04:37 PDT 2010


#492: shp2pgsql behaving differently with -w and without
----------------------+-----------------------------------------------------
 Reporter:  martijnm  |       Owner:  pramsey
     Type:  defect    |      Status:  new    
 Priority:  medium    |   Milestone:         
Component:  postgis   |     Version:  1.4.X  
 Keywords:            |  
----------------------+-----------------------------------------------------
 Today we ran into some unexpected behaviour of the shp2pgsql loader.


 We tried loading a shapefile (which had a polygon which did not close its
 exterior ring). I find it strange that putting a switch (or not putting
 it), gives two different results (successfully loaded in one, and
 unsuccessful load in the other).


 When loading without -w switch, it happily loads the data into the
 database:

 {{{
 $ shp2pgsql -S -d -g geometry open.shp bug_open|psql -d gisbase
 Shapefile type: Polygon
 Postgis type: POLYGON[2]
 Password:
 SET
 ERROR:  column not found in geometry_columns table
 CONTEXT:  SQL statement "SELECT DropGeometryColumn('', $1 , $2 , $3 )"
 PL/pgSQL function "dropgeometrycolumn" line 4 at SQL statement
 ERROR:  table "bug_open" does not exist
 BEGIN
 NOTICE:  CREATE TABLE will create implicit sequence "bug_open_gid_seq" for
 serial column "bug_open.gid"
 NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
 "bug_open_pkey" for table "bug_open"
 CREATE TABLE
                    addgeometrycolumn
 --------------------------------------------------------
  martijn.bug_open.geometry SRID:-1 TYPE:POLYGON DIMS:2
 (1 row)

 INSERT 0 1
 COMMIT
 }}}

 After loading, all kinds of errors start popping up (correct!):

 {{{
 $ psql -d gisbase
 Password:
 psql (8.4.2)
 Type "help" for help.

 gisbase=# select st_isvalid(geometry) from bug_open;
 NOTICE:  IllegalArgumentException: Points of LinearRing do not form a
 closed linestring
  st_isvalid
 ------------
  f
 (1 row)

 gisbase=# select st_issimple(geometry) from bug_open;
 NOTICE:  IllegalArgumentException: Points of LinearRing do not form a
 closed linestring
 ERROR:  POSTGIS2GEOS conversion failed
 gisbase=#
 }}}

 But sometimes also with unexpected results:

 {{{
 gisbase=# select st_pointn(geometry,1) from bug_open;
  st_pointn
 -----------

 (1 row)
 }}}



 When running with -w switch the WKT parser stops the import (which is
 correct imho):

 {{{
 $ shp2pgsql -w -S -d -g geometry open.shp bug_open|psql -d gisbase
 Shapefile type: Polygon
 Postgis type: POLYGON[2]
 Password:
 SET
                dropgeometrycolumn
 ------------------------------------------------
  martijn.bug_open.geometry effectively removed.
 (1 row)

 DROP TABLE
 BEGIN
 NOTICE:  CREATE TABLE will create implicit sequence "bug_open_gid_seq" for
 serial column "bug_open.gid"
 NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
 "bug_open_pkey" for table "bug_open"
 CREATE TABLE
                    addgeometrycolumn
 --------------------------------------------------------
  martijn.bug_open.geometry SRID:-1 TYPE:POLYGON DIMS:2
 (1 row)

 ERROR:  geometry requires more points
 HINT:  "POLYGON((0 1,1 0,0 0))" <-- parse error at position 22 within
 geometry
 CONTEXT:  SQL function "geomfromtext" statement 1
 ROLLBACK
 }}}


 Tested with shp2pgsql:

 {{{
 RCSID: $Id: shp2pgsql.c 4867 2009-11-20 12:02:29Z mcayland $ RELEASE: 1.4
 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
 }}}

 With the database running on a separate machine (sun, 64-bit):

 {{{
 select postgis_full_version();
                                   postgis_full_version
 ----------------------------------------------------------------------------------------
  POSTGIS="1.4.1" GEOS="3.2.0-CAPI-1.6.0" PROJ="Rel. 4.7.1, 23 September
 2009" USE_STATS
 }}}

-- 
Ticket URL: <http://trac.osgeo.org/postgis/ticket/492>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-devel mailing list