Online Book Reader

Home Category

Mapping With Drupal - Alan Palazzolo [15]

By Root 316 0
able to use any fields that contain a latitude and longitude; these values do not need to come from the Geofield or Location module.

The downside is that it is not very flexible or extensible: there is no ability to do spatial querying on the data (e.g., to show all the schools within 20 miles of the nuclear power plant), and there is no way to store lines or polygons. Also, most users may only know the address of a location; they will not have a latitude and longitude. However, if you are importing spatial data from another source and already have a latitude and longitude, this can sometimes be the best method. Usually Geofield is better because it will allow you to do spatial calculations, as well as displaying your data on a map.

Geo


Though the Geo module does not exist for Drupal 7, it is still an important module conceptually. The main goal of Geo is to provide a robust interface between a spatial database such as PostGIS or MySQL and Drupal so as to fully use the capabilities of these storage engines in your Drupal application. Other modules are in progress to do this in Drupal 7. If you are going to create spatially complex and demanding maps, this subject is discussed in The Future of Mapping with Drupal.

Data Input


The Geofield and Location modules store spatial information in different ways, so the data must be input in different ways. The tutorials in this section show how to work with Drupal and these modules to collect and store spatial data.

Geofield Module


As explained in Geofield, the Geofield module has many different ways to collect spatial data. This tutorial will explain the simplest configuration, and will provide the basis for exploring more advanced techniques.

Basic configuration of Geofield


Setting up the Geofield module includes a few extra steps not normally followed when setting up a Drupal module. Geofield requires that you add the geoPHP library. GeoPHP is an open source PHP library for doing spatial operations, such as converting geographic data from JSON to WKT or calculating the area of a polygon.

Download the latest stable release of the Geofield module to your site’s modules directory.

Download the latest stable release of the Libraries module to your site’s modules directory. The Libraries module is used by Drupal modules like Geofield that require a third-party library or plug-in.

If it is not already there, create a libraries directory inside your Drupal installation’s sites/all directory.

Download the geoPHP library (alternatively, the git repository can be cloned, or it can be downloaded as a zip file from the project’s github page).

NOTE

The geoPHP library, an open source library for doing geospatial operations, also aims to provide a transparent layer on top of the GEOS extension in PHP. Geometry Engine, Open Source (GEOS) is a C++ port of the Java Topology Suite (JTS), which is an API for modelling and manipulating two-dimensional linear geometry; GEOS is extremely efficient in doing geospatial operations. This means that if you install GEOS on your server, you will get a significant performance increase and will be able to do some more serious geospatial operations within PHP that normally would be done in a geospatial database like PostGIS. For more information, see the GEOS wiki page at geoPHP.

Extract the downloaded geoPHP library and place it inside sites/all/libraries. The file should now show in your directory structure as sites/all/libraries/geoPHP/geoPHP.inc.

Enable the Geofield and Libraries modules at admin/modules. Neither of these modules require any further configuration or permissions.

Adding geographic data to a node with Geofield


The example website that we are building throughout this book contains information about the Drupal community. Right now we will create a new content type to store local user groups. The content type will contain the name of the group, a short description, and some geographical data about where the group is located.

From the Content types page, add a new content type at admin/structure/types/add.

Return Main Page Previous Page Next Page

®Online Book Reader