Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 14:38
    antagomir commented #240
  • 14:23
    pitkant opened #240
  • 14:23
    pitkant assigned #240
  • 13:40
    codecov[bot] commented #239
  • 13:31
    pitkant opened #239
  • 13:31
    pitkant review_requested #239
  • 13:30

    pitkant on pitkant

    Update news (compare)

  • 13:22

    pitkant on pitkant

    Improved data documentation, ad… (compare)

  • Jun 29 08:04
    antagomir commented #210
  • Jun 29 07:31
    pitkant commented #210
  • Jun 28 15:22
    pitkant commented #237
  • Jun 28 14:55

    pitkant on pitkant

    Fix issue #237 (compare)

  • Jun 28 14:54

    pitkant on pitkant

    (compare)

  • Jun 28 10:14
    pitkant commented #227
  • Jun 25 08:54

    github-actions[bot] on gh-pages

    Built site for eurostat: 3.7.11… (compare)

  • Jun 25 08:46

    antagomir on master

    fix (compare)

  • Jun 25 08:35
    antaldaniel commented #210
  • Jun 25 08:32
    antaldaniel commented #227
  • Jun 23 08:14
    isirf commented #237
  • Jun 22 06:38
    mrblasco commented #238
Markus Kainu
@muuankarski

One issue still prevails, as in current implementation of get_eurostat_geospatial user can opt for SpatialPolygonDataFrame , fortified data.frame or sf output. We could provide those conversions "on-the-fly" if we will rely on the json-files from eurostat (now they come preprocessed using download.file()). If we would provide all three it would require following steps on-the-fly.

# =======================================================
# If user passes output_class = "sf" OR does not spesify it (default behaviour)
## Download and return a sf-object
# =======================================================
library(sf)
library(dplyr)
jsontemp <- tempfile()
download.file("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v1/geojson/nuts-2013/NUTS_RG_60M_2013_4258_LEVL_0.geojson",
              jsontemp)
shape <- sf::st_read(jsontemp, stringsAsFactors = FALSE)
return(shape)

# =======================================================
# If user passes output_class = "sp" this is done in addition to default behaviour
## Convert sf-object into sp-object SpatialPolygonDataFrame
# =======================================================
shape_sp <- as(shape, "Spatial")
return(shape_sp)

# =======================================================
# If user passes output_class = "data.frame" this is done in addition to steps above
## Convert SpatialPolygonDataFrame into "fortified" regular data.frame to be plotted with ggplot2::geom_polygon
# =======================================================
shape_sp$id <- row.names(shape_sp)
fortified <- broom::tidy(shape_sp)
fortified <- left_join(fortified,shape_sp@data)
return(fortified)

@jlehtoma what do you think, is that feasible to do on-the-fly OR should we provide just a sf-output and nothing else..?

Leo Lahti
@antagomir
sf could be default and others optional ?
Markus Kainu
@muuankarski

Yep, that is the current behavior (in sf-branch), but providing the other options would require adding broom-dependency at least.

I could try with preserving the exact same behavior as currently, but change the source and processing. A new attribute would be nuts_level where user could pass either 0,1,2,3 or all. all would be default allowing the current behavior of subsetting with inner_join only.

Leo Lahti
@antagomir
Sound very good to me. I think we can import one more package but it is true that we are starting to have quite many imported packages. Could investigate at some point if these can be reduced.. or splitting data retrieval and geovisualization components in separate packages is also an option (though perhaps a bit complicated one)
Markus Kainu
@muuankarski
rOpenGov/eurostat@57d1686
now the basic idea is implemented. At least, cache needs to be revised. Can test with:
library(eurostat)
library(dplyr)
library(sf)
# sf
shape_sf <- get_eurostat_geospatial(nuts_level = "0", output_class = "sf")
shape_sf %>% select(NUTS_ID) %>% plot()
# data.frame
shape_df <- get_eurostat_geospatial(nuts_level = "0", output_class = "df")
shape_df %>% ggplot2::ggplot(.) + ggplot2::geom_polygon(aes(x=long,y=lat,group=group,fill=NUTS_ID))
# spdf
shape_spdf <- get_eurostat_geospatial(nuts_level = "0", output_class = "spdf")
sp::spplot(obj = shape_spdf, "NUTS_ID")
Leo Lahti
@antagomir
is this in master now ?
Markus Kainu
@muuankarski
no no, in simplefeatures branch
Leo Lahti
@antagomir
yees
i saw wrong
Markus Kainu
@muuankarski
i double checked..
Leo Lahti
@antagomir
yes it works ! (after adding library(ggplot2) in the beginning)
Markus Kainu
@muuankarski
\o/
Perhaps there is a better method for fetching this json data http://ec.europa.eu/eurostat/cache/GISCO/distribution/v1/geojson/nuts-2013/NUTS_RG_60M_2013_4258_LEVL_3.geojson than download.file()...
Leo Lahti
@antagomir
might be
Markus Kainu
@muuankarski
instead of download.file() I implemented it using httr::GETnow, the two options are listed below:
resolution <- "60"
# option 1
resp <- httr::GET(paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v1/geojson/nuts-2013/NUTS_RG_",resolution,"M_2013_4258_LEVL_1.geojson"))
nuts1 <- sf::st_read(httr::content(resp, as="text"), stringsAsFactors = FALSE)
# option 2
jsontemp <- tempfile()
download.file(paste0("http://ec.europa.eu/eurostat/cache/GISCO/distribution/v1/geojson/nuts-2013/NUTS_RG_",resolution,"M_2013_4258_LEVL_1.geojson"), jsontemp)
nuts1 <- sf::st_read(jsontemp, stringsAsFactors = FALSE)
Leo Lahti
@antagomir
you are a piece of gold
Markus Kainu
@muuankarski
I had a similar feeling for a second! Now have to hurry back to normal life and being a piece of shit!
Leo Lahti
@antagomir
!
Markus Kainu
@muuankarski
rOpenGov/eurostat@ff6defa here is the fix. Commits do show up nicely in the right side listing ->
Leo Lahti
@antagomir
nicee
Joona Lehtomäki
@jlehtoma
Very nice!
Leo Lahti
@antagomir
FedData package has functionality to download GIS data in US: https://ropensci.org/blog/technotes/2017/08/24/FedData-release
Joona Lehtomäki
@jlehtoma
Was just linking the same here, seems worth exploring
Leo Lahti
@antagomir
!