教程

本教程演示如何使用应用程序模式插件和来自两个属性文件的数据配置两个复杂的功能类型。

地理坐标系

此示例使用 Geoscience Markup Language (GeoSciML) 2.0 ,GML 3.1应用程序架构:

"GeoSciML is an application schema that specifies a set of feature-types and supporting structures for information used in the solid-earth geosciences."

本教程定义了两种特征类型:

  1. gsml:GeologicUnit 它描述了“地球上的物质体”。

  2. gsml:MappedFeature 在本例中,它描述了特征在地图上的表示。 gsml:GeologicUnit .

因为一个人 gsml:GeologicUnit 可以在地球表面的几个不同的位置观察到,它可以有一个多值 gsml:occurrence 属性,每个属性都是 gsml:MappedFeature .

安装

  • 照常安装geoserver。

  • 安装应用程序架构插件 geoserver-*-app-schema-plugin.zip

    • 将JAR文件放入 WEB-INF/lib .

    • 这个 tutorial 文件夹包含用于本教程的地理服务器配置(数据目录)。

      • 替换现有的 data 目录与教程数据目录,

      • 或编辑 WEB-INF/web.xml 设置 GEOSERVER_DATA_DIR 指向教程数据目录。(请确保取消对设置 GEOSERVER_DATA_DIR

  • 执行servlet容器所需的任何配置,然后启动servlet。例如,如果您使用的是Tomcat,请在 server.xml 然后重新启动Tomcat。

  • geoserver第一次启动教程配置时,它将下载所需的所有模式(xsd)文件,并将它们存储在 app-schema-cache 数据目录中的文件夹。 您必须连接到Internet才能工作。

datastore.xml

每个数据存储配置文件 datastore.xml 指定映射文件的位置并触发将其作为应用程序架构数据源加载。此文件不应与映射文件中指定的源数据存储区混淆。

为了 gsml_GeologicUnit 文件是 workspaces/gsml/gsml_GeologicUnit/datastore.xml ::

<dataStore>
    <id>gsml_GeologicUnit_datastore</id>
    <name>gsml_GeologicUnit</name>
    <enabled>true</enabled>
    <workspace>
        <id>gsml_workspace</id>
    </workspace>
    <connectionParameters>
        <entry key="namespace">urn:cgi:xmlns:CGI:GeoSciML:2.0</entry>
        <entry key="url">file:workspaces/gsml/gsml_GeologicUnit/gsml_GeologicUnit.xml</entry>
        <entry key="dbtype">app-schema</entry>
    </connectionParameters>
</dataStore>

为了 gsml:MappedFeature 文件是 workspaces/gsml/gsml_MappedFeature/datastore.xml ::

<dataStore>
    <id>gsml_MappedFeature_datastore</id>
    <name>gsml_MappedFeature</name>
    <enabled>true</enabled>
    <workspace>
        <id>gsml_workspace</id>
    </workspace>
    <connectionParameters>
        <entry key="namespace">urn:cgi:xmlns:CGI:GeoSciML:2.0</entry>
        <entry key="url">file:workspaces/gsml/gsml_MappedFeature/gsml_MappedFeature.xml</entry>
        <entry key="dbtype">app-schema</entry>
    </connectionParameters>
</dataStore>

备注

确保 entry 元素。

映射文件

在映射文件中配置应用程序架构功能类型:

  • workspaces/gsml/gsml_GeologicUnit/gsml_GeologicUnit.xml

  • workspaces/gsml/gsml_MappedFeature/gsml_MappedFeature.xml

命名空间

每个映射文件都包含命名空间前缀定义::

<Namespace>
    <prefix>gml</prefix>
    <uri>http://www.opengis.net/gml</uri>
</Namespace>
<Namespace>
    <prefix>gsml</prefix>
    <uri>urn:cgi:xmlns:CGI:GeoSciML:2.0</uri>
</Namespace>
<Namespace>
    <prefix>xlink</prefix>
    <uri>http://www.w3.org/1999/xlink</uri>
</Namespace>

只需要声明映射文件中使用的那些命名空间前缀,因此 gsml:GeologicUnit 有更少的。

源数据存储

本教程的数据包含在两个属性文件中:

  • workspaces/gsml/gsml_GeologicUnit/gsml_GeologicUnit.properties

  • workspaces/gsml/gsml_MappedFeature/gsml_MappedFeature.properties

Java属性 描述属性文件的格式。

对于本例,每个功能类型使用相同的源数据存储配置。这个 directory 参数指示源数据包含在按其功能类型命名的属性文件中,与对应的映射文件位于同一目录中::

<sourceDataStores>
     <DataStore>
         <id>datastore</id>
         <parameters>
             <Parameter>
                 <name>directory</name>
                 <value>file:./</value>
             </Parameter>
         </parameters>
     </DataStore>
 </sourceDataStores>

数据存储 有关如何使用其他类型的数据存储(如数据库)的说明。

目标类型

这两种功能类型都由相同的XML模式(geosciml 2.0的顶级模式)定义。这在 targetTypes 第节。输出功能的类型在中定义 targetElementtypeMapping 以下部分:

<targetTypes>
    <FeatureType>
        <schemaUri>http://www.geosciml.org/geosciml/2.0/xsd/geosciml.xsd</schemaUri>
    </FeatureType>
</targetTypes>

在这种情况下,模式是发布的,但是由于OASISXML目录用于模式解析,因此可以根据需要使用目录中的私有或修改的模式。

映射

这个 typeMappings 元素以配置元素开始。从映射文件 gsml:GeologicUnit ::

<typeMappings>
    <FeatureTypeMapping>
        <sourceDataStore>datastore</sourceDataStore>
        <sourceType>gsml_GeologicUnit</sourceType>
        <targetElement>gsml:GeologicUnit</targetElement>
  • 映射开始于 sourceDataStore ,它提供上面使用的任意标识符来命名 sourceDataStores 部分。

  • sourceType 提供源简单功能类型的名称。在这种情况下,它是简单的功能类型 gsml_GeologicUnit ,源于文件的行 gsml_GeologicUnit.properties 与映射文件在同一目录中。

  • 使用数据库时 sourceType 是表或视图的名称。数据库标识符对于Postgis必须是小写,对于OracleSpace必须是大写。

  • targetElement 是输出复杂功能类型的名称。

gml:id映射

第一个映射设置 gml:id 要成为源属性文件中指定的功能ID::

<AttributeMapping>
    <targetAttribute>
        gsml:GeologicUnit
    </targetAttribute>
    <idExpression>
        <OCQL>ID</OCQL>
    </idExpression>
</AttributeMapping>
  • targetAttribute 是应用映射的元素的xpath,在本例中是顶级功能类型。

  • idExpression 是只能用于设置 gml:id 在一个功能上。如果任何字段或cql表达式的计算结果为 NCName .

普通映射

大多数映射都由目标和源组成。这是一个来自 gsml:GeologicUnit ::

<AttributeMapping>
    <targetAttribute>
        gml:description
        </targetAttribute>
    <sourceExpression>
        <OCQL>DESCRIPTION</OCQL>
    </sourceExpression>
</AttributeMapping>
  • 在这种情况下, gml:description 只是 DESCRIPTION 属性文件中的字段。

  • 对于数据库,字段名是列的名称(表/视图设置在 sourceType 以上)。数据库标识符对于Postgis必须是小写,对于OracleSpace必须是大写。

  • cql表达式可用于计算内容。请小心,因为对cql计算值的查询会阻止有效的SQL查询的构造。

  • 源表达式可以是单引号的cql文本。

客户端属性

除了元素内容之外,映射还可以设置一个或多个“客户机属性”(XML属性)。这是一个来自 gsml:MappedFeature ::

<AttributeMapping>
    <targetAttribute>
        gsml:specification
    </targetAttribute>
    <ClientProperty>
        <name>xlink:href</name>
        <value>GU_URN</value>
    </ClientProperty>
</AttributeMapping>
  • 此映射会留下 gsml:specification 元素为空,但设置 xlink:href 属性的值 GU_URN 字段。

  • 倍数 ClientProperty 可以设置映射。

在本例中,从映射到 gsml:GeologicUnit 同时提供元素内容和XML属性:

<AttributeMapping>
    <targetAttribute>
        gml:name[1]
        </targetAttribute>
    <sourceExpression>
        <OCQL>NAME</OCQL>
    </sourceExpression>
    <ClientProperty>
        <name>codeSpace</name>
        <value>'urn:x-test:classifierScheme:TestAuthority:GeologicUnitName'</value>
    </ClientProperty>
</AttributeMapping>
  • 这个 codespace XML属性通过提供cql文本设置为固定值。

  • 有多个映射用于 gml:name 和索引 [1] 意味着这个映射的目标是第一个。

目标属性节点

如果属性的类型是抽象的,则 targetAttributeNode 映射必须用于指定具体类型。此映射必须发生在属性内容的映射之前。

以下是映射文件中的示例 gsml:MappedFeature ::

<AttributeMapping>
    <targetAttribute>gsml:positionalAccuracy</targetAttribute>
    <targetAttributeNode>gsml:CGI_TermValuePropertyType</targetAttributeNode>
</AttributeMapping>
<AttributeMapping>
    <targetAttribute>gsml:positionalAccuracy/gsml:CGI_TermValue/gsml:value</targetAttribute>
    <sourceExpression>
        <OCQL>'urn:ogc:def:nil:OGC:missing'</OCQL>
    </sourceExpression>
    <ClientProperty>
        <name>codeSpace</name>
        <value>'urn:ietf:rfc:2141'</value>
    </ClientProperty>
</AttributeMapping>
  • gsml:positionalAccuracy 属于类型 gsml:CGI_TermValuePropertyType ,这是抽象的,因此必须映射到其具体子类型 gsml:CGI_TermValuePropertyType 用一个 targetAttributeNode 在映射其内容之前进行映射。

  • 这个例子还演示了映射可以应用到嵌套属性的任意深度。对于深度嵌套,这将变得不可管理,在这种情况下,特性链接是首选的。

特征链

在功能链接中,一个功能类型用作封闭功能类型的属性(按值或按引用)::

<AttributeMapping>
    <targetAttribute>
        gsml:occurrence
    </targetAttribute>
    <sourceExpression>
        <OCQL>URN</OCQL>
        <linkElement>gsml:MappedFeature</linkElement>
        <linkField>gml:name[2]</linkField>
    </sourceExpression>
    <isMultiple>true</isMultiple>
</AttributeMapping>
  • 在这种情况下,从映射到 gsml:GeologicUnit ,我们为其指定映射 gsml:occurrence .

  • 这个 URN 源的字段 gsml_GeologicUnit 简单的功能是用作“外键”,它映射到第二个 gml:name 在每个 gsml:MappedFeature .

  • 每个 gsml:MappedFeature 具有 gml:name[2] 等于 URNgsml:GeologicUnit 在建工程包括 gsml:occurrence 性质 gsml:GeologicUnit (按值)。

WFS响应

当geoserver运行时,在Web浏览器中测试应用程序模式WFS。如果geoserver正在监听 localhost:8080 可以使用以下链接查询两种功能类型:

GSML:地质学家

已使用功能链接构造多值属性 gsml:occurrence 属于 gsml:GeologicUnit .此属性是 gsml:MappedFeature .WFS对 gsml:GeologicUnit 将两种功能类型的输出组合为一个响应。第一个 gsml:GeologicUnit 有两个 gsml:occurrence 属性,而第二个属性有一个。特征实例之间的关系是数据驱动的。

由于教程配置中的映射文件不包含这些功能类型的所有强制属性的属性映射,因此WFS响应不是 schema-valid 对照geosciml 2.0模式。通过向映射文件添加更多的属性映射,可以实现模式有效性。

备注

这些功能类型是根据GML 3.1(WFS 1.1.0的默认值)定义的;其他GML版本将不起作用。

警告

Web界面尚不支持应用程序架构存储或层管理。

确认

gsml_GeologicUnit.propertiesgsml_MappedFeature.properties 来源于澳大利亚维多利亚初级工业部提供的数据。为了本教程的目的,这些数据已经被修改到没有实际意义的程度。