Go to content Go to navigation and search

Home

Current Oracle Spatial Blog Articles

    GeoRaptor 4.x Update 2 (Project has Stalled)
    Tip: Drop that Spatial Index!
    Convert Single Geometry to Multi-part Geometry in Oracle Spatial
    Optimized Rectangle to 5 Point Polygon
    Centroid Package now supports Y ordinate seeding
    Convert GeoJSON document to Sdo_Geometry objects
    Implementation Of Travelling Salesman Problem
    Create Polygon From Bearings And Distances
    Function That Returns a Compass Point From a Whole Circle Bearing
    Playing around with Centroids by using different seed values
    Simple Oracle C Sprintf or Java String.format
    Some Oriented Point Functions
    Extracting Inner Rings Changed Ordinate Ordering: A Trap For Players Who Don't Read Documentation!
    PLS-00306: wrong number or types of arguments in call to 'SDO_GEOMETRY'
    Converting Google Earth Formatted Longitude/Latitude points to decimal degrees
    Oracle Business Intelligence Warehousing and Analytics - Spatial Summit
    How far inside, is inside? Measuring actual distance.
    Noding and building a polygon from single, overlapping linestrings
    Analyzing Spatial Query Performance Improvements in Oracle Spatial and Graph 12c Through Cross-Vendor Comparison
    ST_VertexN / ST_PointN - Extracting a specific point from any geometry
    Convert Single Point stored in SDO_ORDINATES to SDO_POINT_TYPE
    Aggregate APPEND Islands and XOR polygons
    Circular Arcs in Geodetic Polygons
    Some SDO_GEOMETRY/DIMINFO handling functions
    Applying And Extending Oracle Spatial - Book Released
    Changing all DIMINFO sdo_tolerance values for all metadata records in one go.
    Building Polygons from Incomplete Linestrings using ST_PolygonBuilder
    Computing Cardinal Directions to nearby geometries
    Intersecting two aggregated polygon layers with SC4O
    Spatial and Oracle 12c
    Update Triggers and SDO_GEOMETRY Equality
    Duplicate Geometry data and Data Models
    CENTROID package update
    How to calculate cumulative length of a linestring
    Useful Package of Wrapper Functions for Sdo_Util.AffineTransforms
    Compute Location from known Lat/Long point using delta easting and northing in miles
    SDO_AGGR_SET_UNION
    Sorting SDO_GEOMETRY data using the ORDER BY clause of a SELECT statement
    Creating linestrings from points
    Rounding Coordinates or Ordinates in SDO_GEOMETRY
    Effects of Sdo_Geometry Ordinate Precision on Performance
    Effects of Sdo_Geometry Ordinate Precision on Storage
    The Spatial filtering of geometries: The effect of tolerances on relationships
    Application of Delaunay Triangulation and Inverse Distance Weighting (IDW) in Oracle for Soils Interpolation
    Selecting all SDO_GTYPE values for all tables/sdo_geometry columns in a schema
    CENTROID package - Tips for Use
    Announcing the Spatial Companion For Oracle (SC4O)
    Filtering Rings (Oracle Spatial)
    Splitting a polygon using one or more linestrings
    isValid, isSimple, Dimension and CoordDim methods for SDO_Geometry
    Line Merging or Collecting lines together: ST_LineMerger
    ST_DeleteVertex for Oracle SDO_Geometry based on Jaspa/JTS
    3D/4D and SRID aware Conversion functions for SDO_Geometry: WKT and EWKT
    Topological vs Non-Topological Simplification/Generalization of Aggregated Area Geometies in Oracle
    Filtering very short linestrings via bitmap function index
    CENTROID For Oracle
    Gridding a sdo_geometry line/polygon object (Oracle)
    Finding centre and radius of a circular geometry
    Constraining geometry type for sdo_geometry column in a table.
    CASE Statements and SDO_GEOMETRY
    The Power of Constraints and Indexes for Spatial Constraints: stopping duplicate points
    Replacement for SDO_GEOM.RELATE - ST_Relate based on JTS
    Changing Oracle Spatial Index Parameters on existing index
    Writing Excel Spreadsheets files from within the Oracle database using Java and PL/SQL
    Writing xSV (eg csv) files from within the Oracle database using Java and PL/SQL
    A simple spike finder for Spatial/Locator
    JTS Java class compilation for 11g and above
    Random Spatial Search Procedure
    Geometry Snapping using JTS in Oracle
    Exposing JTS's MinimumBoundingCircle functionality
    Exposing JTS's Densifier functionality
    Using JTS's Comparison Functions - HausdorffSimilarityMeasure & AreaSimilarityMeasure with SDO_GEOMETRY
    Free JTS-based Area/Length Functions
    Handy way of systematically fixing polygon geometries with 13349 and other errors
    Standalone CENTROID package now available for download
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 4 Processing Geodetic data
    Configurable Buffer: JTS and Oracle
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 3
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 2
    Free Union, Intersection, Xor and Difference Functions for Oracle Locator - Part 1
    Building Lines into Polygons in Oracle Locator / Spatial
    Finding Intersection Points between Line and Polygon
    SDO2GeoJSON
    Free version of sdo_length
    Alternative to my SQL based GetNumRings function
    External Tables and SDO_Geometry data.
    layer_gtype keyword issue when indexing linear data on 11g
    String Tokenizer for Oracle
    Free Aggregate Method for Concatenating 2D Lines in Oracle Locator 10g
    Reducing 5 Vertex Polygon to Optimized Rectangle
    Square Buffer
    Converting decimal seconds to string
    SDO_GEOM.VALIDATE_GEOMETRY_WITH_CONTEXT - 13356 Issues
    Valid conversion unit values for Oracle sdo_geom.sdo_length()
    Removing Steps in Gridded Vector Data - SmoothGrid for Oracle
    Oracle Spatial DISJOINT search/filtering
    Creating SDO_Geometry from geometric data recorded in the columns of a table
    Concave Hull Geometries in Oracle 11gR2
    Projecting SDO_GEOM_METADATA DIMINFO XY ordinates
    Instantiating MDSYS.VERTEX_TYPE
    New PL/SQL Packages - Rotate oriented point
    GeoRaptor Development Team
    Fast Refreshing Materialized View Containing SDO_GEOMETRY and SDO_GEOM.SDO_AREA function
    Performance of PL/SQL Functions using SQL vs Pure Code
    Implementing the BEST VicGrid Projection in Oracle 10gR2
    Making Sdo Geometry Metadata Update Generic Code
    ORA-13011 errors when using SDO_GEOM.VALIDATE_LAYER_WITH_CONTEXT()
    Extract Polygons from Compound Polygon
    Detecting sdo_geometries with compound (3-point Arcs) segments
    GEOMETRY_COLUMNS for Oracle Spatial
    Convert GML to SDO_Geometry in Oracle 10gR2
    Spatial Sorting of Data via Morton Key
    Swapping Ordinates in an SDO_GEOMETRY object
    New To_3D Function
    Extend (Reduce/Contract/Skrink) Function for Oracle
    Loading and Processing GPX 1.1 files using Oracle XMLDB
    Loading Spatial Data from an external CSV file in Oracle
    Calling the Oracle Spatial shapefile loader from within the Oracle database itself
    Implementing SDO_VertexUpdate/ST_VertexUpdate for Oracle
    Implementing SDO_RemovePoint/ST_RemovePoint for Oracle
    Implementing SDO_AddPoint/ST_AddPoint for Oracle
    ESRI ArcSDE Exverted and Inverted Polygons and Oracle Spatial
    Funky Fix Ordinates By Formula
    Implementing a SetPoint/ST_SetPoint function in Oracle
    Implementing an ST_SnapToGrid (PostGIS) function for Oracle Spatial
    Generating random point data
    Implementing an Affine/ST_Affine function for Oracle Spatial
    Implementing a Scale/ST_Scale function for Oracle Spatial
    Implementing a Parallel/ST_Parallel function for linestring data for Oracle Spatial
    Implementing a Rotate/ST_Rotate function for Oracle Spatial
    Limiting table list returned when connecting to Oracle Database using ODBC
    ST_Azimuth for Oracle: AKA Cogo.Bearing
    Implementing a Translate/ST_Translate/Move function for Oracle Spatial
    Elem_Info_Array Processing: An alternative to SDO_UTIL.GetNumRings and querying SDO_ELEM_INFO itself
    Minumum Bounding Rectangle (MBR) Object Type for Oracle
    How to extract elements from the result of an sdo_intersection of two polygons.
    How to restart a database after failed parameter change
    Fixing failed spatial indexes after import using data pump
    generate_series: an Oracle implementation in light of SQL Design Patterns
    Multi-Centroid Shootout
    Oracle Spatial Centroid Shootout
    On the use of ROLLUP in Oracle SELECT statements
    Surrounding Parcels
    Spatial Pipelining
    Using Oracle's SDO_NN Operator - Some examples
    Converting distances and units of measure in Oracle Locator
    Split Sdo_Geometry Linestring at a known point
    Forcing an Sdo_Geometry object to contain only points, lines or areas
    Unpacking USER_SDO_GEOM_METADATA's DIMINFO structure using SQL
    Generating multi-points from single point records in Oracle Spatial
    Object Tables of Sdo_Geometry
    Oracle Locator vs Oracle Spatial: A Reflection on Oracle Licensing of the SDO_GEOM Package
    FAST REFRESHing of Oracle Materialized Views containing Sdo_Geometry columns
    Australian MGA/AMG Zone Calculation from geographic (longitude/latitude) data
    Loading Shapefiles (SHP) into Oracle Spatial
    Oracle Spatial Mapping and Map Rendering Performance Tips
    The significance of sdo_lb/sdo_ub in USER_SDO_GEOM_METDATA: Do I need it?
    Oracle Spatial Forum - Melbourne April 2007
    Layer_GTypes for spatial indexes
    Oracle's SQL/MM Compliant Types
    Tips and Tricks

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 09: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 [3]

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 · 10 September 2012, 17: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 · 10 September 2012, 23:24 · #

Hi Simon,

Thanks for the extensive and very usefull SC40 package.
Great work !!

I installed it and found it easy to use.

Only one qeustion about the use of:
@param p_precision : number of decimal places of precision of a geometry

I tried to use different number for the precision, only with number 1 I got a result, using 2 or 3 no result was given, also noticed a diffence in the calculated area with SDO_AREA.

Could you explain to me the use of p_precision?

Thanks a lot
regards,
Rinus

example 1 using 2 or 3:

SDO_GEOM.SDO_AREA(SDO_GEOM.SDO_INTERSECTION(HEH.GEOMETRY, KAD.GEOMETRY,0.001), 0.001, ‘unit = SQ_M’) As INTERSECTION_ORA
,SDO_GEOM.SDO_AREA(SC4O.ST_Intersection(HEH.GEOMETRY, KAD.GEOMETRY,2), 0.001, ‘unit = SQ_M’) As INTERSECTION_SC40

INTERSECTION_ORA INTERSECTION_SC40
——————————— ———————————
191671.00433228

example 2 using 1

SDO_GEOM.SDO_AREA(SDO_GEOM.SDO_INTERSECTION(HEH.GEOMETRY, KAD.GEOMETRY,0.001), 0.001, ‘unit = SQ_M’) As INTERSECTION_ORA
,SDO_GEOM.SDO_AREA(SC4O.ST_Intersection(HEH.GEOMETRY, KAD.GEOMETRY,1), 0.001, ‘unit = SQ_M’) As INTERSECTION_SC40

INTERSECTION_ORA INTERSECTION_SC40
——————————— ———————————
191671.00433228 191647.036302333

— Rinus Koppenaal · 2 September 2013, 08:17 · #