Community Documentation

Geofield 2.x

Last updated January 9, 2013. Created by Brandonian on November 29, 2012.
Edited by balagan. Log in to edit this page.

Changes since 1.x

  • Pluggable backend architecture - Data storage can work natively with Postgres/PostGIS databases via a plugin.
  • Native FormAPI elements - Geofield provides 3 FormAPI elements (Lat/Lon, Bounding Box, and Proximity) for use in custom forms.
  • Consolidation of Field Widgets - The HTML5 Geolocation widget from 1.x has been merged into the Lat/Lon widget.
  • Views-powered proximity queries

Geofield from a developer perspective

Database

Geofield stores the following columns in the database.

  • geom - the canonical representation of the geometry. Stored as WKB if accessing directly, automatically adjusted to WKT when loaded with entity_load.
  • geo_type
  • lat - For non-points calculated from centerpoint
  • lon - For non-points, calculated from centerpoint
  • left
  • top
  • right
  • bottom
  • geohash - http://en.wikipedia.org/wiki/Geohash - very useful for fast proximity searches via solr.

Geofield defines a pluggable system to change the column type of geom. We do this to allow for database-specific optimizations, like using geometry columns in Postgres/PostGIS. A plugin for doing just that can be found at https://github.com/phayes/geofield_postgis.

Saving data programmatically

Saving geospatial data in Geofield can be tricky. To help make it easier, Geofield can accept data in a wide array of formats. For an example entity with a field named 'field_geofield,' one could save data under $node->field_geofield[und][$delta] in the following formats.

  • An array with a 'geom' value in WKT format.
  • An array with an 'input_format' value of GEOFIELD_INPUT_WKT, which processes the 'geom' value as wkt data.
  • An array with an 'input_format' value of GEOFIELD_INPUT_GEOJSON, which process the 'geom' value as geojson data.
  • An array with an 'input_format' value of GEOFIELD_INPUT_LAT_LON, which processes the 'lat' and 'lon' values as geo data.
  • An array with an 'input_format' value of GEOFIELD_INPUT_BOUNDS, which processes the 'top', 'right', 'bottom', and 'left' values as geo data.
  • A string that can be parsed by any of geoPHP's processors.

Comments

These this & this page has examples of GEOFIELD_INPUT_WKT & GEOFIELD_INPUT_LAT_LON in action connecting to a drupal service via JSON.

Page status

About this page

Drupal version
Drupal 7.x
Level
Beginner, Intermediate
Audience
Site builders
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.