translating wfs query to sql/xml query

33
Translating WFS Query to SQL/XML Query Vânia Vidal Fernando Lemos Fábio Feitosa Departamento de Computação Universidade Federal do Ceará

Upload: rose-horn

Post on 03-Jan-2016

128 views

Category:

Documents


0 download

DESCRIPTION

Translating WFS Query to SQL/XML Query. Vânia Vidal Fernando Lemos Fábio Feitosa Departamento de Computação Universidade Federal do Ceará. Outline. WFS Specification Contributions Feature Type Specification Extension of Feature Type Translating WFS Query to SQL/XML Query Conclusions. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Translating WFS Query to SQL/XML Query

Translating WFS Query to SQL/XML Query

Vânia VidalFernando LemosFábio Feitosa

Departamento de ComputaçãoUniversidade Federal do Ceará

Page 2: Translating WFS Query to SQL/XML Query

Outline

WFS Specification Contributions Feature Type Specification Extension of Feature Type Translating WFS Query to SQL/XML Query Conclusions

Page 3: Translating WFS Query to SQL/XML Query

WFS Specification

OpenGis Consortium promotes the development and use of

advanced open system standards and techniques in the geoprocessing area and related information technologies

WFS publishes GML views of geographic features

stored in data sources users can query and update data stores

through a feature type schema

Page 4: Translating WFS Query to SQL/XML Query

WFS Specification

WFS request GetCapabilities DescribeFeatureType GetFeature Transaction LockFeature

Page 5: Translating WFS Query to SQL/XML Query

Contributions

Correspondence Assertions specify the mappings between

feature type schemas and relational schemas

TranslateWFSQuery Algorithm translates a WFS query over a feature type schema

into a SQL/XML query over the relational schema translation is based on the correspondence assertions

Page 6: Translating WFS Query to SQL/XML Query

WFS GetFeature Request

DeegreeWFS Server BDR

WFS QuerySQL Query Q1

result of Q1GML

Deegree WFS

Our approach

GML PublisherWFS Server BDR

WFS Query SQL/XML Query

GMLGML

SQL Query Qn

result of Qn

Page 7: Translating WFS Query to SQL/XML Query

Feature Type Specification

Feature Type F over a relational schema S

F = <T, R, A>

whereT is the XML Schema type for feature instances

R is the name of the master relation schema, which contains the geometric attribute

A is the set of correspondence assertions, which fully specifies T in terms of R

Page 8: Translating WFS Query to SQL/XML Query

Example

area

Pluviometry* (TPluviometry)

month value

TStation code geometry name address (TAddress)

street city (TCity)

agency

zipcode

name

Relational Schema DB_StationXML Schema type forFeature Type F_Station

Master Relation Schema

Station_rel

CODE

GEOM_POINTNAMESTREETZIPCODECODECITY (FK)CODEAGENCY (FK)

Pluviometry_rel

CODESTATION (FK)MONTH

VALUE

Agency_rel

CODEAGENCY

NAMEPHONEFAX

City_rel

CODECITY

NAMEAREA

Page 9: Translating WFS Query to SQL/XML Query

Correspondence Assertions of F_Station

Master Relation Schema

Page 10: Translating WFS Query to SQL/XML Query

Extension of a Feature Type

Extension of F = <T, R, A> for an instance s of schema S a sequence of F-elements of type T,

such that each F-element matches a tuple of s(R)

F = { $f | $f is an instance of T and rs(R) such that $fAr}

SQL/XML query definition of an extension of F

F = SELECT XMLELEMENT( "Extension_of_F ", XMLAGG( XMLELEMENT( "F", [RT](r) )) FROM R r

[RT](r) constructs the content for an instance $f of T such that $f A r as specified by the CAs of F

Page 11: Translating WFS Query to SQL/XML Query

SQL/XML Definition for Extension of F_Station

SELECT XMLELEMENT( "Extension_of_F_Station", XMLAGG( XMLELEMENT( "F_Station", XMLFOREST(S.CODE AS "code"), XMLFOREST( SDO_UTIL.TO_GMLGEOMETRY(S.GEOM_POINT) AS "geometry"), XMLFOREST(S.NAME AS "name"), XMLELEMENT( "address", XMLFOREST(S.STREET AS "street"), XMLELEMENT( "city", (SELECT XMLCONCAT( XMLFOREST(C.NAME AS "name"), XMLFOREST(C.AREA AS "area")) FROM City_rel C WHERE C.CODECITY = S.CODECITY) ), XMLFOREST(S.ZIPCODE AS "zipcode") ), (SELECT XMLAGG(XMLELEMENT( "pluviometry", XMLFOREST(PL.MONTH AS "month"), XMLFOREST(PL.VALUE AS "value") ) ) FROM Pluviometry_rel PL WHERE S.CODE = PL.CODESTATION), XMLFOREST( (SELECT A.NAME FROM Agency_rel A WHERE A.CODEAGENCY = S.CODEAGENCY) AS "agency")) ) )FROM Station_rel S;

[TStation / code] [Station_rel / CODE][TStation / geometry] [Station_rel / GEOM_POINT]

[TStation / name] [Station_rel / NAME][TStation / address] [Station_rel / NULL]

[TAddress / street] [Station_rel / STREET][TAddress / city] [Station_rel / FK1]

[TCity / name] [City_rel / NAME]

[TCity / area] [City_rel / AREA]

[TAddress / zipcode] [Station_rel / ZIPCODE][TStation / pluviometry] [Station_rel / FK2

-1][TPluviometry / month] [Pluviometry_rel / MONTH]

[TPluviometry / area] [Pluviometry_rel / AREA]

[TStation / agency] [Station_rel / FK3 / NAME]

Page 12: Translating WFS Query to SQL/XML Query

An Instance of DB_Station

Page 13: Translating WFS Query to SQL/XML Query

Station_ rel

CODE NAME STREET ZI PCODE GEOM_ POINT CODE AGENCY

CODECI TY

164 Serragem R. Prinicpal s/n 62755000 -4.45,-38.5 1 2309458

165 Arisco Sitio Penha 62755000 -4.65,-38.55 2 2309458

481 Arruda R. São Francisco,606 62113000 -3.85,-40.66 1 2312908

Extension of F_Station

Page 14: Translating WFS Query to SQL/XML Query

Agency_ rel

CODEAGENCY NAME PHONE FAX

1 FUNCEME 31011088 31011093

2 SUDENE 34339031 34339045

Extension of F_Station

Page 15: Translating WFS Query to SQL/XML Query

Pluviometry_ rel

CODESTATI ON MONTH VALUE

164 01 87.8

164 02 171.6

165 01 50.4

481 03 150

Extension of F_Station

Page 16: Translating WFS Query to SQL/XML Query

City_ rel

CODECI TY NAME AREA

2309458 OCARA 1450

2312908 SOBRAL 19820

Extension of F_Station

Page 17: Translating WFS Query to SQL/XML Query

WFS Query

<Query> element of a GetFeature request: delivers feature instances of a given feature type,

where each feature instance matches a tuple of the Master Table

<Query> element contains: a mandatory attribute typeName

used to indicate the name of the feature type to be queried a sequence of zero or more <wfs:PropertyName> elements

used to specify what properties to retrieve the value of each <wfs:PropertyName> element is an XPath expression that

references a property or sub-property of the relevant feature type an optional <Filter> element

used to define spatial and non-spatial constraints on a query encoded as described in the OGC Filter Encoding Implementation Spec

Page 18: Translating WFS Query to SQL/XML Query

<wfs:Query typeName="F_Station"> <wfs:PropertyName>name</wfs:PropertyName> <wfs:PropertyName>address / city</wfs:PropertyName> <wfs:PropertyName>pluviometry</wfs:PropertyName> <wfs:PropertyName>geometry</wfs:PropertyName> <ogc:Filter> <ogc:And> <ogc:PropertyIsEqualTo> <ogc:PropertyName>agency</ogc:PropertyName> <ogc:Literal>FUNCEME</ogc:Literal> </ogc:PropertyIsEqualTo> <ogc:BBox> <ogc:PropertyName>geometry</ogc:PropertyName> <gml:Envelope> <gml:lowercorner>-5.2 -42.5</gml:lowercorner> <gml:upperCorner>-2.5 -38.7</gml:upperCorner> </gml:Envelope> </ogc:BBox> </ogc:And> </ogc:Filter> </wfs:Query>

FOR $f in document("F")/Station

WHERE $f satisfies the filter of QW RETURN <gml:featureMember>{ <F_Station> { $f/name, $f/address/city, $f/pluviometry, $f/geometry }</F_Station> }<gml:featureMember>

QW : WFS Query over F_Station QX : Canonical XQuery for QW

The result of Qw is the result of evaluating QX on an extension of F_Station

Page 19: Translating WFS Query to SQL/XML Query

XML fragment resulting from QW

<gml:FeatureMember> <F_Station> <name>Serragem</name> <city> <name>OCARA</name> <area>1450</area> </city> <pluviometry> <month>1</month> <value>87.8</value> </pluviometry> <pluviometry> <month>2</month> <value>171.6</value> </pluviometry> <geometry> <gml:Point> <gml:coordinates cs="," decimal="." ts=""> -4.45,-38.5</gml:coordinates> </gml:Point> </geometry> </F_Station> </gml:FeatureMember> <gml:FeatureMember> <F_Station> <name>Arruda</name> <city> <name>SOBRAL</name> <area>19820</area> </city> <pluviometry> <month>3</month> <value>150</value> </pluviometry> <geometry> <gml:Point> <gml:coordinates cs="," decimal="." ts=""> -3.85,-40.66</gml:coordinates> </gml:Point> </geometry> </F_Station> </gml:FeatureMember>

<wfs:Query typeName="F_Station"> <wfs:PropertyName>name</wfs:PropertyName> <wfs:PropertyName>address / city</wfs:PropertyName> <wfs:PropertyName>pluviometry</wfs:PropertyName> <wfs:PropertyName>geometry</wfs:PropertyName> <ogc:Filter> <ogc:And> <ogc:PropertyIsEqualTo> <ogc:PropertyName>agency</ogc:PropertyName> <ogc:Literal>FUNCEME</ogc:Literal> </ogc:PropertyIsEqualTo> <ogc:BBox> <ogc:PropertyName>geometry</ogc:PropertyName> <gml:Envelope> <gml:lowercorner>-5.2 -42.5</gml:lowercorner> <gml:upperCorner>-2.5 -38.7</gml:upperCorner> </gml:Envelope> </ogc:BBox> </ogc:And> </ogc:Filter> </wfs:Query>

QW : WFS Query

Page 20: Translating WFS Query to SQL/XML Query

WFS Query

Definition:Let

QW be a WFS Query over feature type F

Qx be the canonical XQuery for QW

QS be a SQL/XML query over S which returns a set of <gml:featureMember> elements.

Then, we say that QS is a correct translation for QW iff,

for any instance S of S,

if F is the extension of F on S

S1 is the set of <gml:featureMember> elements resulting from evaluating QS on S and

S2 is the set of <gml:featureMember> elements resulting from evaluating QX on F

then S1 = S2

Page 21: Translating WFS Query to SQL/XML Query

Input: WFS query QW

Output: SQL/XML query QS

Let <P,L > := TranslateFilter( f ), where f is the filter of QW

In case of

Case 1: QW has no <wfs:PropertyName> elements

Qs = SELECT

XMLELEMENT( "gml:featureMember",

XMLELEMENT( "F",

[RT][r]

) )

FROM R r, L WHERE P

TranslateWFSQuery Algorithm

Page 22: Translating WFS Query to SQL/XML Query

Case 2: QW has n <wfs:PropertyName> elements

Let Pathi be the value of i-th <wfs:PropertyName> element of QW.

Let Qi [r] := TranslatePath(Pathi)

Qs = SELECT XMLELEMENT( " gml:featureMember ",

XMLELEMENT( " F ", Q1 [r] … Qn [r] ) ) FROM R r, L WHERE P

TranslateWFSQuery Algorithm

Page 23: Translating WFS Query to SQL/XML Query

TranslateWFSQuery Algorithm

TranslateFilter( f )returns a tuple <P,L>

where

P is an SQL conditional expression

L is a list of relations names required to process P such that,

for any instance $t of T if $t A r, where r is a tuple of R,

then $t satisfies f iff r satisfies P

Page 24: Translating WFS Query to SQL/XML Query

TranslatePath(F) Algorithm

Input: a path F = p1 /…/ pn of type T

Output: SQL/XML subquery Q[r] that computes the value of path F

Theorem:

For any instance $t of Extension of F, where $t Ar, then Q[r] returns a set S of pn-elements where S = $t/ p1 /…/ pn

Page 25: Translating WFS Query to SQL/XML Query

<wfs:Query typeName="F_Station"> <wfs:PropertyName>name</wfs:PropertyName> <wfs:PropertyName>address / city</wfs:PropertyName> <wfs:PropertyName>pluviometry</wfs:PropertyName> <wfs:PropertyName>geometry</wfs:PropertyName> <ogc:Filter> <ogc:And> <ogc:PropertyIsEqualTo> <ogc:PropertyName>agency</ogc:PropertyName> <ogc:Literal>FUNCEME</ogc:Literal> </ogc:PropertyIsEqualTo> <ogc:BBox> <ogc:PropertyName>geometry</ogc:PropertyName> <gml:Envelope> <gml:lowercorner>-5.2 -42.5</gml:lowercorner> <gml:upperCorner>-2.5 -38.7</gml:upperCorner> </gml:Envelope> </ogc:BBox> </ogc:And> </ogc:Filter> </wfs:Query>

FOR $f in document("F")/Station

WHERE $f satisfies the filter of QW RETURN <gml:featureMember>{ <F_Station> { $f / name,

$f / address/city,

$f / pluviometry,

$f / geometry }</F_Station> }<gml:featureMember>

QW : WFS Query QX : Canonical XQuery for QW

Translation for QW

Page 26: Translating WFS Query to SQL/XML Query

SELECT XMLELEMENT("gml:FeatureMember", XMLELEMENT("Station", Q1[S], .........…..…………………..TranslatePath( name )

Q2[S],……........................TranslatePath( address / city)

Q3[S],…………….…………TranslatePath( pluviometry )

Q4[S]…………………………..TranslatePath( geometry )) )FROM Station_rel S, LWHERE P

Translation for QW

SQL/XML Query

Page 27: Translating WFS Query to SQL/XML Query

TranslatePath( name )

[TStation / name] [Station_rel / NAME]

Translation for QW

SQL/XML Query

SELECT XMLELEMENT("gml:FeatureMember", XMLELEMENT("Station") XMLFOREST(S.NAME AS "name"), Q2[S], Q3[S], Q4[S])FROM Station_rel S, LWHERE P

Page 28: Translating WFS Query to SQL/XML Query

SELECT XMLELEMENT("gml:FeatureMember", XMLELEMENT("Station") XMLFOREST(S.NAME AS "name"), XMLELEMENT( "city", (SELECT XMLCONCAT( XMLFOREST(C.NAME AS "name"), XMLFOREST(C.AREA AS "area") ) FROM City_rel C WHERE C.CODECITY = S.CODECITY)), Q3[S], Q4[S] )FROM Station_rel S, LWHERE P

TranslatePath( address / city )

[TStation / address] [Station_rel / NULL]

+ [TAddress / city] [Station_rel / FK1]+ [TCity / name] [City_rel / NAME]+ [TCity / area] [City_rel / AREA]

Translation for QW

SQL/XML Query

Page 29: Translating WFS Query to SQL/XML Query

SELECT XMLELEMENT("gml:FeatureMember", XMLELEMENT("Station") XMLFOREST(S.NAME AS "name"), XMLELEMENT( "city", (SELECT XMLCONCAT( XMLFOREST(C.NAME AS "name"), XMLFOREST(C.AREA AS "area") ) FROM City_rel C WHERE C.CODECITY = S.CODECITY)), (SELECT XMLAGG(XMLELEMENT("pluviometry", XMLFOREST(PL.MONTH AS "month"), XMLFOREST(PL.VALUE AS "value") ) ) FROM Pluviometry_rel PL WHERE S.CODE = PL.CODESTATION), Q[ S ])FROM Station_rel S, LWHERE P

TranslatePath( pluviometry )

[TStation / pluviometry] [Station_rel / FK2-1]

+ [TPluviomety / month] [Pluviometry_rel / MONTH]

+ [TPluviomety / value] [Pluviometry_rel / VALUE]

Translation for QW

SQL/XML Query

Page 30: Translating WFS Query to SQL/XML Query

SELECT XMLELEMENT("gml:FeatureMember", XMLELEMENT("Station") XMLFOREST(S.NAME AS "name"), XMLELEMENT( "city", (SELECT XMLCONCAT( XMLFOREST(C.NAME AS "name"), XMLFOREST(C.AREA AS "area") ) FROM City_rel C WHERE C.CODECITY = S.CODECITY)), (SELECT XMLAGG(XMLELEMENT("pluviometry", XMLFOREST(PL.MONTH AS "month"), XMLFOREST(PL.VALUE AS "value") ) ) FROM Pluviometry_rel PL WHERE S.CODE = PL.CODESTATION), XMLFOREST(SDO_UTIL.TO_GMLGEOMETRY(S.GEOM_POINT) AS "geometry") )FROM Station_rel S, LWHERE P

TranslatePath( geometry )

[TStation / geometry] [Station_rel / GEOM_POINT]

Translation for QW

SQL/XML Query

Page 31: Translating WFS Query to SQL/XML Query

SELECT XMLELEMENT("gml:FeatureMember", XMLELEMENT("Station") XMLFOREST(S.NAME AS "name"), XMLELEMENT( "city", (SELECT XMLCONCAT( XMLFOREST(C.NAME AS "name"), XMLFOREST(C.AREA AS "area") ) FROM City_rel C WHERE C.CODECITY = S.CODECITY)), (SELECT XMLAGG(XMLELEMENT("pluviometry", XMLFOREST(PL.MONTH AS "month"), XMLFOREST(PL.VALUE AS "value") ) ) FROM Pluviometry_rel PL WHERE S.CODE = PL.CODESTATION), XMLFOREST(SDO_UTIL.TO_GMLGEOMETRY(S.GEOM_POINT) AS "geometry") )FROM Station_rel S, Agency_rel AWHERE S.CODEAGENCY = A.CODEAGENCY AND A.NAME = 'FUNCEME' AND mdsys.sdo_relate( S.GEOM_POINT, mdsys.sdo_geometry(2003, NULL, NULL, mdsys.sdo_elem_info_array(1, 1003, 3), mdsys.sdo_ordinate_array(-5.2, -42.5, –2.5, -38.7)), 'mask=ANYINTERACT querytype=WINDOW') = 'TRUE'

<P,L > := TraslateFilter(f )

SQL/XML Query

Translation for QW

Page 32: Translating WFS Query to SQL/XML Query

TranslateWFSQuery Algorithm

Theorem:Let

Qw be a WFS Query over F

QX be a canonical XQuery for QW

QS be a SQL/XML query over S generated by TranslateWFSQuery

S1 be a set of <featureMember> elements resulting from QX on F

S2 be a set of <featureMember> elements resulting from QS on S

Then

S1 = S2

Page 33: Translating WFS Query to SQL/XML Query

Conclusions

Contributions: a formalism to specify the mapping between

a feature type schema and a relational database schema an algorithm that translates

a WFS query over a feature type schema into a SQL/XML query over the relational database schema,based on feature type's correspondence assertions.

Future work: development of GML Publisher, a framework for publishing

geographic data stored in relational databases as GML