Go to content Go to navigation and search

Home

Current Oracle Spatial Blog Articles


Search

Browse

RSS / Atom

Email me

textpattern

Creative Commons License
All Blog Articles, Data Models and Free Source Code by Simon Greener, The SpatialDB Advisor is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Free JTS-based Area/Length Functions

Saturday September 10 2011 at 21:21

KeywordsST_Area ST_Length JTS free area length oracle locator sdo_geometry
Summary

Oracle’s sdo_area and sdo_length functions are not free in versions of the Oracle database up to, but not including, 11g. From 11g onwards, these functions are free. For those still on 10g databases, I have exposed the Jts area and length functions via my Jts package.

One way of providing an area and length capability for Oracle 10g that is free from licensing issues is to use Java Topology Suite’s (JTS) GetArea() and GetLength() functions.

Being as I have already created the framework with the JTS package and installer I have added access to JTS Area and Length to this package.

Here is an example of their use:

  1. SELECT DISTINCT
  2.        round(JTS.ST_Area(a.geometry,3),3) AS area,
  3.        round(sdo_geom.sdo_area(a.geometry,0.0005),3) AS areaSDO,
  4.        round(JTS.ST_Length(a.geometry,3),3) AS len,
  5.        round(sdo_geom.sdo_length(a.geometry,0.0005),3) AS lenSDO,
  6.        CASE WHEN a.geometry.get_gtype() IN (1) THEN 'Point'
  7.             WHEN a.geometry.get_gtype() IN (5) THEN 'MultiPoint'
  8.             WHEN a.geometry.get_gtype() IN (2) THEN 'Line'
  9.             WHEN a.geometry.get_gtype() IN (6) THEN 'MultiLine'
  10.             WHEN a.geometry.get_gtype() IN (3) AND geom.isRectangle(a.geometry.sdo_elem_info)>0 THEN 'Area(Rectangle)'
  11.             WHEN a.geometry.get_gtype() IN (3) AND geom.isRectangle(a.geometry.sdo_elem_info)=0 THEN 'Area'
  12.             WHEN a.geometry.get_gtype() IN (7) AND geom.isRectangle(a.geometry.sdo_elem_info)>0 THEN 'MultiArea(Rectangle)'
  13.             WHEN a.geometry.get_gtype() IN (7) AND geom.isRectangle(a.geometry.sdo_elem_info)=0 THEN 'MultiArea'
  14.             ELSE 'Not Supported'
  15.         END geometryType
  16.   FROM ORACLE_TEST_GEOMETRIES a
  17.  WHERE a.geometry IS NOT NULL
  18.    AND a.geometry.sdo_gtype IS NOT NULL
  19.    AND a.geometry.get_dims() = 2
  20.    AND sdo_geom.validate_geometry(a.geometry, 0.0005) = 'TRUE'
  21.    AND ( a.geometry.get_gtype() IN (1,5) OR ( a.geometry.sdo_elem_info IS NOT NULL AND geom.isCompound(a.geometry.sdo_elem_info) = 0 ) )
  22.    AND a.geometry.get_gtype() <> 4
  23.   ORDER BY 5,1,3;
  24. -- Results...
  25. AREA                   AREASDO                LEN                    LENSDO                 GEOMETRYTYPE
  26. ---------------------- ---------------------- ---------------------- ---------------------- --------------------
  27. 37.5                   37.5                   27.071                 27.071                 Area
  28. 175                    175                    84.142                 84.142                 Area
  29. 10959.69               10959.69               558.094                558.094                Area
  30. 489449.547             489449.547             4462.934               4462.934               Area
  31. 26                     26                     52                     52                     Area(Rectangle)
  32. 50                     50                     30                     30                     Area(Rectangle)
  33. 160000                 160000                 1600                   1600                   Area(Rectangle)
  34. 910000                 910000                 5200                   5200                   Area(Rectangle)
  35. 0                      0                      10                     10                     Line
  36. 0                      0                      25.322                 25.322                 Line
  37. 0                      0                      27.071                 27.071                 Line
  38. 0                      0                      32.361                 32.361                 Line
  39. 0                      0                      1131.371               1131.371               Line
  40. 27                     27                     54.828                 54.828                 MultiArea
  41. 41                     41                     42.944                 42.944                 MultiArea
  42. 31                     31                     30                     30                     MultiArea(Rectangle)
  43. 49.5                   49.5                   41.071                 41.071                 MultiArea(Rectangle)
  44. 320000                 320000                 3200                   3200                   MultiArea(Rectangle)
  45. 0                      0                      10                     10                     MultiLine
  46. 0                      0                      15                     15                     MultiLine
  47. 0                      0                      30.688                 30.688                 MultiLine
  48. 0                      0                      0                      0                      MultiPoint
  49. 0                      0                      0                      0                      Point
  50. .
  51.  23 ROWS selected

See my JTS package header description for the call signatures for these functions.

Creative Commons License

post this at del.icio.uspost this at Diggpost this at Technoratipost this at Redditpost this at Farkpost this at Yahoo! my webpost this at Windows Livepost this at Google Bookmarkspost this to Twitter

Comment