../../_images/logo_pygeoapi.png ../../_images/OSGeo_project.png

Inicio Rápido de pygeoapi

pygeoapi es una herramienta para publicar rápida y fácilmente los servicios de OGC Open API en la web. Se basa en las potentes bibliotecas de código abierto de la comunidad (geo)python.

En esta guía de inicio rápido le guiaremos en la configuración del software y lo usaremos para algunos casos específicos. A lo largo del camino vamos a participar con algún software relacionado, porque pygeoapi es un producto que normalmente se combina con otros componentes para cumplir con un caso de negocio.

Conocimientos previos

pygeoapi es una aplicación web de Python para el dominio espacial, por lo que debe tener en cuenta los conceptos de aplicaciones web y aspectos geoespaciales como formatos de cuadrícula y vectores, estándares OGC y sistemas de proyección. Se recomienda el conocimiento de Python, aunque puede hacerlo sin ejecutar la aplicación desde OSGeoLive.

Configure e inicie el servicio

  1. En el menú Inicio, seleccione Structure ‣ osgeolive ‣ appmenupath ‣ pygeoapi. La aplicación abrirá una página web en http://localhost:5000

  2. vaya a la carpeta de usuario /usr/local/share/pygeoapi y busque un archivo pygeoapi-config.yml. Este archivo contiene la configuración del servicio.

  3. Abra el archivo sudo nano pygeoapi-config.yml.

  4. Actualice algunos parámetros del archivo, como Título y Autor. Y guarde el archivo.

  5. Reinicie el servicio, por ejemplo cerrando el terminal e iniciando el servicio de nuevo

    ../../_images/pygeoapi_screenshot.png

Configurar nuevo servicio

Ahora implementará un conjunto de datos vectorial en pygeoapi y expondrá sus características como API de OGC - Características. API de OGC: las características son un estándar de OGC para exponer las características vectoriales como un servicio web. API de OGC: las características son la alternativa de OpenAPI para WFS.

pygeoapi es compatible con una amplia gama de backends para utilizarlos como origen vectorial, por ejemplo, geopaquete, PostGIS, Elasticsearch, WFS, etc. A través del proveedor GDAL OGR se puede añadir un conjunto casi ilimitado de otras fuentes vectoriales.

Interesting datasets to expose as OGC API - Features consist of real world data having multiple attributes and links to other resources. OSGeoLive contains a number of datasets we can use. An example is /var/www/html/openlayers/examples/data/geojson/countries.geojson. You can configure it in pygeoapi using the GeoJSON provider.

  1. Descargue el archivo GeoJSON y colóquelo en la carpeta tests/data.

  2. Update pygeoapi-config.yml to add countries as a new collection to pygeoapi (insert snippet below between the other collections. Mind the nesting, nesting is important in YAML syntax).

countries:
   type: collection
   title: Countries
   description: Countries of the world
   keywords:
      - industry
   links:
      - type: text/html
        rel: canonical
        title: information
        href: https://openlayers.org
        hreflang: en-US
   extents:
      spatial:
         bbox: [-180,-90,180,90]
   providers:
      - type: feature
        name: GeoJSON
        data: /var/www/html/openlayers/examples/data/geojson/countries.geojson
        id_field: name
  1. Reiniciar pygeoapi

Compruebe que la colección está disponible a través de su navegador en http://localhost:5000/collections/countries

Uso de un explorador web para consultar la API

Now that we have the service available we can query it using various client tooling. Each of the features of the collection is available in common formats, such as HTML, GeoJSON and GML. To start we can use a web browser to browse through the service. From http://localhost:5000/collections/countries, drill down to individual features. The service will automatically detect (accept header) that you are using a web browser and will return the HTML representation of features. Notice in the top right corner explicit links to override the accept header and request specific representations of the feature (?f=json).

Cada API abierta tiene una página de documentación interactiva en http://localhost:5000/openapi. En esta página web interactiva se puede leer sobre los diversos métodos en el servicio, pero también interactuar directamente con ellos a través de formularios web.

../../_images/openapidoc.png

OGC API’s have been developed with the W3C Spatial Data on the Web Best Practices in mind. An important aspect of these best practices is search engine optimization. Pygeoapi adds some crawl optimizations on top of the requirements of the Open API standards; collection metadata can be crawled by search engines in a structured way, with the goal to make the collections discoverable in tools like Google Dataset Search. To evaluate the structured data capabilities you can use the Structured Data Testing tools of Yandex or Google. Copy the html source of the countries collection page (or the url of a collection page of an online pygeoapi instance) into a structured data testing tool and evaluate what structured data the tool is able to extract from it. The search engine will use that information in its datasets index.

Using OGC API - Features in Desktop GIS

En esta guía de inicio rápido utilizamos QGIS para consultar el servicio, pero es posible un flujo de trabajo similar en otras herramientas SIG, por ejemplo, ArcGIS, FME, OpenLayers.

Starting from QGIS 3.14 you can add an OGC API - Features layer as vector layer. From the Layer / Add Layer menu select Add WFS Layer....

../../_images/qgis-wfs.png

En la ventana que se abre crear una nueva conexión, escriba la url al servicio http://localhost:5000.

Haga clic en Aceptar y, a continuación, en conectar para cargar las colecciones disponibles en el servicio.

../../_images/qgis-layers.png

Seleccione la colección países y haga clic en ‘Agregar’ para agregar la capa en el mapa QGIS.