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

[FEATURE] function to combine point and polygon representations of entities in a single command #252

Open
Robinlovelace opened this issue Apr 25, 2022 · 2 comments

Comments

@Robinlovelace
Copy link
Member

Robinlovelace commented Apr 25, 2022

Is your feature request related to a problem? Please describe.

Sometimes entities like pubs are represented as points and polygons but you have to manually get both then get the centroid of the polygons to get the result.

Describe the solution you'd like

A function, e.g. called oe_get_centroids() could solve the problem.

Describe alternatives you've considered

I've thought about adding this functionality in another package but think it would be a good fit here.

Additional context

Here's a prototype of such a function that seemed worked: https://github.com/cyipt/actdev/blob/main/code/get_pois.R

Happy to put in a PR this is a good idea!

@Robinlovelace
Copy link
Member Author

Robinlovelace commented Apr 25, 2022

Reprex:

# Get pubs in Leeds
source("https://github.com/cyipt/actdev/raw/main/code/get_pois.R")
q = "SELECT * FROM 'points' WHERE amenity IN ('pub')"
pubs_west_yorkshire = get_pois(region_name = "west yorkshire", q = q)
#> The input place was matched with: West Yorkshire
#> Warning: The query selected a layer which is different from layer argument. We
#> will replace the layer argument.
#> The chosen file was already detected in the download directory. Skip downloading.
#> The corresponding gpkg file was already detected. Skip vectortranslate operations.
#> Reading query `SELECT * FROM 'points' WHERE amenity IN ('pub')' from data source `/mnt/57982e2a-2874-4246-a6fe-115c199bc6bd/data/osm/geofabrik_west-yorkshire-latest.gpkg' 
#>   using driver `GPKG'
#> Simple feature collection with 925 features and 12 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -2.107578 ymin: 53.54942 xmax: -1.233516 ymax: 53.9456
#> Geodetic CRS:  WGS 84
#> The input place was matched with: West Yorkshire
#> Warning: The query selected a layer which is different from layer argument. We
#> will replace the layer argument.
#> The chosen file was already detected in the download directory. Skip downloading.
#> The corresponding gpkg file was already detected. Skip vectortranslate operations.
#> Reading query `SELECT * FROM 'multipolygons' WHERE amenity IN ('pub')' from data source `/mnt/57982e2a-2874-4246-a6fe-115c199bc6bd/data/osm/geofabrik_west-yorkshire-latest.gpkg' 
#>   using driver `GPKG'
#> Simple feature collection with 1 feature and 25 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -1.533704 ymin: 53.84149 xmax: -1.533252 ymax: 53.84161
#> Geodetic CRS:  WGS 84
#> Loading required package: sf
#> Linking to GEOS 3.10.1, GDAL 3.4.0, PROJ 8.2.0; sf_use_s2() is TRUE
#> Warning in st_centroid.sf(osm_polygons): st_centroid assumes attributes are
#> constant over geometries of x
pubs_leeds = pubs_west_yorkshire[si::si_zones, ]
plot(pubs_leeds)

Created on 2022-04-25 by the reprex package (v2.0.1)

@agila5
Copy link
Collaborator

agila5 commented May 9, 2022

Hi Robin and thanks for your message! I like the idea (maybe in a slightly more general form to mimic the key = ... and value = ... approach in osmdata), but I need some time to implement the first prototype. I will add a PR here as soon as possible.

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