wkt.inc 1.0 KB

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