[postgis-users] Create LINESTRING with a LOOP
paallen at attglobal.net
paallen at attglobal.net
Mon Apr 23 08:00:32 PDT 2007
Mark,
Thanks for your suggestion. After pouring over
the documentation more I gave up on starting with
a null linestring and just put a IF THEN in to
check for the 1st & 2nd points. Below was my fix.
But actually I started off using a large text
string, then feeding it into the EWKT all at once
and that is where I ran into problems. Which is
why I then tried to build up the line using
geometries incrementally.
This script was just a really simplified example
of what I need to do. My real function is looping
through a series of records (<100-200) containing
distances & orientations along a curved line and
calculating coordinates for a from/to (begin/end)
distance (using Minimum Curvature Alogrithm that I
have written in pl/pgsql). And it appears that
for really long LINESTRINGS it craps out. If I
run the function returning just a text string of
the coordinates, the coordinates look fine. But
when I convert them to a LINESTRING it returns
nothing. If I reduce the length, or number of
nodes, it works.
So now the question is, "Is there a limit to the
number of nodes in a LINESTRING?" ?
I cannot believe so but it is the only solution
that I can think of.
Phil
CREATE OR REPLACE FUNCTION mc_test2( )
RETURNS geometry AS
$BODY$
DECLARE
gline geometry;
gpt geometry;
x integer;
str text;
str1 text;
BEGIN
x := 1;
WHILE (x <= 5) LOOP
str := $$SRID=32717;POINT($$ || 400000 + x ||
$$ $$ || 900000 + x || $$ $$ || 3500 + x || $$ $$
|| x || $$)$$;
IF (x > 2) THEN
gline := AddPoint(gline, GeomFromEWKT(str));
ELSIF (x=1) THEN
str1 := str;
ELSIF (x=2) THEN
gline := MakeLine(GeomFromEWKT(str1),
GeomFromEWKT(str) );
END IF;
x := x+1;
END LOOP;
RETURN gline;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE;
More information about the postgis-users
mailing list