[postgis-users] Converting Multilinestrings to Linestrings

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


Leigh, 

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;

http://www.postgis.org/documentation/manual-svn/ST_Dump.html

Leo and Regina
http://www.postgis.us


-----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
linestrings? 

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.

--strk;

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





More information about the postgis-users mailing list