[postgis-users] Calculate z value based on attribute field

Sandro Santilli strk at keybit.net
Tue Apr 19 10:54:47 PDT 2011


On Tue, Apr 19, 2011 at 01:45:48PM -0400, Stephen Woodbridge wrote:
> On 4/19/2011 8:52 AM, Gis Mage wrote:
> >Hello list!
> >
> >I've got a table in PostGIS with the_geom field with 2 dimensions.
> >I wonder how can I add a z dimension and fill it up with values from
> >attribute field elev (its type is integer) ?
> 
> One way would be to add a new geometry column and then populate it, 
> maybe something like (untested):
> 
> select addgeomtrycolumn('myschema', 'mytable', 'geom3d', 4326, 'POINT', 3);
> 
> update mytable set geom3d=setsrid(makepoint(st_x(the_geom), 
> st_y(the_geom), z_column::double percision), 4326);

A geometry type agnostic way would be to union whatever you have
with a 3d point known to be contained in it. GEOS would then use
the only Z value to fill up an elevation grid used to elevate
the resulting geometry:

 -- untested query
 update mytable set geom3d = st_union(the_geom,
	st_setsrid(st_makepoint(
		st_x(st_pointonsurface(the_geom)),
		st_y(st_pointonsurface(the_geom)),
		z_column), st_srid(the_geom)));

--strk; 

  ()   Free GIS & Flash consultant/developer
  /\   http://strk.keybit.net/services.html



More information about the postgis-users mailing list