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

Create max augement to set number of features to show on map with sensible default #25

Closed
Robinlovelace opened this issue Sep 13, 2018 · 10 comments
Assignees
Projects
Milestone

Comments

@Robinlovelace
Copy link
Member

No description provided.

@Robinlovelace
Copy link
Member Author

Reproducible example below. The idea is that the view function (existing or created) will check the number of features (or maybe vertices with sf::st_coordinates()) in the current bounding box before sending anything. If there are more than max in there there function will sample from the points. When you zoom-in more features will be shown. That would be awesome. It's what we do in CyIPT.

@Robinlovelace
Copy link
Member Author

# reproducible example
library(stplanr)
ac <- read_stats19_ac() # 214 mb compressed data
names(ac)
ac = ac[!is.na(ac$Latitude), ]
ac_sf = sf::st_as_sf(ac, coords = c("Longitude", "Latitude"))

pryr::object_size(ac_sf) # 600 MB
# now we've generated a large spatial dataset let's see how long it takes to visualize

system.time({
  plot(ac_sf$geometry) # note: blocks your R session for ages: unhelpful, we need an alternative!
})

system.time({
  plot(ac_sf$geometry[sample(nrow(ac_sf), size = 1e4)]) # way faster but also clunky
})

# now interactively
mapview::mapview(ac_sf) # freezes your R session

# with leaflet WIP...
library(leaflet)

# with geoplumber ...

@layik layik added this to In progress in geoplumber Sep 13, 2018
@Robinlovelace
Copy link
Member Author

Here's the beginnings of making the max arg work:

# Below is part of stats19 endpoint:
library(stplanr)
ac <- read_stats19_ac() # 214 mb compressed data
names(ac)
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, ]
plot(sf::st_geometry(ac_lnd[sample(nrow(ac_lnd), 1000), ]))
ac_sf_mini = ac_sf[1:1000, ]
#' @get /api/uol
uol_geojson <- function(res){
  res$body <- ac_sf_mini
  res
}

@layik layik self-assigned this Sep 18, 2018
@layik
Copy link
Member

layik commented Sep 18, 2018

Poor "plumber", cannot convert sf object into GeoJSON on its own.
Two things: 1) code below uses geojsonio not geojsonsf as it fails to parse, 2)code is NOT reprex'able @Robinlovelace.

I wonder if @SymbollixAU would like to have a look at (1) or perhaps open an issue so we can continue using geojsonsf blazing fast package. Error is Error in rcpp_geojson_to_sf(geojson, expand_geometries) : Not compatible with STRSXP: [type=list].

# Below is part of stats19 endpoint:
library(stplanr)
ac <- read_stats19_ac() # 214 mb compressed data
names(ac)
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, ]
plot(sf::st_geometry(ac_lnd[sample(nrow(ac_lnd), 1000), ]))
ac_sf_mini = ac_sf[1:1000, ]
ac_sf_mini <- geojsonio::geojson_json(ac_sf_mini)

#' @get /api/uol
uol_geojson <- function(res){
  res$headers$`Content-type` <- "application/json" # not necessary.
  res$body <- ac_sf_mini
  res
}

@layik layik closed this as completed Sep 18, 2018
geoplumber automation moved this from In progress to Done Sep 18, 2018
@layik layik reopened this Sep 18, 2018
geoplumber automation moved this from Done to In progress Sep 18, 2018
@Robinlovelace
Copy link
Member Author

Heads-up @SymbolixAU - @layik the tag didn't work 1st time around. Maybe open-up an issue if one would be appreciated 😄

@layik
Copy link
Member

layik commented Sep 18, 2018

Done SymbolixAU/geojsonsf#29

@SymbolixAU
Copy link

SymbolixAU commented Sep 18, 2018

closed in SymbolixAU/geojsonsf#29 (comment)

you need to use sf_geojson() to go from sf to geojson

@layik
Copy link
Member

layik commented Sep 19, 2018

Thanks @SymbolixAU

Correct code then:

# Below is part of stats19 endpoint:
library(stplanr)
ac <- read_stats19_ac() # 214 mb compressed data
names(ac)
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, ]
plot(sf::st_geometry(ac_lnd[sample(nrow(ac_lnd), 1000), ]))
ac_sf_mini = ac_sf[1:1000, ]
ac_sf_mini <- geojsonsf::sf_geojson(ac_sf_mini)

#' @get /api/uol
uol_geojson <- function(res){
  res$headers$`Content-type` <- "application/json" # not necessary.
  res$body <- ac_sf_mini
  res
}

@layik
Copy link
Member

layik commented Sep 27, 2018

Other tickets just jump the priority queue over this one.

@layik layik added this to the V0.2 milestone Oct 15, 2018
@layik
Copy link
Member

layik commented May 10, 2020

title not clear so closing but happy to reopen again.

@layik layik closed this as completed May 10, 2020
geoplumber automation moved this from In progress to Done May 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
geoplumber
  
Done
Development

No branches or pull requests

2 participants