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

R crashes if esri shape file loaded with sf has empty geometry #176

Closed
vfridkin opened this issue Aug 30, 2018 · 4 comments
Closed

R crashes if esri shape file loaded with sf has empty geometry #176

vfridkin opened this issue Aug 30, 2018 · 4 comments

Comments

@vfridkin
Copy link

vfridkin commented Aug 30, 2018

R crashes if the geometry column (from using sf) contains an empty list record.

R Studio Version 1.1.456
R version 3.5.1

Based on slack question.

Shape file: SA2_2016_AUST.shp
Source: https://datapacks.censusdata.abs.gov.au/datapacks/
2016_SA2_shape.zip

In code below, placed files in abs_data/sa2_esri_shapefile

library(tidyverse)
library(googleway)
library(sf)

shape_path <- "abs_data/sa2_esri_shapefile"
shape_file <- "SA2_2016_AUST"
shape_file_path <- paste0(shape_path, "/", shape_file, '.shp')

sa2_shape <- sf::st_read(shape_file_path)
sa2_shape <- sa2_shape %>%
  filter(STATE_NAME == "Victoria")

p <- google_map("") %>% 
  googleway::add_polygons(data = sa2_shape,  polyline = "geometry")

image

Workaround is to add filter on AREA_SQKM:

  sa2_shape <- sa2_shape %>%
    filter(STATE_NAME == "Victoria",
           AREA_SQKM > 0)
@SymbolixAU
Copy link
Collaborator

Thanks. I can reproduce this error and will look into it.

@SymbolixAU
Copy link
Collaborator

The specific error is from googlePolylines not handling the empty geometry object

googlePolylines::encode( sa2_shape[sa2_shape$AREA_SQKM == 0, ] ) ## crashes
# vs
googlePolylines::encode( sa2_shape[sa2_shape$AREA_SQKM != 0,  ] )

@SymbolixAU
Copy link
Collaborator

SymbolixAU commented Aug 30, 2018

Reproducible

These all cause RStudio / R to crash

googlePolylines::encode( sf::st_sfc(sf::st_multipoint()) )
googlePolylines::encode( sf::st_sfc(sf::st_multilinestring()) )
googlePolylines::encode( sf::st_sfc(sf::st_multipolygon()) )

non-MULTI* objects are fine

googlePolylines::encode( sf::st_sfc(sf::st_point()) )
googlePolylines::encode( sf::st_sf(geometry = sf::st_sfc(sf::st_point())) )

googlePolylines::encode( sf::st_sfc(sf::st_linestring()) )
googlePolylines::encode( sf::st_sf(geometry = sf::st_sfc(sf::st_linestring())) )

googlePolylines::encode( sf::st_sfc(sf::st_polygon()) )
googlePolylines::encode( sf::st_sf(geometry = sf::st_sfc(sf::st_polygon())) )

Working through this on googlePolylines issue

@SymbolixAU
Copy link
Collaborator

closed - SymbolixAU/googlePolylines#32

@SymbolixAU SymbolixAU removed their assignment Jan 16, 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

1 participant