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.

Replacement for SDO_GEOM.RELATE - ST_Relate based on JTS

Monday November 07 2011 at 20:51

Keywordsreplacement sdo_geom.relate ST_Relate enterprise edition
Summary

This article presents a replacement for Oracle Spatial’s Sdo_Geom.Relate function by exposing Java Topology Suite functionality via an ST_Relate function in my Spatial Companion For Oracle (Sc4o) package + Java code.

Even old dogs like me forget things and have to learn them again. You know, I am sure that I knew that SDO_GEOM.RELATE was a Spatial licensed feature and not available in Locator, but I clean forgot until a situation with a customer required me to look at an alternative.

The reason is because this customer is trying to reduce their Oracle license costs (as part of a future migration to SQL Server) by dropping their Enterprise license and going back to Standard Edition. As part of this, an audit of Spatial feature usage showed that a limited number of functions were being used eg SDO_UNION and one or two SDO_LRS functions but what I had forgotten about was the use of SDO_GEOM.RELATE.

Now my SC4O wrapper over the Java Topology Suite 1.12 has been a great success but did not include a replacement for RELATE. Dipping in to the JTS toolkit I have found, and now exposed, the relevant components to be able to release a “replacement” for SDO_GEOM.RELATE.

I put “replacement” in inverted commas as it does not replace SDO_GEOM.RELATE exactly as it is implemented. To do so would require another 3 or 4 days work or testing but I can see little value in doing so. If anyone is interested in what this work might entail please contact me.

Anyway, here is the SC4O function wrapper:

  1.  /**
  2.     * ST_Relate
  3.     * Implements a license free version of sdo_geom.RELATE.
  4.     * @note Supports JTS named topological relationships and not Oracle specific keywords like OVERLAPBDYDISJOINT
  5.     * @param p_geom1     : sdo_geometry : geometry which will be compared to second
  6.     * @param p_mask      : varchar2     : Mask containing DETERMINE, ANYINTERACT or a list of comma separated topological relationships
  7.     * @param p_geom2     : sdo_geometry : geometry which will be compared to first.
  8.     * @param p_precision : number of decimal places of precision of a geometry
  9.     * @return String     : Result of processing
  10.     * @throws SQLException
  11.     * @history Simon Greener, November 2011, Original coding.
  12.     */
  13.   FUNCTION ST_Relate(p_geom1     IN mdsys.sdo_geometry,
  14.                      p_mask      IN varchar2,
  15.                      p_geom2     IN mdsys.sdo_geometry,
  16.                      p_precision IN NUMBER)
  17.     RETURN varchar2 Deterministic;

Here is an example test SQL statement.

  1. SELECT a.id1, a.geom1.sdo_gtype,
  2.        a.id2, a.geom2.sdo_gtype,
  3.        sdo_geom.relate(geom1,'DETERMINE',  geom2,0.05) AS sdo_relate,
  4.            SC4O.ST_Relate(geom1,'DETERMINE',  geom2,1   ) AS jtso_relate,
  5.        sdo_geom.relate(geom1,'TOUCH',      geom2,0.05) AS sdo_touch,
  6.            SC4O.ST_Relate(geom1,'TOUCHES',    geom2,1   ) AS jtso_touch,
  7.        sdo_geom.relate(geom1,'ANYINTERACT',geom2,0.05) AS sdo_anyinteract,
  8.            SC4O.ST_Relate(geom1,'ANYINTERACT',geom2,1   ) AS jtso_anyinteract,
  9.        sdo_geom.relate(geom2,'DETERMINE',  geom1,0.05) AS sdo_relate_rev,
  10.            SC4O.ST_Relate(geom2,'DETERMINE',  geom1,1   ) AS jtso_relate_rev
  11.  FROM (SELECT 104 AS id1, sdo_geometry('LINESTRING(1700 200, 1700 900, 2200 900, 1700 1300, 2200 1300)',NULL) AS geom1,
  12.               110 AS id2, sdo_geometry('POINT(1700 200)',NULL) AS geom2
  13.          FROM dual
  14.        UNION ALL
  15.        SELECT 104 AS id1, sdo_geometry('LINESTRING(1700 200, 1700 900, 2200 900, 1700 1300, 2200 1300)',NULL) AS geom1,
  16.               109 AS id2, sdo_geometry('POINT(2200 900)',NULL) AS geom2
  17.          FROM dual
  18.        UNION ALL
  19.        SELECT 104 AS id1, sdo_geometry('LINESTRING(1700 200, 1700 900, 2200 900, 1700 1300, 2200 1300)',NULL) AS geom1,
  20.               111 AS id2, sdo_geometry('LINESTRING(1300 400, 2200 1300)',NULL) AS geom2
  21.          FROM dual
  22.        UNION ALL
  23.        SELECT 101 AS id1, sdo_geometry('POLYGON((1300 600, 1700 600, 1700 1300, 1300 1300, 1300 600))',NULL) AS geom1,
  24.               108 AS id2, sdo_geometry('POINT(1400 600)',NULL) AS geom2
  25.          FROM dual
  26.        UNION ALL
  27.        SELECT 101 AS id1, sdo_geometry('POLYGON((1300 600, 1700 600, 1700 1300, 1300 1300, 1300 600))',NULL) AS geom1,
  28.               109 AS id2, sdo_geometry('POINT(2200 900)',NULL) AS geom2
  29.          FROM dual
  30.        UNION ALL
  31.        SELECT 101 AS id1, sdo_geometry('POLYGON((1300 600, 1700 600, 1700 1300, 1300 1300, 1300 600))',NULL) AS geom1,
  32.               105 AS id2, sdo_geometry('POINT(1400 1100)',NULL) AS geom2
  33.          FROM dual
  34.        UNION ALL
  35.        SELECT 101 AS id1, sdo_geometry('POLYGON((1300 600, 1700 600, 1700 1300, 1300 1300, 1300 600))',NULL) AS geom1,
  36.               106 AS id2, sdo_geometry('POINT(1300 1300)',NULL)  AS geom2
  37.          FROM dual
  38.        UNION ALL
  39.        SELECT 101 AS id1, sdo_geometry('POLYGON((1300 600, 1700 600, 1700 1300, 1300 1300, 1300 600))',NULL) AS geom1,
  40.               104 AS id1, sdo_geometry('LINESTRING(1700 200, 1700 900, 2200 900, 1700 1300, 2200 1300)',NULL) AS geom2
  41.          FROM dual
  42.        UNION ALL
  43.        SELECT 101 AS id1, sdo_geometry('POLYGON((1300 600, 1700 600, 1700 1300, 1300 1300, 1300 600))',NULL) AS geom1,
  44.               112 AS id2, sdo_geometry('POLYGON((1200 300, 1600 300, 1600 800, 1200 800, 1200 300))',NULL) AS geom2
  45.          FROM dual
  46.        UNION ALL
  47.        SELECT 101 AS id1, sdo_geometry('POLYGON((1300 600, 1700 600, 1700 1300, 1300 1300, 1300 600))',NULL) AS geom1,
  48.               102 AS id2, sdo_geometry('POLYGON((1400 1300, 1600 1300, 1600 1650, 1400 1650, 1400 1300))',NULL) AS geom2
  49.          FROM dual
  50.        UNION ALL
  51.        SELECT 101 AS id1, sdo_geometry('POLYGON((1300 600, 1700 600, 1700 1300, 1300 1300, 1300 600))',NULL) AS geom1,
  52.               103 AS id2, sdo_geometry('POLYGON((1600 1300, 1400 1300, 1400 1000, 1600 1000, 1600 1300))',NULL) AS geom2
  53.          FROM dual
  54.        ) a;

And the answer is as follows.

ST_Relate is downloadable as part of the C4O package.

I hope this is of interest to someone.

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 [2]

Hello I have found you web site when googling about oracle spatial.It helped us a lot we learned so much from this site.
In our company we have a small GIS project we were using oracle sdo_relate operator for free but now we have to use sdo_geom.relate which is not free .Today our only the thing that we have to use sdo_geom.relate function and we do not want to pay to oracle.
So we are interested with your sdo_geom.relate replacement.Now how can we test your PL/sql package.I checked it’s not in the download section.
I have one more question we are reaching you from Turkey do you have any partner in Turkey that we could get support or training?Sometimes we really need it but we do have any option.
Again thank you for these sharings.

Best regards
Ümit KÖSE
Deputy IT Manager at Yurtiçikargo Servisi A.Ş
contact 0090 212 365 28 57

— ümit köse · 11 September 2012, 03:51 · #

Ümit,

> Comment: Hello I have found you web site when googling about oracle spatial.It helped us a lot we learned so much from this site.

I am pleased as that is what it was set up to do: help real practitioners apply spatial solutions to their business problems in a cost effective manner.

> In our company we have a small GIS project we were using oracle sdo_relate operator for free but now we have to use sdo_geom.relate which is not free .Today our only the thing that we have to use sdo_geom.relate function and we do not want to pay to oracle. So we are interested with your sdo_geom.relate replacement.Now how can we test your PL/sql package.I checked it’s not in the download section.

The Relate function is actually now called ST_Relate (I will modify the posting as it was from before the releae of SC4O) and is a part of my Spatial Companion 4 Oracle (SC4O) PL/SQL Package + Java. If you are running XE this approach will not work because of the Java requirement: you have to run a minimum of Standard Edition.

So, I suggest you download the SC4O package from my website and install using the appropriate install script.

> I have one more question we are reaching you from Turkey do you have any partner in Turkey that we could get support or training? Sometimes we really need it but we do have any option.

No I do not have any partner in Turkey as the “products” on my website – including the GeoRaptor extension for SQL Developer 3.x – are all open source and free. I am linked to companies in Turkey via my LinkedIn account. I can ask them if you are interested? If not, I can provide remote mentoring services in which I guide one of your staff (must speak English I am afraid as I am rather mono-lingual) in the application of specific functionality to your problems.

> Again thank you for these sharings.

My pleasure. I hope they are useful.

BTW I do provide services to improve or extend any of the free code on my website. I would prefer to charge for major functional work (very reasonable rates) but normally do not charge for fixing existing functionality.

regards
Simon

— Simon Greener · 11 September 2012, 09:24 · #