Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for NULL/empty geoJSON points. #91

Open
7 of 9 tasks
SimonGoring opened this issue Nov 26, 2021 · 2 comments
Open
7 of 9 tasks

Support for NULL/empty geoJSON points. #91

SimonGoring opened this issue Nov 26, 2021 · 2 comments

Comments

@SimonGoring
Copy link

SimonGoring commented Nov 26, 2021

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)
@dcooley
Copy link
Collaborator

dcooley commented Nov 27, 2021

yes that should be do-able. As an interim solution you can use sf directly to read the geojson

library(sf)

sf <- sf::st_read(
  '{
  "type": "FeatureCollection",
  "features": [
    { "type": "Feature", "properties": null, "geometry": {"type":"Point","coordinates":[]} },
  { "type": "Feature", "properties": null, "geometry": {"type":"Point","coordinates":[1.0, 1.0]} }
  ]}'
)

sf

# Simple feature collection with 2 features and 0 fields (with 1 geometry empty)
# Geometry type: POINT
# Dimension:     XY
# Bounding box:  xmin: 1 ymin: 1 xmax: 1 ymax: 1
# Geodetic CRS:  WGS 84
# geometry
# 1 POINT EMPTY
# 2 POINT (1 1)

@dcooley
Copy link
Collaborator

dcooley commented Dec 3, 2021

On branch issue91 these examples now work

library(sf)
library(geojsonsf)

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":[]} }
  ]}'


geojsonsf::geojson_sf(geojson)

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":[]}}')

dcooley added a commit that referenced this issue Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants