[postgis-users] Get points from a MULTILINESTRING
Dylan Beaudette
dylan.beaudette at gmail.com
Thu May 17 11:19:38 PDT 2007
Thanks for posting this example, I was thinking about how I would do a very
similar thing the other day.
Any ideas on if a variant of this might make it into the main PostGIS
codebase?
cheers,
dylan
On Wednesday 16 May 2007 17:56, TECHER David wrote:
> Hi Tyler
>
> The following code is a simple example in PL/PGSQL, not in C
>
> I hope it could help you for trying to writting your code in C ;)
>
> The PLP/PGSQL code is as the end of my message
>
> Example
>
> testgis=# SELECT * FROM points_from_linetype('MULTILINESTRING((0 0,1 1,1
> 2),(2 3,3 2,5 4))'::geometry);
> idx_geom | idx_point | point_x | point_y
> ----------+-----------+---------+---------
> 1 | 1 | 0 | 0
> 1 | 2 | 1 | 1
> 1 | 3 | 1 | 2
> 2 | 1 | 2 | 3
> 2 | 2 | 3 | 2
> 2 | 3 | 5 | 4
> (6 lignes)
>
> testgis=# SELECT * FROM points_from_linetype('LINESTRING(2 3,3 2,5
> 4)'::geometry);
> idx_geom | idx_point | point_x | point_y
> ----------+-----------+---------+---------
> 1 | 1 | 2 | 3
> 1 | 2 | 3 | 2
> 1 | 3 | 5 | 4
> (3 lignes)
>
> Here is the code..You can improve it I think :)
>
>
> DROP TYPE PointSetFromLinetype CASCADE;
>
> CREATE TYPE PointSetFromLinetype AS (idx_geom int4,idx_point
> int4,point_x double precision, point_y double precision);
>
>
> CREATE OR REPLACE FUNCTION points_from_linetype(geometry) RETURNS SETOF
> PointSetFromLinetype AS $$
> DECLARE
> geom ALIAS FOR $1;
> Idx_Geom int4 :=1;
> Num_Geom int4 :=0;
> Nb_Points_In_Ring int4;
> Idx_Point int4 := 1;
> j PointSetFromLinetype;
> BEGIN
> /*
> Get the number of points
> */
> SELECT INTO Num_Geom NumGeometries(multi(geom))+1 ;
> /* Parsing the Geometry */
> WHILE Idx_Geom < Num_Geom
> LOOP
> SELECT INTO Nb_Points_In_Ring
> npoints(GeometryN(multi(geom),Idx_Geom))+1;
> WHILE Idx_Point < Nb_Points_In_Ring
> LOOP
> SELECT INTO j
> Idx_Geom,Idx_Point,x(pointn(GeometryN(multi(geom),Idx_Geom),Idx_Point)),y(p
>ointn(GeometryN(multi(geom),Idx_Geom),Idx_Point)); RETURN NEXT j;
> Idx_Point := Idx_Point + 1;
> END LOOP; -- End - FOR 1
> Idx_Point := 1;
> Idx_Geom := Idx_Geom + 1;
> END LOOP; -- End - while
> END;
> $$ LANGUAGE plpgsql stable;
>
> --david;
> http://www.davidgis.fr
>
> Tyler Durden a écrit :
> > Hi,
> > I'm new to postgis and I'm trying to build a extension in C that
> > receives a MULTILINESTRING geom and I need to get all points
> > contained.
> >
> > Any ideas?
> >
> > Thanks i advance,
> > Tyler
> > _______________________________________________
> > postgis-users mailing list
> > postgis-users at postgis.refractions.net
> > http://postgis.refractions.net/mailman/listinfo/postgis-users
>
> ___________________________________________________________________________
> Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son
> interface révolutionnaire. http://fr.mail.yahoo.com
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
--
Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
530.754.7341
More information about the postgis-users
mailing list