filter/sift GeoJSON in R
R
Latest commit e63a2ff Nov 28, 2016 @sckott sckott fix example
Permalink
Failed to load latest commit information.
R fix example Nov 28, 2016
data first commit Nov 28, 2016
inst first commit Nov 28, 2016
man fix example Nov 28, 2016
tests fixed test Nov 28, 2016
.Rbuildignore first commit Nov 28, 2016
.gitignore first commit Nov 28, 2016
.travis.yml install other things on travis for protobuf Nov 28, 2016
CONDUCT.md added CoC and more info to footer readme Nov 28, 2016
DESCRIPTION first commit Nov 28, 2016
LICENSE first commit Nov 28, 2016
NAMESPACE first commit Nov 28, 2016
README.Rmd add travis badge to readme Nov 28, 2016
README.md add travis badge to readme Nov 28, 2016
geofilter.Rproj first commit Nov 28, 2016

README.md

geofilter

Build Status

geofilter does filtering on GeoJSON

Filtering is done with jqr, an R client for the C library jq. We could just parse to R objects with jsonlite then operate on lists or conver to other classes, but jq allows us to slice and dice/search/etc. geojson (which is just json really) without having to parse the entire json string (which is increasingly important as your input GeoJSON gets bigger).

This used to be within the geoops package, but was broken out here.

Installation

devtools::install_github("ropenscilabs/geofilter")
library("geofilter")

filter geojson

x <- "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-99.74,32.45]},\"properties\":{}}]}"
x <- as.geojson(x)
#> Error in eval(expr, envir, enclos): could not find function "as.geojson"
sift_client(x, ".features[].geometry[]")
#> [1] "[\"Point\", [-99.74,32.45]]"

sifting with jq

Using Zillow data, plot all data

library("leaflet")
file <- system.file("examples", "zillow_or.geojson", package = "geofilter")
dat <- jsonlite::fromJSON(file, FALSE)
library("leaflet")
leaflet() %>%
  addTiles() %>%
  addGeoJSON(dat) %>%
  setView(-122.8, 44.8, zoom = 8)

alldata

Filter to features in Multnomah County only

json <- paste0(readLines(file), collapse = "")
res <- sifter(json, COUNTY == Multnomah)

Check that only Multnomah County came back

res %>%
  jqr::index() %>%
  jqr::dotstr(properties.COUNTY)
#> [
#>     "Multnomah",
#>     "Multnomah",
#>     "Multnomah",
#>     "Multnomah",
#>     "Multnomah",
#>     "Multnomah",
#>     "Multnomah",
#>     "Multnomah",
#>     "Multnomah",
...

Plot it

leaflet() %>%
  addTiles() %>%
  addGeoJSON(res) %>%
  setView(-122.6, 45.5, zoom = 10)

alldata

Meta

  • Please report any issues or bugs.
  • License: MIT
  • Get citation information for geofilter in R doing citation(package = 'geofilter')
  • Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

ropensci_footer