Ticket #1145 (closed bug: fixed)

Opened 6 years ago

Last modified 5 years ago

Format/GeoJSON does not parse features with null geometries

Reported by: bartvde Owned by:
Priority: major Milestone: 2.7 Release
Component: Format.GeoJSON Version: 2.5
Keywords: Cc:
State: Complete

Description (last modified by euzuro) (diff)

When there is no geometry, Geoserver outputs "geometry": null in the GeoJSON output. However OpenLayers cannot parse this and will end up with 0 features.

An easy way to fix this is to add a null check for obj.geometry in parseFeature:

        if (obj.geometry) {
          try {
              geometry = this.parseGeometry(obj.geometry);
          } catch(err) {
              // deal with bad geometries
              throw err;
          }
        }

But there can be more code which assumes that a geometry object exists (like the bounds code probably), so this needs to be discussed more.

Attachments

geojson_null.patch Download (6.9 KB) - added by crschmidt 5 years ago.

Change History

Changed 6 years ago by elemoine

I've looked at  http://wiki.geojson.org/GeoJSON_draft_version_5 and null geometries are indeed something that needs to be expected.

Changed 5 years ago by euzuro

  • description modified (diff)

Changed 5 years ago by euzuro

  • milestone set to 2.7 Release

this seems like a genuine concern.

Changed 5 years ago by crschmidt

  • priority changed from minor to major

Changed 5 years ago by crschmidt

Changed 5 years ago by crschmidt

  • state set to Review

Changed 5 years ago by crschmidt

  • owner tschaub deleted

Changed 5 years ago by elemoine

  • state changed from Review to Commit

In parseGeometry you could just define the geometry local variable a bit later:

parseGeometry: function(obj) { 
    if (obj == null) { 
        return null; 
    }
    var geometry;

no big deal.

Please commit.

Changed 5 years ago by crschmidt

  • status changed from new to closed
  • state changed from Commit to Complete
  • resolution set to fixed

(In [7689]) "Format.GeoJSON does not parse features with null geometries", r=elemoine (Closes #1145)

Note: See TracTickets for help on using tickets.