[postgis-devel] BOX3D creation issue (concat)

Obe, Regina robe.dnd at cityofboston.gov
Fri Oct 26 04:31:03 PDT 2007


James,
 
Its a bit strange you would post this since I complained about this too
very recently.  But I think you want to post this to Postgis-users
instead of dev group.
 
Anyrate the short-answer is that BOXES are not really geometries so you
do have to expand it out to a Polygon.
 
Here is a function I posted that I use (not sure if this is the best,
but the best I have come up with as a workaround).  Your above is really
just a BOX2D since you have no Z or m dimension so this should work fine
for you.
 
First you create a function like this - just run this script in
Postgresql
 
CREATE FUNCTION pgis_makeboxgeom(xmin float, ymin float, xmax float,

ymax float, SRID int) 

RETURNS geometry As

$$

SELECT ST_GeomFromText('POLYGON((' || $1 || ' ' || $2 || ',' || $1 || '

' || $4 || ',' || $3 || ' ' || $4 || ', ' || $3 || ' ' || $2 || ',' ||

$1 || ' ' || $2 || '))', $5)

$$

language 'sql' IMMUTABLE STRICT;

 

--

Then to use - change your query to

select pgis_makeboxgeom(m.mkt_bdry_min_long,
m.mkt_bdry_min_lat,m.mkt_bdry_max_long,m.mkt_bdry_max_lat,4326)::box3d

from markets m where m.market_id = 1;

 

If you don't need it to be a real box and are fine with geometry (you
can simply leave out the CAST so its)

select pgis_makeboxgeom(m.mkt_bdry_min_long,
m.mkt_bdry_min_lat,m.mkt_bdry_max_long,m.mkt_bdry_max_lat,4326) 

from markets m where m.market_id = 1;

 

Hope that helps,

Regina


________________________________

From: postgis-devel-bounces at postgis.refractions.net
[mailto:postgis-devel-bounces at postgis.refractions.net] On Behalf Of
James DeMichele
Sent: Thursday, October 25, 2007 7:57 PM
To: postgis-devel at postgis.refractions.net
Subject: [postgis-devel] BOX3D creation issue (concat)



Hi,

I am having an issue creating a BOX3D and using concat to create the
BOX3D. Here is the table I have that I am using to get my bounding
points from:

 

postgres=# select * from markets;

market_id         | 1

name              | sample

days_to_old       | 45

display_name      | Sample Area

mkt_bdry_min_lat  | 46.7285

mkt_bdry_min_long | -123.038

mkt_bdry_max_lat  | 48.2984

mkt_bdry_max_long | -120.906

 

When I attempt to construct a BOX3D using a query that concats these
items together such as:

 

select 'BOX3D(' || m.mkt_bdry_min_long || ' ' || m.mkt_bdry_min_lat ||
', ' || m.mkt_bdry_max_long || ' ' || m.mkt_bdry_max_lat || ')'::box3D
from markets m where m.market_id = 1;

 

ERROR:  BOX3D parser - doesnt start with BOX3D(

 

----------------------

I found some information that suggested I attempt to make a Geometry out
of this string instead. So I tried this:

 

select GeometryFromText('BOX3D(' || m.mkt_bdry_min_long || ' ' ||
m.mkt_bdry_min_lat || ', ' || m.mkt_bdry_max_long || ' ' ||
m.mkt_bdry_max_lat || ')', 4326) from markets m where m.market_id = 1;

 

ERROR:  Invalid OGC WKT (does not start with P,L,M,C or G)

 

----------------------

I also found some information that suggests using "expand(geometry,
float)." But, I don't want to have to figure out how to expand anything
since I already have the exact bounding box.

 

Any help in figuring out how to construct this Box3D would be greatly
appreciated.

 

Thanks.

 

-James




-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-devel/attachments/20071026/41f76483/attachment.html>


More information about the postgis-devel mailing list