Upload .gpx

Events happening in the community are now at Drupal community events on www.drupal.org.
ChocolateTeapot's picture

I'm using OpenLayers WKT to plot a trail (linestring) and an OpenLayers preset to display the trail.

I'd like to be able to upload a .gpx file as an alternative to plotting the trail.

I understand that Geocode can do this, but I'm not sure how. Ideally I'd want to import the .gpx into the same OpenLayers WKT field in the database that I'm using to plot the trail.

I'd also like to allow authenticated users to be able to upload .gpx files.

Can anyone point me in the right direction please?

Thanks.

Comments

I managed importing GPX by

derhasi's picture

I managed importing GPX by using Geo Field of http://drupal.org/project/geo and as you mentioned http://drupal.org/project/geocode. With geocode installed you can select a filefield to provide the gpx data in the geo field settings. The GPX data then will be converted to a WKT linestring in geo field.

If you want the data to be in the OpenLayers WKT field, you could write the geo field's value to the OpenLayers WKT. But you also can use both fields in the same view.
The best solution would propably writing a geocode handler for the openlayers wkt.

Thanks very much for your

ChocolateTeapot's picture

Thanks very much for your help.

I have Geo, Geo Data, Geo Field, Geo UI, Geocode, FileField, OpenLayers, OpenLayers CCK, OpenLayers UI enabled.

The options I get when I'm creating a new field are File, Geospacial Data, Geospacial Data Reference and OpenLayers WKT. I'm guessing that I need to select Geospacial Data which then gives me the options Well Known Text, Longitude/Latitude, Geocoded value from another field. I can't see how to associate geo data to a file upload field.

Thanks again.

After you added your

derhasi's picture

After you added your filefield that will hold the gpx file, you have to add a new field of type "Geospatial Data" with the widget "Geocoded value from another field". The widget settings provide you with the opportunity to select the Filefield with handler 'geocode_filefield' and return value 'linestring'.

See screenshots:
http://drp.ly/1grddN
http://drp.ly/1gr8cJ

I get it, thanks very much. I

ChocolateTeapot's picture

I get it, thanks very much.

I just need to figure out how to display the resulting linestring on an OpenLayers map. You mentioned you could write the geo field's value to the OpenLayers WKT and The best solution would probably writing a geocode handler for the openlayers wkt. I'll investigate writing a handler, it's not something that I've come across before.

Thanks again for your help.

There are several ways you

derhasi's picture

There are several ways you can deal with that:

  • Let openlayers WKT and Geospatial Data coexist, so the user can either mark a location, or upload a gpx file, or both. So you have to show both value sets in the map. This can be managed by building two Openlayers Data views, and integrating both in your preset.

  • Use openlayers WKT as primary field, and overwrite its value on a gpx filefield submission. Therefore you have to geocode the filefield during form submission by your own, using geocode functions -

    <?php
    function geocode($handler, $input, $return = 'point', $options = array())
    ?>
    might help - and pass the value to your Openlayers WKT field as value.
  • Write an additional widget (I mentioned handler before, but it has to be a cck widget), like in geocode_widget. This will replace the Openlayers Widget with an invisible widget (like it is done with Geospatial Data Field).

The solution (one of these or another) surely depends on the use case.

Thanks. I like the idea of

ChocolateTeapot's picture

Thanks.

I like the idea of writing the data back to the Openlayers WKT, I think it will be more useful in the long run.

Unfortunately I have no Drupal coding experience so it's going to be a bit of a learning curve. Can you point me to somewhere that I can read up about it please? I'm assuming that I won't have to write a custom module?

Thanks again.

Unfortunately you have to

derhasi's picture

Unfortunately you have to write a custom module / mini module.
That has to extend the form submission of the node form, or hook_nodeapi, with additional handling that might use function geocode().

Something like that call should convert the gpx-file to a linestring.

<?php
  $linestring
= geocode('geocode_filefield', $file, 'linestring');
?>

This then could be added to the openlayers wkt field value.

This solution definitely needs coding experience in Drupal. Maybe http://drupal.org/developing/modules or http://api.drupal.org/api/drupal/developer--examples--nodeapi_example--n... will help you jumping in the big field of drupal modules.

Thanks, you've been really

ChocolateTeapot's picture

Thanks, you've been really helpful.

Initial geocode patch

agileware's picture

This post is a bit old now but I have made a patch for geocode for this at http://drupal.org/node/853190

I still have a bit of work to do on adding some extra functionality but it is functional at this stage.

Note that you will also probably want the patch at http://drupal.org/node/973994
That patch makes it so that the file is only imported if it is a new file, not on every node save,
otherwise every time you save your node the gpx file import will overwrite any changes the user
has made to data using the openlayers map/wkt field.

Agileware are an Australian Web Team specialising in Drupal, WordPress and CiviCRM.
Agileware provide development, support and hosting services.
https://agileware.com.au

Location and Mapping

Group organizers

Group categories

Wiki type

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: