schemamapping.rst 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. .. _wfs_schema_mapping:
  2. WFS schema mapping
  3. ==================
  4. One of the functions of the GeoServer WFS is to automatically map the internal schema of a dataset to a feature type schema. This mapping is performed according to the following rules:
  5. * The name of the feature element maps to the name of the dataset.
  6. * The name of the feature type maps to the name of the dataset with the string "Type" appended to it.
  7. * The name of each attribute of the dataset maps to the name of an element particle contained in the feature type.
  8. * The type of each attribute of the dataset maps to the appropriate XML schema type (``xsd:int``, ``xsd:double``, and so on).
  9. For example, a dataset has the following schema::
  10. myDataset(intProperty:Integer, stringProperty:String, floatProperty:Float, geometry:Point)
  11. This schema would be mapped to the following XML schema, available via
  12. a ``DescribeFeatureType`` request for the ``topp:myDataset`` type:
  13. .. code-block:: xml
  14. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  15. xmlns:gml="http://www.opengis.net/gml"
  16. xmlns:topp="http://www.openplans.org/topp"
  17. targetNamespace="http://www.openplans.org/topp"
  18. elementFormDefault="qualified">
  19. <xsd:import namespace="http://www.opengis.net/gml"
  20. schemaLocation="http://localhost:8080/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>
  21. <xsd:complexType name="myDatasetType">
  22. <xsd:complexContent>
  23. <xsd:extension base="gml:AbstractFeatureType">
  24. <xsd:sequence>
  25. <xsd:element maxOccurs="1" minOccurs="0" name="intProperty" nillable="true" type="xsd:int"/>
  26. <xsd:element maxOccurs="1" minOccurs="0" name="stringProperty" nillable="true" type="xsd:string"/>
  27. <xsd:element maxOccurs="1" minOccurs="0" name="floatProperty" nillable="true" type="xsd:double"/>
  28. <xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:PointPropertyType"/>
  29. </xsd:sequence>
  30. </xsd:extension>
  31. </xsd:complexContent>
  32. </xsd:complexType>
  33. <xsd:element name="myDataset" substitutionGroup="gml:_Feature" type="topp:myDatasetType"/>
  34. </xsd:schema>
  35. Schema customization
  36. --------------------
  37. The GeoServer WFS supports a limited amount of schema output customization. A custom schema may be useful for the following:
  38. * Limiting the attributes which are exposed in the feature type schema
  39. * :ref:`Changing <wfs_schema_type_changing>` the types of attributes in the schema
  40. * Changing the structure of the schema (for example, changing the base feature type)
  41. For example, it may be useful to limit the exposed attributes in the example dataset described above. Start by retrieving the default output as a benchmark of the complete schema. With the feature type schema listed above, the ``GetFeature`` request would be as follows:
  42. .. code-block:: xml
  43. <topp:myDataset gml:id="myDataset.1">
  44. <topp:intProperty>1</topp:intProperty>
  45. <topp:stringProperty>one</topp:stringProperty>
  46. <topp:floatProperty>1.1</topp:floatProperty>
  47. <topp:geometry>
  48. <gml:Point srsName="urn:x-ogc:def:crs:EPSG:4326">
  49. <gml:pos>1.0 1.0</gml:pos>
  50. </gml:Point>
  51. </topp:geometry>
  52. </topp:myDataset>
  53. To remove ``floatProperty`` from the list of attributes, the following steps would be required:
  54. #. The original schema is modified to remove the ``floatProperty``, resulting in the following type definition:
  55. .. code-block:: xml
  56. <xsd:complexType name="myDatasetType">
  57. <xsd:complexContent>
  58. <xsd:extension base="gml:AbstractFeatureType">
  59. <xsd:sequence>
  60. <xsd:element maxOccurs="1" minOccurs="0" name="intProperty" nillable="true" type="xsd:int"/>
  61. <xsd:element maxOccurs="1" minOccurs="0" name="stringProperty" nillable="true" type="xsd:string"/>
  62. <!-- remove the floatProperty element
  63. <xsd:element maxOccurs="1" minOccurs="0" name="floatProperty" nillable="true" type="xsd:double"/>
  64. -->
  65. <xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:PointPropertyType"/>
  66. </xsd:sequence>
  67. </xsd:extension>
  68. </xsd:complexContent>
  69. </xsd:complexType>
  70. #. The modification is saved in a file named ``schema.xsd``.
  71. #. The ``schema.xsd`` file is copied into the feature type directory for the
  72. ``topp:myDataset`` which is::
  73. $GEOSERVER_DATA_DIR/workspaces/<workspace>/<datastore>/myDataset/
  74. where ``<workspace>`` is the name of the workspace containing your data store and ``<datastore>`` is the name of the data store which contains ``myDataset``
  75. The modified schema will only be available to GeoServer when the configuration is reloaded or GeoServer is restarted.
  76. A subsequent ``DescribeFeatureType`` request for ``topp:myDataset`` confirms the ``floatProperty`` element is absent:
  77. .. code-block:: xml
  78. <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  79. xmlns:gml="http://www.opengis.net/gml"
  80. xmlns:topp="http://www.openplans.org/topp"
  81. targetNamespace="http://www.openplans.org/topp"
  82. elementFormDefault="qualified">
  83. <xsd:import namespace="http://www.opengis.net/gml"
  84. schemaLocation="http://localhost:8080/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>
  85. <xsd:complexType name="myDatasetType">
  86. <xsd:complexContent>
  87. <xsd:extension base="gml:AbstractFeatureType">
  88. <xsd:sequence>
  89. <xsd:element maxOccurs="1" minOccurs="0" name="intProperty" nillable="true" type="xsd:int"/>
  90. <xsd:element maxOccurs="1" minOccurs="0" name="stringProperty" nillable="true" type="xsd:string"/>
  91. <xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:PointPropertyType"/>
  92. </xsd:sequence>
  93. </xsd:extension>
  94. </xsd:complexContent>
  95. </xsd:complexType>
  96. <xsd:element name="myDataset" substitutionGroup="gml:_Feature" type="topp:myDatasetType"/>
  97. </xsd:schema>
  98. A ``GetFeature`` request will now return features that don't include the ``floatProperty`` attribute:
  99. .. code-block:: xml
  100. <topp:myDataset gml:id="myDataset.1">
  101. <topp:intProperty>1</topp:intProperty>
  102. <topp:stringProperty>one</topp:stringProperty>
  103. <topp:geometry>
  104. <gml:Point srsName="urn:x-ogc:def:crs:EPSG:4326">
  105. <gml:pos>1.0 1.0</gml:pos>
  106. </gml:Point>
  107. </topp:geometry>
  108. </topp:myDataset>
  109. .. _wfs_schema_type_changing:
  110. Type changing
  111. -------------
  112. Schema customization may be used to perform some **type changing**, although this is limited by the fact that a changed type must be in the same *domain* as the original type. For example, integer types must be changed to integer types, temporal types to temporal types, and so on.
  113. The most common change type requirement is for geometry attributes. In many cases the underlying data set does not have the necessary metadata to report the specific geometry type of a geometry attribute. The automatic schema mapping would result in an element definition similar to the following:
  114. .. code-block:: xml
  115. <xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:GeometryPropertyType"/>
  116. However if the specific type of the geometry is known, the element definition above could be altered. For point geometry, the element definition could be altered to :
  117. .. code-block:: xml
  118. <xsd:element maxOccurs="1" minOccurs="0" name="geometry" nillable="true" type="gml:PointPropertyType"/>