complex-features.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. .. _app-schema.complex-features:
  2. Complex Features
  3. ================
  4. To understand complex features, and why you would want use them, you first need
  5. to know a little about simple features.
  6. Simple features
  7. ---------------
  8. A common use of GeoServer WFS is to connect to a data source such as a database
  9. and access one or more tables, where each table is treated as a WFS simple feature type.
  10. Simple features contain a list of properties that each have one piece of simple information such as a string or number.
  11. (Special provision is made for geometry objects, which are treated like single items of simple data.)
  12. The Open Geospatial Consortium (OGC) defines three Simple Feature profiles; SF-0, SF-1, and SF-2.
  13. GeoServer simple features are close to OGC SF-0, the simplest OGC profile.
  14. GeoServer WFS simple features provide a straightforward mapping from a database table or
  15. similar structure to a "flat" XML representation, where every column of the table maps to
  16. an XML element that usually contains no further structure.
  17. One reason why GeoServer WFS is so easy to use with simple features is that the conversion
  18. from columns in a database table to XML elements is automatic. The name of each element is the
  19. name of the column, in the namespace of the data store. The name of the feature type defaults to
  20. the name of the table. GeoServer WFS can manufacture an XSD type definition for every simple feature type it serves.
  21. Submit a DescribeFeatureType request to see it.
  22. Benefits of simple features
  23. ```````````````````````````
  24. * Easy to implement
  25. * Fast
  26. * Support queries on properties, including spatial queries on geometries
  27. Drawbacks of simple features
  28. ````````````````````````````
  29. * When GeoServer automatically generates an XSD, the XML format is tied to the database schema.
  30. * To share data with GeoServer simple features, participants must either use the same database schema or translate between different schemas.
  31. * Even if a community could agree on a single database schema, as more data owners with different data are added to a community, the number of columns in the table becomes unmanageable.
  32. * Interoperability is difficult because simple features do not allow modification of only part of the schema.
  33. Simple feature example
  34. ``````````````````````
  35. For example, if we had a database table ``stations`` containing information about GPS stations::
  36. | id | code | name | location |
  37. +----+------+----------------+--------------------------+
  38. | 27 | ALIC | Alice Springs | POINT(133.8855 -23.6701) |
  39. | 4 | NORF | Norfolk Island | POINT(167.9388 -29.0434) |
  40. | 12 | COCO | Cocos | POINT(96.8339 -12.1883) |
  41. | 31 | ALBY | Albany | POINT(117.8102 -34.9502) |
  42. GeoServer would then be able to create the following simple feature WFS response fragment::
  43. <gps:stations gml:id="stations.27">
  44. <gps:code>ALIC</gps:code>
  45. <gps:name>Alice Springs</gps:name>
  46. <gps:location>
  47. <gml:Point srsName="urn:x-ogc:def:crs:EPSG:4326">
  48. <gml:pos>-23.6701 133.8855</gml:pos>
  49. </gml:Point>
  50. </gps:location>
  51. </gps:stations>
  52. * Every row in the table is converted into a feature.
  53. * Every column in the table is converted into an element, which contains the value for that row.
  54. * Every element is in the namespace of the data store.
  55. * Automatic conversions are applied to some special types like geometries, which have internal structure, and include elements defined in GML.
  56. Complex features
  57. ----------------
  58. Complex features contain properties that can contain further nested properties to arbitrary depth. In particular,
  59. complex features can contain properties that are other complex features. Complex features can be used to represent
  60. information not as an XML view of a single table, but as a collection of related objects of different types.
  61. ============================================================ =====================================================
  62. Simple feature Complex feature
  63. ============================================================ =====================================================
  64. Properties are single data item, e.g. text, number, geometry Properties can be complex, including complex features
  65. XML view of a single table Collection of related identifiable objects
  66. Schema automatically generated based on database Schema agreed by community
  67. One large type Multiple different types
  68. Straightforward Richly featured data standards
  69. Interoperability relies on simplicity and customisation Interoperability through standardization
  70. ============================================================ =====================================================
  71. Benefits of complex features
  72. ````````````````````````````
  73. * Can define information model as an object-oriented structure, an *application schema*.
  74. * Information is modelled not as a single table but as a collection of related objects whose associations and types may vary from feature to feature (polymorphism), permitting rich expression of content.
  75. * By breaking the schema into a collection of independent types, communities need only extend those types they need to modify. This simplifies governance and permits interoperability between related communities who can agree on common base types but need not agree on application-specific subtypes..
  76. Drawbacks of complex features
  77. `````````````````````````````
  78. * More complex to implement
  79. * Complex responses might slower if more database queries are required for each feature.
  80. * Information modelling is required to standardize an application schema. While this is beneficial, it requires effort from the user community.
  81. Complex feature example
  82. ```````````````````````
  83. Let us return to our ``stations`` table and supplement it with a foreign key ``gu_id`` that describes
  84. the relationship between the GPS station and the geologic unit to which it is
  85. physically attached::
  86. | id | code | name | location | gu_id |
  87. +----+------+----------------+--------------------------+-------+
  88. | 27 | ALIC | Alice Springs | POINT(133.8855 -23.6701) | 32785 |
  89. | 4 | NORF | Norfolk Island | POINT(167.9388 -29.0434) | 10237 |
  90. | 12 | COCO | Cocos | POINT(96.8339 -12.1883) | 19286 |
  91. | 31 | ALBY | Albany | POINT(117.8102 -34.9502) | 92774 |
  92. The geologic unit is stored in the table ``geologicunit``::
  93. | gu_id | urn | text |
  94. +-------+---------------------------------------+---------------------+
  95. | 32785 | urn:x-demo:feature:GeologicUnit:32785 | Metamorphic bedrock |
  96. ...
  97. The simple features approach would be to join the ``stations`` table with the ``geologicunit``
  98. table into one view and then deliver "flat" XML that contained all the properties of both.
  99. The complex feature approach is to deliver the two tables as separate feature types.
  100. This allows the relationship between the entities to be represented while preserving their individual identity.
  101. For example, we could map the GPS station to a ``sa:SamplingPoint`` with a ``gsml:GeologicUnit``.
  102. The these types are defined in the following application schemas respectively:
  103. * http://schemas.opengis.net/sampling/1.0.0/sampling.xsd
  104. * Documentation: OGC 07-002r3: http://portal.opengeospatial.org/files/?artifact_id=22467
  105. * http://www.geosciml.org/geosciml/2.0/xsd/geosciml.xsd
  106. * Documentation: http://www.geosciml.org/geosciml/2.0/doc/
  107. The complex feature WFS response fragment could then be encoded as::
  108. <sa:SamplingPoint gml:id="stations.27>
  109. <gml:name codeSpace="urn:x-demo:SimpleName">Alice Springs</gml:name>
  110. <gml:name codeSpace="urn:x-demo:IGS:ID">ALIC</gml:name>
  111. <sa:sampledFeature>
  112. <gsml:GeologicUnit gml:id="geologicunit.32785">
  113. <gml:description>Metamorphic bedrock</gml:description>
  114. <gml:name codeSpace="urn:x-demo:Feature">urn:x-demo:feature:GeologicUnit:32785</gml:name>
  115. </gsml:GeologicUnit>
  116. </sa:sampledFeature>
  117. <sa:relatedObservation xlink:href="urn:x-demo:feature:GeologicUnit:32785" />
  118. <sa:position>
  119. <gml:Point srsName="urn:x-ogc:def:crs:EPSG:4326">
  120. <gml:pos>-23.6701 133.8855</gml:pos>
  121. </gml:Point>
  122. </sa:position>
  123. </sa:SamplingPoint>
  124. * The property ``sa:sampledFeature`` can reference any other feature type, inline (included in the response) or by reference (an ``xlink:href`` URL or URN). This is an example of the use of polymorphism.
  125. * The property ``sa:relatedObservation`` refers to the same GeologicUnit as ``sa:sampledFeature``, but by reference.
  126. * Derivation of new types provides an extension point, allowing information models to be reused and extended in a way that supports backwards compatibility.
  127. * Multiple sampling points can share a single GeologicUnit. Application schemas can also define multivalued properties to support many-to-one or many-to-many associations.
  128. * Each GeologicUnit could have further properties describing in detail the properties of the rock, such as colour, weathering, lithology, or relevant geologic events.
  129. * The GeologicUnit feature type can be served separately, and could be uniquely identified through its properties as the same instance seen in the SamplingPoint.
  130. Portrayal complex features (SF0)
  131. ````````````````````````````````
  132. Portrayal schemas are standardized schemas with flat attributes, also known as simple feature level 0 (SF0). Because a community schema is still required (e.g. GeoSciML-Portrayal), app-schema plugin is still used to map the database columns to the attributes.
  133. * :doc:`WFS CSV output format <../../services/wfs/outputformats>` is supported for complex features with portrayal schemas. At the moment, propertyName selection is not yet supported with csv outputFormat, so it always returns the full set of attributes.
  134. * Complex features with nesting and multi-valued properties are not supported with :doc:`WFS CSV output format <../../services/wfs/outputformats>`.