hrecht / cherry-blossoms-analysis

Analysis and map tile creation for cherry-blossoms project
https://www.hrecht.com/cherry-blossoms/
4 stars 0 forks source link

{arcgislayers} in case you want to use arcgis hub data in the future :) #1

Closed JosiahParry closed 7 months ago

JosiahParry commented 7 months ago

This analysis was super cool! I noticed you hand crafted and processed Feature Layer queries :)

In case you want to use data like this in the future you can make it a little bit easier by using the arcgislayers package!

library(arcgis)
#> Attaching core arcgis packages:
#> → arcgisutils v0.2.0.9000
#> → arcgislayers v0.2.0

# create a reference to the feature layer
cherry_blossoms <- arc_open(
  "https://services2.arcgis.com/j23KFYd23hRWewtZ/arcgis/rest/services/CHERRY_BLOSSOM_DATA_FINAL/FeatureServer/0"
)

# read all features as sf in parallel
all_trees <- arc_select(cherry_blossoms)

# preview
head(all_trees)
#> Simple feature collection with 6 features and 6 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: -8577336 ymin: 4704984 xmax: -8572557 ymax: 4709696
#> Projected CRS: WGS 84 / Pseudo-Mercator
#>   FID                      SciName         CmmnName Species  Genus Cultivar
#> 1   1               Prunus species      Cherry Spp.  <Null> Prunus         
#> 2   2             Prunus yedoensis   Yoshino Cherry  <Null> Prunus         
#> 3   3 Prunus serrulata 'Snowgoose' Snowgoose Cherry  <Null> Prunus         
#> 4   4             Prunus yedoensis   Yoshino Cherry  <Null> Prunus         
#> 5   5               Prunus species      Cherry Spp.  <Null> Prunus         
#> 6   6               Prunus species      Cherry Spp.  <Null> Prunus         
#>                   geometry
#> 1 POINT (-8572557 4704984)
#> 2 POINT (-8572657 4705214)
#> 3 POINT (-8572620 4705181)
#> 4 POINT (-8572618 4705115)
#> 5 POINT (-8576760 4708402)
#> 6 POINT (-8577336 4709696)

Created on 2024-03-20 with reprex v2.0.2

hrecht commented 7 months ago

OMG thank you. I did not know this existed. How long has it been around?? I've been manually pulling from the API in R for years 😮

JosiahParry commented 7 months ago

Unofficially for like 6-8 months. But "officially" like a week and a half ;)

hrecht commented 7 months ago

Haha okay that makes me feel a lot better, I wrote this code more than a week and a half ago. Definitely will use it in the future.

hrecht commented 7 months ago

Not the right place for this question but - I see the documentation says arcgislayers requires [arcgisutils](https://github.com/R-ArcGIS/arcgisutils) for authorization. - do we need an auth token just for reading from the API? I don't actually have an account myself, I don't publish to ArcGIS, just pull data.

JosiahParry commented 7 months ago

Feel free to strike up a convo at https://github.com/R-ArcGIS/arcgislayers/discussions/ if you want :)

But, no. You definitely do not need a token. That is only for reading content that is privately shared. anything that is publicly available doesn't need a token.

A token would be used for publishing, though, for example

hrecht commented 7 months ago

I ran the code and it worked like a charm, thanks again. So much nicer than my initial code. I'll open a proper issue for the token documentation!