You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/layers/read-layers.qmd
+23-20Lines changed: 23 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,11 @@ ArcGIS Online and Enterprise web services can easily be read into R using`{arcgi
15
15
16
16
Metadata for all of the above service types can be accessed using `arc_open()`. Feature data can be read in using `arc_select()` for FeatureLayer, Table, and ImageServer.
17
17
18
-
This tutorial will teach you the basics of reading data from hosted Feature Layers into R as [`{sf}`](https://r-spatial.github.io/sf/) objects using`{arcgislayers}`.
18
+
This tutorial will teach you the basics of reading data from hosted Feature Layers into R as [`{sf}`](https://r-spatial.github.io/sf/) objects using`{arcgislayers}`.
19
+
20
+
:::{.callout-note}
21
+
When leveraging Esri hosted content, organizations should review the [ArcGIS Online terms of use](https://doc.arcgis.com/en/arcgis-online/reference/terms-of-use.htm), as well as the terms of use for the data layer to ensure they are in compliance with extracting data and/or making it available in other systems.
22
+
:::
19
23
20
24
## Objective
21
25
@@ -28,21 +32,21 @@ The objective of this tutorial is to teach you how to:
28
32
29
33
## Obtaining a feature layer url
30
34
31
-
For this example, you will read in population data of major US cities from ArcGIS Online.
35
+
For this example, you will read in population data of major US cities from ArcGIS Online.
32
36
33
-
You will use the functions `arc_open()` and `arc_select()` to read data from ArcGIS Online into R. However, these functions require the url of the hosted feature service. To find this, navigate to the [item](https://www.arcgis.com/home/item.html?id=9df5e769bfe8412b8de36a2e618c7672) in ArcGIS Online.
37
+
You will use the functions `arc_open()` and `arc_select()` to read data from ArcGIS Online into R. However, these functions require the url of the hosted feature service. To find this, navigate to the [item](https://www.arcgis.com/home/item.html?id=9df5e769bfe8412b8de36a2e618c7672) in ArcGIS Online.
34
38
35
39
36
40

37
-
When you scroll down, on the right hand side, you will see a button to view the service itself.
41
+
When you scroll down, on the right hand side, you will see a button to view the service itself.
38
42
39
43
{width=45%}
40
44
41
-
Clicking this will bring you to the Feature Service. Inside of a Feature Server there may be many layers or tables that you can use. In this case, there is only one layer. Click the hyperlinked **USA Major Cities**.
45
+
Clicking this will bring you to the Feature Service. Inside of a Feature Server there may be many layers or tables that you can use. In this case, there is only one layer. Click the hyperlinked **USA Major Cities**.
Before you can read in the Feature Layer, you need to load the `arcgis` R package. If you do not have `arcgis` installed, install it with `pak::pak("r-arcgis/arcgis")` or `install.packages("arcgis")`.
58
62
59
63
:::{.aside}
60
-
`{pak}` is an R package that makes it faster and easier to install R packages. If you do not have it installed, run `install.packages("pak")` first.
64
+
`{pak}` is an R package that makes it faster and easier to install R packages. If you do not have it installed, run `install.packages("pak")` first.
61
65
:::
62
66
63
67
```{r}
@@ -77,39 +81,39 @@ flayer <- arc_open(furl)
77
81
flayer
78
82
```
79
83
80
-
`arc_open()` will create a `FeatureLayer` object. Under the hood, this is really just a list containing the feature layer's metadata.
84
+
`arc_open()` will create a `FeatureLayer` object. Under the hood, this is really just a list containing the feature layer's metadata.
81
85
82
86
:::{.callout-note collapse="true" title="FeatureLayer details for the curious"}
83
-
The `FeatureLayer` object is obtained by adding `?f=json` to the feature layer url and processing the json. All of the metadata is stored in the `FeatureLayer` object. You can see this by running `unclass(flayer)`. Be warned! It gets messy.
87
+
The `FeatureLayer` object is obtained by adding `?f=json` to the feature layer url and processing the json. All of the metadata is stored in the `FeatureLayer` object. You can see this by running `unclass(flayer)`. Be warned! It gets messy.
84
88
:::
85
89
86
-
With this `FeatureLayer` object, you can read data from the service into R!
90
+
With this `FeatureLayer` object, you can read data from the service into R!
87
91
88
92
## Reading from a Feature Layer
89
93
90
94
Once you have a `FeatureLayer` object, you can read its data into memory using the `arc_select()` function. By default, if you use `arc_select()` on a `FeatureLayer` without any additional arguments, the entire service will be brought into memory.
91
95
92
96
:::{.callout-warning}
93
-
Avoid reading in more data than you need! Reading an entire feature service is fine for datasets with fewer than 5,000 features. But when there are more than 10,000 features, performance and memory may be throttled.
97
+
Avoid reading in more data than you need! Reading an entire feature service is fine for datasets with fewer than 5,000 features. But when there are more than 10,000 features, performance and memory may be throttled.
94
98
95
99
Exceptionally detailed geometries require more data to be transferred across the web and may be slower to process and may require adjustment of the `page_size` argument of `arc_select()`.
96
100
:::
97
101
98
-
Store the results of `arc_select()` in the object `cities`.
102
+
Store the results of `arc_select()` in the object `cities`.
99
103
100
104
```{r, message = FALSE}
101
105
cities <- arc_select(flayer)
102
106
cities
103
107
```
104
108
105
-
The result is an `sf` object that you can now work with using **`sf`** and any other R packages.
109
+
The result is an `sf` object that you can now work with using **`sf`** and any other R packages.
106
110
107
-
### Specifying output fields
111
+
### Specifying output fields
108
112
109
-
In some cases, you may have Feature Layers with many extraneous fields. You can specify which fields to return to R using the `fields` argument.
113
+
In some cases, you may have Feature Layers with many extraneous fields. You can specify which fields to return to R using the `fields` argument.
110
114
111
115
:::{.callout-tip}
112
-
Remember to only read in the data that you need. Adding unneeded fields uses more memory and takes longer to process.
116
+
Remember to only read in the data that you need. Adding unneeded fields uses more memory and takes longer to process.
113
117
:::
114
118
115
119
`fields` takes a character vector of field names. To see which fields are available in a Feature Layer, you can use the utility function `list_fields()`.
@@ -122,11 +126,11 @@ fields[, 1:4]
122
126
For the sake of readability, only the first 4 columns are displayed.
123
127
:::
124
128
125
-
Let's try reading in only the `"STATE_ABBR"`, `"POPULATION"`, and `"NAME"` fields.
129
+
Let's try reading in only the `"STATE_ABBR"`, `"POPULATION"`, and `"NAME"` fields.
126
130
127
131
```{r}
128
132
arc_select(
129
-
flayer,
133
+
flayer,
130
134
fields = c("STATE_ABBR", "POPULATION", "NAME")
131
135
)
132
136
```
@@ -135,7 +139,7 @@ arc_select(
135
139
136
140
Not only can you limit the number of columns returned from a Feature Layer, but you can also limit the number of rows returned. This is very handy in the case of Feature Layers with hundreds of thousands of features. Reading all of those features into memory would be slow, costly (in terms of memory), and, in many cases, unnecessary!
137
141
138
-
The `where` argument of `arc_select()` permits you to provide a very simple SQL where clause to limit the features returned. Let's explore the use of the `where` argument.
142
+
The `where` argument of `arc_select()` permits you to provide a very simple SQL where clause to limit the features returned. Let's explore the use of the `where` argument.
139
143
140
144
Let's modify the above `arc_select()` statement to return only the features in California, using the where clause `STATE_ABBR = 'CA'`
141
145
@@ -210,4 +214,3 @@ There is also a helper `get_all_layers()` to fetch all of layers of a `FeatureSe
Copy file name to clipboardExpand all lines: docs/layers/read-rasters.qmd
+14-10Lines changed: 14 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,11 @@ Metadata for all of the above service types can be accessed using `arc_open()`.
18
18
19
19
This tutorial will teach you the basics of reading data from hosted image services into R as [`{terra} SpatRaster`](https://rspatial.github.io/terra/reference/rast.html) objects using`{arcgislayers}`. The source for an image service is published raster or imagery data. To learn more about image services, see the [Image services documentation](https://enterprise.arcgis.com/en/server/latest/publish-services/windows/key-concepts-for-image-services.htm).
20
20
21
+
:::{.callout-note}
22
+
When leveraging Esri hosted content, organizations should review the [ArcGIS Online terms of use](https://doc.arcgis.com/en/arcgis-online/reference/terms-of-use.htm), as well as the terms of use for the data layer to ensure they are in compliance with extracting data and/or making it available in other systems.
23
+
:::
24
+
25
+
21
26
## Objective
22
27
23
28
The objective of this tutorial is to teach you how to:
@@ -29,13 +34,13 @@ The objective of this tutorial is to teach you how to:
29
34
30
35
## Obtaining an image service url
31
36
32
-
For this example, you will read in multispectral Landsat imagery of the Ouarkziz Crater from ArcGIS Online.
37
+
For this example, you will read in multispectral Landsat imagery of the Ouarkziz Crater from ArcGIS Online.
33
38
34
-
You will use the functions `arc_open()` and `arc_raster()` to read image data from ArcGIS Online into R. However, these functions require the url of the hosted image service. To find this, navigate to the [item](https://www.arcgis.com/home/item.html?id=d9b466d6a9e647ce8d1dd5fe12eb434b) in ArcGIS Online.
39
+
You will use the functions `arc_open()` and `arc_raster()` to read image data from ArcGIS Online into R. However, these functions require the url of the hosted image service. To find this, navigate to the [item](https://www.arcgis.com/home/item.html?id=d9b466d6a9e647ce8d1dd5fe12eb434b) in ArcGIS Online.
35
40
36
41
37
42

38
-
When you scroll down, on the right hand side, you will see a button to view the service itself.
43
+
When you scroll down, on the right hand side, you will see a button to view the service itself.
First, load the `arcgis` R package. If you do not have `arcgis` installed, install it with `pak::pak("r-arcgis/arcgis")` or `install.packages("arcgis")`.
51
56
52
57
:::{.aside}
53
-
`{pak}` is an R package that makes it faster and easier to install R packages. If you do not have it installed, run `install.packages("pak")` first.
58
+
`{pak}` is an R package that makes it faster and easier to install R packages. If you do not have it installed, run `install.packages("pak")` first.
54
59
:::
55
60
56
61
```{r}
@@ -74,17 +79,17 @@ imgsrv <- arc_open(url)
74
79
imgsrv
75
80
```
76
81
77
-
`arc_open()` will create a `ImageServer` object. Under the hood, this is really just a list containing the image service's metadata.
82
+
`arc_open()` will create a `ImageServer` object. Under the hood, this is really just a list containing the image service's metadata.
78
83
79
84
:::{.callout-note collapse="true" title="ImageServer details for the curious"}
80
-
The `ImageServer` object is obtained by adding `?f=json` to the image server url and processing the json. All of the metadata is stored in the `ImageServer` object. You can see this by running `unclass(imgsrv)`. Be warned! It gets messy.
85
+
The `ImageServer` object is obtained by adding `?f=json` to the image server url and processing the json. All of the metadata is stored in the `ImageServer` object. You can see this by running `unclass(imgsrv)`. Be warned! It gets messy.
81
86
:::
82
87
83
-
With this `ImageServer` object, you can read data from the service into R!
88
+
With this `ImageServer` object, you can read data from the service into R!
84
89
85
90
## Reading from a Image Service
86
91
87
-
Once you have a `ImageServer` object, you can access the image data using the `arc_raster()` function. Pass the coordinates for a bounding box into the function using the `xmin`, `ymin`, `xmax`, and `ymax` arguments. Store the results of `arc_raster()` in the object `crater`.
92
+
Once you have a `ImageServer` object, you can access the image data using the `arc_raster()` function. Pass the coordinates for a bounding box into the function using the `xmin`, `ymin`, `xmax`, and `ymax` arguments. Store the results of `arc_raster()` in the object `crater`.
88
93
89
94
:::{.callout-warning}
90
95
Avoid reading in more data than you need! When extracting data from an image service, it is best practice to include a bounding box to limit the extraction to just the area that you need. Make sure to provide the bounding box coordinates in the Coordinate Reference System (CRS) of the image service or use the `bbox_crs` argument to specify another CRS for these coordinates.
@@ -101,7 +106,7 @@ crater <- arc_raster(
101
106
crater
102
107
```
103
108
104
-
The result is a `SpatRaster` object that you can now work with using **`terra`** and any other R packages.
109
+
The result is a `SpatRaster` object that you can now work with using **`terra`** and any other R packages.
0 commit comments