This module provides a field for geospatial data that can be added to entities. In other words end users can add points, lines or areas on a map as part of a content. This module is similar to the Geofield module, but spatial operations and data storage rely on PostGIS.

The PostGIS module goes well together with the OpenLayers, OpenLayers Editor and the GeoServer modules. It is also part of the Cartaro distribution.

Editing using Drupal PostGIS module and OpenLayers

Requirements

In order to correctly install the module some dependencies need to be met. Note that only PostGIS is obligatory whilst the other things listed here enhance the user experience.

PostGIS 1.5 or later
Some features might work with older versions. PostGIS is an extension for the Postgres database and provides sophisticated support for spatial data (map features). Read its documentation for help with getting it working.
OpenLayers module
If the geospatial data shall be displayed on maps. When OpenLayers is not available you can only see a textual representation of the data (WKT to be specific).
Feeds module
If you want to import , from CSV files, geospatial data stored as KML, WKT or GML.
GDAL module
To read and import vector data from OGR web services or files in all formats supported by the GDAL/OGR library.

Set Up

First download the PostGIS module from its project page and install it like any other Drupal module. During installation the module will check if it has access to a Postgres database with PostGIS (your database for Drupal).

Now that the module is installed you will have a new field available for your content types. That means you won't see anything of the module unless you defined a content type using the new field.

Navigate to Administration » Structure » Content types and add or edit an existing content type. Add a new field in the Manage Fields tab. Choose Geospatial data as field and the widget as desired (you want OpenLayers Map to edit on a map instead of typing the coordinates yourself).

When asked for the number of values to store, respond with how many features you need. For example if you want to have a map with up to 3 points you'd choose 3 in the Number of values box.
You are now able to add spatial data when using the new content type.

Usage

Edit or add content that holds a Geospatial data field. Use the map (or textual input field) provided to add point, lines or areas. The map can be rendered when a user displays your content.

Customizing the Map Style

In case the default map style does not fit to your individual needs or you want to use own tiles the maps can be adjusted. Do so by configuring a map using the OpenLayers module but ensure to activate the PostGIS output layer. The default styles section allows to select a SLD file to use for rendering. Support for styled raster graphics is available preconfigured as part of the Cartaro distribution.

Now that your map is configured open the Manage Display tab of your content type. You will find a gear icon to the right that allows to select the map to use when presenting your data to the users.

Import data from a CSV file

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

  • Fetcher: File upload
  • Parser: CSV parser
  • Processor: Node processor
  • Node processor Settings:
    • Bundle: (select the target content type)
  • Mapping for Node processor:
    • geometry_field -> 'your geospatial field' from WKT, KML or GML depending on the format in which it is stored
    • ... other CSV file fields ...