Combining points and polygons - in package or an add-on package? #215
Robinlovelace
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
Hi @Robinlovelace! Are you sure that the code written in that function is appropriate for For example: # package
library(osmextract)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright.
#> Check the package website, https://docs.ropensci.org/osmextract/, for more details.
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
# get supermarks
supermarkets_points <- oe_get(
"Isle of Wight",
layer = "points",
extra_tags = "shop",
query = "SELECT * FROM points WHERE shop = 'supermarket'"
)
#> The input place was matched with: Isle of Wight
#> The chosen file was already detected in the download directory. Skip downloading.
#> The corresponding gpkg file was already detected. Skip vectortranslate operations.
#> Reading layer `points' from data source
#> `C:\Users\Utente\Documents\osm-data\geofabrik_isle-of-wight-latest.gpkg'
#> using driver `GPKG'
#> Simple feature collection with 7 features and 11 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -1.29727 ymin: 50.58849 xmax: -1.145604 ymax: 50.76113
#> Geodetic CRS: WGS 84
supermarkets_polygons <- oe_get(
"Isle of Wight",
layer = "multipolygons",
extra_tags = "multipolygons",
query = "SELECT * FROM multipolygons WHERE shop = 'supermarket'"
)
#> The input place was matched with: Isle of Wight
#> The chosen file was already detected in the download directory. Skip downloading.
#> The corresponding gpkg file was already detected. Skip vectortranslate operations.
#> Reading layer `multipolygons' from data source
#> `C:\Users\Utente\Documents\osm-data\geofabrik_isle-of-wight-latest.gpkg'
#> using driver `GPKG'
#> Simple feature collection with 18 features and 26 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -1.515673 ymin: 50.63308 xmax: -1.142295 ymax: 50.76222
#> Geodetic CRS: WGS 84
# intersection
lengths(st_intersects(supermarkets_points, supermarkets_polygons))
#> [1] 0 0 0 0 0 0 0 Created on 2021-06-30 by the reprex package (v2.0.0) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Sometimes it's useful to combine polygons and points. For example, supermarkets are represented as both points and polygons. I've written a test function that combines them: https://github.com/Nowosad/SIGR2021/blob/master/workshop1/osm_combine.R
Think this is worth packaging but, in the interests of keeping osmextract small and maintainable would suggest putting this general osm processing functionality in separate package, e.g. called
osmextras
.Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions