SlideShare a Scribd company logo
A brief guide to Oracle Spatial Extension Simone Campora (simone.campora@epfl.ch)
Spatial Databases A spatial database  is a database that is optimized to store and query data related to objects in space, including points, lines and polygons. Up to now the market proposes:
Oracle Spatial Extension (11g r1) Forms a separately-licensed option component of the Oracle Database  to aid users in managing geographic and location-data natively Oracle 4  Oracle 7  Oracle 8  Oracle 10  First spatial extension Spatial Data Option (SDO) Oracle Spatial R-Tree indexing Network Model Raster handling Topologies Geocoding
Supported geometries
Spatial Database Generalities
Supported Data Formats While managing spatial data you might have to import data from heterogeneous sources Different GIS (Geographic Information Systems) softwares might support different data types Visit  http://www.safe.com/products/desktop/formats/index.php   for a complete list  data sources – supported types
Oracle Hierarchical Model Oracle datatypes have a hierarchical model
Geometries  Geometries refers to spatial objects Their distribution is not uniform but if follows the spatial location of real entities
Spatial Indexing Special indexes are needed to face performant storage and query of geometries Most famous are R-Tree Quad-Tree
R - Tree R-trees  are tree data structures that are similar to B-trees, but are used for indexing multi-dimensional information;  A common real-world usage for an R-tree might be: "Find all museums within 2 kilometres (1.2 mi) of my current location". The data structure splits space with hierarchically nested, and possibly overlapping, minimum bounding rectangles (MBRs, otherwise known as bounding boxes, i.e. "rectangle", what the "R" in R-tree stands for).
Quadtree A  quadtree  is a tree data structure in which each internal node has up to four children.  Quadtrees are most often used to partition a two dimensional space by recursively subdividing it into four quadrants or regions. The regions may be square or rectangular, or may have arbitrary shapes.
Spatial Query Processing Optional Filter Spatial Data Layer Primary Filter: Spatial Index Data Selection Secondary Filter: Spatial Functions Results
Oracle Spatial Data Types
SDO_GEOMETRY Is composed of CREATE TABLE forest( name VARCHAR2(30), animal_population NUMBER(9), geom MDSYS.SDO_GEOMETRY); Methods GET_DIMS()  :NUMBER GET_GTYPE  :NUMBER
SDO_GTYPE It defines the geometry type stored into the SDO_GEOMETRY object Geometry Type Dimensions Name 2D 3D 4D UNKNOWN_GEOMETRY 2000 3000 4000 POINT 2001 3001 4001 LINESTRING 2002 3002 4002 POLYGON 2003 3003 4003 COLLECTION 2004 3004 4004 MULTIPOINT 2005 3005 4005 MULTILINESTRING 2006 3006 4006 MULTIPOLYGON 2007 3007 4007 NOT OGC
SDO_POINT Used to store Point data It is ignored if SDO_ELEM_INFO and SDO_ORDINATES are not NULL It is of type  SDO_POINT_TYPE X NUMBER Y NUMBER Z NUMBER Example:  GPS Receiver
SDO_ELEM_INFO It is store as a SDO_ELEM_INFO_ARRAY: VARRAY (1048576) OF NUMBER Its entries must be considered grouping elements by 3 Starting position of the coordinates (starting from 1) Element type (as shown in the table) Interpretation Number Element Type Interpretation 0 UNKNOWN_ELEMENT 1 POINT Number of points of the collection 2 LINESTRING Lines 3 POLYGON 1 lines 1003 External 2 arcs 2003 Internal 3 optimized rectangle 4 circle 4 COMPOUND LINESTRING Number of elements 5 COMPOUNG POLYGON Number of elements 1005 External 2005 Internal
SDO_ORDINATES Stored as SDO_ORDINATE_ARRAY VARRAY (1048576) OF NUMBER It contains a list of object’s coordinates
Examples 1/5 – inserting a Point INSERT INTO pollution VALUES ( 34.6,57.4,etc…, MDSYS.SDO_GEOMETRY( 3001, 352257, MDSYS.SDO_POINT_TYPE(521030,240120,550), null,null) ); SDO_POINT SDO_ELEM_INFO SDO_ORDINATES SDO_GTYPE SDO_SRID
Examples 2/5 – inserting a line INSERT INTO roads VALUES (‘motorway’,’NYC’,etc…, mdsys.sdo_geometry( 2002,352257,null, mdsys.sdo_elem_info_array(1,2,1), mdsys.sdo_ordinate_array(10,10, 20,25, 30,10, 40,10)) ); 10,10 20,25 30,10 40,10
Examples 3/5 – inserting a polygon INSERT INTO roads VALUES (‘motorway’,’NYC’,etc…, mdsys.sdo_geometry( 2003,352257,null, mdsys.sdo_elem_info_array(1,1003,1, 13,2003,3), mdsys.sdo_ordinate_array(2,10, 3,0, 10,0, 12,10, 5,12, 2,10, 4,3, 6,9)) ); (2,10) (2,10) (3,0) (10,0) (12,10) (5,12) (4,3) (6,9)
Oracle Spatial Coordinates System
Projections Projected and Georeferenced  2D projection of the global sphere Cartesian projections Example : Swiss projection Not Georeferenced Local systems not linked to the earth global representation Cartesian projections Ex ample: «non-earth» of MapInfo GIS software Georeferenced not projected Not projected on a spefici plane Latitude Longitude positioning system Example: Oracle, decmal degrees –180 to 180 and – 90  to 90 Example : WGS84
SDO_SRID It is a INTEGER number that identifies which coordinate system is used by the SDO_GEOMETRY The table MDSYS.CS_SRS is defining such reference systems. Description Type Description CS_NAME VARCHAR2(68) Short Name SRID NUMBER(38) Reference System ID AUTH_SRID NUMBER(38) ‘ Oracle’ AUTH_NAME VARCHAR2(256) SRID name WKTEXT VARCHAR2(2046) OGC name CS_BOUNDS MDSYS.SDO_GEOMETRY Can be null
How to Change the SRID? 1. Drop Spatial Indexes drop index town_sidx;  2. Update metadata table update user_sdo_geom_metadata set srid = 352257  where table_name = ‘towns’ and column_name = ‘geom’; 3. Update the SDO_SRID of each object update towns t set t.geom.sdo_srid = 352257;  4. Adjust tolerances update user_sdo_geom_metadata u set u.diminfo = mdsys.sdo_dim_array( mdsys.sdo_dim_element(‘x’,400000,600000,0.005), mdsys.sdo_dim_element(‘y’,100000,300000,0.005)), where table_name = ‘towns’ and column_name = ‘geom’ 5. Recreate Spatial Indexes create index  town_idx on towns(geom) indextype is mdsys.spatial_index;
Oracle Spatial Operators
Spatial Operators Make use of spatial indexes They MUST have a spatial index defined at least for the first spatial type used They are only used within the WHERE clause
SDO_FILTER  SDO_FILTER(<geometry-1>,<geometry-2>,‘QUERYTYPE=WINDOW’) = ‘TRUE’; geometry-1 (searched object) Must be a column table Must be a SDO_GEOMETRY Must be indexed geometry-2 Must be a variable or column table Must be SDO_GEOMETRY ‘ QUERYTYPE = WINDOW’ Necessary parameter Oracle advises to use only WINDOW select s.nom, s.type from sondages s Where sdo_filter ( s.geom,  mdsys.sdo_geometry (2003,352257,null, mdsys.sdo_elem_info_array(1,1003,3), mdsys.sdo_ordinate_array(540300,212500,541300,213500)), ‘ querytype=WINDOW’) = ‘TRUE’;
SDO_RELATE  SDO_RELATE(<geometry-1>,<geometry-2>, ‘MASK=<mask> QUERYTYPE=WINDOW’) = ‘TRUE’; Used similarly to SDO_FILTER You can use MASK keywords linked by «+» that means OR operation  For example: COVEREDBY, TOUCH, INSIDE, ANYINTERACT select t1.name, t1.na,e  from towns t1, towns t2 where c2.name = ‘NYC’ and sdo_relate ( t1.geom,t2.geom,  ‘ mask=TOUCH querytype=WINDOW’)=‘TRUE’;
SDO_WITHIN_DISTANCE   SDO_WITHIN_DISTANCE( <geometry-1>,<geometry-2>, ‘DISTANCE=<n>,[optional parameters]’) = ‘TRUE’; geometry-2 A buffer will be created starting from this object DISTANCE Distance to be considered QUERYTYPE (optional) Using a primary and secondaryfilter Si QUERYTYPE=FILTER: uses a primary filter only UNIT (optionnel) Defines a specific unit measure that can be different from the SRS definition select  a.name from buildings b, streets a where b.id= 2198376 and sdo_within_distance  ( a.geom,b.geom,‘distance=1 UNIT=kilometer’)=‘TRUE’;
SDO_NN (nearest neighbor)   SDO_NN(<geometry-1>,<geometry-2>,‘[paramètres optionnels]’) = ‘TRUE’; SDO_NUM_RES (optional) number of neighbors to return (default = 1) SDO_BATCH_SIZE (optional) To be used instead of SDO_NUM_RES: it returns subsets of nearest neighbors until all the criteria defined by the «  where» condition are satisfied. UNIT (optionnel avec l’utilisation de SDO_NN_DISTANCE) Measure unit select  s.type from streets s, polls p where s.id = 1289 and sdo_nn(s.geom,p.geom,’sdo_num_res=5 unit=meter’,1) = ‘TRUE’;
Oracle Spatial FUNCTIONS
Spatial Functions Are not requiring spatial indexes Can be used on small tables without indexing Can be used either in the «  SELECT» or «  WHERE » clauses. The input geometries must have the same reference system
SDO_GEOM.RELATE SDO_GEOM.RELATE( <geometry-1>,’<mask>’,<geometry-2>,<tolerance>); geometry-1 (searched object) SDO_GEOMETRY object geometry-2 SDO_GEOMETRY object mask Spatial Relationships to be tested tolerance Tolérance  on the data granularity REMINDER:  use SDO_RELATE in the where clause because  SDO_GEOM.RELATE doesn’t use spatial indexing: it is slower select c.name, sdo_geom.relate(d.geom,’determine’,t.geom,0.5) relation from districts d, towns t where d.distname = ‘NY’ and d.distname = t.district;
Oracle Spatial Analysis
Spatial Analysis Oracle spatial functionalities are used to analyze spatial objects The following examples are using spatial functions and operators in order to compute some basic analysis
Calculate a Surface SDO_GEOM.SDO_AREA (<geometry>,<tolerance> [, <unit>]) geometry SDO_GEOMETRY that defines a polygon unit Unit of the results: for a list of possible units look at: select sdo_unit from  mdsys.sdo_dist_units; select sum(sdo_geom.sdo_area(c1.geom,0.5,’unit=sq_meter’)) surface from towns t1, towns t2 where t2.name = ‘New York’ and  sdo_relate (t1.geom,t2.geom, ’ mask=TOUCH querytype=WINDOW’) = ‘TRUE’;
Calculate the Length SDO_GEOM.SDO_LENGTH (<geometry>,<tolerance> [, <unit>]) Calculate the Distance SDO_GEOM.SDO_DISTANCE (<geometry-1>, <geometry-2>,<tolerance> [, <unit>]) select name,sdo_geom.sdo_length(geom,0.5,’unit=kilometer’) length from streets where number = 1234; select sdo_geom.sdo_distance(f1.geom,f2.geom,0.5) distance from forests f1, forests f2 where f1.id = 1 and f2.id = 2;
Buffer Calculation SDO_GEOM.SDO_BUFFER (<geometry>,<distance>, <tolerance> [, ‘<params>’]) geometry SDO_GEOMETRY distance Distance of the buffer zone Returns: SDO_GEOMETRY select sdo_geom.sdo_buffer (geom,25,0.5,’unit=km’)  buffer from streets where number = 120;
Logic Functions SDO_GEOM.SDO_XXX (<geometry-1>,<geometry-2>,<tolerance>) SDO_GEOM.SDO_UNION  SDO_GEOM.SDO_INTERSECTION  SDO_GEOM.SDO_DIFFERENCE SDO_GEOM.SDO_XOR
References http://en.wikipedia.org/wiki/Oracle_Spatial http://fdo.osgeo.org/ http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28400/sdo_intro.htm Marc Riedo GIS Technology I - EPFL cours slides

More Related Content

PDF
JSON Data Parsing in Snowflake (By Faysal Shaarani)
PPTX
Introduction to Oracle Spatial
PPTX
Mongo DB 102
PDF
QGIS Module 4
PPTX
QGIS Basic Training
PDF
SQL on everything, in memory
PPTX
PPTX
Oracle: Joins
JSON Data Parsing in Snowflake (By Faysal Shaarani)
Introduction to Oracle Spatial
Mongo DB 102
QGIS Module 4
QGIS Basic Training
SQL on everything, in memory
Oracle: Joins

Viewers also liked (15)

PPT
Oracle Spatial Databases
PDF
Algebra - liczby zespolone - cz. 1
PDF
Postępowanie administracyjne, postępowanie egzekucyjne w administracji i post...
PDF
Servidores de mapas en alta disponibilidad CyLiconValley
PDF
Using FME to Convert TIGER Spatial Data From Oracle Spatial To ESRI Shapefiles
PDF
De SIOSE a PostGIS en cuatro sesiones
PDF
Oracle Spatial de la A a la Z - JUGM 2010
PPT
Introdución a PostGis
PPTX
Oracle Spatial de la A a la Z - Unidad 1
PDF
Curso spatial analyst ARCGIS INGEMMET Juan Salcedo
ODP
OpenLayers vs. Leaflet
KEY
Vestige: Managing tags for #a4i
PPTX
Sistemas información geográfica
PPT
1. źródła prawa oraz wybrane regulacje prawne z zakresu prawa pracy dot. bhp ...
PDF
Conferencia ESRI 2014. Gestión de la componente geográfica del negocio median...
Oracle Spatial Databases
Algebra - liczby zespolone - cz. 1
Postępowanie administracyjne, postępowanie egzekucyjne w administracji i post...
Servidores de mapas en alta disponibilidad CyLiconValley
Using FME to Convert TIGER Spatial Data From Oracle Spatial To ESRI Shapefiles
De SIOSE a PostGIS en cuatro sesiones
Oracle Spatial de la A a la Z - JUGM 2010
Introdución a PostGis
Oracle Spatial de la A a la Z - Unidad 1
Curso spatial analyst ARCGIS INGEMMET Juan Salcedo
OpenLayers vs. Leaflet
Vestige: Managing tags for #a4i
Sistemas información geográfica
1. źródła prawa oraz wybrane regulacje prawne z zakresu prawa pracy dot. bhp ...
Conferencia ESRI 2014. Gestión de la componente geográfica del negocio median...
Ad

Similar to Oracle Spatial (20)

PPTX
Spatial Databases
PPT
What is a spatial database system? How is it different from a RDBMS?
PPT
Spatial Database Systems
PPT
Building a Spatial Database in PostgreSQL
PPTX
Spot db consistency checking and optimization in spatial database
PDF
Spatial Support in MySQL
ODP
Intro To PostGIS
PDF
MySQL 8.0 GIS Overview
PDF
Spatial Data in SQL Server
PPTX
Spatial Data in SQL Server
PDF
Design and implementation of three dimensional objects in database management...
PDF
Enterprise geodatabase sql access and administration
PDF
#dbhouseparty - Spatial Technologies - @Home and Everywhere Else on the Map
PPTX
PPT
Intro to spatial databases: GIS, Postgres.
PPT
Introduction to spatialdatabases lecture slides
PDF
Database@Home - Maps and Spatial Analyses: How to use them
PPT
Ch1revised
PDF
MySQL 8.0 Graphical Information System - Mid Atlantic Developers Conference
Spatial Databases
What is a spatial database system? How is it different from a RDBMS?
Spatial Database Systems
Building a Spatial Database in PostgreSQL
Spot db consistency checking and optimization in spatial database
Spatial Support in MySQL
Intro To PostGIS
MySQL 8.0 GIS Overview
Spatial Data in SQL Server
Spatial Data in SQL Server
Design and implementation of three dimensional objects in database management...
Enterprise geodatabase sql access and administration
#dbhouseparty - Spatial Technologies - @Home and Everywhere Else on the Map
Intro to spatial databases: GIS, Postgres.
Introduction to spatialdatabases lecture slides
Database@Home - Maps and Spatial Analyses: How to use them
Ch1revised
MySQL 8.0 Graphical Information System - Mid Atlantic Developers Conference
Ad

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharma ospi slides which help in ospi learning
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Presentation on HIE in infants and its manifestations
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Computing-Curriculum for Schools in Ghana
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Anesthesia in Laparoscopic Surgery in India
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
O7-L3 Supply Chain Operations - ICLT Program
Module 4: Burden of Disease Tutorial Slides S2 2025
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
human mycosis Human fungal infections are called human mycosis..pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Microbial diseases, their pathogenesis and prophylaxis
Pharma ospi slides which help in ospi learning
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Presentation on HIE in infants and its manifestations
Pharmacology of Heart Failure /Pharmacotherapy of CHF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Cell Structure & Organelles in detailed.
Abdominal Access Techniques with Prof. Dr. R K Mishra
Computing-Curriculum for Schools in Ghana
O5-L3 Freight Transport Ops (International) V1.pdf

Oracle Spatial

  • 1. A brief guide to Oracle Spatial Extension Simone Campora (simone.campora@epfl.ch)
  • 2. Spatial Databases A spatial database is a database that is optimized to store and query data related to objects in space, including points, lines and polygons. Up to now the market proposes:
  • 3. Oracle Spatial Extension (11g r1) Forms a separately-licensed option component of the Oracle Database to aid users in managing geographic and location-data natively Oracle 4 Oracle 7 Oracle 8 Oracle 10 First spatial extension Spatial Data Option (SDO) Oracle Spatial R-Tree indexing Network Model Raster handling Topologies Geocoding
  • 6. Supported Data Formats While managing spatial data you might have to import data from heterogeneous sources Different GIS (Geographic Information Systems) softwares might support different data types Visit http://www.safe.com/products/desktop/formats/index.php for a complete list data sources – supported types
  • 7. Oracle Hierarchical Model Oracle datatypes have a hierarchical model
  • 8. Geometries Geometries refers to spatial objects Their distribution is not uniform but if follows the spatial location of real entities
  • 9. Spatial Indexing Special indexes are needed to face performant storage and query of geometries Most famous are R-Tree Quad-Tree
  • 10. R - Tree R-trees are tree data structures that are similar to B-trees, but are used for indexing multi-dimensional information; A common real-world usage for an R-tree might be: &quot;Find all museums within 2 kilometres (1.2 mi) of my current location&quot;. The data structure splits space with hierarchically nested, and possibly overlapping, minimum bounding rectangles (MBRs, otherwise known as bounding boxes, i.e. &quot;rectangle&quot;, what the &quot;R&quot; in R-tree stands for).
  • 11. Quadtree A quadtree is a tree data structure in which each internal node has up to four children. Quadtrees are most often used to partition a two dimensional space by recursively subdividing it into four quadrants or regions. The regions may be square or rectangular, or may have arbitrary shapes.
  • 12. Spatial Query Processing Optional Filter Spatial Data Layer Primary Filter: Spatial Index Data Selection Secondary Filter: Spatial Functions Results
  • 14. SDO_GEOMETRY Is composed of CREATE TABLE forest( name VARCHAR2(30), animal_population NUMBER(9), geom MDSYS.SDO_GEOMETRY); Methods GET_DIMS() :NUMBER GET_GTYPE :NUMBER
  • 15. SDO_GTYPE It defines the geometry type stored into the SDO_GEOMETRY object Geometry Type Dimensions Name 2D 3D 4D UNKNOWN_GEOMETRY 2000 3000 4000 POINT 2001 3001 4001 LINESTRING 2002 3002 4002 POLYGON 2003 3003 4003 COLLECTION 2004 3004 4004 MULTIPOINT 2005 3005 4005 MULTILINESTRING 2006 3006 4006 MULTIPOLYGON 2007 3007 4007 NOT OGC
  • 16. SDO_POINT Used to store Point data It is ignored if SDO_ELEM_INFO and SDO_ORDINATES are not NULL It is of type SDO_POINT_TYPE X NUMBER Y NUMBER Z NUMBER Example: GPS Receiver
  • 17. SDO_ELEM_INFO It is store as a SDO_ELEM_INFO_ARRAY: VARRAY (1048576) OF NUMBER Its entries must be considered grouping elements by 3 Starting position of the coordinates (starting from 1) Element type (as shown in the table) Interpretation Number Element Type Interpretation 0 UNKNOWN_ELEMENT 1 POINT Number of points of the collection 2 LINESTRING Lines 3 POLYGON 1 lines 1003 External 2 arcs 2003 Internal 3 optimized rectangle 4 circle 4 COMPOUND LINESTRING Number of elements 5 COMPOUNG POLYGON Number of elements 1005 External 2005 Internal
  • 18. SDO_ORDINATES Stored as SDO_ORDINATE_ARRAY VARRAY (1048576) OF NUMBER It contains a list of object’s coordinates
  • 19. Examples 1/5 – inserting a Point INSERT INTO pollution VALUES ( 34.6,57.4,etc…, MDSYS.SDO_GEOMETRY( 3001, 352257, MDSYS.SDO_POINT_TYPE(521030,240120,550), null,null) ); SDO_POINT SDO_ELEM_INFO SDO_ORDINATES SDO_GTYPE SDO_SRID
  • 20. Examples 2/5 – inserting a line INSERT INTO roads VALUES (‘motorway’,’NYC’,etc…, mdsys.sdo_geometry( 2002,352257,null, mdsys.sdo_elem_info_array(1,2,1), mdsys.sdo_ordinate_array(10,10, 20,25, 30,10, 40,10)) ); 10,10 20,25 30,10 40,10
  • 21. Examples 3/5 – inserting a polygon INSERT INTO roads VALUES (‘motorway’,’NYC’,etc…, mdsys.sdo_geometry( 2003,352257,null, mdsys.sdo_elem_info_array(1,1003,1, 13,2003,3), mdsys.sdo_ordinate_array(2,10, 3,0, 10,0, 12,10, 5,12, 2,10, 4,3, 6,9)) ); (2,10) (2,10) (3,0) (10,0) (12,10) (5,12) (4,3) (6,9)
  • 23. Projections Projected and Georeferenced 2D projection of the global sphere Cartesian projections Example : Swiss projection Not Georeferenced Local systems not linked to the earth global representation Cartesian projections Ex ample: «non-earth» of MapInfo GIS software Georeferenced not projected Not projected on a spefici plane Latitude Longitude positioning system Example: Oracle, decmal degrees –180 to 180 and – 90 to 90 Example : WGS84
  • 24. SDO_SRID It is a INTEGER number that identifies which coordinate system is used by the SDO_GEOMETRY The table MDSYS.CS_SRS is defining such reference systems. Description Type Description CS_NAME VARCHAR2(68) Short Name SRID NUMBER(38) Reference System ID AUTH_SRID NUMBER(38) ‘ Oracle’ AUTH_NAME VARCHAR2(256) SRID name WKTEXT VARCHAR2(2046) OGC name CS_BOUNDS MDSYS.SDO_GEOMETRY Can be null
  • 25. How to Change the SRID? 1. Drop Spatial Indexes drop index town_sidx; 2. Update metadata table update user_sdo_geom_metadata set srid = 352257 where table_name = ‘towns’ and column_name = ‘geom’; 3. Update the SDO_SRID of each object update towns t set t.geom.sdo_srid = 352257; 4. Adjust tolerances update user_sdo_geom_metadata u set u.diminfo = mdsys.sdo_dim_array( mdsys.sdo_dim_element(‘x’,400000,600000,0.005), mdsys.sdo_dim_element(‘y’,100000,300000,0.005)), where table_name = ‘towns’ and column_name = ‘geom’ 5. Recreate Spatial Indexes create index town_idx on towns(geom) indextype is mdsys.spatial_index;
  • 27. Spatial Operators Make use of spatial indexes They MUST have a spatial index defined at least for the first spatial type used They are only used within the WHERE clause
  • 28. SDO_FILTER SDO_FILTER(<geometry-1>,<geometry-2>,‘QUERYTYPE=WINDOW’) = ‘TRUE’; geometry-1 (searched object) Must be a column table Must be a SDO_GEOMETRY Must be indexed geometry-2 Must be a variable or column table Must be SDO_GEOMETRY ‘ QUERYTYPE = WINDOW’ Necessary parameter Oracle advises to use only WINDOW select s.nom, s.type from sondages s Where sdo_filter ( s.geom, mdsys.sdo_geometry (2003,352257,null, mdsys.sdo_elem_info_array(1,1003,3), mdsys.sdo_ordinate_array(540300,212500,541300,213500)), ‘ querytype=WINDOW’) = ‘TRUE’;
  • 29. SDO_RELATE SDO_RELATE(<geometry-1>,<geometry-2>, ‘MASK=<mask> QUERYTYPE=WINDOW’) = ‘TRUE’; Used similarly to SDO_FILTER You can use MASK keywords linked by «+» that means OR operation For example: COVEREDBY, TOUCH, INSIDE, ANYINTERACT select t1.name, t1.na,e from towns t1, towns t2 where c2.name = ‘NYC’ and sdo_relate ( t1.geom,t2.geom, ‘ mask=TOUCH querytype=WINDOW’)=‘TRUE’;
  • 30. SDO_WITHIN_DISTANCE SDO_WITHIN_DISTANCE( <geometry-1>,<geometry-2>, ‘DISTANCE=<n>,[optional parameters]’) = ‘TRUE’; geometry-2 A buffer will be created starting from this object DISTANCE Distance to be considered QUERYTYPE (optional) Using a primary and secondaryfilter Si QUERYTYPE=FILTER: uses a primary filter only UNIT (optionnel) Defines a specific unit measure that can be different from the SRS definition select a.name from buildings b, streets a where b.id= 2198376 and sdo_within_distance ( a.geom,b.geom,‘distance=1 UNIT=kilometer’)=‘TRUE’;
  • 31. SDO_NN (nearest neighbor) SDO_NN(<geometry-1>,<geometry-2>,‘[paramètres optionnels]’) = ‘TRUE’; SDO_NUM_RES (optional) number of neighbors to return (default = 1) SDO_BATCH_SIZE (optional) To be used instead of SDO_NUM_RES: it returns subsets of nearest neighbors until all the criteria defined by the «  where» condition are satisfied. UNIT (optionnel avec l’utilisation de SDO_NN_DISTANCE) Measure unit select s.type from streets s, polls p where s.id = 1289 and sdo_nn(s.geom,p.geom,’sdo_num_res=5 unit=meter’,1) = ‘TRUE’;
  • 33. Spatial Functions Are not requiring spatial indexes Can be used on small tables without indexing Can be used either in the «  SELECT» or «  WHERE » clauses. The input geometries must have the same reference system
  • 34. SDO_GEOM.RELATE SDO_GEOM.RELATE( <geometry-1>,’<mask>’,<geometry-2>,<tolerance>); geometry-1 (searched object) SDO_GEOMETRY object geometry-2 SDO_GEOMETRY object mask Spatial Relationships to be tested tolerance Tolérance on the data granularity REMINDER: use SDO_RELATE in the where clause because SDO_GEOM.RELATE doesn’t use spatial indexing: it is slower select c.name, sdo_geom.relate(d.geom,’determine’,t.geom,0.5) relation from districts d, towns t where d.distname = ‘NY’ and d.distname = t.district;
  • 36. Spatial Analysis Oracle spatial functionalities are used to analyze spatial objects The following examples are using spatial functions and operators in order to compute some basic analysis
  • 37. Calculate a Surface SDO_GEOM.SDO_AREA (<geometry>,<tolerance> [, <unit>]) geometry SDO_GEOMETRY that defines a polygon unit Unit of the results: for a list of possible units look at: select sdo_unit from mdsys.sdo_dist_units; select sum(sdo_geom.sdo_area(c1.geom,0.5,’unit=sq_meter’)) surface from towns t1, towns t2 where t2.name = ‘New York’ and sdo_relate (t1.geom,t2.geom, ’ mask=TOUCH querytype=WINDOW’) = ‘TRUE’;
  • 38. Calculate the Length SDO_GEOM.SDO_LENGTH (<geometry>,<tolerance> [, <unit>]) Calculate the Distance SDO_GEOM.SDO_DISTANCE (<geometry-1>, <geometry-2>,<tolerance> [, <unit>]) select name,sdo_geom.sdo_length(geom,0.5,’unit=kilometer’) length from streets where number = 1234; select sdo_geom.sdo_distance(f1.geom,f2.geom,0.5) distance from forests f1, forests f2 where f1.id = 1 and f2.id = 2;
  • 39. Buffer Calculation SDO_GEOM.SDO_BUFFER (<geometry>,<distance>, <tolerance> [, ‘<params>’]) geometry SDO_GEOMETRY distance Distance of the buffer zone Returns: SDO_GEOMETRY select sdo_geom.sdo_buffer (geom,25,0.5,’unit=km’) buffer from streets where number = 120;
  • 40. Logic Functions SDO_GEOM.SDO_XXX (<geometry-1>,<geometry-2>,<tolerance>) SDO_GEOM.SDO_UNION SDO_GEOM.SDO_INTERSECTION SDO_GEOM.SDO_DIFFERENCE SDO_GEOM.SDO_XOR
  • 41. References http://en.wikipedia.org/wiki/Oracle_Spatial http://fdo.osgeo.org/ http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28400/sdo_intro.htm Marc Riedo GIS Technology I - EPFL cours slides