[postgis-users] Converting Multilinestrings to Linestrings

Paragon Corporation lr at pcorp.us
Fri May 7 21:33:53 PDT 2010


If your multilinestrings contain more than one linestring each, then use
ST_Dump instead of ST_GeometryN.  You'll probably want to create a new table
as well to explode the single row into multiple rows.

Then to insert into the new table the insert would be

INSERT INTO newtable(field1,field2, original_gid,  the_geom)
SELECT field1,  field2, gid, (ST_Dump(the_geom)) .geom
FROM oldtable;


Leo and Regina

-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of strk
Sent: Friday, May 07, 2010 6:06 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] Converting Multilinestrings to Linestrings

On Fri, May 07, 2010 at 02:57:09AM -0700, Leigh Holcombe wrote:

> Is there a way to force linestring data to be imported as a linestring 
> instead of as a multilinestring?

Yes, shp2pgsql -S

> Is there a way to transform all the multilinestrings in a dataset into

1. Drop the type constraint (enforce_geotype_xxxx) 2. Update the geometries
3. Re-insert the type constraint 4. Update the geometry_columns record

> Is there a way to convert a multilinestring into a linestring easily 
> and quickly on the fly (I'm doing PHP/LAPP programming)?

ST_GeometryN(the_geom, 1) gives you the first LINESTRING of the (pseudo)set.


  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html
postgis-users mailing list
postgis-users at postgis.refractions.net

More information about the postgis-users mailing list