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
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
WFS Specification WFS request GetCapabilities DescribeFeatureType GetFeature Transaction LockFeature
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
WFS GetFeature Request Deegree WFS Server BDR WFS Query SQL Query Q 1 result of Q 1 GML Deegree WFS Our approach GML Publisher WFS Server BDR WFS Query SQL/XML Query GML SQL Query Q n result of Q n … …
Feature Type Specification Feature Type F over a relational schema S F = where T 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
Example Relational Schema DB_Station XML Schema type for Feature Type F_Station Master Relation Schema
Correspondence Assertions of F_Station Master Relation Schema
Extension of a Feature Type Extension of F = 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 r s (R) such that $f A r} SQL/XML query definition of an extension of F F = SELECT XMLELEMENT( "Extension_of_F ", XMLAGG( XMLELEMENT( "F", [R T](r) )) FROM R r [R T](r) constructs the content for an instance $f of T such that $f A r as specified by the CAs of F
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 / FK 1 ] [TCity / name] [ City_rel / NAME] [TCity / area] [ City_rel / AREA] [TAddress / zipcode] [ Station_rel / ZIPCODE] [TStation / pluviometry] [ Station_rel / FK 2 -1 ] [TPluviometry / month] [ Pluviometry_rel / MONTH] [TPluviometry / area] [ Pluviometry_rel / AREA] [TStation / agency] [ Station_rel / FK 3 / NAME]
An Instance of DB_Station
Extension of F_Station
WFS 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 element contains: a mandatory attribute typeName used to indicate the name of the feature type to be queried a sequence of zero or more elements used to specify what properties to retrieve the value of each element is an XPath expression that references a property or sub-property of the relevant feature type an optional element used to define spatial and non-spatial constraints on a query encoded as described in the OGC Filter Encoding Implementation Spec
Q W : WFS Query over F_Station Q X : Canonical XQuery for Q W The result of Q w is the result of evaluating Q X on an extension of F_Station
XML fragment resulting from Q W Q W : WFS Query
WFS Query Definition: Let Q W be a WFS Query over feature type F Qx be the canonical XQuery for Q W Q S be a SQL/XML query over S which returns a set of elements. Then, we say that Q S is a correct translation for Q W iff, for any instance S of S, if F is the extension of F on S S 1 is the set of elements resulting from evaluating Q S on S and S 2 is the set of elements resulting from evaluating Q X on F then S 1 = S 2
Input: WFS query Q W Output: SQL/XML query Q S Let := TranslateFilter( f ), where f is the filter of Q W In case of Case 1: Q W has no elements Q s = SELECT XMLELEMENT( "gml:featureMember", XMLELEMENT( "F", [R T][r] ) ) FROM R r, L WHERE P TranslateWFSQuery Algorithm
Case 2: Q W has n elements Let Path i be the value of i-th element of Q W. Let Q i [r] := TranslatePath(Path i ) Q s = SELECT XMLELEMENT( " gml:featureMember ", XMLELEMENT( " F ", Q 1 [r] … Q n [r] ) ) FROM R r, L WHERE P TranslateWFSQuery Algorithm
TranslateFilter( f ) returns a tuple 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
TranslatePath( F ) Algorithm Input:a path F = p 1 /…/ p n 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 A r, then Q[r] returns a set S of p n - elements where S = $t / p 1 /…/ p n
Q W : WFS Query Q X : Canonical XQuery for Q W Translation for Q W
SELECT XMLELEMENT("gml:FeatureMember", XMLELEMENT(" Station ", Q 1 [S], …..………………….. TranslatePath ( name ) Q 2 [S], …… TranslatePath ( address / city) Q 3 [S], …………….………… TranslatePath ( pluviometry ) Q 4 [S] ………………………….. TranslatePath ( geometry ) ) ) FROM Station_rel S, L WHERE P Translation for Q W SQL/XML Query
TranslatePath( name ) [TStation / name] [Station_rel / NAME] Translation for Q W SQL/XML Query SELECT XMLELEMENT("gml:FeatureMember", XMLELEMENT(" Station ") XMLFOREST( S.NAME AS " name "), Q 2 [S], Q 3 [S], Q 4 [S] ) FROM Station_rel S, L WHERE P
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)), Q 3 [ S ], Q 4 [ S ] ) FROM Station_rel S, L WHERE P TranslatePath( address / city ) [TStation / address] [Station_rel / NULL] + [TAddress / city] [Station_rel / FK 1 ] + [TCity / name] [City_rel / NAME] + [TCity / area] [City_rel / AREA] Translation for Q W 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, L WHERE P TranslatePath( pluviometry ) [TStation / pluviometry] [Station_rel / FK 2 -1 ] + [TPluviomety / month] [Pluviometry_rel / MONTH] + [TPluviomety / value] [Pluviometry_rel / VALUE] Translation for Q W 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, L WHERE P TranslatePath( geometry ) [TStation / geometry] [Station_rel / GEOM_POINT] Translation for Q W 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 A WHERE 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' := TraslateFilter( f ) SQL/XML Query Translation for Q W
TranslateWFSQuery Algorithm Theorem: Let Q w be a WFS Query over F Q X be a canonical XQuery for Q W Q S be a SQL/XML query over S generated by TranslateWFSQuery S 1 be a set of elements resulting from Q X on F S 2 be a set of elements resulting from Q S on S Then S 1 = S 2
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