SpatialDB Advisor
|
Current Oracle Spatial Blog Articles • isValid, isSimple, Dimension and CoordDim methods for SDO_Geometry • Line Merging or Collecting lines together: ST_LineMerger • ST_RemovePoint 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 • SURVEY: The Future of GeoRaptor • Replacement for SDO_GEOM.RELATE - JTS Relate • 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 • Saving Storage Space Part 1: Storage Effects of Sdo_Geometry Coordinate Precision • 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 • GeoRaptor 3.0 Officially released. • 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 • Converting Google Earth Formatted Longitude/Latitude points to decimal degrees • 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 • Filtering Rings (Oracle Spatial) • 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
|
Introduction The “production” database included a single table (containing around 70 million individual point records that described around 13,000 individual hydrographic surveys. Dynamic searching and visualising individual surveys in the base table was considered to be too slow to be used in the interactive mapping that was required for the data discovery web application so “surrogate” vector linestrings existed against which searching and visualisation would occur.
No one had yet been able to implement search and visualisation against the base point data: until I came along. I have not included a description of the original tables in this blog; what I have done is create a set of tables and scripts to generate random data which are included in a download for you to run yourself. Also, to simplify the material for this article, I will not discuss how the original code handles surveys with more 3D points than Oracle’s Sdo_Geometry Sdo_Ordinate_Array can hold (which is ( 1048576 – 1 ) / 3 = 349,525 coordinates): all generated data will not break this limit. The rest of this article describes the testing that was done testing different methods for the creation of single multi-point records from the base single point data. The article also shows how Oracle’s PL/SQL profiling package was used in improving the performance of the actual code. Note that all timings in this article are based on Oracle’s DBMS_PROFILER package whose use will be described in another blog article.
Note, sb_eno is the enterprise identifier of a single singlebeam survey; the pointno is the survey point within a singlebeam survey – normally, sb_eno,pointno is the primary key but, for simplicity, the generated pointno will actually be unique across all surveys. To populate this table we can do this:
This data does not need to be indexed so this is not covered. Target Tables The target table that will hold our multipoint sdo_geometry objects is:
Generating the MultiPoint objects
Of course, in a perfect world, the generation of the multipoint sdo_geometries should be as simple as (the APPEND hint provides a more efficient “direct path” insert into the table):
However, except for small datasets, this method is slow (some numbers justifying this assertion will be provided later). Method Two: “Appendix D” The Oracle Spatial Team’s recommended approach for the most efficient use of the SDO_AGGR_UNION function is documented in Section D.4 of Appendix D of the Oracle® Spatial User’s Guide and Reference 10g Release 2 (10.2) documentation.
The general idea here is to avoid expensive “context swapping” in the Oracle aggregation engine by implementing a form of “parallelisation”. The numbers presented later will show that this is effective but that it still does not perform fast enough compared to other methods. Method Three: Pipelined Function During my testing at GeoScience Australia I had the idea of using PL/SQL to generate the multi-points using a well-known, scalable, Oracle collection aggregation technique. The best way to describe this is by example in the following PL/SQL (the code includes a number of standard optimisations familiar to PL/SQL developers i.e., the use of CURSORs, BULK COLLECTion, FORALL “array” insertion, ROWTYPEs etc). It is the SQL statement that is of most interest and has been highlighted in the code. This first method included the use of a pipelined function (pipelined function use will be covered in another blog) which turned an Sdo_Point object into an Sdo_Ordinate_Array object which could then be BULK COLLECTED in the highlighted SQL:
The BULK COLLECT aggregates the individual Sdo_Ordinate_Arrays returned by the function into a single array for the survey. What I discovered was this approach was substantially faster than the previous two methods. After getting this to work, I then realised I didn’t need the Function as is described in the next method. Method Four: PL/SQL SDO_Ordinate_Array aggregation The next improvement to the algorithm was to get rid of the custom “asOrdinates” function in favour of using the Oracle Spatial type library directly.
All the heavy lifting in this approach is done by directly referencing the individual ordinates coded in the geometry’s 3D Sdo_Point object and converting them into an Sdo_Ordinate_Array which can then be BULK COLLECTED into a resultant Sdo_Ordinate_Array. This method was the fastest of all the methods used. However, because some surveys where larger than can be represented in an Sdo_Ordinate_Array, I did look at creating “custom” point arrays that did not have the million ordinate restriction that is in the MDSYS.SDO_ORDINATE_ARRAY object. Method Five: Custom array of SDO_Point_Type Another method using aggregation involved the use of a custom array of SDO_Point_Type as in the following PL/SQL. (One of the advantages of this approach is the fact that the aggregation SELECT statement can be used for all multi-point aggregation regardless as to whether the resulting object breaks the SDO_Ordinate_Array limit; a negative is the need to turn the array of SDO_Point_Type back into array bound “safe” SDO_Ordinate_Arrays on insert. But the method is illustrative of what can be done if one “thinks outside the square”.)
Timing To ensure that the performance of all four methods can be compared, the first two methods were “wrapped” by PL/SQL such that the SELECT statement was executed once for each sb_eno. Also, the final methods went through a few different interations in the handling of those surveys whose points broke the SDO_Ordinate_Array limit (see the actual SQL for how this was handled). The first chart shows how substantially different the “native” versus “custom” methods can be: one cannot see the actual timings for the “custom” methods:
When one removes the “native” methods, one can see more clearly the relative performance of the “custom” methods.
Conclusion Replication of the full, 67 million row raw point data, to a 13,000 row multi-point table was achieved in less than 50 minutes of processing. This was a substantial improvement and as a result of the work GeoScience Australia moved to a database replication strategy that included the efficient generation of multi-point survey data from the raw observations. This also gives the end-user the ability to work with the actual points in a web application instead of the surrogate averaged linework resulting in more accurate analysis and data discovery. The “take home message” for users of Oracle Spatial/Locator should look to the power of the whole database to solve data warehousing and analysis problems and not just the Spatial packages themselves. A fully worked example showing the fastest method for you to try youself is available here ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
![]()
![]() |
Comment [2]
I modified you sample for lat and long. When I do method 4 I get lat and long sometimes with lat first and sometimes with long first. I am I doing something wrong? Thanks Bill
— Bill King · 20 May 2010, 05:39 · #
The code just aggregates what is in the sdo_point.
It is likely that some of your data has Lat in X and Long in Y and others Lat in Y and Long in X.
Check that this is the case (or not).
regards
Simon
— Simon · 24 May 2010, 18:59 · #