<span class="Apple-style-span" style="font-family: 'Times New Roman'; font-size: medium; "><pre style="font-family: courier; font-size: 10pt; ">This merge function works flawlessly. I especially like the abstracting</pre>
<pre style="font-family: courier; font-size: 10pt; ">of Z as my z' are pretty well abstract anyway:</pre><pre style="font-family: courier; font-size: 10pt; ">Kevin Neufeld wrote the following:</pre><pre style="font-family: courier; font-size: 10pt; ">
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</pre><pre style="font-family: courier; font-size: 10pt; ">And then the Magician's Apprentice steps in:</pre><pre><font class="Apple-style-span" face="courier">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;</font></pre><pre style="font-family: courier; font-size: 10pt; "><br></pre><pre style="font-family: courier; font-size: 10pt; ">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]
)
);</pre><pre style="font-family: courier; font-size: 10pt; ">This actually ran but with unexpected results:</pre><pre style="font-family: courier; font-size: 10pt; ">st_asewkt</pre><pre style="font-family: courier; font-size: 10pt; ">
blank-> i.e. nothing</pre><pre style="font-family: courier; font-size: 10pt; ">1 row</pre><pre style="font-family: courier; font-size: 10pt; ">where I was expecting something like</pre><pre style="font-family: courier; font-size: 10pt; ">
st_asewkt</pre><pre style="font-family: courier; font-size: 10pt; ">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)</pre><pre style="font-family: courier; font-size: 10pt; ">1 Row</pre><pre style="font-family: courier; font-size: 10pt; ">
I'm frankly surprised it ran for me at all. But this is the case where the apprentice</pre><pre style="font-family: courier; font-size: 10pt; ">mutters the incantation and finds himself in a room full of brooms or the dog starts</pre>
<pre style="font-family: courier; font-size: 10pt; ">talking in Polish.
On 4/19/2010 2:19 PM, Chris English wrote:
><i> Hello,
</i>><i>
</i>><i> I've been wrestling around with 3D and have gotten my table/geom to x,y,z
</i>><i> so that
</i>><i>
</i>><i> SELECT ST_AsEwkt(the_geom) FROM <table>
</i>><i> LIMIT 1;
</i>><i>
</i>><i> returns
</i>><i> "MULTIPOLYGON(((611630.148961496 690526.520745486 0,611619.960661661
</i>><i> 690507.134957485 0,
</i>><i> 611545.79119058 690545.364867903 0,611556.435198162 690565.595798574
</i>><i> 0,611630.148961496 690526.520745486 0)))"
</i>><i>
</i>><i> In another column are the values I'd like to use for Z, or calculate
</i>><i> Z from.
</i>><i>
</i>><i> And then brain death. What sort of statement would I be using to
</i>><i> update the Z part of the XYZ, as a calculated result
</i>><i> from another column.
</i>><i>
</i>><i> Any help or suggestions greatly appreciated.
</i>><i>
</i>><i> Chris
</i>><i>
</i></pre><div><br></div></span><br>-- <br>He doesn't fully understand what he thinks he knows about the problem.<br>