4.1 LandCoverObject

LandCoverObject

LandCoverObject is associated to another feature type, LandCoverClass, which will be included in the same mapping file (LandCoverObject_mapping.xml). 
The first step is building the well-known workspace directories/files structure for app-schema:


The content of all files is trivial except for the LandCoverObject_mapping.xml

The first step is setting all the namespaces that will be used:

    <namespaces>
        <Namespace>
            <prefix>lcb</prefix>
            <uri>http://inspire.jrc.ec.europa.eu/schemas/lcb/2.0</uri>
        </Namespace>
        <Namespace>
            <prefix>base</prefix>
            <uri>urn:x-inspire:specification:gmlas:BaseTypes:3.2</uri>
        </Namespace>
        <Namespace>
            <prefix>xlink</prefix>
            <uri>http://www.w3.org/1999/xlink</uri>
        </Namespace>
        <Namespace>
            <prefix>xsi</prefix>
            <uri>http://www.w3.org/2001/XMLSchema-instance</uri>
        </Namespace>
    </namespaces>

And creating the correspondant workspaces (check http://docs.geoserver.org/stable/en/user/data/app-schema/secondary-namespaces.html):

Next step is setting the data sources. As said before, there are two data sources for Land Cover: a Shapefile and a database with some tables:

    <sourceDataStores>
        <DataStore>
            <id>shpLandCover</id>
            <parameters>
                <Parameter>
                    <name>url</name>
                    <value>
                        file:../../../data/tutorial/Land_Cover.shp
                    </value>
                </Parameter>
                <Parameter>
                    <name>memory mapped buffer</name>
                    <value>false</value>
                </Parameter>
                <Parameter>
                    <name>create spatial index</name>
                    <value>true</value>
                </Parameter>
                <Parameter>
                    <name>charset</name>
                    <value>ISO-8859-1</value>
                </Parameter>
            </parameters>
        </DataStore>
        
    <!-- 
            Using Property Interpolation: properties are loaded from "WEB-INF/classes/app-schema.properties"
        -->
        <DataStore>
            <id>bd_postgis</id>
            <parameters>
                <Parameter>
                    <name>dbtype</name>
                    <value>postgis</value>
                </Parameter>
                 <Parameter>
                    <name>host</name>
                    <value>${pg.hostname}</value>
                </Parameter>
                <Parameter>
                    <name>port</name>
                    <value>${pg.port}</value>
                </Parameter>
                <Parameter>
                    <name>database</name>
                    <value>${pg.dbname}</value>
                </Parameter>
                <Parameter>
                    <name>user</name>
                    <value>${pg.username}</value>
                </Parameter>
                <Parameter>
                    <name>passwd</name>
                    <value>${pg.pwd}</value>
                </Parameter>
                <Parameter>
                    <name>Expose primary keys</name>
                    <value>true</value>
                </Parameter>
            </parameters>
        </DataStore>
    </sourceDataStores>

Next step is defining the target types which, in this case, reside in an application schema called "LandCoverBase.xsd". This schema isn't directly available on-line on INSPIRE's site. It's only available as part of a ZIP file with the rest of the INSPIRE application schemas (http://inspire.jrc.ec.europa.eu/index.cfm/pageid/2/list/datamodels). 
We have published this schemas in our own server at: http://${server.ip}/datos/inspire_data_model/xsds/  (we make use of the property interpolation)

    <targetTypes>
        <FeatureType>
            <schemaUri>
                http://${server.ip}/datos/inspire_data_model/xsds/LandCoverBase.xsd
            </schemaUri>
        </FeatureType>
    </targetTypes>

Now comes the hardest part, the type mappings. The first feature type to be mapped is going to be the lcb:LandCoverObject. The main source for this type will be the Shapefile:

<FeatureTypeMapping>
    <sourceDataStore>
        shpLandCover
    </sourceDataStore>
    <sourceType>
        Land_Cover
    </sourceType>
    <targetElement>
        lcb:LandCoverObject
    </targetElement>

The first attribute to be set is the gml:id of the feature. Every feature type in INSPIRE has an attribute called "inspireid" which is composed of a namespace and a local id. We will use the same values to compose the "gml:id" property:

<AttributeMapping>
    <targetAttribute>
        lcb:LandCoverObject
    </targetAttribute>
    <idExpression>
        <OCQL>
            strConcat('Gijon.LC.LandCoverObject.', id)
        </OCQL>
    </idExpression>
</AttributeMapping>

<AttributeMapping>
    <targetAttribute>
        lcb:inspireId/base:Identifier/base:localId
    </targetAttribute>
    <sourceExpression>
        <OCQL>
            id
        </OCQL>
    </sourceExpression>
</AttributeMapping>

<AttributeMapping>
    <targetAttribute>
            lcb:inspireId/base:Identifier/base:namespace
    </targetAttribute>
    <sourceExpression>
        <OCQL>
            'Gijon.LC.LandCoverObject'
        </OCQL>
    </sourceExpression>
</AttributeMapping>

The next attribute is the "lcb:classificationValue" which is of type "lcb:LandCoverClass". This complex feature type will be mapped later in the same file, but we can define now the link between them using the CORINEClas column of the Shapefile and the valueId attribute of lcbLandCoverClass.
                
 <AttributeMapping>
    <targetAttribute>
        lcb:classificationValue
    </targetAttribute>
    <sourceExpression>
           <OCQL>CORINEClas</OCQL>
           <linkElement>lcb:LandCoverClass</linkElement>
           <linkField>lcb:valueId</linkField>
       </sourceExpression>
 </AttributeMapping>

Next attribute is "lcb:ClassificationMosaic". It's used to represent polygons that have more than one class, each one with a percentage of presence (i.e. 90% coniferous forest, 10% Pastures). In our case each polygon has only one class, so this attribute will allways be null:

    <AttributeMapping>
            <targetAttribute>
                lcb:classificationMocaic
            </targetAttribute>
            <ClientProperty>
                <name>xsi:nil</name>
                <value>true</value>                        
            </ClientProperty>
    </AttributeMapping>

Something similar happens with attribute "lcb:parameterDescription". It stores the landscape elements that define the land cover of the polygon. There's no information about it, so it will also be null:

    <AttributeMapping>
        <targetAttribute>
            lcb:parameterDescription
        </targetAttribute>
        <ClientProperty>
            <name>xsi:nil</name>
            <value>true</value>                        
        </ClientProperty>
    </AttributeMapping>

The last attribute that will be mapped is the "lcb:beginLifespanVersion". There's no source for such information, so it will be a constant date.
                
    <AttributeMapping>
            <targetAttribute>
                lcb:beginLifespanVersion
            </targetAttribute>
            <sourceExpression>
                <OCQL>
                    '2011-01-01'
                </OCQL>
            </sourceExpression>
    </AttributeMapping>

LandCoverClass

The lcb:LandCoverObject is complete, but the data type for the lcb:classificationValue, lcb:LandCoverClass, isn't mapped yet. The source data for this type is the database table "lc_categories".

    <FeatureTypeMapping>
        <sourceDataStore>
            bd_postgis
        </sourceDataStore>
        <sourceType>
            lc_categories
        </sourceType>
        <targetElement>
            lcb:LandCoverClass
        </targetElement>

The first attribute to be set is the gml:id of the LandCoverClass which is composed as a namespace plus the id read from the table.

<attributeMappings>
    <AttributeMapping>
        <targetAttribute>
            lcb:LandCoverClass
        </targetAttribute>
        <idExpression>
            <OCQL>
                strConcat('Gijon.LC.LandCoverClass.', id)
            </OCQL>
        </idExpression>
    </AttributeMapping>

The lcb:valueId and lcb:value (the code and the textual description of the class) are also read from the correspondant fields of the database:

    <AttributeMapping>
        <targetAttribute>
            lcb:valueId
        </targetAttribute>
        <sourceExpression>
            <OCQL>
                id_class
            </OCQL>
        </sourceExpression>
    </AttributeMapping>
    <AttributeMapping>
        <targetAttribute>
            lcb:value
        </targetAttribute>
        <sourceExpression>
            <OCQL>
                descr_en
            </OCQL>
        </sourceExpression>
    </AttributeMapping>

The data for the attribute lcb:observationDate is not available. Its value will be a known date when the data was developed. 

    <AttributeMapping>
        <targetAttribute>
            lcb:observationDate
        </targetAttribute>
        <sourceExpression>
            <OCQL>
                '2008-09-01'
            </OCQL>
        </sourceExpression>
    </AttributeMapping>


The last attribute of the lcb:LandCoverClass is lcb:linkedClassificationSystem which is a reference to the classification system this class belongs to:

    <AttributeMapping>
        <targetAttribute>
            lcb:linkedClassificationSystem
        </targetAttribute>
        <ClientProperty>
            <name>xlink:href</name>
            <value>
                strConCat('http://${server.ip}:${server.port}/geoserver/wfs?request=GetFeature&amp;typeName=lcb:ClasssificationSystem#Gijon.LC.ClassificationSystem.',id_lc_class_system)
            </value>
        </ClientProperty>
    </AttributeMapping>

The complete code of the mapping file is:

<?xml version="1.0" encoding="UTF-8"?>
<as:AppSchemaDataAccess xmlns:as="http://www.geotools.org/app-schema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.geotools.org/app-schema AppSchemaDataAccess.xsd">
    <namespaces>
        <Namespace>
            <prefix>lcb</prefix>
            <uri>
                http://inspire.jrc.ec.europa.eu/schemas/lcb/2.0
            </uri>
        </Namespace>
        <Namespace>
            <prefix>base</prefix>
            <uri>
                urn:x-inspire:specification:gmlas:BaseTypes:3.2
            </uri>
        </Namespace>
        <Namespace>
            <prefix>xlink</prefix>
            <uri>http://www.w3.org/1999/xlink</uri>
        </Namespace>
        
        <Namespace>
            <prefix>xsi</prefix>
            <uri>http://www.w3.org/2001/XMLSchema-instance</uri>
        </Namespace>
    </namespaces>
    <sourceDataStores>
        <DataStore>
            <id>shpLandCover</id>
            <parameters>
                <Parameter>
                    <name>url</name>
                    <value>
                        file:../../../data/tutorial/Land_Cover.shp
                    </value>
                </Parameter>
                <Parameter>
                    <name>memory mapped buffer</name>
                    <value>false</value>
                </Parameter>
                <Parameter>
                    <name>create spatial index</name>
                    <value>true</value>
                </Parameter>
                <Parameter>
                    <name>charset</name>
                    <value>ISO-8859-1</value>
                </Parameter>
            </parameters>
        </DataStore>
        
        <DataStore>
            <id>bd_postgis</id>
            <parameters>
                <Parameter>
                    <name>dbtype</name>
                    <value>postgis</value>
                </Parameter>

                <!-- using Property Interpolation: properties are loaded from "WEB-INF/classes/app-schema.properties"
                -->                
                <Parameter>
                    <name>host</name>
                    <value>${pg.hostname}</value>
                </Parameter>
                <Parameter>
                    <name>port</name>
                    <value>${pg.port}</value>
                </Parameter>
                <Parameter>
                    <name>database</name>
                    <value>${pg.dbname}</value>
                </Parameter>
                <Parameter>
                    <name>user</name>
                    <value>${pg.username}</value>
                </Parameter>
                <Parameter>
                    <name>passwd</name>
                    <value>${pg.pwd}</value>
                </Parameter>

                <Parameter>
                    <name>Expose primary keys</name>
                    <value>true</value>
                </Parameter>
            </parameters>
        </DataStore>
    </sourceDataStores>

    <targetTypes>
        <FeatureType>
            <schemaUri>
                http://${server.ip}/datos/inspire_data_model/xsds/LandCoverBase.xsd
            </schemaUri>
        </FeatureType>
    </targetTypes>

    <typeMappings>
        <FeatureTypeMapping>
            <sourceDataStore>
                shpLandCover
            </sourceDataStore>
            <sourceType>
                Land_Cover
            </sourceType>
            <targetElement>
                lcb:LandCoverObject
            </targetElement>
            <attributeMappings>

                <AttributeMapping>
                    <targetAttribute>
                        lcb:LandCoverObject
                    </targetAttribute>
                    <idExpression>
                        <OCQL>strConcat('Gijon.LC.LandCoverObject.', id)</OCQL>
                    </idExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>
                        lcb:inspireId/base:Identifier/base:localId
                    </targetAttribute>
                    <sourceExpression>
                        <OCQL>
                            <!-- inspireID -->
                            id
                        </OCQL>
                    </sourceExpression>
                </AttributeMapping>
                <AttributeMapping>
                        <targetAttribute>
                            lcb:inspireId/base:Identifier/base:namespace
                        </targetAttribute>
                        <sourceExpression>
                            <OCQL>
                                'Gijon.LC.LandCoverObject'
                            </OCQL>
                        </sourceExpression>
                </AttributeMapping>
                
                 <AttributeMapping>
                        <targetAttribute>
                            lcb:classificationValue
                        </targetAttribute>
                        <sourceExpression>
                            <OCQL>CORINEClas</OCQL>
                            <linkElement>lcb:LandCoverClass</linkElement>
                            <linkField>lcb:valueId</linkField>
                        </sourceExpression>
                </AttributeMapping>
                
                <!-- El classification Mosaic sera siempre NULO por el momento -->
                 <AttributeMapping>
                        <targetAttribute>
                            lcb:classificationMocaic
                        </targetAttribute>
                        <ClientProperty>
                            <name>xsi:nil</name>
                            <value>true</value>                        
                        </ClientProperty>
                </AttributeMapping>
                
                <AttributeMapping>
                    <targetAttribute>
                        lcb:parameterDescription
                    </targetAttribute>
                    <ClientProperty>
                        <name>xsi:nil</name>
                        <value>true</value>                        
                    </ClientProperty>
                </AttributeMapping>
                
                <AttributeMapping>
                        <targetAttribute>
                            lcb:beginLifespanVersion
                        </targetAttribute>
                        <sourceExpression>
                            <OCQL>
                                '2011-01-01'
                            </OCQL>
                        </sourceExpression>
                </AttributeMapping>
            </attributeMappings>
        </FeatureTypeMapping>

        <FeatureTypeMapping>
            <sourceDataStore>
                bd_postgis
            </sourceDataStore>
            <sourceType>
                lc_categories
            </sourceType>
            <targetElement>
                lcb:LandCoverClass
            </targetElement>
            <attributeMappings>
                <AttributeMapping>
                    <targetAttribute>
                        lcb:LandCoverClass
                    </targetAttribute>
                    <idExpression>
                        <OCQL>
                            strConcat('Gijon.LC.LandCoverClass.', id)
                        </OCQL>
                    </idExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>
                        lcb:valueId
                    </targetAttribute>
                    <sourceExpression>
                        <OCQL>
                            id_class
                        </OCQL>
                    </sourceExpression>
                </AttributeMapping>
                <AttributeMapping>
                        <targetAttribute>
                            lcb:value
                        </targetAttribute>
                        <sourceExpression>
                            <OCQL>
                                descr_en
                            </OCQL>
                        </sourceExpression>
                </AttributeMapping>
                <AttributeMapping>
                    <targetAttribute>
                        lcb:observationDate
                    </targetAttribute>
                    <sourceExpression>
                        <OCQL>
                            '2008-09-01'
                        </OCQL>
                    </sourceExpression>
                </AttributeMapping>                
                <AttributeMapping>
                    <targetAttribute>
                        lcb:linkedClassificationSystem
                    </targetAttribute>
                    <ClientProperty>
                        <name>xlink:href</name>
                        <value>
                                strConCat('http://${server.ip}:${server.port}/geoserver/wfs?request=GetFeature&amp;typeName=lcb:ClasssificationSystem#Gijon.LC.ClassificationSystem.',id_lc_class_system)
                        </value>
                    </ClientProperty>
                </AttributeMapping>
            </attributeMappings>
        </FeatureTypeMapping>
    </typeMappings>
</as:AppSchemaDataAccess>
  



Comments