wkt.inc 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * Plugin to provide a WKT geocoder.
  6. */
  7. /**
  8. * Plugins are described by creating a $plugin array which will be used
  9. * by the system that includes this file.
  10. */
  11. $plugin = array(
  12. 'title' => t("WKT"),
  13. 'description' => t('Get the geometry of a WKT string'),
  14. 'callback' => 'geocoder_wkt',
  15. 'field_types' => array('text', 'text_long', 'file', 'geofield', 'computed'),
  16. 'field_callback' => 'geocoder_wkt_field',
  17. );
  18. /**
  19. * Process WKT
  20. */
  21. function geocoder_wkt($wkt, $options = array()) {
  22. geophp_load();
  23. return geoPHP::load($wkt, 'wkt');
  24. }
  25. function geocoder_wkt_field($field, $field_item) {
  26. if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
  27. return geocoder_wkt($field_item['value']);
  28. }
  29. if ($field['type'] == 'geofield') {
  30. return geocoder_wkt($field_item['wkt']);
  31. }
  32. if ($field['type'] == 'file') {
  33. if ($field_item['fid']) {
  34. $file = file_load($field_item['fid']);
  35. $wkt = file_get_contents($file->uri);
  36. return geocoder_wkt($wkt);
  37. }
  38. }
  39. }