[postgis-users] Shp2pgsql - ability to generate a linestring table

Michael Fuhr mike at fuhr.org
Fri Sep 15 13:34:32 PDT 2006


On Fri, Sep 15, 2006 at 12:15:56PM -0700, Stewart Nimmo wrote:
> When running "shp2pgsql" on a polyline shape file,  the resulting table is
> always a geometry type "multilinestring".  I am expecting and require a
> geometry type of  "linestring" . 
> 
> Is "multilinestring" the default geometry type for polyline shape files
> being converted with shp2pgsql.

Apparently so.  The SetPgType() function in loader/shp2pgsql.c has
the following code:

    case SHPT_ARC: /* PolyLine */
            pgtype = "MULTILINESTRING";
            wkbtype = MULTILINETYPE ;
            pgdims = 2;
            break;

Maybe I'm missing something but I don't see an option to change
that.  One possible way around this behavior would be to use -w to
get WKT format, then filter the output before loading it into the
database.  Here's a simple example:

shp2pgsql -Dw filename.shp tablename | \
perl -pe 's/MULTILINESTRING/LINESTRING/g;
          s/(LINESTRING)\s*\(\((.*?)\)\)/$1($2)/g' | \
psql dbname

This worked for me in simple tests but I'd recommend examining the
filter's output before using it.

-- 
Michael Fuhr



More information about the postgis-users mailing list