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

strk at refractions.net strk at refractions.net
Mon Sep 18 02:07:18 PDT 2006


The problem is that there's no LINESTRING type in shapefiles.
SHPT_ARC type is *any* number of lines into a record.
So, the only way would be scanning the whole shapefile and IFF
all records only have a single item use LINESTRING TYPE.

Alternatively, you could just
update yourtable set the_geom =  GeometryN(the_geom, 1);
after import... (discarding all but first geom in a set).

--strk;

On Fri, Sep 15, 2006 at 02:34:32PM -0600, Michael Fuhr wrote:
> 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
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users

-- 

 /"\    ASCII Ribbon Campaign
 \ /    Respect for low technology.
  X     Keep e-mail messages readable by any computer system.
 / \    Keep it ASCII. 




More information about the postgis-users mailing list