API4INSPIRE

Documentation of APIs for INSPIRE

Linking Features and Multiple xlinks

Usually, feature chaining is used to include additional features with a multiplicity above one within a feature. However, this functionality can also be used to provide a list of xlinks referencing a related feature or alternative resource such as a codelist. As with Feature Chaining, two database tables are required:

In our example, links to the featureType OtherFT (data contained in ex_mainft) are provided by xlinks within the ex:other attribute of the MainFT (data contained in ex_otherft), with a cardinality of 0..* . The association table ex_main_other_as provides the links between between the tables, (2 attributes, mainid and otherid).

The header section of the FeatureTypeMapping is the same as for normal chained features, described in the previous section in more detail. In this example, the mappingName _main_to_other is provided. The association table ex_main_other_as providing information on the link between MainFT and OtherFT is provided in the sourceType element. The targetElement is the featureType being linked, in this case OtherFT.

Within the attributeMappings, two AttributeMapping blocks must be provided as follows:

<FeatureTypeMapping>
  <mappingName>_main_to_other</mappingName>
  <sourceDataStore>idDataStoreInsp</sourceDataStore>
  <sourceType>ex_main_other_as</sourceType>
  <targetElement>ex:OtherFT</targetElement>
  <attributeMappings>
	<encodeIfEmpty>true</encodeIfEmpty>
	<AttributeMapping>
	  <targetAttribute>FEATURE_LINK</targetAttribute>
	  <!-- FK in linked table -->
	  <sourceExpression>
		<OCQL>mainid</OCQL>
	  </sourceExpression>
	</AttributeMapping>
	<AttributeMapping>
	  <targetAttribute>ex:other</targetAttribute>
	</AttributeMapping>
  </attributeMappings>
</FeatureTypeMapping>	

Once the link has been set up as described above, it only needs to be inserted as a AttributeMapping into the mapping of the MainFT as as shown below. The targetAttribute is the name of the XML element as in basic feature mapping, in this example ex:other. The elements encodeIfEmpty and isMultiple should be set to true.

In the sourceExpression the linkage to the chained dataType is provided via the following elements:

In the ClientProperty, we provide the XML attribute to be mapped to, as well as the content of this attribute as follows:

<AttributeMapping>
  <targetAttribute>ex:other</targetAttribute>
  <encodeIfEmpty>true</encodeIfEmpty>
  <sourceExpression>
    <!-- PK in main table, what the FK in the linked table links to -->
    <OCQL>gmlid</OCQL>
    <linkElement>_main_to_other</linkElement>
    <linkField>FEATURE_LINK</linkField>
  </sourceExpression>
  <isMultiple>true</isMultiple>
  <ClientProperty>
    <name>xlink:href</name>
    <!-- here we can now access fields from the linked table. -->
    <!-- otherid is from the table ex_main_other_as referenced in the FeatureTypeMapping _main_to_other -->
    <value>strconcat(strconcat('https://service.datacove.eu/geoserver/ogc/features/collections/ex:OtherFT/items/', otherid), '?f=application%2Fgeo%2Bjson')</value>
  </ClientProperty>
</AttributeMapping>					

In most cases where we use the string “FEATURE_LINK”, this simple string suffices. However, there are cases where different types are nested under the same element. In those cases, the FEATURE_LINK can be formulated as an array, the first instance as “FEATURE_LINK[1]”, the second as “FEATURE_LINK[2]”. Note that the index must be included in both mentions of FEATURE_LINK (so both in the main as well as in the nested feature mapping)