[postgis-users] [From Oracle Spatial to PostGIS] How to store rectangles?

Simon Greener simon at spatialdbadvisor.com
Sun Apr 26 15:41:51 PDT 2009


> I'm porting an application from Oracle Spatial to PostGIS.
> In particular I've come across this code in an INSERT statment:
> rectangle
> ,MDSYS.SDO_ORDINATE_ARRAY("+topleftlat+", "+topleftlon+",
> "+bottomrightlat+", "+bottomrightlon+")),null)
> I understand this loads a rectangle in 2 points.
> I've written this postGIS code:
> GeomFromText('POLYGON("+topleftlat+" "+topleftlon+" "+bottomrightlat+"
> "+bottomrightlon+"))', -1)
> Obviously it doesn't work yet. Is this the right direction? Is there a way
> to store rectangles in postGIS in a similar fashion?

See the PostGIS manual (I have slightly modified the relevant entry):

SELECT addGeometryColumn('myschema','mytable','bbox','4326','GEOMETRY','2'); 
UPDATE mytable set bbox = ST_MakeBox2D(ST_MakePoint(bottomrightlon,bottomrightlat), ST_MakePoint(topleftlon, topleftlat))

Note that in PostGIS and Oracle X = Longitude and Y = Latitude

Hope this helps

SpatialDB Advice and Design, Solutions Architecture and Programming,
Oracle Database 10g Administrator Certified Associate; Oracle Database 10g SQL Certified Professional
Oracle Spatial, SQL Server, PostGIS, MySQL, ArcSDE, Manifold GIS, FME, Radius Topology and Studio Specialist.
39 Cliff View Drive, Allens Rivulet, 7150, Tasmania, Australia.
Website: www.spatialdbadvisor.com
  Email: simon at spatialdbadvisor.com
  Voice: +61 362 396397
Mobile: +61 418 396391
Skype: sggreener
Longitude: 147.20515 (147° 12' 18" E)
Latitude: -43.01530 (43° 00' 55" S)

More information about the postgis-users mailing list