Online Book Reader

Home Category

Mapping With Drupal - Alan Palazzolo [14]

By Root 333 0
store and what you will need to do with it. Halfway through is too late to decide that you want to input the routes of your mountain bike rides and should have been using Geofield rather than Location!

Geofield


The Geofield module is a new module that was created for Drupal 7. Geofield allows geographical data to be attached to an entity, such as a node. It provides several different widgets for data input and formatters for data output. It integrates with several of the other popular mapping modules (including OpenLayers, GMap, and Geocoder), and there are plans to integrate with more.

Of all the modules that handle geographic data storage in Drupal 7, the Geofield module is the one that has seen most development recently and takes the most advantage of the new Fields API. For these reasons, it is the best choice for all but the simplest mapping applications.

For data storage the Geofield module can be configured to handle many formats:

Latitude and Longitude

Data can be entered either as Decimal Degrees (122.340932) or as Degrees-Minutes-Seconds (123° 49’ 55.2” W). The Degrees-Minutes-Seconds input is tolerant of inconsistent input (123° 49’ 55.2” W or 40:26:46N). Decimal Degrees is what you are most likely to be using.

Bounding Box

The latitude and longitude of each corner of a rectangle can be entered in four text fields.

Well Known Text (WKT)

A text area for direct WKT input (see Data Types for an explanation of WKT).

In addition to these formats, the Geofield module can store data for points, lines, polygons, and bounding boxes drawn on a map by a user. Geofield can integrate with the Geocoder module to store spatial data that has been extracted from addresses, KML files, GeoJSON data, and geotagged images. This is discussed in Geocoder and Addressfield.

Location


The Location module has been around since Drupal 4.6 in 2005 and is one of the oldest spatial modules for Drupal. The Location module allows spatial data (such as a full address or latitude and longitude) to be attached to nodes and users.

The Location module’s strengths include an established interface; the interface of this module may not be perfect, but it has been around long enough for most Drupal users to have come across it at some point. Location is also quite full-featured, handling address data from around the world, as well as plugging into geocoding services.

Of course, “full-featured” also means that the module can be heavy and may load lots of functionality you do not need. A more serious drawback is that the Location module does not allow for line or polygon spatial data types. You can only store simple point data (a single latitude and longitude for each location). You will not be able to make a map that shows hiking routes or the area affected by an oil spill.

The architecture (how the code is written) of the Location module, which was appropriate when it was first conceived, does not follow current Drupal conventions. For example, it stores locations in a separate table and attaches them to entities like nodes and users with custom code, as opposed to using the Fields API, which is the best practice in Drupal 7. The Location module cannot currently attach spatial information to any entities other than users and nodes.

NOTE

The developers of the Location module are planning a new version of the module that will handle location data as entities. You can follow the progress of this in the Location module’s issue queue.

Despite these drawbacks, there are two good reasons to use the Location module. If you are upgrading a site from Drupal 6 or earlier that uses the Location module, it will be easier to keep your data in the same format. Additionally, as will be discussed in Chapter 4, it is quicker and simpler to create maps based on the Location module than it is to use Geofield.

Text fields


Text fields are a very simple, yet valid, way of storing spatial data in Drupal. All that is needed are two text fields to store latitude and longitude. As will be discussed in Chapter 4, most mapping modules are

Return Main Page Previous Page Next Page

®Online Book Reader