You are here

function farm_area_extract_geoms in farmOS 7

Helper function to extract geometries from areas.

Parameters

array $ids: An array of area term IDs.

Return value

array Returns an array of geometry strings in WKT format.

3 calls to farm_area_extract_geoms()
farm_livestock_move_form in modules/farm/farm_livestock/farm_livestock.farm_quick.move.inc
Form for adding animal movement logs.
farm_log_populate_geometry in modules/farm/farm_log/farm_log.module
Helper function for populating a log's geometry from an area reference field.
farm_movement_populate_geometry in modules/farm/farm_movement/farm_movement.module
Helper function for populating a movement field collection geometry from the "move to" area reference field.

File

modules/farm/farm_area/farm_area.module, line 261

Code

function farm_area_extract_geoms($ids = array()) {

  // Start an empty array of geometries to return.
  $geoms = array();

  // If the array of IDs is empty, bail.
  if (empty($ids)) {
    return $geoms;
  }

  // Load the areas.
  $areas = array();
  foreach ($ids as $id) {
    if ($area = taxonomy_term_load($id)) {
      $areas[] = $area;
    }
  }

  // If no areas are referenced, bail.
  if (empty($areas)) {
    return $geoms;
  }

  // Iterate over the areas to find geometries.
  $geoms = array();
  foreach ($areas as $area) {
    if (!empty($area->field_farm_geofield[LANGUAGE_NONE])) {
      foreach ($area->field_farm_geofield[LANGUAGE_NONE] as $geofield) {
        if (!empty($geofield['geom'])) {
          $geoms[] = $geofield['geom'];
        }
      }
    }
  }

  // Return the geometries.
  return $geoms;
}