Skip to content

Support for NULL/empty geoJSON points. #91

@SimonGoring

Description

@SimonGoring

The RFC allows for empty geoJSON objects link:

RFC 7946


3.1.  Geometry Object

   o  A GeoJSON Geometry object of any type other than "GeometryCollection" has a member with the name "coordinates". The value of the "coordinates" member is an array.  The structure of the elements in this array is determined by the type of geometry.  GeoJSON processors MAY interpret Geometry objects with empty "coordinates" arrays as null objects.

Currently the following fails:

> geojson_sf('{
  "type": "FeatureCollection",
  "features": [
    { "type": "Feature", "properties": null, "geometry": {"type":"Point","coordinates":[]} } 
  ]}')

Error in rcpp_geojson_to_sf(geojson, expand_geometries) : 
  Invalid lon/lat object

Is this something that can be fixed?


TODO:

  • geojson_sf('{ "type": "Feature", "properties": null, "geometry": {"type":"Point","coordinates":[]} }')
  • geojson_sf('{ "type": "Feature", "properties": null, "geometry": {"type":"MultiPoint","coordinates":[]}}')
  • geojson_sf('{ "type": "Feature", "properties": null, "geometry": {"type":"LineString","coordinates":[]}}')
  • geojson_sf('{ "type": "Feature", "properties": null, "geometry": {"type":"MultiLineString","coordinates":[]}}')
  • geojson_sf('{ "type": "Feature", "properties": null, "geometry": {"type":"Polygon","coordinates":[]}}')
  • geojson_sf('{ "type": "Feature", "properties": null, "geometry": {"type":"MultiPolygon","coordinates":[]}}')
  • geojson_sf('{ "type": "Feature", "properties": null, "geometry": {"type": "GeometryCollection", "geometries":[{"type":"Point","coordinates":[]},{"type":"LineString","coordinates":[]}]}}')
  • geojson <- '{ "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": null, "geometry": {"type":"Point","coordinates":[]} }, { "type": "Feature", "properties": null, "geometry": {"type":"MultiPoint","coordinates":[]} }, { "type": "Feature", "properties": null, "geometry": {"type":"LineString","coordinates":[]} }, { "type": "Feature", "properties": null, "geometry": {"type":"MultiLineString","coordinates":[]} }, { "type": "Feature", "properties": null, "geometry": {"type":"Polygon","coordinates":[]} }, { "type": "Feature", "properties": null, "geometry": {"type":"MultiPolygon","coordinates":[]} } ]}'

  • round trip
geo <- '{
  "type": "FeatureCollection",
  "features": [
  { "type": "Feature", "properties": null, "geometry": {"type":"Point","coordinates":[]} },
  { "type": "Feature", "properties": null, "geometry": {"type":"MultiPoint","coordinates":[]} },
  { "type": "Feature", "properties": null, "geometry": {"type":"LineString","coordinates":[]} },
  { "type": "Feature", "properties": null, "geometry": {"type":"MultiLineString","coordinates":[]} },
  { "type": "Feature", "properties": null, "geometry": {"type":"Polygon","coordinates":[]} },
  { "type": "Feature", "properties": null, "geometry": {"type":"MultiPolygon","coordinates":[]} },
	{ "type": "Feature", "properties": null, "geometry": {"type": "GeometryCollection", "geometries":[{"type":"Point","coordinates":[]},{"type":"LineString","coordinates":[]}]}}
  ]}'


sf <- geojsonsf::geojson_sf(geo)
geo <- geojsonsf::sf_geojson(sf)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions