将矢量数据发布到OGC API-功能

OGC API - Features 为矢量数据提供地理空间数据访问功能。

要向pygeoapi添加向量数据,可以使用中的数据集示例 配置 作为基线,并进行相应修改。

提供者

下面列出了pygeoapi核心特性提供程序,以及支持的查询参数列表。

供应商

特性过滤器/显示

结果类型

口技

日期时间

肮脏的

SkipGeometry

CQL

交易记录

CRS

CSV

✅/✅

结果/命中

Elasticsearch

✅/✅

结果/命中

ERDDAP Tabledap Service

❌/❌

结果/命中

ESRI Feature Service

✅/✅

结果/命中

GeoJSON

✅/✅

结果/命中

MongoDB

✅/❌

结果

OGR

✅/❌

结果/命中

PostgreSQL

✅/✅

结果/命中

SQLiteGPKG

✅/❌

结果/命中

SensorThings API

✅/✅

结果/命中

Socrata

✅/✅

结果/命中

备注

  • 支持的所有提供程序 bbox 还支持 bbox-crs 参数。 bbox-crs 是在比利亚皮核心内处理的。

  • 所有提供程序都支持 crs 参数重新投影(转换)响应数据。一些应用程序,如postgresql和ogr,执行本机操作:‘✅n’。

连接示例

以下是基于支持的提供程序的具体连接示例。支持 crs 在查询时,需要同时配置受支持的CRS列表和“存储CRS”。另请参阅 CRS支持配置 。当没有配置CRS信息时,假定默认CRS/‘存储CRS’值http://www.opengis.net/def/crs/OGC/1.3/CRS84。即:具有标准GeoJSON中长、后轴排序的WGS84。

CSV

要发布CSV文件,该文件必须包含需要在中指定的x和y几何图形列 geometry 剖面图 provider 定义。

providers:
    - type: feature
      name: CSV
      data: tests/data/obs.csv
      id_field: id
      geometry:
          x_field: long
          y_field: lat
      crs:
          - http://www.opengis.net/def/crs/EPSG/0/28992
          - http://www.opengis.net/def/crs/OGC/1.3/CRS84
          - http://www.opengis.net/def/crs/EPSG/0/4326
      storage_crs: http://www.opengis.net/def/crs/EPSG/0/28992

GeoJSON

要发布GeoJSON文件,该文件必须是有效的GeoJSON FeatureCollection。

providers:
    - type: feature
      name: GeoJSON
      data: tests/data/file.json
      id_field: id

弹性搜索

备注

需要Python包ElasticSearch和ElasticSearch-DSL

备注

支持ElasticSearch 8或更高版本。

要发布Elasticsearch索引,索引中需要以下内容:

  • 索引必须是有效GeoJSON功能的文档

  • 索引映射必须定义GeoJSON geometry 作为一个 geo_shape

providers:
    - type: feature
      name: Elasticsearch
      editable: true|false  # optional, default is false
      data: http://localhost:9200/ne_110m_populated_places_simple
      id_field: geonameid
      time_field: datetimefield

此提供程序支持上表所示的CQL查询。

参见

CQL支持 有关如何使用通用查询语言(CQL)筛选具有特定查询的集合的更多详细信息。

ESRI要素服务

要发布 ESRI Feature ServiceESRI Map Service 在中指定服务图层的URL data 菲尔德。

  • id_field 通常会是 OBJECTIDobjectid ,或 FID

  • 如果地图或要素服务未公开共享, usernamepassword 可以在配置中设置字段以对服务进行身份验证。

providers:
    - type: feature
      name: ESRI
      data: https://sampleserver5.arcgisonline.com/arcgis/rest/services/NYTimes_Covid19Cases_USCounties/MapServer/0
      id_field: objectid
      time_field: date_in_your_device_time_zone # Optional time field
      crs: 4326 # Optional crs (default is EPSG:4326)
      username: username # Optional ArcGIS username
      password: password # Optional ArcGIS password

OGR

备注

需要使用Python包gdal

GDAL/OGR 支持多种空间文件格式,如shapefile、DXF、GPX、KML,也支持WFS等服务。在https://gdal.org/drivers/vector.上阅读完整列表和配置选项其他格式和功能可通过 virtual format 例如,将此驱动程序用于平面数据库文件(CSV)。

OGR提供程序需要安装最新(3+)版本的GDAL。

providers:
    - type: feature
      name: OGR
      data:
        source_type: ESRI Shapefile
        source: tests/data/dutch_addresses_shape_4326/inspireadressen.shp
        source_options:
          ADJUST_GEOM_TYPE: FIRST_SHAPE
        gdal_ogr_options:
          SHPT: POINT
      id_field: fid
      layer: inspireadressen
providers:
    - type: feature
      name: OGR
      data:
        source_type: WFS
        source: WFS:https://geodata.nationaalgeoregister.nl/rdinfo/wfs?
        source_options:
            VERSION: 2.0.0
            OGR_WFS_PAGING_ALLOWED: YES
            OGR_WFS_LOAD_MULTIPLE_LAYER_DEFN: NO
         gdal_ogr_options:
            GDAL_CACHEMAX: 64
            GDAL_HTTP_PROXY: (optional proxy)
            GDAL_PROXY_AUTH: (optional auth for remote WFS)
            CPL_DEBUG: NO
      crs:
        - http://www.opengis.net/def/crs/OGC/1.3/CRS84
        - http://www.opengis.net/def/crs/EPSG/0/4326
        - http://www.opengis.net/def/crs/EPSG/0/4258
        - http://www.opengis.net/def/crs/EPSG/0/28992
      storage_crs: http://www.opengis.net/def/crs/EPSG/0/28992
      id_field: gml_id
      layer: rdinfo:stations
providers:
     - type: feature
       name: OGR
       data:
         source_type: ESRIJSON
         source: https://map.bgs.ac.uk/arcgis/rest/services/GeoIndex_Onshore/boreholes/MapServer/0/query?where=BGS_ID+%3D+BGS_ID&outfields=*&orderByFields=BGS_ID+ASC&f=json
         source_capabilities:
             paging: True
         open_options:
             FEATURE_SERVER_PAGING: YES
         gdal_ogr_options:
             EMPTY_AS_NULL: NO
             GDAL_CACHEMAX: 64
             # GDAL_HTTP_PROXY: (optional proxy)
             # GDAL_PROXY_AUTH: (optional auth for remote WFS)
             CPL_DEBUG: NO
       id_field: BGS_ID
       layer: ESRIJSON
providers:
     - type: feature
       name: OGR
       data:
         source_type: PostgreSQL
         source: "PG: host=127.0.0.1 dbname=test user=postgres password=postgres"
       id_field: osm_id
       layer: osm.hotosm_bdi_waterways # Value follows a 'my_schema.my_table' structure
       geom_field: foo_geom

备注

注:以前的配置参数 source_srstarget_srs 可用于转换/重新投影每个请求的数据。从pygeapi版本0.15.0开始,不再支持这些字段。原因是,pygeapi现在支持按照OGC API功能标准“第2部分”进行CRS处理。 storage_crs :基本上与 source_crs 但要遵守标准(和轴顺序!)应设置为源数据/服务的实际或默认CRS。当忽略默认http://www.opengis.net/def/crs/OGC/1.3/CRS84时(如果假定)。 crs 是受支持的CRSS的数组,如果省略,同样的缺省值也适用。这个 crsbbox-crs 查询参数现在可以使用,并且必须出现在 crs 数组(或应用默认设置)。这个 crs 查询参数的用法如下: http://localhost:5000/collections/foo/items?crs=http%3A%2F%2Fwww.opengis.net%2Fdef%2Fcrs%2FEPSG%2F0%2F28992

MongoDB

备注

需要使用Python包pymongo

备注

支持Mongo 5或更高版本。

MongoDB 是一个功能强大、用途广泛的NoSQL数据库,它提供了许多优势,使其成为许多应用程序的首选。使用MongoDB的主要原因之一是它能够处理大量非结构化数据,这使得它非常适合管理各种数据类型,如文本、地理空间和多媒体数据。此外,MongoDB灵活的文档模型允许轻松的模式演变,使开发人员能够快速迭代并适应不断变化的需求。

GeoJSON MongoDB官方提供支持,因此可以使用以下命令将GeoJSON文件添加到MongoDB

mongoimport --db test -c points --file "path/to/file.geojson" --jsonArray

这里 test 是数据库的名称, points 是目标集合名称。

  • 每个文档必须是具有有效几何图形的GeoJSON要素。

providers:
    - type: feature
      name: MongoDB
      data: mongodb://localhost:27017/testdb
      collection: testplaces

甲骨文

备注

需要使用Python包oracledb

providers:
    - type: feature
      name: OracleDB
      data:
          host: 127.0.0.1
          port: 1521 # defaults to 1521 if not provided
          service_name: XEPDB1
          # sid: XEPDB1
          user: geo_test
          password: geo_test
          # external_auth: wallet
          # tns_name: XEPDB1
          # tns_admin /opt/oracle/client/network/admin
          # init_oracle_client: True

      id_field: id
      table: lakes
      geom_field: geometry
      title_field: name
      # sql_manipulator: tests.test_oracle_provider.SqlManipulator
      # sql_manipulator_options:
      #     foo: bar
      # mandatory_properties:
      # - bbox
      # source_crs: 31287 # defaults to 4326 if not provided
      # target_crs: 31287 # defaults to 4326 if not provided

提供程序支持使用SID或SERVICE_NAME通过主机和端口进行连接。对于TNS命名,必须设置系统环境变量TNS_ADMIN或配置参数TNS_ADMIN。

提供程序支持外部身份验证。目前,只实现了钱包身份验证。

有时需要使用Oracle客户端进行连接。在这种情况下,必须将init_oracleClient设置为True。

该提供程序支持SQL操纵器插件类。这样,就可以操作SQL语句了。例如,这对于行级授权或带有提示的解释计划的操作很有用。

有关该功能的更多信息,可以在test/test_oracleProvider.py中的测试类中找到。

《PostgreSQL》

备注

需要使用Python包SQlalChemy、GeoalChemy2和心理Copg2-BINARY

必须安装了PostGIS。

备注

几何图形必须使用EPSG:4326

providers:
    - type: feature
      name: PostgreSQL
      data:
          host: 127.0.0.1
          port: 3010 # Default 5432 if not provided
          dbname: test
          user: postgres
          password: postgres
          search_path: [osm, public]
      id_field: osm_id
      table: hotosm_bdi_waterways
      geom_field: foo_geom

还可以在提供程序中配置多个数据库连接选项,以便正确调整SQLalChemy引擎客户端。这些是可选的,如果未指定,将使用引擎的默认设置。另请参阅 SQLAlchemy docs

providers:
   - type: feature
     name: PostgreSQL
     data:
         host: 127.0.0.1
         port: 3010 # Default 5432 if not provided
         dbname: test
         user: postgres
         password: postgres
         search_path: [osm, public]
     options:
         # Maximum time to wait while connecting, in seconds.
         connect_timeout: 10
         # Number of *milliseconds* that transmitted data may remain
         # unacknowledged before a connection is forcibly closed.
         tcp_user_timeout: 10000
         # Whether client-side TCP keepalives are used. 1 = use keepalives,
         # 0 = don't use keepalives.
         keepalives: 1
         # Number of seconds of inactivity after which TCP should send a
         # keepalive message to the server.
         keepalives_idle: 5
         # Number of TCP keepalives that can be lost before the client's
         # connection to the server is considered dead.
         keepalives_count: 5
         # Number of seconds after which a TCP keepalive message that is not
         # acknowledged by the server should be retransmitted.
         keepalives_interval: 1
     id_field: osm_id
     table: hotosm_bdi_waterways
     geom_field: foo_geom

PostgreSQL提供程序还能够连接到云SQL数据库。

providers:
    - type: feature
      name: PostgreSQL
      data:
          host: /cloudsql/INSTANCE_CONNECTION_NAME # e.g. 'project:region:instance'
          dbname: reference
          user: postgres
          password: postgres
      id_field: id
      table: states

这就是配置的目的 Google Cloud SQL 连接看起来像是。这个 host 块包含必要的套接字连接信息。

该提供程序支持上面提供程序表中所示的CQL查询。

参见

CQL支持 有关如何使用通用查询语言(CQL)筛选具有特定查询的集合的更多详细信息。

SQLiteGPKG公司

备注

Spatialite安装要求

SQLite文件:

providers:
    - type: feature
      name: SQLiteGPKG
      data: ./tests/data/ne_110m_admin_0_countries.sqlite
      id_field: ogc_fid
      table: ne_110m_admin_0_countries

地理包文件:

providers:
    - type: feature
      name: SQLiteGPKG
      data: ./tests/data/poi_portugal.gpkg
      id_field: osm_id
      table: poi_portugal

SensorThings接口

STA提供程序能够从OGC SensorThings API端点创建功能集合。有三个STA实体是可配置的:事物、数据流和观测。有关SensorThings实体模型的完整说明,请参见 here 。对于每个实体 Things ,pygeapi将展开与 Thing ,包括与其关联的 Location ,从中派生要素集合的几何图形。同样, Datastreams 已扩展为包括关联的 ThingSensorObservedProperty

默认id_field为 @iot.id 。STA提供商添加一个必填字段, entity ,和一个可选字段, intralink 。这个 entity 字段是指要将哪个STA实体用于要素集合。这个 intralink 字段控制其他STA提供程序如何操作该提供程序,默认情况下为false。如果 intralink 对于pygeapi实例内的相邻STA提供程序集合为true,则展开的实体改为由指向另一个实体的pyGeoapi内链接表示,或者它的 uri_field 如果申报的话。

providers:
    - type: feature
      name: SensorThings
      data: https://sensorthings-wq.brgm-rec.fr/FROST-Server/v1.0/
      uri_field: uri
      entity: Datastreams
      time_field: phenomenonTime
      intralink: true

如果全部配置了这三个实体,STA提供商将把一个完整的STA端点表示为OGC-API功能集合。这个 Things 要素将包括指向中关联要素的链接 Datastreams 要素集合,以及 Observations 要素将包括指向中关联要素的链接 Datastreams 要素集合。SensorThings的docker示例中包含配置了三个实体的示例。

苏格拉塔

要发布 Socrata Open Data API (SODA) 终结点,比利亚皮严重依赖于 sodapy

  • data 是Soda终结点的域。

  • resource_id 是4x4资源ID模式。

  • geom_field 是BBox查询工作所必需的。

  • token 是可选的,可以包括在配置中以传递 app token 敬苏格拉塔。

providers:
    - type: feature
      name: Socrata
      data: https://soda.demo.socrata.com/
      resource_id: emdb-u46w
      id_field: earthquake_id
      geom_field: location
      time_field: datetime # Optional time_field for datetime queries
      token: my_token # Optional app token

ERDDAP Tabledap服务

备注

需要使用Python包 requests

从ERDDAP发布的步骤 Tabledap 服务,您的索引中需要以下各项:

providers:
    - type: feature
      name: ERDDAPTabledap
      data: http://osmc.noaa.gov/erddap/tabledap/OSMC_Points
      id_field: PLATFORM_CODE
      time_field: time
      options:
          filters: "&parameter=\"SLP\"&platform!=\"C-MAN%20WEATHER%20STATIONS\"&platform!=\"TIDE GAUGE STATIONS (GENERIC)\""
          max_age_hours: 12

备注

如果 datetime 参数由客户端传递,则该参数将重写 options.max_age_hours 布景。

控制属性的顺序

可以使用控制顺序以及显示/取消显示任何受支持的要素提供程序的属性 properties 提供程序定义中的关键字,请参见下面的示例:

properties:
    - waterway
    - depth
    - name

数据访问示例

  • 列出所有集合*http://localhost:5000/collections

  • DataSet*http://localhost:5000/collections/foo概述

  • 可查询*http://localhost:5000/collections/foo/queryables

  • 浏览功能*http://localhost:5000/collections/foo/items

  • 分页*http://localhost:5000/collections/foo/items?offset=10&limit=10

  • Csv输出*http://localhost:5000/collections/foo/items?f=csv

  • 查询要素(空间)*http://localhost:5000/collections/foo/items?bbox=-180,-90、180、90

  • 查询要素(使用bbox-crs查询空间)*http://localhost:5000/collections/foo/items?bbox=120000,450000,130000,460000&bbox-crs=http%3A%2F%2Fwww.opengis.net%2Fdef%2Fcrs%2FEPSG%2F0%2F28992

  • 查询要素(属性)*http://localhost:5000/collections/foo/items?propertyname=foo

  • 查询要素(时态)*http://localhost:5000/collections/foo/items?datetime=2020-04-10T14:11:00Z

  • 查询要素(时态)并按属性升序排序(如果未指定+/-,则假定为+)*http://localhost:5000/collections/foo/items?datetime=2020-04-10T14:11:00Z&sortby=+datetime

  • 查询要素(时态)并按属性降序排序*http://localhost:5000/collections/foo/items?datetime=2020-04-10T14:11:00Z&sortby=-datetime

  • 查询给定(和支持的)CRS*http://localhost:5000/collections/foo/items?crs=http%3A%2F%2Fwww.opengis.net%2Fdef%2Fcrs%2FEPSG%2F0%2F32633中的功能

  • 查询给定边界框中的要素并返回给定CRS*http://localhost:5000/collections/foo/items?bbox=120000,450000,130000,460000&bbox-crs=http%3A%2F%2Fwww.opengis.net%2Fdef%2Fcrs%2FEPSG%2F0%2F28992&crs=http%3A%2F%2Fwww.opengis.net%2Fdef%2Fcrs%2FEPSG%2F0%2F32633中的要素

  • 获取特定功能*http://localhost:5000/collections/foo/items/123

  • 获取给定(和支持的)CRS*http://localhost:5000/collections/foo/items/123?crs=http%3A%2F%2Fwww.opengis.net%2Fdef%2Fcrs%2FEPSG%2F0%2F32633中的特定功能

备注

当不是时 crs 和/或 bbox-crs 则假定默认CRS http://www.opengis.net/def/crs/OGC/1.3/CRS84(WGS84in Lon,稍后排序)。如果满足以下条件,则pygeapi可能会执行必要的转换 storage_crs 与此默认设置不同。然后,要素始终在该默认CRS中返回(根据GeoJSON标准)。在所有情况下,无论是否提供这些查询参数,HTTP头 Content-Crs 表示响应中的功能(S)的CRS。

备注

.../items 向GeoJSON返回替代表示(提示下载)的查询将使响应文件名与集合名称和适当的文件扩展名匹配(例如 my-dataset.csv )

备注

提供者 id_field 值支持斜杠(即 my/cool/identifier )。然后,客户端请求将负责相应地对标识符进行编码(即 http://localhost:5000/collections/foo/items/my%2Fcool%2Fidentifier )