[postgis-users] multilinestringm to linestring en masse?

Obe, Regina robe.dnd at cityofboston.gov
Tue Oct 16 07:16:03 PDT 2007


For 1 - SELECT count(gid)
		FROM sometable WHERE ST_NumGeometries(the_geom) > 1

would return a count of all records that are truly multilines.

For 2 - If you find the above returns 0.  Then you can safely do this

create a new table then 
INSERT INTO newtable(..)
	fields, ST_GeometryN(the_geom,1)
FROM sometable

Or create a new geom field in your table
SELECT AddGeometryColumn('public', 'sometable', 'new_geom', <srid>,
'LINESTRING',2);

UPDATE sometable SET new_geom = ST_GeometryN(the_geom,1);

Then do a 
SELECT DropGeometryColumn('public', 'sometable', 'the_geom')


Hope that helps,
Regina
-----Original Message-----
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Webb
Sprague
Sent: Tuesday, October 16, 2007 10:01 AM
To: PostGIS Users Discussion
Subject: [postgis-users] multilinestringm to linestring en masse?

Hi all,

I am sorry for relying so heavily on the list ... but I have a column
of geometries imported through shp2pgsql that are multilinestringm and
need to be plain old linestrings.

(1) How can I check en masse that this operation would be well
defined?  IE, that there is only a single linestring in each geom ,
etc?

(2) How can I do the conversion (ie which function for update
the_new_geom = FUNC(the_geom)?  I tried st_dump, but I can't even
figure out how to pull the geometry out of the returned pair.

(3) I want to do this so I can interpolate and edit the linestrings.
Is this the right way to go about setting up such a thing?

Some data/ results:

-- the data

or_gis=# select astext(the_geom) from hwys2006 where
hwyname='HATFIELD' and hwy_seg_id = 19644;

  astext
------------------------------------------------------------------------
------------------------------------------------------------------------
--------
 MULTILINESTRING((1032221.983 95706.992,1032248.7 95674,1032804.8
95003.1,1033343.7 94346.8,1033802.5 93781.1,1034597.6
92784.6,1034910.378 92332.902))

---  st_dump()

or_gis=# select astext(the_geom), st_dump(the_geom) from hwys2006
where hwyname='HATFIELD' and hwy_seg_id = 19644;
astext|MULTILINESTRING((1032221.983 95706.992,1032248.7
95674,1032804.8 95003.1,1033343.7 94346.8,1033802.5 93781.1,1034597.6
92784.6,1034910.378 92332.902))
st_dump|({1},0102000060B00B000007000000A8C64BF73B802F415A643BDFAF5DF7405
C8FC2F5281C32406666666671802F4100000000A05BF7401E85EB51B81E32409A999999C
9842F419A999999B131F74048E17A14AE47324066666666FF882F41CDCCCCCCAC08F7407
03D0AD7A370324000000000958C2F419A99999951E5F64052B81E85EB91324033333333C
B922F419A99999909A7F64090C2F5285CCF32404C3789C13C952F41508D976ECE8AF6402
85C8FC2F5E83240)

-- an attempt at interpolation

or_gis=# select astext(the_geom),
astext(st_line_interpolate_point(the_geom, .5)) from hwys2006 where
hwyname='HATFIELD' and hwy_seg_id = 19644;
ERROR:  line_interpolate_point: 1st arg isnt a line
or_gis=#

Thanks again!
W
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.




More information about the postgis-users mailing list