Interface for spatial operations in geographical database
Karine Reis Ferreira João Argemiro Carvalho Paiva Gilberto Câmara
GeoInfo2003 Summary
• Introduction – New generation of GIS and spatial DBMS – Challenges – TerraLib • Goal • API for spatial operations – Vector and raster data • Conclusion and future works
GeoInfo 2003 New generation of GIS
• DBMS (Database Management System) to manage spatial data [Rigaux et al, 2002] – Object-relational DBMS and spatial extension
• Transition from the monolithic systems to Spatial Information Appliances [Egenhofer, 1999] – Small GIS tailored to specific user needs
• Modular and extensible [Voisard and Schweppe,1997] – Support for addition of independent autonomous systems
GeoInfo 2003 GIS and DBMS
• Use of DBMS to store, manipulate and manage spatial data (descriptive and geometrical data) – Relational DBMS ° Scheme ° Binary long type (BLOB) – Object-relational DBMS GIS ° Spatial data types defined by spatial extensions attributes
DBMS
GeoInfo 2003 Spatial Extension
• Extends object-relational DBMS for treat spatial data: – Data Model: spatial data types (SDTs) – Query language: operations and query on SDTs – Spatial indexing methods (ex. R-Tree) and spatial join
• DBMS + spatial extension = Spatial DBMS
• Oracle Spatial, IBM DB2 Spatial Extender, Informix Spatial Datablade, PostGIS (PostgreSQL) and Spatial Extension in MySQL (release 4.1)
GeoInfo 2003 Spatial Extension
• Oracle Spatial: – Spatial data type: SDO_GEOMETRY – Operators and functions ° SDO_RELATE, SDO_BUFFER, SDO_AREA – Spatial indexing: R-Tree e QuadTree
CREATE TABLE STATES ( state_id NUMBER, SELECT ES.state_id name VARCHAR2(100) FROM STATES ES, RIVERS RI geometry MDSYS.SDO_GEOMETRY); WHERE RI.gid = 234 AND SDO_RELATE(ES.geometry, RI.geometry, ‘mask=CONTAINS querytype=WINDOW’)= ’TRUE’;
GeoInfo 2003 Challenges
• Develop small GIS that: – supports different DBMS, relational and object- relational – treats the differences between spatial DBMS – extends necessary spatial data types for geographical applications, ex. raster data – provides spatial operations on spatial data types stored in different DBMS
GeoInfo 2003 TerraLib
• Open source GIS software library • Provides support for the development of: – Small GIS ° DBMS for manage spatial data • Support for different DBMS – Oracle, Oracle Spatial, MySQL, SQL Server, PostgreSQL
GeoInfo 2003 TerraLib
• Interface with DBMS
TeDatabase TerraLib
ADO Driver MySQL Driver OracleSpatial Driver PostgreSQL Driver
MySQL Oracle PostgreSQL Access Spatial SQLServer
GeoInfo 2003 TerraLib
• TerraLib data model
TeDatabase createPolygonTable(tableName)
MySQL Driver OracleSpatial Driver
MySQL Oracle Spatial
GeoInfo 2003 Goal
Development of a generic programming interface or API (Application Programming Interface) for spatial operations in geographical database in the TerraLib environment.
GeoInfo 2003 Challenges
• Develop small GIS that: – supports different DBMS, relational and object- relational – treats the differences between spatial DBMS – extends necessary spatial data types for geographical applications, ex. raster data – provides spatial operations on spatial data types stored in different DBMS
GeoInfo 2003 API for spatial operations
• Function set for spatial operations on geographical data stored in DBMS • Generic API: supports relational and object-relational DBMS • Explores spatial extension functionalities DBMS TerraLib Oracle Access Spatial Spatial Spatial Operations Operations Geographic API for Application Spatial MySQL Operations Postgre SQL
GeoInfo 2003 API for spatial operations
• Vector and raster data
Boolean Scalar Spatial
Unary Buffer calculateLength (VD) - ConvexHull calculateArea Centroid
Binary Intersection SpatialRelation (VD + VD) calculateDistance Union NearestNeighbors Difference/XOr
Binary - Zonal Mask (VD + RD)
VD: Vector Data RD: Raster Dada
GeoInfo 2003 API – Vector data
• DBMS without spatial extension – TeDatabase (1) Get geometries from database (2) Use TerraLib functions to compute operations
SELECT * TerraLib FROM geomTable WHERE sigla= “MG”
DBMS (1) calculateArea (“MG”)
blob TePolygon area (2)
double Area (TePolygon poly) GeoInfo 2003 API – Vector data
• DBMS with spatial extension – Oracle Spatial Driver ° Use operators and functions of the spatial extension with SQL language ° Operations are computed by spatial DBMS
SELECT SDO_GEOM.SDO_AREA( TerraLib geomTable, spatial_data, ...) FROM geomTable WHERE sigla= “MG”
DBMS calculateArea (“MG”) Oracle Spatial area
GeoInfo 2003 API – Vector data
• SpatialRelation Operation – Returns the geographical objects which present a specific topological relation – Topological relation [Egenhofer et al, 1994] ° TeDisjoint ° TeContains ° TeTouches ° TeIntersects ° TeCrosses ° TeEquals ° TeWithin ° TeCovers ° TeCoveredBy ° TeOverlap
GeoInfo 2003 API – Vector data
• SpatialRelation Operation – DBMS without spatial extension (1) Gets geometries from database based in their minimal boundary rectangle (MBR) (2) Uses TerraLib topological functions
GeoInfo 2003 API – Vector data
• SpatialRelation Operation – DBMS without spatial extension (1) Gets geometries from database based in their minimal boundary rectangle (MBR) (2) Uses TerraLib topological functions
GeoInfo 2003 API – Vector data
• SpatialRelation Operation – Oracle Spatial Driver ° Builds a SQL query using the SDO_RELATE operator ° Operation computed by spatial extension
SELECT geomTable1.* FROM state_polygons geomTable1, state_polygons geomTable2 WHERE geomTable2.object_id = 'MG' AND SDO_RELATE(geomTable1.spatial_data, geomTable2.spatial_data, 'mask = TOUCH querytype=WINDOW')='TRUE'
GeoInfo 2003 API – Vector data
• Buffer Operation – Generates a new geometry based on a distance to a specific geographical object – Oracle Spatial Driver
SELECT SDO_GEOM.SDO_BUFFER(g.spatial_data, m.diminfo, 1.0) FROM test_Line g, USER_SDO_GEOM_METADATA m WHERE m.table_name = 'test_Line' AND m.column_name = 'spatial_data' AND object_id = '17' Oracle Spatial
GeoInfo 2003 API – Vector data
• Buffer Operation – Generates a new geometry based on a distance to a specific geographical object – Oracle Spatial Driver
SDO_GEOMETRY (2003, NULL, NULL, SDO_ELEM_INFO_ARRAY (1, 1005, 8, 1, 2, 2, 5, 2, 1, ..., 9, 2, 2), SDO_ORDINATE_ARRAY (18, 17, 19, 18, 18, 19, 16.4142136, 19, 14.7071068, 20.7071068, 14, Oracle 21, ..., 20.7071068) Spatial
GeoInfo 2003 API – Vector data
• Buffer Operation – SDO_GEOMETRY ° Compound polygon: straight line segments (2 points) and circular arcs (3 points). – TePolygon ° straight line segments (2 points)
GeoInfo 2003 API – Vector data
• Buffer Operation – Generates a TePolygon from a SDO_GEOMETRY ° TeGenerateArc function ∑ Generates an arc through 3 points
pt3 pt2 s ptn pt1 r ? C(x0, y0)
GeoInfo 2003 API – Raster Data • Zonal Operation • Calculates statistics of a region or zone of a raster data
GeoInfo 2003 API – Raster Data • Zonal Operation • Calculates statistics of a region or zone of a raster data
GeoInfo 2003 API – Raster Data • Mask Operation – Clips a raster data using a mask
GeoInfo 2003 API – Raster Data • Mask Operation – Clips a raster data using a mask
GeoInfo 2003 API – Raster Data • Mask Operation – Clips a raster data using a mask
GeoInfo 2003 API – Raster Data
• Mechanism to traverse a raster data only in a region inside or outside a specific polygon • Developed: – Iterator concept on TeRaster structure ° IteratorPoly – Route strategies
GeoInfo 2003 API – Raster Data
• Iterator is an abstraction of a pointer to a sequence [Stroustrup, 1999] • Generic programming: disconnect data structures from algorithms
Algorithm TeCalculateStatistics(itBegin, itEnd, stat)
TeRaster::iteratorPoly itBegin = raster->begin(poly, TeBoxPiIn) Iterator TeRaster::iteratorPoly itEnd = raster->end(poly, TeBoxPixelIn)
Data TeRaster* raster Structure GeoInfo 2003 Conclusions • Spatial operations are essential in a geographical application • The developed API: – Provides spatial operations on a high level of abstraction for the developers of geographical application – Explores a new generation of object-relational DBMS that manage geographical data
GeoInfo 2003 Future Works
• Implement other operations on raster data: – Mathematical Operations – Reclassify – Slice – Weight • Extend the API to support new spatial extensions – Spatial Extension in MySQL (release 4.1) • Use future resources of spatial extensions to treat raster data (ex. Oracle Spacial)
GeoInfo 2003