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

Reproducible parsing error #29

Closed
layik opened this issue Sep 18, 2018 · 5 comments
Closed

Reproducible parsing error #29

layik opened this issue Sep 18, 2018 · 5 comments

Comments

@layik
Copy link

layik commented Sep 18, 2018

Not quite sure what is happening here but here is a chunk of reproducible code:

library(stplanr)
ac <- read_stats19_ac() # 214 mb compressed data
#> [1] "Data saved at: /tmp/RtmpwlFrbm/Accidents0514.csv" 
#> [2] "Data saved at: /tmp/RtmpwlFrbm/Casualties0514.csv"
#> [3] "Data saved at: /tmp/RtmpwlFrbm/Vehicles0514.csv"
#> Parsed with column specification:
#> cols(
#>   .default = col_integer(),
#>   Accident_Index = col_character(),
#>   Longitude = col_double(),
#>   Latitude = col_double(),
#>   Date = col_character(),
#>   Time = col_time(format = ""),
#>   `Local_Authority_(Highway)` = col_character(),
#>   LSOA_of_Accident_Location = col_character()
#> )
#> See spec(...) for full column specifications.
#> Warning in .parse_hms(..., order = "HM", quiet = quiet): Some strings
#> failed to parse, or all strings are NAs
ac = ac[!is.na(ac$Latitude), ]
ac_sf = sf::st_as_sf(ac, coords = c("Longitude", "Latitude"), crs = 4326)
b = spData::lnd

ac_lnd = ac_sf[b, ]
#> although coordinates are longitude/latitude, st_intersects assumes that they are planar
ac_sf_mini = ac_sf[1:1000, ]
ac_sf_mini <- geojsonsf::geojson_sf(ac_sf_mini)
#> Error in rcpp_geojson_to_sf(geojson, expand_geometries): Not compatible with STRSXP: [type=list].

Created on 2018-09-18 by the reprex package (v0.2.0).

@Robinlovelace
Copy link

It maybe something funny in ac. Try removing the Time column and see if that works. If so it may be an issue with stplanr - ropensci/stplanr#270 instead.

@SymbolixAU
Copy link
Collaborator

I'm not at a computer to test, but are you converting geojson to sf, or sf to geojson?

geojsonsf::sf_geojson( sf )
## vs 
geojsonsf::geojson_sf( geo )

@SymbolixAU
Copy link
Collaborator

SymbolixAU commented Sep 18, 2018

@Robinlovelace @layik

confirmed; you've used the wrong function. geojson_sf is 'geojson-to-sf', whereas sf_geojson is 'sf-to-geojson'

geo <- geojsonsf::sf_geojson( ac_sf_mini )

str(geo)
# chr "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"properties\":{\"Accident_Index\":\"200501"| __truncated_

@layik
Copy link
Author

layik commented Sep 19, 2018

Ah, my apologies, I will be much more careful before posting an issue. New to the package thats all.

@SymbolixAU
Copy link
Collaborator

Not a problem!

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