Upload
steven-astor
View
233
Download
0
Tags:
Embed Size (px)
Citation preview
Object Relational ModelSpatial Queries
Object Relational ModelSpatial Queries
Query ModelQuery Model
Spatial LayerData
Table wherecoordinates are stored
PrimaryFilter
Spatial Index
Index retrieves area of interest (window)
ReducedData Set
SecondaryFilter
SpatialFunctions
Proceduresthat determineexact relationship
ExactResult
Set
Spatial Operators vs FunctionsSpatial Operators vs Functions
• Spatial operators:Spatial operators:
– Take advantage of spatial indexesTake advantage of spatial indexes
– Require that spatial index exists on the first Require that spatial index exists on the first geometry specified in the operator.geometry specified in the operator.
• Spatial Functions:Spatial Functions:
– Do not take advantage of spatial indexesDo not take advantage of spatial indexes
– Could be used on small tables that are not Could be used on small tables that are not spatially indexedspatially indexed
• Spatial operators:Spatial operators:
– Take advantage of spatial indexesTake advantage of spatial indexes
– Require that spatial index exists on the first Require that spatial index exists on the first geometry specified in the operator.geometry specified in the operator.
• Spatial Functions:Spatial Functions:
– Do not take advantage of spatial indexesDo not take advantage of spatial indexes
– Could be used on small tables that are not Could be used on small tables that are not spatially indexedspatially indexed
Spatial Operators vs FunctionsSpatial Operators vs Functions
• SDO_RELATE
– Performs a primary and secondary filter
• SDO_WITHIN_DISTANCE
– Gets all geometries that are within some distance from a selected geometry
• SDO_NN
– Gets the ‘n’ closest geometries
• SDO_RELATE
– Performs a primary and secondary filter
• SDO_WITHIN_DISTANCE
– Gets all geometries that are within some distance from a selected geometry
• SDO_NN
– Gets the ‘n’ closest geometries
• SDO_GEOM.RELATE
– To determine the relationship between two geometries
– To perform a spatial query without using a spatial index (I.e. on a small table)
• SDO_GEOM.WITHIN_DISTANCE
– Generates a buffer around a geometry and performs a secondary filter
• SDO_GEOM.RELATE
– To determine the relationship between two geometries
– To perform a spatial query without using a spatial index (I.e. on a small table)
• SDO_GEOM.WITHIN_DISTANCE
– Generates a buffer around a geometry and performs a secondary filter
Operators Functions
Spatial OperatorsSpatial Operators
The SDO_RELATE operatorThe SDO_RELATE operator
boolean := SDO_RELATE ( <geometry-1>, <geometry-2>, ‘MASK=<mask> QUERYTYPE=<querytype> [other optional parameters]’ )
boolean := SDO_RELATE ( <geometry-1>, <geometry-2>, ‘MASK=<mask> QUERYTYPE=<querytype> [other optional parameters]’ )
• Performs an exact query (primary and secondary filter)
• Returns TRUE or FALSE
• Performs an exact query (primary and secondary filter)
• Returns TRUE or FALSE
Required argumentsRequired arguments
• GEOMETRY-1
– A column of type SDO_GEOMETRY
• GEOMETRY-2
– Variable or column of type SDO_GEOMETRY
• MASK
– Identify spatial relationship to test
• QUERYTYPE
– Valid values are JOIN or WINDOW
• GEOMETRY-1
– A column of type SDO_GEOMETRY
• GEOMETRY-2
– Variable or column of type SDO_GEOMETRY
• MASK
– Identify spatial relationship to test
• QUERYTYPE
– Valid values are JOIN or WINDOW
A
B
A
B
A
B
A
B
A
B
A red B green
A
B
B Inside AA Contains B
B Covered by A A Covers B
Touch
OverlapBoundaries Intersect
OverlapBoundaries Disjoint
Equal
Disjoint
Topological relationshipsTopological relationships
1.1. DISJOINTDISJOINT: boundaries and interiors do not intersect: boundaries and interiors do not intersect
2.2. TOUCH TOUCH: boundaries intersect but interiors do not intersect: boundaries intersect but interiors do not intersect
3.3. OVERLAPBDYDISJOINT OVERLAPBDYDISJOINT: interior of one object intersects : interior of one object intersects boundary and interior of other object, but two boundaries do boundary and interior of other object, but two boundaries do not intersect (example: a line originates outside a polygon not intersect (example: a line originates outside a polygon and ends inside the polygon)and ends inside the polygon)
4.4. OVERLAPBDYINTERSECT OVERLAPBDYINTERSECT: boundaries and interiors of the : boundaries and interiors of the two objects intersecttwo objects intersect
5.5. EQUAL EQUAL: the two objects have the same boundary and interior: the two objects have the same boundary and interior
TopologicalTopological relationshipsrelationships
6. 6. CONTAINSCONTAINS: interior and boundary of one object is : interior and boundary of one object is completely contained in the interior of other objectcompletely contained in the interior of other object
7. 7. COVERSCOVERS: interior of one object is completely contained in : interior of one object is completely contained in interior of other object and their boundaries intersectinterior of other object and their boundaries intersect
8. 8. INSIDEINSIDE: opposite of CONTAINS; A INSIDE B implies B : opposite of CONTAINS; A INSIDE B implies B CONTAINS ACONTAINS A
9. 9. COVEREDBYCOVEREDBY: opposite of COVERS; A COVEREDBY B : opposite of COVERS; A COVEREDBY B implies B COVERS Aimplies B COVERS A
10. 10. ANYINTERACTANYINTERACT: the objects are non-disjoint: the objects are non-disjoint
Topological relationships (cont.d)Topological relationships (cont.d)
select c.city, c.pop90 from cities c where sdo_relate ( c.location, mdsys.sdo_geometry (2003, null, null, mdsys.sdo_elem_info_array (1,1003,3), mdsys.sdo_ordinate_array (-109,37,-102,40)), 'mask=ANYINTERACT') = 'TRUE';
select c.city, c.pop90 from cities c where sdo_relate ( c.location, mdsys.sdo_geometry (2003, null, null, mdsys.sdo_elem_info_array (1,1003,3), mdsys.sdo_ordinate_array (-109,37,-102,40)), 'mask=ANYINTERACT') = 'TRUE';
SDO_RELATE - An exampleSDO_RELATE - An example
• Find all cities in a selected rectangular area• Find all cities in a selected rectangular area
select c.county, c.state_abrv from counties c, states s where s.state = 'New Hampshire' and sdo_relate (c.geom, s.geom, 'mask=INSIDE+COVEREDBY querytype=WINDOW') = 'TRUE';
select c.county, c.state_abrv from counties c, states s where s.state = 'New Hampshire' and sdo_relate (c.geom, s.geom, 'mask=INSIDE+COVEREDBY querytype=WINDOW') = 'TRUE';
SDO_RELATE - A window querySDO_RELATE - A window query
• Find all counties in the state of New Hampshire• Find all counties in the state of New Hampshire
select c1.county, c1.state_abrv from counties c1, counties c2 where c2.state = 'New Jersey' and c2.county = 'Passaic' and sdo_relate (c1.geom, c2.geom, 'mask=TOUCH querytype=WINDOW') = 'TRUE';
select c1.county, c1.state_abrv from counties c1, counties c2 where c2.state = 'New Jersey' and c2.county = 'Passaic' and sdo_relate (c1.geom, c2.geom, 'mask=TOUCH querytype=WINDOW') = 'TRUE';
SDO_RELATE - Another window querySDO_RELATE - Another window query
• Find all counties around county Passaic• Find all counties around county Passaic
SDO_RELATE - join vs window querySDO_RELATE - join vs window query
• Find all interstates that cross county Passaic in NJ
• Find all interstates that cross a county in Arizonawith pop density <10
This requires compatible indexes on the layers !
• Find all interstates that cross county Passaic in NJ
• Find all interstates that cross a county in Arizonawith pop density <10
This requires compatible indexes on the layers !
select i.interstate from interstates i, counties c where c.state = 'New Jersey' and c.county = ‘Passaic’ and sdo_relate (i.geom, c.geom, 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE';
select i.interstate from interstates i, counties c where c.state = 'New Jersey' and c.county = ‘Passaic’ and sdo_relate (i.geom, c.geom, 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE';
select i.interstate from interstates i, counties c where c.state = 'Arizona' and c.poppsqmi < 10 and sdo_relate (i.geom, c.geom, 'mask=ANYINTERACT querytype=JOIN') = 'TRUE';
select i.interstate from interstates i, counties c where c.state = 'Arizona' and c.poppsqmi < 10 and sdo_relate (i.geom, c.geom, 'mask=ANYINTERACT querytype=JOIN') = 'TRUE';
Optional argumentsOptional arguments
• IDXTAB1
– Index table to associate with first geometry in operator.
– By default, the primary index table is used.
• IDXTAB2
– Index table to associate with the second geometry in operator
– By default, the primary index table is used.
– Only supported if QUERYTYPE=JOIN
• IDXTAB1
– Index table to associate with first geometry in operator.
– By default, the primary index table is used.
• IDXTAB2
– Index table to associate with the second geometry in operator
– By default, the primary index table is used.
– Only supported if QUERYTYPE=JOIN
The SDO_WITHIN_DISTANCE operatorThe SDO_WITHIN_DISTANCE operator
boolean := SDO_WITHIN_DISTANCE ( <geometry-1>, <geometry-2>, ‘DISTANCE=<n>, QUERYTYPE=<querytype> [other optional parameters]’ )
boolean := SDO_WITHIN_DISTANCE ( <geometry-1>, <geometry-2>, ‘DISTANCE=<n>, QUERYTYPE=<querytype> [other optional parameters]’ )
• Performs an exact or approximate query
• Euclidean distance only
• Returns TRUE or FALSE
• Performs an exact or approximate query
• Euclidean distance only
• Returns TRUE or FALSE
ArgumentsArguments
• GEOMETRY-1
– A column of type SDO_GEOMETRY
• GEOMETRY-2
– Variable or column of type SDO_GEOMETRY
• DISTANCE (required)
– The distance (expressed in the units used for the coordinate system)
• QUERYTYPE (optional)
• GEOMETRY-1
– A column of type SDO_GEOMETRY
• GEOMETRY-2
– Variable or column of type SDO_GEOMETRY
• DISTANCE (required)
– The distance (expressed in the units used for the coordinate system)
• QUERYTYPE (optional)
• Find all cities within a distance from an interstate
• Find interstates within a distance from a city
• Find all cities within a distance from an interstate
• Find interstates within a distance from a city
select c.city, c.state_abrv from cities c, interstates i where highway = ‘I4’ and sdo_within_distance ( c.location, i.geom,‘distance=0.5') = 'TRUE';
select c.city, c.state_abrv from cities c, interstates i where highway = ‘I4’ and sdo_within_distance ( c.location, i.geom,‘distance=0.5') = 'TRUE';
SDO_WITHIN_DISTANCE ExamplesSDO_WITHIN_DISTANCE Examples
select i.highway from interstates i, cities c where city = 'Tampa' and sdo_within_distance ( i.geom, c.location,'distance=0.5') = 'TRUE';
select i.highway from interstates i, cities c where city = 'Tampa' and sdo_within_distance ( i.geom, c.location,'distance=0.5') = 'TRUE';
• Find all cities within a distance from a state
Also returns all cities in Florida !
• Find all cities within a distance from a state
Also returns all cities in Florida !
select c.city, c.state_abrv from cities c, states s where s.state='Florida' and sdo_within_distance ( c.location, s.geom, 'distance=1.5') = 'TRUE';
select c.city, c.state_abrv from cities c, states s where s.state='Florida' and sdo_within_distance ( c.location, s.geom, 'distance=1.5') = 'TRUE';
SDO_WITHIN_DISTANCE ExamplesSDO_WITHIN_DISTANCE Examples
The SDO_NN operatorThe SDO_NN operator
boolean := SDO_NN ( <geometry-1>, <geometry-2>, ‘SDO_NUM_RES=<n>, [other optional parameters]’ )
boolean := SDO_NN ( <geometry-1>, <geometry-2>, ‘SDO_NUM_RES=<n>, [other optional parameters]’ )
• Calculates the N closest geometries
• Euclidean distance only
• Returns TRUE or FALSE
• Calculates the N closest geometries
• Euclidean distance only
• Returns TRUE or FALSE
ArgumentsArguments
• GEOMETRY-1
– A column of type SDO_GEOMETRY
• GEOMETRY-2
– Variable or column of type SDO_GEOMETRY
• SDO_NUM_RES (required)
– Number of objects to select
• GEOMETRY-1
– A column of type SDO_GEOMETRY
• GEOMETRY-2
– Variable or column of type SDO_GEOMETRY
• SDO_NUM_RES (required)
– Number of objects to select
• Find the 5 nearest cities from Orlando• Find the 5 nearest cities from Orlando
select c1.city, c1.state_abrv from cities c1, cities c2 where c2.city = 'Orlando' and sdo_nn ( c1.location, c2.location, 'sdo_num_res = 6') = 'TRUE' and c1.rowid <> c2.rowid;
select c1.city, c1.state_abrv from cities c1, cities c2 where c2.city = 'Orlando' and sdo_nn ( c1.location, c2.location, 'sdo_num_res = 6') = 'TRUE' and c1.rowid <> c2.rowid;
SDO_NN ExampleSDO_NN Example
• Find the 10 nearest cities from Orlando ordered by distance
• Find the 10 nearest cities from Orlando ordered by distance
select c1.city, c1.state_abrv, sdo_geom.sdo_distance ( c1.location, c2.location, 0.005) distance from cities c1, cities c2 where c2.city = 'Orlando' and sdo_nn ( c1.location, c2.location, 'sdo_num_res = 11') = 'TRUE' and c1.rowid <> c2.rowid order by distance;
select c1.city, c1.state_abrv, sdo_geom.sdo_distance ( c1.location, c2.location, 0.005) distance from cities c1, cities c2 where c2.city = 'Orlando' and sdo_nn ( c1.location, c2.location, 'sdo_num_res = 11') = 'TRUE' and c1.rowid <> c2.rowid order by distance;
SDO_NN ExampleSDO_NN Example