[postgis-users] forced conversion of linestring to mulitlinestring when using shp2pgsql utility ?

Nicolas Ribot nicky666 at gmail.com
Wed Jan 28 01:09:39 PST 2009

> Hi,
> The -S option worked very well. But I am still not clear about how to load a shape file that has many linestrings and a few mulitlinestrings. When using the -S option it failed. You mentioned something about exploding multilinestrings into linestrings by dropping the enforce_geom_type constraint on my table. I will like to have more clarification about how this can be done using the shp2pgsql utility.
> Also how can I use the ST_Dump utility to do the samething ?

Hi Roman,

Indeed, the -S option is useful if input shapefile only contains linestrings.
In case of mix geometry type, you will have to load the data with
shp2pgsql (without the -S) switch and then to perform a sql query to
explode the multi objects into simple one. Here , st_dump will help.

A query taken from an old thread
exploding multi objects into simple one:

SELECT generate_series(1,(Select ST_NumGeometries(the_geom))) as id,
ST_GeometryN(the_geom, generate_series(1, ST_NumGeometries(the_geom)))
AS the_geom
into single_lines FROM lines;


More information about the postgis-users mailing list