Would you support Geofield allowing for GeoRSS input?

I'm experimenting with a few different ways of importing locative data (embedded as GeoRSS) from a Twitter feed with the Feeds module.

I can use Location Feeds to turn the GeoRSS into Lat/Lon for the Location module, but I'd rather use Geofield than Location.

Comments

ekes’s picture

Status: Active » Needs review
StatusFileSize
new6.68 KB

I've worked on the feeds integration a bit today. Patch attached. Some explanation of what what and why:-

  1. The module was providing individual targets for every value of the field. Which did actually work to a point, but because the values were not submitted by a widget, and only node_save is called geofield_compute_values() was never invoked.
  2. Simplepie 1.3 and Feeds own Common Syndication Parser both parse just points out of RSS/Atom. The provide these in different formats in the source. SimplePie offers lon and lat as separate source arrays. CSP offers a (probably D6 legacy) TermGeo object.

Because of #1 I removed most of the targets as just confusing. I couldn't find any point where all values would be saved. For example mapping the lon and lat (of which there maybe multiple), you don't know when to call geofield_compute_values(). I left WKT, because if anyone has a source, you can call compute values for this.

To create a point where you do know you have all the values to be able to call geofield_compute_values() I created a new 'source'. This has the bonus of hiding the complexity from the user; but I guess will mean adding new alternative formats into the code in the future.

phayes’s picture

I think it makes sense that WKT vs. Lat/Lon vs. bounding box are treated as seperate sources / ways that data can be imported. Obviously WKT is the most powerful, but it also makes sense to support Lat / Lon points. I think this is a great start

jeffschuler’s picture

Thanks, ekes!
The patch in #1 is working for me with CSP and geofield (combined) for source and target.

jeffschuler’s picture

Status: Needs review » Needs work

I'm getting these errors
Notice: Undefined offset: 0 in geofield_feeds_combined_source() (line 54 of /sites/all/modules/geofield/geofield.feeds.inc).
and
Notice: Use of undefined constant FeedsGeoTermElement - assumed 'FeedsGeoTermElement' in geofield_feeds_combined_source() (line 54 of /sites/all/modules/geofield/geofield.feeds.inc).

Maybe:

-  elseif (isset($item['geolocations']) && is_a($item['geolocations'][0], FeedsGeoTermElement)) {
+  elseif (isset($item['geolocations'][0]) && is_a($item['geolocations'][0], 'FeedsGeoTermElement')) {
jeffschuler’s picture

Status: Needs work » Needs review
StatusFileSize
new7.11 KB

I just found a need for the lat/long fields that the patch in #1 removes. And re-reading your comment in #2, phayes, I believe you're saying that those fields should remain.

This patch keeps the individual lat, long fields as well as the bounding box fields. I added geofield_set_target_simple() (same as previous geofield_set_target()) to cover these. phayes: did you want to maintain geo_type and SRID?

The patch also makes the change I suggested in #4 as well as a few minor docs/formatting issues.

batje’s picture

This is a real nice patch, especially if you combine it with this pre_save patch

batje’s picture

Title: GeoRSS Support » Feeds Integration

changed the title, as the current patch supports Feeds in General, for example with feeds_jsonpath_parser

Brandonian’s picture

Status: Needs review » Fixed

Thanks for the patch, jeffschuler! Patch applied and committed.

levelos’s picture

Status: Fixed » Needs work

Just trying this out as I was working on a similar patch, thanks folks. I'm getting a major bug, though. Using Feeds JSON parser (not really relevant, just FYI), i'm matching a WKT geometry to a WKT target and am getting the following error
Invalid argument supplied for foreach() geofield.feeds.inc:165

Why is geofield_set_target_wkt() expecting value to be an array?

levelos’s picture

Status: Needs work » Needs review
StatusFileSize
new771 bytes

Here's a patch that takes care of it, although I'm still not clear why $value would be in array in the first place.

Brandonian’s picture

Status: Needs review » Fixed

Thanks for the patch, levelos! I suspect that $value is an array because of how Geofield stores extra metadata with it's values, but I'm not 100% sure, to be honest.

I've committed the patch with minor modifications. Please be sure to change indents from tabs to spaces in your next patch. :-)

levelos’s picture

That's great, thanks @Brandonian! Think it's worth digging into why an array was expected? We're doing quite a bit of work on a project importing Geo data into a Geofield using Feeds now and I'd be happy to get it "just right." Re: tabs, that's odd, definitely use spaces in all my editors. Maybe a git diff setting? I'll double check.

BTW - Awesome to see all the work going towards a stable release, thanks!

Brandonian’s picture

I'm always for actually being able to understand why code acts the way it does, so if you get to it, please share the knowledge.

levelos’s picture

Assuming you know who authored the initial patch? Can we loop them in? Really wasn't clear to me from reviewing the code so I wouldn't want to make assumptions.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

gaëlg’s picture

It might be due to a code update, but this is the code that worked for me (no need for a $field array):

  if (is_array($value)) {
    foreach ($value as $key => $wkt) {
      $geofield_values[] = geofield_compute_values($wkt, 'wkt');
    }
  }
  else {
    $geofield_values[] = geofield_compute_values($value, 'wkt');
  }
Exploratus’s picture

Issue summary: View changes

Iw as having issues with D7

I replaced:

 $geofield_values = array();
  foreach ($values as $wkt) {
    $field = array('wkt' => $wkt);
    $geofield_values[] = geofield_compute_values($field, 'wkt');
  }

WITH

 $geofield_values = array();
  foreach ($values as $wkt) {
    $geofield_values[] = geofield_compute_values($wkt, 'wkt');
  }