[postgis-users] Populating Multipolygon Z as calculation -Merge Function
Chris English
emailchrisenglish at gmail.com
Wed Apr 21 08:34:29 PDT 2010
This merge function works flawlessly. I especially like the abstracting
of Z as my z' are pretty well abstract anyway:
Kevin Neufeld wrote the following:
I did something similar a few years back with LINESTRINGs. I had a
large 3D linear dataset that I was constantly fine-tuning and adjusting
the Z component of. Rather than always modifying the stored geometry
(which was a real pain since just rebuilding the index took a couple of
hours), I extracted the Z components out as a double[] into a separate
table that I could update as needed. I wrote a very simple plpgsql
function that merged the 3 ordinate back into the geometry for viewing
purposes, but this allowed me to do a bunch of analysis on the Z array
directly with other simple plpgsql functions, like min/max z values,
min/max slope, std deviation, waterfall detection algorithms, smoothed
elevation algorithms, etc.
Although it's old, the merging function might be of some use to you, it
went something like:
CREATE OR REPLACE FUNCTION adddimension(geometry, double precision[])
RETURNS geometry AS
'SELECT makeline(
makepoint(
x(pointn($1, index)),
y(pointn($1, index)),
$2[index]))
FROM
(select generate_series(1, numpoints($1)) AS index,
$1 as the_geom) foo'
LANGUAGE 'sql' VOLATILE;
Which yields results like:
select asewkt(
adddimension(
'LINESTRING(1 1, 2 2)'::geometry,
ARRAY[3, 4]
)
)
asewkt
-------------------------
LINESTRING(1 1 3,2 2 4)
(1 row)
Cheers,
Kevin
And then the Magician's Apprentice steps in:
CREATE OR REPLACE FUNCTION adddimension_z(geometry, double precision[])
RETURNS geometry AS
'SELECT ST_GeomFromEWKT( *//I think I'm trying to build a
Multipolygon object so chose this
makepoint(
x(pointn($1, index)),
y(pointn($1, index)),
$2[index]))
FROM
(select generate_series(1, numpoints($1)) AS index,
$1 as the_geom) foo'
LANGUAGE 'sql' VOLATILE;
SELECT ST_AsEWKT(
adddimension_z(
'MULTIPOLYGON(((1 1, 2 2, 3 3,4 4,5 5, 6 6, 7 7,1 1)))'::geometry,
ARRAY[1,2,3,4,5,6,7,1]
)
);
This actually ran but with unexpected results:
st_asewkt
blank-> i.e. nothing
1 row
where I was expecting something like
st_asewkt
MULTIPOLYGON(1 1 1, 2 2 2, 3 3 3, 4 4 4, 5 5 5, 6 6 6, 7 7 7, 1 1 1)
1 Row
I'm frankly surprised it ran for me at all. But this is the case
where the apprentice
mutters the incantation and finds himself in a room full of brooms or
the dog starts
talking in Polish.
On 4/19/2010 2:19 PM, Chris English wrote:
>* Hello,*>**>* I've been wrestling around with 3D and have gotten my table/geom to x,y,z*>* so that*>**>* SELECT ST_AsEwkt(the_geom) FROM <table>*>* LIMIT 1;*>**>* returns*>* "MULTIPOLYGON(((611630.148961496 690526.520745486 0,611619.960661661 *>* 690507.134957485 0,*>* 611545.79119058 690545.364867903 0,611556.435198162 690565.595798574 *>* 0,611630.148961496 690526.520745486 0)))"*>**>* In another column are the values I'd like to use for Z, or calculate *>* Z from.*>**>* And then brain death. What sort of statement would I be using to *>* update the Z part of the XYZ, as a calculated result*>* from another column.*>**>* Any help or suggestions greatly appreciated.*>**>* Chris*>**
--
He doesn't fully understand what he thinks he knows about the problem.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20100421/5e1992fc/attachment.html>
More information about the postgis-users
mailing list