[postgis-users] Get points from a MULTILINESTRING
TECHER David
davidtecher at yahoo.fr
Wed May 16 17:56:11 PDT 2007
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(pointn(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
More information about the postgis-users
mailing list