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.

Implementing a Parallel/ST_Parallel function for linestring data for Oracle Spatial

Monday January 26 2009 at 00:00

I have a MOVE/ST_TRANSLATE function in my GEOM PL/SQL package that moves all the points in an SDO_GEOMETRY object by a shift vector defined as a delta x and delta y.

But when I considered the idea of moving an SDO_GEOMETRY linestring object a set distance parallel to itself then the MOVE function becomes pointless as the direction of the movement of each vertex in the linestring is different depending on the direction of each segment (or vector) within the linestring.

The PARALLEL function is implemented in my GEOM package because of its dependence on other functions particularly the GetVector function. So, if you wish to see how it was implemented, download that package and have a look. Here is the documentation header and signature definition from the package.

  /** ----------------------------------------------------------------------------------------
  * function   : Parallel
  * precis     : Function that moves the supplied linestring left/right a fixed amount. Bends in the linestring, when moved, can remain vertex-connected or be converted to curves.
  * version    : 1.0
  * usage      : FUNCTION Parallel(p_geometry   in mdsys.sdo_geometry, 
  *                                 p_distance   in number,
  *                                 p_tolerance  in number,
  *                                 p_curved     in number := 0)
  *                 RETURN mdsys.sdo_geometry DETERMINISTIC;
  *               eg select Parallel(mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,1,10)),10,0.05) from dual;
  * param      : p_geometry  : Original linestring/multilinestring
  * paramtype  : p_geometry  : mdsys.sdo_geometry
  * param      : p_distance  : Distance to move parallel -vs = left; +ve = right
  * paramtype  : p_distance  : number
  * param      : p_tolerance : Standard Oracle diminfo tolerance.
  * paramType  : p_tolerance : Number
  * param      : p_curved    : Boolean flag indicating whether to stroke bends in line (1=stroke;0=leave alone)
  * paramType  : p_curved    : Integer (but really boolean)
  * return     : input geometry moved parallel by p_distance units
  * returnType : mdsys.sdo_geometry
  * history    : Simon Greener - Devember 2008 - Original coding.
  * copyright  : Free for public use
  FUNCTION Parallel(p_geometry   in mdsys.sdo_geometry, 
                    p_distance   in number,
                    p_tolerance  in number,
                    p_curved     in number := 0)
    RETURN mdsys.sdo_geometry DETERMINISTIC;

It is one of those interesting issues of software engineering that when we encapsulate functionality we end up with inter-dependence between elements. While PL/SQL’s packages allow for dependent objects to be associated within the same package, one still ends up with cross-package dependencies. I have often thought of not using packages – which would not be that difficult – but one would end up with needing a separate schema to hold the myriad of functions and object types that would be created c.f., PostGIS’s large function set. But one limitation stopping me form not using packages is the fact that Oracle standalone procedures and functions do not allow overloading: this is only possible within packages.

Let’s begin our testing by creating a table to hold the output of each test so we can generate a graphic with any GIS capable of connecting to Oracle (I use Manifold GIS Ultimate Edition ).

drop   table test_parallel;
create table test_parallel (
  oid    number,
  geom   mdsys.sdo_geometry );

Let’s start with something perhaps not so obvious: moving a single point “parallel” 10 meters:

select Geom.Parallel(mdsys.sdo_geometry(2001,null,null,sdo_elem_info_array(1,1,1),sdo_ordinate_array(1,1)),10,0.05) 
  from dual;

Error report:
SQL Error: ORA-20001: p_linestring is null or is not a linestring
ORA-06512: at "CODESYS.GEOM", line 3870
ORA-06512: at line 1

Yes, it is a silly thing to do and my function correctly detects it and throws an exception. Also, polygons are not handled by my function.

Prompt Neither should polygons
select Geom.Parallel(mdsys.sdo_geometry('POLYGON((2 2, 2 7, 12 7, 12 2, 2 2))',NULL),10,0.05)  as geom
  from dual; 

Error report:
SQL Error: ORA-20001: p_linestring is null or is not a linestring
ORA-06512: at "CODESYS.GEOM", line 3870
ORA-06512: at line 1

I guess I could handle polygons by changing the way I handle the first and last point in the polygon. When I do this I will modify this article and upload the changed function.

Now, let’s move a simple linestring 10 meters to the right and left (-ve).

truncate table test_parallel;
insert into test_parallel 
select 1, mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,1,10)) from dual
union all
select 2, Geom.Parallel(mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,1,10)),10,0.05) from dual
union all
select 3, Geom.Parallel(mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,1,10)),-10,0.05) from dual

Simple linestring moved parallel

Now let’s look at a linestring composed of two segments with an acute angle bend between them. Because it makes no sense to apply a curve to the acute angle after moving parallel we set the p_curved parameter to 0 (setting to 1 will produce the same result).

Prompt Test Acute Angle
truncate table test_parallel;
insert into test_parallel 
select 1, mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,10,10,20,1)) from dual
union all
select 2, Geom.Parallel(mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,10,10,20,1)),5,0.05,0) from dual;

Linestring with acute deflection

Now let’s look at a linestring composed of two segments with an obtuse angle bend between them. Because curving the angle of the resultant paralleled line makes sense, first we will create the parallel line without a curve, then with one.

Prompt Test Obtuse angle - Not curved
truncate table test_parallel;
insert into test_parallel 
select 1, mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,10,10,20,1)) from dual
union all
select 2, Geom.Parallel(mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,10,10,20,1)),-5,0.05,0) from dual;

Prompt Test Obtuse angle - Curved
truncate table test_parallel;
insert into test_parallel 
select 1, mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,10,10,20,1)) from dual
union all
select 2, Geom.Parallel(mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,10,10,20,1)),-5,0.05,1) from dual;

Not Curved Curved
Linestring with obtuse deflection Linestring with obtuse deflection with curved parallel

I don’t support linestrings with circular curves (as yet).

Prompt Compound Linestrings not supported
select 1, Geom.Parallel(MDSYS.SDO_GEOMETRY(2002,null,null,MDSYS.SDO_ELEM_INFO_ARRAY(1,4,3,1,2,1,3,2,2,7,2,1),MDSYS.SDO_ORDINATE_ARRAY(-2.5,4.5,6.5,13.5,9.9,15,13.3,13.7,23.3,4.7)),5,0.05,1) 
  from dual;

Error report:
SQL Error: ORA-20001: Compound linestrings are not supported.
ORA-06512: at "CODESYS.GEOM", line 3873
ORA-06512: at line 1

But 3D linestrings are OK.

Prompt Check 3D linestring processing
select Geom.Parallel(mdsys.sdo_geometry(3002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,1,1,10,1)),10,0.05) as geom
  from dual;

Check 3D linestring processing

1 rows selected

What happens if we hit two line segments which have no deflection angle (ie one goes straight on after the other)?

Prompt Check lines that are parallel or continue from last line without deflection
truncate table test_parallel;
insert into test_parallel
select 1, mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,1,10,1,100)) from dual
union all
select 2, Geom.Parallel(mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,1,10,1,100)),10,0.05) from dual;

Line with no deflection between vectors/segments

Yes, the function handles this situation correctly. And it also handles it correctly for 3D linestrings:

Prompt Check 3D lines that are parallel or continue from last line without deflection
select Geom.Parallel(mdsys.sdo_geometry(3002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(1,1,9,1,10,9,1,100,9)),10,0.05) as geom
  from dual;

Check 3D lines that are parallel or continue from last line without deflection

1 rows selected

Now check a multilinestring with an acute and obtuse angle with p_curved = 1 (ie true).

truncate table test_parallel;
Prompt Check multilinestring with one linestring with an acute angle and the other an obtuse angle
insert into test_parallel 
select 1, mdsys.sdo_geometry(2006,null,null,sdo_elem_info_array(1,2,1,5,2,1),sdo_ordinate_array(1,1,10,10,20,1,50,50,100,0,150,50)) from dual;
union all
select 2, Geom.Parallel(mdsys.sdo_geometry(2006,null,null,sdo_elem_info_array(1,2,1,5,2,1),sdo_ordinate_array(1,1,10,10,20,1,50,50,100,0,150,50)),10,0.05,1) from dual;

Multilinestring with acute/obtuse angle parallel curved

Now, quickly check 3D and 4D linestrings with measures. Note that the NULL values in the SDO_Ordinate array are set to 0 by the SDO_UTIL.APPEND function (I will change this at some stage).

Prompt Check 2D line with LRS measures
select Geom.parallel(SDO_GEOMETRY(3302, NULL, NULL,
                     SDO_ORDINATE_ARRAY(5,10,0, 20,5,NULL, 35,10,NULL, 55,10,100)),1,0.05,1) 
         as geom
  from dual;

Check 2D line with LRS measures

1 rows selected

Prompt Check 3D line with LRS measures
select Geom.parallel(SDO_GEOMETRY(4402, NULL, NULL,
                     SDO_ORDINATE_ARRAY(5,10,500,0, 20,5,501,NULL, 35,10,502,NULL, 55,10,503,100)),1,0.05,1)
         as geom
  from dual;

Check 3D line with LRS measures

1 rows selected

Finally, let’s finish with a linestring with many acute/obtuse bends creating a parallel line on the left and on the right all with p_curved = 1.

Prompt Finish with left/right parallel of linestring with acute/obtuse bends with p_curve = 1
truncate table test_parallel;
insert into test_parallel (oid,geom)
select 1, mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(0,0,45,45,90,0,135,45,180,0,180,-45,45,-45,0,0)) as geom 
  from dual
union all
select rin + 1, Parallel(b.geom,case when rin = 2 then -1 else 1 end * 10,0.005,1) as geom
  from (select level as rin, mdsys.sdo_geometry(2002,null,null,sdo_elem_info_array(1,2,1),sdo_ordinate_array(0,0,45,45,90,0,135,45,180,0,180,-45,45,-45,0,0)) as geom 
         from dual
         where level between 1 and 2
         connect by level < 3) b;

Final linestring with left/right parallels all curved.

I hope this function is useful 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 [5]

Hi Simon.
I’m a programmer and i work with PostGIS spatial DB. I need to use exactly amazing Parallel function that create parallel linestring. Who i can implement it in PostGIS? Is it free?

Yehuda Elimelech 7 June 2010, 14:45 #

Hello Simon!! As Yehuda said, I work with Postgis too, and I will be very grateful if you can tell me if is possible to implement this function in Postgis. In positive case, what is the way.
Thank’s a lot.

Felipe 7 July 2011, 10:08 #


I have an implementation for PostGIS that has all the curve support stripped out of it. If you don’t want curve support then I can post it.

In addition, the code still does not handle the situation where two lines collapse and disappear. It can be done but I have had no need to worry about it as it is for cases where the parallel distance is very large.

This function is also the basis for a square buffer function as well.


Simon Greener 7 July 2011, 11:26 #

Measure of degree of parallelism

Given a line segment and several close line segment neighbours of different lengths, how could one determine which neighbour is closest and the most parallel by some measure.

I have some ideas on how this could proceed, but would dearly like to save implementation time if this has been done elsewhere.

Purpose: match a road segment from one dataset to a corresponding road segment in another dataset for the purpose of attribute transfer..

Many thanks.

SteveH 18 September 2014, 05:10 #

Hi Simon

I need this function in my firm. exactly matches,
and many connected linestrings parralled to one linestring or one multilinestring ??

Many thanks


Taekjoon Lee 19 April 2016, 12:24 #