Examples

Last updated on
30 April 2025

In order to make full use of geodata you should use a content type with a geometry field, e.g. as provided by the PostGIS module.

The process to import data into Drupal is described in the documentation of the feeds module in the section on creating an importer configuration.

The available vector formats available to be used with GDAL module can be found in the GDAL/OGR documentation. The GDAL module ability to discover fields from a datasource and make them available to Feeds module rely on GDAL/OGR system library. We will use the ogrinfo command line tool for this purpose. For example, the available fields in a KML file can be viewed with:

$ ogrinfo MyKMLFile.kml
Had to open data source read-only.
INFO: Open of `MyKMLFile.kml'
      using driver `KML' successful.
1: Layer #0 (3D Point)

As we can see, there is a layer (Layer #0) with data suitable to be imported. To discover the actual fields of this layer:

$ ogrinfo MyKMLFile.kml "Layer #0"
Had to open data source read-only.
INFO: Open of `ex.kml'
      using driver `KML' successful.

Layer name: Layer #0
Geometry: 3D Point
Feature Count: 1
Extent: (-122.082204, 37.422290) - (-122.082204, 37.422290)
Layer SRS WKT:
GEOGCS["WGS 84",
    DATUM["WGS_1984",
        SPHEROID["WGS 84",6378137,298.257223563,
            AUTHORITY["EPSG","7030"]],
        TOWGS84[0,0,0,0,0,0,0],
        AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,
        AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,
        AUTHORITY["EPSG","9108"]],
    AUTHORITY["EPSG","4326"]]
Name: String (0.0)
Description: String (0.0)
OGRFeature(Layer #0):0
  Name (String) = Simple placemark
  Description (String) = Attached to the ground. Intelligently places itself at the height of the underlying terrain.
  POINT (-122.082203542568294 37.422289901402507 0)

In the last three lines we can see two metadata fields (Name, Description) and one geometry field (POINT). The metadata fields will be available to the Feeds module, taking into account that the name is case sensitive for Feeds.

The geometry field can be of different types, point, line, polygon, etc. The data from this field will be always returned in WKT format by the GDAL/OGR library. This field will be available in Feeds module under the _geometry_ name. Sometimes it is necessary to change this name to avoid name collision with other fields. In this case it is possible to change where the geometries will be available for Feeds module in the Vector geodata parser settings modifying the Name for the geometry field setting.

In the next examples it is possible to see different use cases.

Import data from a KML file

We will create a new Feeds Importer for KML files with the following configuration settings:

  • Fetcher: File upload
  • File upload settings:
    • Allowed file extensions: kml
  • Parser: Vector geodata parser
  • Processor: Node processor
  • Node processor Settings:
    • Bundle: (select the target content type)
  • Mapping for Node processor:
    • Name -> Title
    • _geometry_ -> 'your geospatial field' from WKT. The geometry from the KML file will be converted into WKT.
    • ... other KML file fields ...

Import data from a Shapefile

Shapefile format are made up of several files. To make possible for the Feeds and GDAL modules deal with them it is necessary to bundle in a zip file. If your shape file contains non english characters you need to convert it to UTF-8 before importing. To do it using QGIS 2.0 you need to import the shape file with the command "Add Vector Layer" and set the encoding to latin1, than "Save as" and set the encoding for the new shape file to UTF-8.

We will create a new Feeds Importer for Shapefiles with the following configuration settings:

  • Fetcher: File upload
  • File upload settings:
    • Allowed file extensions: zip
  • Parser: Vector geodata parser
  • Processor: Node processor
  • Node processor Settings:
    • Bundle: (select the target content type)
  • Mapping for Node processor:
    • Name -> Title
    • _geometry_ -> 'your geospatial field' from WKT. The geometry from the Shapefile file will be converted into WKT.
    • ... other Shapefile file fields ...

Import data from a WFS - OGC WFS service

(For GDAL/OGR >= 1.8.0 only. GDAL/OGR library can also be compiled from source or, for Ubuntu systems, the ubuntugis-unstable repository can be added)

We are going to use also the ogrinfo command line tool to get information about the WFS - OGC WFS service. The different options are explained in the OGR WFS driver documentation.

For the example we are going to use a Feature Server with the Point Of Interest of Switzerland (http://openpoimap.ch).

To list the layers of the WFS server:

ogrinfo -ro WFS:http://openpoimap.ch/featureserver/featureserver.cgi

And to display layer metadata (OGR >= 1.9.0):

ogrinfo -ro WFS:http://openpoimap.ch/featureserver/featureserver.cgi WFSLayerMetadata

The Points Of Interest will be tagged to make it easy to find it. Let's recover the Restaurants for the pois layer. The filter that allows us to do that will be:

<Filter>
   <PropertyIsEqualTo>
      <PropertyName>amenity</PropertyName>
      <Literal>restaurant</Literal>
   </PropertyIsEqualTo>
</Filter>

We should add it to the final WFS query. We can run it in the command line to see the available fields:

ogrinfo "WFS:http://openpoimap.ch/featureserver/featureserver.cgi?service=WFS&request=GetFeature&typename=points&filter=%3CFilter%3E%3CPropertyIsEqualTo%3E%3CPropertyName%3Eamenity%3C/PropertyName%3E%3CLiteral%3Erestaurant%3C/Literal%3E%3C/PropertyIsEqualTo%3E%3C/Filter%3E" points

Add a new content type called Restaurant with, at least, a geospatial field to store the restaurant location.

We will create a new Feeds Importer for a WFS - OGC WFS service with the following configuration settings:

  • Fetcher: HTTP Fetcher
  • Parser: Vector geodata parser
  • Processor: Node processor
  • Node processor Settings:
    • Bundle: (select the target content type)
  • Mapping for Node processor:
    • Name -> Title
    • _geometry_ -> 'your geospatial field' from WKT. The geometry from the WFS layer will be converted into WKT.
    • ... other WFS layer fields ...

Now, from http://mysite.org/import page we can chose our new created importer and enter the URL of the WFS server with the desired filters:

http://openpoimap.ch/featureserver/featureserver.cgi?service=WFS&request=GetFeature&typename=points&filter=%3CFilter%3E%3CPropertyIsEqualTo%3E%3CPropertyName%3Eamenity%3C/PropertyName%3E%3CLiteral%3Erestaurant%3C/Literal%3E%3C/PropertyIsEqualTo%3E%3C/Filter%3E

Help improve this page

Page status: Not set

You can: