Go to content Go to navigation and search


Current Oracle Spatial Blog Articles

    Using Oracle's ST_GEOMETRY type hierarchy with SDO_GEOMETRY: ST_PointN and ST_NumPoints
    Making Sdo Geometry Metadata
    SC4O Test log
    The Frontage Problem: Creating references from land parcel street frontage boundary to point in street
    Scheduling the Export of Spatial Data in Oracle to a Shapefile each night
    Oracle CENTROID package update
    Book: "Applying And Extending Oracle Spatial"
    Create Polygons and Linestrings From Bearings And Distances (COGO)
    Simple Implementation Of Travelling Salesman Problem
    ST_Densify for Object PLSQL
    PLSQL ST_AsEWKT and ST_FromWKT Functions For Oracle (any version)
    Useful Package of Wrapper Functions for Sdo_Util.AffineTransforms
    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
    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
    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
    Compute Location from known Lat/Long point using delta easting and northing in miles
    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
    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
    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
    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



RSS / Atom

Email me


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.

Split Sdo_Geometry Linestring at a known point

Tuesday January 29 2008 at 06:06

I recently received an email from someone asking me:

Just wondering if you could shed some light on a problem I have. In oracle using PLSQL I need to cut a polyline at two know (sic) points (not necessarly vertices and the line may be not be straight) and copy the cut line into another table. I would prefer not to go to linear referencing to do this. I cannot seem to find a function that will cut polylines. I can find the concatinate (sic) functions but this does not help much.

I’m new to oracal (sic) spatial but have a very extensive GIS background mostly ESRI and was suprised that there was not a built in function to split a line.

Any help you could offer would be greatly appreciated and really help me out.

It is true that there there is no function in Oracle Locator/Spatial that can split a linestring at a known point and return the “halfs” as separate linestrings. The closest LRS function in LRS is:

     geom_segment IN SDO_GEOMETRY,
     split_measure IN NUMBER,
     segment_1 OUT SDO_GEOMETRY,
     segment_2 OUT SDO_GEOMETRY);

But note that it does not take a point sdo_geometry but, suprise, surprise, a measure! (Also it is a procedure and not a function.)

My correspondant happened to be lucky as I had just been playing around with some of the vector functions in my GEOM PL/SQL package to find the nearest vector (segment of a linestring) closest to other objects eg:

codesys@XE> select rownum as id,
  2         b.startcoord.x as x1,
  3         b.startcoord.y as y1,
  4         b.endcoord.x as x2,
  5         b.endcoord.y as y2,
  6         sdo_geom.sdo_distance(mdsys.sdo_geometry(2002,NULL,NULL,
  7                                        mdsys.sdo_elem_info_array(1,2,1),
  8                                        mdsys.sdo_ordinate_array(b.startcoord.x,b.startcoord.y,b.endcoord.x,b.endcoord.y)),
  9                               mdsys.sdo_geometry(2001,null,
 10                                        mdsys.sdo_point_type(380326.792,5167489.29,NULL),NULL,NULL),0.005) as linedist
 11    from projline2d a,
 12         table(codesys.geom.getpipedvector2d(a.geom)) b
 13* where linetype = 'VERTEX'
codesys@XE> /
        ID         X1         Y1         X2         Y2   LINEDIST
---------- ---------- ---------- ---------- ---------- ----------
         1 380326.792 5167089.29 380326.792 5167889.29          0
         2 380326.792 5167889.29 380826.792 5167889.29    399.996
         3 380826.792 5167889.29 380126.792 5167489.29 99.2243147

I realised that this was the basis of what my correspondant wanted so I created a procedure called Split and have integrated it into my geom PL/SQL package. The procedure’s type signature is as follows:

procedure Split( p_line      in mdsys.sdo_geometry,
                 p_point     in mdsys.sdo_geometry,
                 p_tolerance in number,
                 p_out_line1 out mdsys.sdo_geometry,
                 p_out_line2 out mdsys.sdo_geometry )

This procedure can be called as follows:

codesys@XE> declare
  2    v_line mdsys.sdo_geometry := mdsys.sdo_geometry(2006,NULL,NULL, mdsys.sdo_elem_info_array(1,2,1,5,2,1), mdsys.sdo_ordinate_array(0,0,5,5,5,5,10
  3    v_point mdsys.sdo_geometry := mdsys.sdo_geometry(2001,null,mdsys.sdo_point_type(2.5,2.5,NULL),NULL,NULL);
  4    v_oline1 mdsys.sdo_geometry;
  5    v_oline2 mdsys.sdo_geometry;
  6    cursor c_vectors(p_geometry in mdsys.sdo_geometry) Is
  7    select rownum as id,
  8           b.x, b.y
  9      from table(sdo_util.getvertices(p_geometry)) b;
 10    procedure printgeom(p_text in varchar2,p_geom in mdsys.sdo_geometry)
 11    Is
 12      v_geom   mdsys.sdo_geometry;
 13    Begin
 14      dbms_output.put_line(p_text || ': Number of Elements ' || sdo_util.GetNumElem(p_geom));
 15      for v_element in 1..sdo_util.GetNumElem(p_geom) loop
 16        v_geom := sdo_util.Extract(p_geom,v_element);   -- Extract element with all sub-elements
 17        dbms_output.put_line('Element ' || v_element || ' Vertices');
 18        for rec in c_vectors(v_geom) loop
 19          dbms_output.put_line(rec.id||','||rec.x||','||rec.y);
 20        end loop;
 21      end loop;
 22    End PrintGeom;
 23  begin
 24    codesys.geom.split(v_line, v_point,0.005,v_oline1,v_oline2);
 25    PrintGeom('Outline1',v_oline1);
 26    PrintGeom('Outline2',v_oline2);
 27  end;
 28  /
Outline1: Number of Elements 1
Element 1 Vertices
Outline2: Number of Elements 2
Element 1 Vertices
Element 2 Vertices
PL/SQL procedure successfully completed.

Now the Split procedure will handle single (2002) and multi-part (2006) linestring geometries. It will also handle situations where the point:

  • Falls on a vertex
  • Falls on the line string between two vertices
  • Does not fall on the linestring at all (A position on the line at the nearest projection of the point to the line is computed and the linestring is split at this point. The position is computed by simple distance ratios and so will not be accurate for geodetic data.)

Function not Procedure

For those who want a function instead of a procedure so that the function can be used in SQL, I have added a Split function that returns a set of sdo_geometries as follows.

  Function Split( p_line      in mdsys.sdo_geometry,
                  p_point     in mdsys.sdo_geometry,
                  p_tolerance in number )
    Return codesys.GeometrySetType pipelined;

This function can be used with a table function in a SQL SELECT statement as follows:

codesys@XE> select b.* 2 from table( codesys.geom.split( mdsys.sdo_geometry(2006,NULL,NULL, mdsys.sdo_elem_info_array(1,2,1,5,2,1), mdsys.sdo_ordinate_array(0,0,5,5,5,5,10,10)), 3 mdsys.sdo_geometry(2001,null,mdsys.sdo_point_type(2.5,2.5,NULL),NULL,NULL), 4 0.005) ) b 5 /

SDO_GEOMETRY(2006, NULL, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1, 5, 2, 1), SDO_ORDINATE_ARRAY(2.5, 2.5, 5, 5, 5, 5, 10,10))

Two caveats:

  • Split does not handle compound linestrings with 3 point arcs. Any results from calling Split with such an arc will not be correct as no check is made as to arc existance.
  • Results for geodetic data will be correct only where the point actually falls on the line: all other situations will result in a rough approximation.

I will describe the algorithm I have created in another posting: I need to prepare some images that show how it works as these will be simpler than laborious text!

Finally, if there are any errors in the function please let me know and I will endeavour to correct them.

I hope the function is useful.

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

I try to use SDO_DISTANCE between a point and a linestring (with SRID=8307)

The returned result is too large.

It works between 2 points, and between a point and a single line.

point := SDO_GEOMETRY(2001, 8307, MDSYS.SDO_POINT_TYPE(geo_long, geo_lat, NULL), NULL, NULL);

SDO_GEOMETRY (2002, 8307, NULL, SDO_ELEM_INFO_ARRAY (1,2,1), liste_point)

SDO_GEOM.SDO_DISTANCE(point, ligne, 0.1, ‘unit=M’) won’t work if “ligne” contains more than 2 points…

Any help would be welcome.


7 December 2009, 23:28 #