-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5395e6f
commit a6522b6
Showing
14 changed files
with
52 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
_arcgis/ | ||
/.quarto/ | ||
.Rproj.user | ||
_site/ | ||
^.quarto*$ | ||
.quarto | ||
./quarto/* | ||
/.quarto/ | ||
/.quarto/ |
17 changes: 17 additions & 0 deletions
17
_freeze/docs/layers/read-rasters/execute-results/html.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"hash": "5ccd2dc4ed13c30630dbb1766df09ddd", | ||
"result": { | ||
"engine": "knitr", | ||
"markdown": "---\ntitle: \"Reading Image Services\"\nfreeze: true\n---\n\n\nArcGIS Online and Enterprise web services can easily be read into R using`{arcgislayers}`. Supported service types include:\n\n - [FeatureServer](https://developers.arcgis.com/rest/services-reference/enterprise/feature-service.htm)\n - [FeatureLayer](https://developers.arcgis.com/rest/services-reference/enterprise/feature-layer.htm)\n - [Table](https://developers.arcgis.com/rest/services-reference/enterprise/feature-layer.htm)\n - [MapServer](https://developers.arcgis.com/rest/services-reference/enterprise/map-service.htm)\n - [GroupLayer](https://developers.arcgis.com/web-map-specification/objects/groupLayer/)\n - [ImageServer](https://developers.arcgis.com/rest/services-reference/enterprise/image-service.htm)\n\n\nMetadata 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.\n\nThis 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).\n\n## Objective\n\nThe objective of this tutorial is to teach you how to:\n\n- find a image service url from ArcGIS Online\n- read in the data from the image service\n- filter the image service by a bounding box\n- use `terra` for viewing and writing\n\n## Obtaining an image service url\n\nFor this example, you will read in multispectral Landsat imagery of the Ouarkziz Crater from ArcGIS Online. \n\nYou 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. \n\n\n![](../images/read-data/multispectral-landsat.png)\nWhen you scroll down, on the right hand side, you will see a button to view the service itself. \n\n![](../images/read-data/view-url-imagery.png){width=45%}\n\nClicking this will bring you to the Image Service, where you can more closely investigate the metadata and supported operations for this service. Navigate to your browser's search bar and copy the url.\n\n```\nhttps://landsat2.arcgis.com/arcgis/rest/services/Landsat/MS/ImageServer\n```\n\n## Opening an Image Service\n\nFirst, load the `arcgis` R package. If you do not have `arcgis` installed, install it with `pak::pak(\"r-arcgis/arcgis\")` or `install.packages(\"arcgis\")`.\n\n:::{.aside}\n`{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. \n:::\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(arcgis)\n```\n\n::: {.cell-output .cell-output-stderr}\n\n```\nAttaching core arcgis packages:\n→ arcgisutils v0.3.0\n→ arcgislayers v0.3.0\n→ arcgisgeocode v0.1.3\n→ arcgisplaces v0.1.0\n```\n\n\n:::\n:::\n\n\nUse the below code to store the image service url in an object called `url`.\n\n\n::: {.cell}\n\n```{.r .cell-code}\nurl <- \"https://landsat2.arcgis.com/arcgis/rest/services/Landsat/MS/ImageServer\"\n```\n:::\n\n\nThen pass this variable to `arc_open()` and save it to `imgsrv` (image service).\n\n\n::: {.cell}\n\n```{.r .cell-code}\nimgsrv <- arc_open(url)\nimgsrv\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n<ImageServer <11 bands, 26 fields>>\nName: Landsat/MS\nDescription: Multispectral Landsat image service covering the landmass of the W\nExtent: -20037507.07 20037507.84 -9694091.07 9691188.93 (xmin, xmax, ymin, ymax)\nResolution: 30 x 30\nCRS: 3857\nCapabilities: Catalog,Image,Metadata\n```\n\n\n:::\n:::\n\n\n`arc_open()` will create a `ImageServer` object. Under the hood, this is really just a list containing the image service's metadata. \n\n:::{.callout-note collapse=\"true\" title=\"ImageServer details for the curious\"}\nThe `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. \n:::\n\nWith this `ImageServer` object, you can read data from the service into R! \n\n## Reading from a Image Service\n\nOnce 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`. \n\n:::{.callout-warning}\nAvoid 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.\n:::\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncrater <- arc_raster(\n imgsrv,\n xmin = \"-846028\",\n ymin = \"3373101\",\n xmax = \"-833783\",\n ymax = \"3380738\"\n)\ncrater\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\nclass : SpatRaster \ndimensions : 400, 400, 11 (nrow, ncol, nlyr)\nresolution : 30.6125, 30.6125 (x, y)\nextent : -846028, -833783, 3370797, 3383042 (xmin, xmax, ymin, ymax)\ncoord. ref. : WGS 84 / Pseudo-Mercator (EPSG:3857) \nsource : file13b4a2cd01c61.tiff \nnames : Coast~rosol, Blue, Green, Red, NearInfrared, Short~red_1, ... \n```\n\n\n:::\n:::\n\n\nThe result is a `SpatRaster` object that you can now work with using **`terra`** and any other R packages. \n\n\n### Using `terra`\n\nFrom here, you can pursue your own raster and imagery workflows using `terra`. For some simple examples, consider plotting the image:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nterra::plotRGB(crater, stretch = \"lin\")\n```\n\n::: {.cell-output-display}\n![](read-rasters_files/figure-html/unnamed-chunk-5-1.png){width=672}\n:::\n:::\n\n\nor saving the image locally:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nterra::writeRaster(crater, \"ouarkziz-crater-RGB.tif\", overwrite = TRUE)\n```\n:::\n", | ||
"supporting": [ | ||
"read-rasters_files" | ||
], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,4 +86,5 @@ format: | |
highlight-style: pygments | ||
|
||
execute: | ||
keep-md: true | ||
freeze: true |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.