Top 5 Recent Articles
ARTICLES CATEGORIES
- Algorithms (22)
- All (399)
- Biography (1)
- Blog (44)
- Business Requirements (1)
- Commentary (1)
- Conversion (2)
- Customers (2)
- Data Models (1)
- Education (2)
- GeoRaptor (13)
- GPS (1)
- Image Processing (2)
- Import Export (8)
- Licensing (2)
- LiDAR (1)
- Linear Referencing (4)
- Manifold GIS (3)
- Mapping (1)
- MySQL Spatial (7)
- Networking and Routing (including Optimization) (5)
- Open Source (18)
- Oracle Spatial and Locator (194)
- Partitioning (1)
- PostGIS (36)
- Projections (1)
- Published Articles (1)
- qGIS (1)
- Recommendations (1)
- Services (1)
- Software Change Log (1)
- Source Code (37)
- Space Curves (9)
- Spatial Database Functions (109)
- Spatial DB comparison (1)
- Spatial XML Processing (11)
- SQL Server Spatial (92)
- Standards (3)
- Stored Procedure (17)
- Tessellation or Gridding (10)
- Tools (2)
- Topological Relationships (1)
- Training (2)
- Triangulation (2)
Using Oracle’s ST_GEOMETRY type hierarchy with SDO_GEOMETRY: ST_PointN and ST_NumPoints
Oracle Spatial has, for many versions, made available an implementation of the OpenGIS SFS type hierarchy.
Today I will show how to use this type hierarchy do extract points from an SDO_GEOMETRY.
The first example extracts the first and last point from a linestring constructed from Well Known Text.
WITH DATA AS ( SELECT TREAT(ST_Geometry.FROM_WKT('LINESTRING(0 0,1 1)',28355) AS ST_Curve) AS line FROM dual ) SELECT a.line.ST_GeometryType() AS geometry_type, a.line.ST_PointN(1).GET_WKT() AS first_point, a.line.ST_PointN(a.line.ST_NumPoints()).GET_WKT() AS last_point FROM DATA A; GEOMETRY_TYPE FIRST_POINT LAST_POINT ------------- --------------- --------------- ST_LINESTRING POINT (0.0 0.0) POINT (1.0 1.0)
The second example finds the first and last point from an SDO_GEOMETRYconstructed from that type.
WITH DATA AS ( SELECT mdsys.ST_CURVE( SDO_GEOMETRY(2002,28355,NULL,SDO_ELEM_INFO_ARRAY(1,2,1),SDO_ORDINATE_ARRAY(0,0,1,1,2,2)) ) AS line FROM dual ) SELECT a.line.ST_GeometryType() AS geometry_type, a.line.ST_PointN(1).GET_WKT() AS first_point, a.line.ST_PointN(a.line.ST_NumPoints()).GET_WKT() AS last_point FROM DATA a; GEOMETRY_TYPE FIRST_POINT LAST_POINT ------------- --------------- --------------- ST_LINESTRING POINT (0.0 0.0) POINT (2.0 2.0)
The last example shows how to extract the first and last point from the exterior ring of a polygon.
WITH DATA AS ( SELECT TREAT( mdsys.ST_Polygon.FROM_WKT( 'POLYGON((0 0,1 0,1 1,0 1,0 0))',28355 ) AS ST_POLYGON) AS poly FROM dual ) SELECT a.poly.ST_GeometryType() AS geometry_type, treat(a.poly.ST_ExteriorRing() AS ST_Curve).ST_PointN(1).GET_WKT() AS first_point, treat(a.poly.ST_ExteriorRing() AS ST_Curve).ST_PointN(a.poly.ST_ExteriorRing().ST_NumPoints()).GET_WKT() AS last_point FROM DATA A; GEOMETRY_TYPE FIRST_POINT LAST_POINT ------------- --------------- --------------- ST_POLYGON POINT (0.0 0.0) POINT (0.0 0.0)
Oracle’s ST_GEOMETRY is a true type hierarchy. TREAT is an Oracle function that casts an object to another related type. One cannot cast/TREAT an ST_LINESTRING to a ST_POLYGON as ST_LINESTRING does not inherit from ST_POLYGON.
I hope this is of use to someone.
Documentation
- MySQL Spatial General Functions
- Oracle LRS Objects
- Oracle Spatial Exporter (Java + pl/SQL)
- Oracle Spatial Object Functions
- Oracle Spatial Object Functions (Multi Page)
- PostGIS pl/pgSQL Functions
- SC4O Oracle Java Topology Suite (Java + pl/SQL)
- SQL Server Spatial General TSQL Functions
- SQL Server Spatial LRS TSQL Functions