[postgis-users] all x point and y point

Alex Mayrhofer axelm-postgis at nona.net
Mon Jun 5 22:12:39 PDT 2006


Patricio Cifuentes Ithal wrote:
> Hi,
> 
> as I can know all points X,Y  of a multiline,  with function the postgis?
> 
> my multiline is:
> 
> SRID=-1;MULTILINESTRING((357495 6292952,357591 6292051,356671 6292396))
> 
> 
> 
> I' need a list.:
> 
> in row's
> 1.  357495 6292952
> 2.  357591 6292051
> 3.  356671 6292396

I'm using a function like this (might not be the most efficient one, and
does not work with MULTILINESTRING atm) - use dissect_line(geom):


--- dissects a line into its X,Y,(Z,M) values, returning a row per point
--- specific return type
CREATE TYPE dissect_line_ret AS
	(x double precision, y double precision,
	 z double precision, m double precision);

--- function itself
CREATE OR REPLACE FUNCTION dissect_line (line geometry)
	RETURNS SETOF dissect_line_ret AS $$

DECLARE
	resultrow dissect_line_ret%ROWTYPE;
	i integer;
	npt integer;
	pt geometry;

BEGIN
	IF GeometryType(line) != 'LINESTRING' THEN
		RAISE NOTICE 'dissect_line: cannot dissect a % geometry',
		GeometryType(line);
		RETURN;
	END IF;
	npt := NumPoints(line);
	FOR i in 1..npt LOOP
		pt := PointN(line,i);
		resultrow.x := x(pt);
		resultrow.y := y(pt);
		resultrow.z := z(pt);
		resultrow.m := m(pt);
		RETURN NEXT resultrow;
	END LOOP;
	RETURN;
END;

$$ LANGUAGE plpgsql;

cheers

Alex
--
http://nona.net/features/map/



More information about the postgis-users mailing list