Download & Extend

Errors uploading GPX & KML files

Project:Geocoder
Version:7.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

I am not entirely sure what this module does as far as GPX or KML files but while trying to figure that out I have run into a few problems. Here is what I have done.

Installed D7, Libraries, Chaos Tools, Geofield, Geocoder API and Libraries. I also installed the geoPHP library. Then I created a file field to upload my GPX files to and geofield set to "geocode from another field" and selected GPX. I did the same for KML files as well. In both instances upon upload I get errors.

For GPX I get:

Warning: DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity, line: 1 in GPX->geomFromText() (line 45 of /*/sites/all/libraries/geoPHP/lib/adapters/GPX.class.php).
Invalid / Empty GPX

For KML I get
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Start tag expected, '<' not found in Entity, line: 1 in KML->geomFromText() (line 53 of /*/sites/all/libraries/geoPHP/lib/adapters/KML.class.php).
Notice: Trying to get property of non-object in KML->geomFromXML() (line 88 of /*/sites/all/libraries/geoPHP/lib/adapters/KML.class.php).
Notice: Trying to get property of non-object in KML->geomFromXML() (line 88 of /*/sites/all/libraries/geoPHP/lib/adapters/KML.class.php).
Cannot create empty collection

Any suggestions on what could be going on or what I should be expecting?
Thanks.

Comments

#3

Status:active» closed (works as designed)

Geofield does not support input from either kml or gpx files due to the complexity of the data involved. Your best bet to get data from either data source is to either write a custom widget to handle it, or to look at something like http://drupal.org/project/feeds_xpathparser to parse the kml file. I can't really vouch for the second option as being stable, but I have had some limited success in D6 using the feeds module as a processor for kml files.

Since both kml and gpx files already have geodata embedded in them, you don't need the geocoder module in this instance. Geocoder is designed to take address data and convert it to coordinates, rather than arbitrary data parsing.

Good luck with your project, hampshire!

#4

Project:Geofield» Geocoder
Version:7.x-1.0-beta1» 7.x-1.x-dev
Status:closed (works as designed)» active

Sorry, posted this in the wrong area, it should have been in Geocoder not Geofield I think.

In addition if I geocode from a text field (copy/paste gpx data) instead of an uploaded file it works fine.

#5

Just confirming I see the same behaviour - Geocoder works fine to geocode from GPX data in a text field, but it won't read the data from a file field.

#6

I encountered the same issue and started debugging with Netbeans, it revealed that the issue of File fields is being treated with a smiley. (geocoder.module @ line 317). Lines 318 & 340 are responsible for the input received by the "geocoder_kml_field" function in kml.inc. There is no way for the kml.inc @ line 33 condition to be true after the aforementioned lines in geocoder.module.

I'll could give this a try but I am not sure how to change stuff without breaking other functionality. Any pointers on that ?

#7

George I agree with you, this line (and it's ironic comment) is biggest source of the problem when the source is a file:

// To avoid any conflicts, just make it text :)
$field_object = array('type' => 'text');

The part I don't understand is how anyone can say that a text field works, because the handlers are expecting to be passed the field object arrray but are actually getting passed the actual data string, or in the case of the files the fid. So pretty much anything short of setting the title or name as the source should result in some sort of error when it tries to make an xml object out of it.

I'm not sure what the developer(s) intent is but I didn't want to have to change all the handlers and fixed it in the geocoder_widget_validate_walkthrough() function itself. I didn't create this as a patch but this is my replacement code starting at what should be line 296 in the original code to the end of the function.

     foreach ($field[$lang][0]['geocoder_source'] as $source) {
        // If the source is a name or text, then there is only one value
        if (($source == 'title' || $source == 'name') && isset($form_state['values'][$source]) && in_array('text',$handler['field_types'])) {
          // simulate the array build of a field object
          $values[0] = array(
            'field' => array('type' => 'text'),
            'item' => array('value' => $form_state['values'][$source]),
          );
        }
        else {
          // get the field info
          $field_info = field_info_field($source);
          if(in_array($field_info['type'],$handler['field_types'])) {
            if (isset($parent) && isset($form_state['values'][$parent][$source][$lang])) {
              foreach ($form_state['values'][$parent][$source][$lang] as $delta => $item) {
                $values[$delta] = array(
                  'field' => $field_info,
                  'item' => $item,
                );
              }
            }
            elseif (!isset($parent) && isset($form_state['values'][$source][$lang])) {
              foreach ($form_state['values'][$source][$lang] as $delta => $item) {
                $values[$delta] = array(
                  'field' => $field_info,
                  'item' => $item,
                );
              }
            }
          }
        }
      }

      foreach ($values as $delta => $value) {
        try {
          $geometry = call_user_func($handler['field_callback'], $value['field'], $value['item']);
        }
        catch(Exception $e) {
          drupal_set_message($e->getMessage(),'error');
          return;
        }

        if ($geometry) {
          $field[$lang][$delta] = geofield_get_values_from_geometry($geometry);
        }
      }
    }
  }
}

#8

I ran into the same bug. Attached patch fixes gpx-upload via filefields and geocoding into a geofield for me.

AttachmentSize
geocoder_gpx.patch 1.83 KB

#9

Status:active» needs review

#10

I'm so subscribing to this.

Same problem here, trying to upload a GPX file to a field and referencing it by "geocode from another field" and selecting GPX.

I get the same error as above.

#11

Status:needs review» closed (fixed)

Committed to dev. Thanks everyone @fago especially for the patch.

http://drupalcode.org/project/geocoder.git/commit/33b3621

#12

Yes! this now works. Good stuff! Thanks all.

nobody click here