Go to content Go to navigation and search

Home

Current Oracle Spatial Blog Articles

    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
    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.

Create Polygons and Linestrings From Bearings And Distances (COGO)

Monday September 03 2018 at 18:31

Keywordspolygon cogo bearing distance create generate
Summary

Generate polygon from a set of bearings and distances ( Cogo )

UPDATE
The original functions have been modified and deployed via my Oracle Object code.
They original code is no longer available.

My COordinate GeOmetry (COGO) package has been around for a long time.

What I had not done was use the power of this package to construct polygons (2003) or linestrings (2002) from a starting point and a set of whole circle bearings (0-360) and distances.

The following article shows how some simple COGO functionality has been added to my Oracle Object type system.

Representing Bearings and Distances

Firstly a data type to represent bearing and distances instructions is created, and some useful Constructors are added to allow for different methods for defining bearings.

  1. -- Create a suitable type for the bearings and distances
  2. --
  3. CREATE OR REPLACE TYPE T_Bearing_Distance
  4. AUTHID DEFINER
  5. AS OBJECT (
  6.   Bearing  NUMBER,
  7.   Distance NUMBER,
  8.   Z        NUMBER,
  9.   Constructor FUNCTION T_BEARING_DISTANCE ( p_sDegMinSec IN varchar2,
  10.                                             p_distance   IN NUMBER )
  11.                 RETURN SELF AS RESULT,
  12.   Constructor FUNCTION T_BEARING_DISTANCE ( p_bearing  IN NUMBER,
  13.                                             p_distance IN NUMBER )
  14.                 RETURN SELF AS RESULT,
  15.   Constructor FUNCTION T_BEARING_DISTANCE ( p_sDegMinSec IN varchar2,
  16.                                             p_distance   IN NUMBER,
  17.                                             p_z          IN NUMBER )
  18.                 RETURN SELF AS RESULT
  19. );
  20. /
  21. SHOW ERRORS
  22. .
  23. -- We need a collection of bearings and distances to create a polygon
  24. --
  25. CREATE TYPE tbl_bearing_distances AS TABLE OF T_Bearing_Distance;
  26. /
  27. SHOW errors

Now we can add three member functions to T_Geometry type.

  • ST_Cogo2Line – Creates single linestring from supplied bearing and distance instructions.
  • ST_Line2Cogo – Creates Cogo Instructions from linestring segments.
  • ST_Cogo2Polygon – Creates single polygon exterior ring from supplied bearing and distance instructions.

(ST_Polygon2Cogo is yet to be built as I have to add the ability to “Move To” in the bearings and distances to handle polygons with many rings.)

ST_Cogo2Line

This function starts with a point (T_GEOMETRY) object, and constructs a single linestring object from the passed in set of bearings and distances. (A dedicated Constructor will be added at some stage to enable objects to be created from scratch.

  1. CREATE OR REPLACE TYPE T_GEOMETRY
  2. AS
  3. ...
  4. .
  5.   -- Create a function that operates on a T_GEOMETRY Point and a set of bearings and distances to create a linestring
  6.   Member FUNCTION ST_Cogo2Line(p_bearings_and_distances IN T_BEARING_DISTANCES)
  7.            RETURN T_Geometry Deterministic,
  8. .
  9. -- Examples
  10. -- Build 2D Line from default constructor
  11. SELECT F.line.ST_Validate() AS vLine,
  12.        f.line.geom          AS line,
  13.        round(f.line.ST_Length(),2) AS meters
  14.   FROM (SELECT t_geometry(sdo_geometry(2001,NULL,sdo_point_type(0.0,3.5,NULL),NULL,NULL),0.005,2,1)
  15.                  .ST_Cogo2Line (
  16.                       t_bearing_distances(
  17.                           t_bearing_distance(180.00,3.50,NULL),
  18.                           t_bearing_distance( 90.00,3.50,NULL),
  19.                           t_bearing_distance(  0.00,3.50,NULL),
  20.                           t_bearing_distance( 43.02,5.43,NULL),
  21.                           t_bearing_distance(270.00,9.50,NULL)
  22.                       )
  23.                  )
  24.                  .ST_Round(8,8) AS line
  25.           FROM dual
  26.        ) f;
  27. .
  28. VLINE LINE                                                                                                                                                        METERS
  29. ----- ----------------------------------------------------------------------------------------------------------------------------------------------------------- ------
  30. TRUE  SDO_GEOMETRY(2002,NULL,NULL,SDO_ELEM_INFO_ARRAY(1,2,1),SDO_ORDINATE_ARRAY(0.0,3.5, 0.0,0.0, 3.5,0.0, 3.5,3.5, 7.2046371,7.46995768, -2.2953629,7.46995768))  25.43
  31. .
  32. -- Build 3D line by decimal degrees using default constructor
  33. SELECT F.line.ST_Validate()        AS vLine,
  34.        f.line.geom                 AS line,
  35.        round(f.line.ST_Length(),2) AS meters
  36.   FROM (SELECT T_Geometry(sdo_geometry(3001,NULL,sdo_point_type(0,3.5,0),NULL,NULL),0.005,2,1)
  37.                    .ST_Cogo2Line(
  38.                        p_bearings_and_distances=>
  39.                          t_bearing_distances(
  40.                           t_bearing_distance(180,  3.5, 0.1),
  41.                           t_bearing_distance(90,   3.5, 0.5),
  42.                           t_bearing_distance(0,    3.5, 1.6),
  43.                           t_bearing_distance(43.02,5.43,2.123),
  44.                           t_bearing_distance(270,  9.5, 0.5)
  45.                        )
  46.                     )
  47.                    .ST_Round(8,8) AS line
  48.           FROM dual
  49.         ) f;
  50. .
  51. VLINE LINE                                                                                                                                                                                  METERS
  52. ----- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------
  53. TRUE  SDO_GEOMETRY(3002,NULL,NULL,SDO_ELEM_INFO_ARRAY(1,2,1),SDO_ORDINATE_ARRAY(0.0,3.5,0.0, 0.0,0.0,0.1, 3.5,0.0,0.5, 3.5,3.5,1.6, 7.2046371,7.46995768,2.123, -2.2953629,7.46995768,0.5))  25.79
  54. .
  55. -- Line by degrees using text constructor
  56. SELECT F.line.ST_Validate()        AS vLine,
  57.        f.line.geom                 AS line,
  58.        round(f.line.ST_Length(),2) AS meters
  59.   FROM (SELECT T_Geometry(sdo_geometry(3001,NULL,sdo_point_type(0,3.5,0),NULL,NULL),0.005,2,1)
  60.                    .ST_Cogo2Line(
  61.                        p_bearings_and_distances=>
  62.                          t_bearing_distances(
  63.                           t_bearing_distance(p_sDegMinSec=>'180',         p_distance=>3.5,  p_z=>0.1),
  64.                           t_bearing_distance(p_sDegMinSec=>'90',          p_distance=>3.5,  p_z=>0.5),
  65.                           t_bearing_distance(p_sDegMinSec=>'0',           p_distance=>3.5,  p_z=>1.6),
  66.                           t_bearing_distance(p_sDegMinSec=>'43^01''21"',  p_distance=>5.43, p_z=>2.0),
  67.                           t_bearing_distance(p_sDegMinSec=>'270',         p_distance=>9.5,  p_z=>0.5),
  68.                           t_bearing_distance(p_sDegMinSec=>'149^58''6.3"',p_distance=>4.613,p_z=>0.1))
  69.                       )
  70.                   .ST_Round(8,8) AS line
  71.           FROM dual
  72.         ) f;
  73. .
  74. VLINE LINE                                                                                                                                                                                                             METERS
  75. ----- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------
  76. TRUE  SDO_GEOMETRY(3002,NULL,NULL,SDO_ELEM_INFO_ARRAY(1,2,1),SDO_ORDINATE_ARRAY(0.0,3.5,0.0, 0.0,0.0,0.1, 3.5,0.0,0.5, 3.5,3.5,1.6, 7.20481032,7.46979603,2.0, -2.29518968,7.46979603,0.5, 0.01351213,3.47609287,0.1))  30.39
  77. .
  78. -- Build 3D line using mixed constructors
  79. SELECT F.line.ST_Validate()        AS vLine,
  80.        f.line.geom                 AS line,
  81.        round(f.line.ST_Length(),2) AS Meters
  82.   FROM (SELECT T_Geometry(sdo_geometry(3001,NULL,sdo_point_type(0,3.5,0),NULL,NULL),0.005,2,1)
  83.                    .ST_Cogo2Line(
  84.                        p_bearings_and_distances=>
  85.                          t_bearing_distances(
  86.                            t_bearing_distance(              180.0,                     3.5,       0.1),  -- << Default Constructor
  87.                            t_bearing_distance(p_sDegMinSec=>'90',          p_distance=>3.5,  p_z=>0.5),
  88.                            t_bearing_distance(              0.0,                       3.5,       1.6),  -- << Default Constructor
  89.                            t_bearing_distance(p_sDegMinSec=>'43^01''21"',  p_distance=>5.43, p_z=>2.0),
  90.                            t_bearing_distance(p_sDegMinSec=>'270',         p_distance=>9.5,  p_z=>0.5),
  91.                            t_bearing_distance(p_sDegMinSec=>'149^58''6.3"',p_distance=>4.613,p_z=>0.1))
  92.                       )
  93.                   .ST_Round(8,8) AS line
  94.           FROM dual
  95.         ) f;
  96. .
  97. VLINE LINE                                                                                                                                                                                                             METERS
  98. ----- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------
  99. TRUE  SDO_GEOMETRY(3002,NULL,NULL,SDO_ELEM_INFO_ARRAY(1,2,1),SDO_ORDINATE_ARRAY(0.0,3.5,0.0, 0.0,0.0,0.1, 3.5,0.0,0.5, 3.5,3.5,1.6, 7.20481032,7.46979603,2.0, -2.29518968,7.46979603,0.5, 0.01351213,3.47609287,0.1))  30.39

ST_Line2COGO

This function starts with a single linestring (T_GEOMETRY) object, and constructs from it a set of bearings and distances.

  1. CREATE OR REPLACE TYPE T_GEOMETRY
  2. AS
  3. ...
  4. .
  5.   Member FUNCTION ST_Line2Cogo (p_unit IN varchar2 DEFAULT NULL)
  6.            RETURN T_BEARING_DISTANCES Pipelined,
  7. .
  8. -- Examples
  9. -- Create 2D Line from COGO then reverse back to COGO ....
  10. WITH DATA AS (
  11. SELECT f.line
  12.   FROM (SELECT t_geometry(sdo_geometry(2001,NULL,sdo_point_type(0.0,3.5,NULL),NULL,NULL),0.005,2,1)
  13.                  .ST_Cogo2Line (
  14.                       t_bearing_distances(
  15.                           t_bearing_distance(180.00,3.50,NULL),
  16.                           t_bearing_distance( 90.00,3.50,NULL),
  17.                           t_bearing_distance(  0.00,3.50,NULL),
  18.                           t_bearing_distance( 43.02,5.43,NULL),
  19.                           t_bearing_distance(270.00,9.50,NULL))
  20.                       ) AS line
  21.           FROM dual
  22.        ) f
  23. )
  24. SELECT COGO.DD2DMS(COGO.ST_Degrees(t.bearing)) AS bearing,
  25.        Round(t.distance,3) AS distance
  26.   FROM DATA a,
  27.        TABLE(a.line.ST_Line2Cogo()) t;
  28. .
  29. BEARING  DISTANCE
  30. -------- --------
  31. 0°0'0"        3.5
  32. 180°0'0"      3.5
  33. 90°0'0"       3.5
  34. 0°0'0"        3.5
  35. 43°1'12"     5.43
  36. 270°0'0"      9.5
  37. .
  38.  6 ROWS selected
  39. .
  40. -- Create 3D Line from COGO then reverse back to COGO ....
  41. WITH DATA AS (
  42. SELECT f.line
  43.   FROM (SELECT t_geometry(sdo_geometry(3001,NULL,sdo_point_type(0.0,3.5,0.2),NULL,NULL),0.005,2,1)
  44.                  .ST_Cogo2Line (
  45.                       t_bearing_distances(
  46.                           t_bearing_distance(180.00,3.50,1.1),
  47.                           t_bearing_distance( 90.00,3.50,2.0),
  48.                           t_bearing_distance(  0.00,3.50,3.0),
  49.                           t_bearing_distance( 43.02,5.43,4.4),
  50.                           t_bearing_distance(270.00,9.50,5.2))
  51.                       ) AS line
  52.           FROM dual
  53.        ) f
  54. )
  55. SELECT COGO.DD2DMS(COGO.ST_Degrees(t.bearing)) AS bearing,
  56.        Round(t.distance,3)                     AS distance,
  57.        t.z
  58.   FROM DATA a,
  59.        TABLE(a.line.ST_Line2Cogo()) t;
  60. .
  61. BEARING  DISTANCE   Z
  62. -------- -------- ---
  63. 0°0'0"      3.506 0.2
  64. 180°0'0"    3.614 1.1
  65. 90°0'0"     3.614   2
  66. 0°0'0"      3.64    3
  67. 43°1'12"    5.608 4.4
  68. 270°0'0"    9.534 5.2
  69. .
  70.  6 ROWS selected

ST_COGO2Polygon

This function, like ST_COGO2Line starts with a point (T_GEOMETRY) object, and constructs a polygon with a single exterior ring from the passed in set of bearings and distances. (A dedicated Constructor will be added at some stage to enable objects to be created from scratch.

  1. CREATE OR REPLACE TYPE T_GEOMETRY
  2. AS
  3. ...
  4.   Member FUNCTION ST_Cogo2Polygon(p_bearings_and_distances IN T_BEARING_DISTANCES)
  5.            RETURN T_Geometry Deterministic,
  6. .
  7. -- Examples
  8. -- Polygon built from default constructor...
  9. SELECT F.poly.ST_Validate()      AS vPoly,
  10.        f.poly.ST_AsText()        AS pWKT,
  11.        round(f.Poly.ST_Area(),2) AS sqM
  12.   FROM (SELECT t_geometry(sdo_geometry(2001,NULL,sdo_point_type(0,3.5,NULL),NULL,NULL),0.005,2,1)
  13.                  .ST_Cogo2Polygon(
  14.                       t_bearing_distances(
  15.                           t_bearing_distance(180,3.5,NULL),
  16.                           t_bearing_distance(90,3.5,NULL),
  17.                           t_bearing_distance(0,3.5,NULL),
  18.                           t_bearing_distance(43.02,5.43,NULL),
  19.                           t_bearing_distance(270,9.5,NULL))
  20.                   )
  21.                  .ST_Round(3,3) AS poly
  22.           FROM dual
  23.        ) f;
  24. .
  25. VPOLY PWKT                                                                               SQM
  26. ----- -------------------------------------------------------------------------------- -----
  27. TRUE  POLYGON ((0.0 3.5, 0.0 0.0, 3.5 0.0, 3.5 3.5, 7.205 7.47, -2.295 7.47, 0.0 3.5)) 38.06
  28. .
  29. -- Different way of building directions.
  30. -- Simple bearing/distance constructors used
  31. WITH DATA AS (
  32. SELECT CAST(MULTISET(
  33.          SELECT bd
  34.            FROM (SELECT 1 AS rin, t_bearing_distance(180.0,3.5) AS bd                      FROM dual UNION ALL
  35.                  SELECT 2,        t_bearing_distance( 90.0,3.5)                            FROM dual UNION ALL
  36.                  SELECT 3,        t_bearing_distance(  0.0,3.5)                            FROM dual UNION ALL
  37.                  SELECT 4,        t_bearing_distance(43.02,round(SQRT(4.5*4.5+2.2*4.2),2)) FROM dual UNION ALL
  38.                  SELECT 5,        t_bearing_distance(270.0,(4.5+3.4+1.6))                  FROM dual )
  39.                  ORDER BY rin
  40.        ) AS t_bearing_distances ) AS directions
  41.   FROM dual
  42. )
  43. SELECT F.poly.ST_Validate()      AS vPoly,
  44.        f.poly.ST_AsText()        AS pWKT,
  45.        round(f.Poly.ST_Area(),2) AS sqM
  46.   FROM (SELECT t_geometry(sdo_geometry(2001,NULL,sdo_point_type(0,3.5,NULL),NULL,NULL),0.005,2,1)
  47.                  .ST_Cogo2Polygon (
  48.                      p_bearings_and_distances=>a.directions
  49.                   )
  50.                  .ST_Round(3,3) AS poly
  51.           FROM DATA a
  52.         ) f;
  53. .
  54. VPOLY PWKT                                                                               SQM
  55. ----- -------------------------------------------------------------------------------- -----
  56. TRUE  POLYGON ((0.0 3.5, 0.0 0.0, 3.5 0.0, 3.5 3.5, 7.205 7.47, -2.295 7.47, 0.0 3.5)) 38.06
  57. .
  58. -- Mixed Constructors with Z for 3D Polygon...
  59. SELECT F.poly.ST_Validate()      AS vPoly,
  60.        f.poly.geom               AS polygon,
  61.        round(f.Poly.ST_Area(),2) AS sqM
  62.   FROM (SELECT t_geometry(sdo_geometry(3001,NULL,sdo_point_type(0,3.5,10.0),NULL,NULL),0.005,2,1)
  63.                  .ST_Cogo2Polygon (
  64.                      t_bearing_distances(
  65.                           t_bearing_distance(180,3.5,11.1),
  66.                           t_bearing_distance(p_sDegMinSec=>'90^0''0"',p_distance=>3.5,p_z=>12.2),
  67.                           t_bearing_distance(0.0,3.5,13.3),
  68.                           t_bearing_distance(p_sDegMinSec=>'43^01''12"',p_distance=>5.43,p_z=>14.4),
  69.                           t_bearing_distance(270.0,9.5,13.3)
  70.                       )
  71.                   )
  72.                  .ST_Round(3,3) AS poly
  73.           FROM dual
  74.        ) f;
  75. .
  76. VPOLY POLYGON                                                                                                                                                                                  SQM
  77. ----- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -----
  78. TRUE  SDO_GEOMETRY(3003,NULL,NULL,SDO_ELEM_INFO_ARRAY(1,1003,1),SDO_ORDINATE_ARRAY(0.0,3.5,10.0, 0.0,0.0,11.1, 3.5,0.0,12.2, 3.5,3.5,13.3, 7.205,7.47,14.4, -2.295,7.47,13.3, 0.0,3.5,10.0)) 43.37

I am considering adding a traverse adjustment option (p_traverse_adjust) to the creation of a polygon exterior ring.

I hope these will be 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