Title: | Pull Data from an 'ArcGIS REST' API |
---|---|
Description: | Functions to efficiently query 'ArcGIS REST' APIs <https://developers.arcgis.com/rest/>. Both spatial and SQL queries can be used to retrieve data. Simple Feature (sf) objects are utilized to perform spatial queries. This package was neither produced nor is maintained by Esri. |
Authors: | Paul Frater [aut, cre] , Zac Driscoll [aut] |
Maintainer: | Paul Frater <[email protected]> |
License: | GPL-3 |
Version: | 0.2.9 |
Built: | 2024-11-07 06:24:36 UTC |
Source: | CRAN |
A package for pulling spatial data from an ArcGIS REST API
The role of the arcpullr package is simple...to pull spatial data from an ArcGIS REST API. These APIs are housed by various different agencies, organizations, entitites, etc., but allow a consistent format for storing and retrieving spatial data
get_spatial_layer
This function makes up the core of the package. It allows users to pull spatial data given a URL of an ArcGIS REST API. There are many additional query parameters that can (and probably should) be added; however, we've simplified many of these out for you with the functions below.
get_layer_by_spatial
family of functionsThese functions allow you to pull layers using a spatial query. The abstract syntax is wrapped into the functions, so all you have to do is pass these functions an sf object of the spatial area, line, or point you want to query by. These functions include get_layer_by_poly, get_layer_by_point, get_layer_by_line, get_layer_by_multipoint, and get_layer_by_envelope. It should be fairly obvious what type of spatial layer each function takes with the exception of get_layer_by_envelope except that it isn't particularly useful for a single point.
get_image_layer
This is one of the core functions of the package. It retrieves image service layers from an ArcGIS REST API designated by the URL
get_map_layer
This is one of the core functions of the package. It retrieves map service layers from an ArcGIS REST API designated by the URL
There are a few utility functions to help you along the way. The first is
plot_layer
, which is a useful way to plot the spatial layer
you've tried to pull just to make sure it works. If you want fancier maps
you'd be better served with ggplot2 or tmaps, though.
Other helpers include the sf_objects
functions, which allow
you to easily create sf points, lines, and polygons with a few coordinates.
Lastly, there is a sql_where
function to help aid in building
more complex SQL WHERE clauses used to query by the where argument in the
retrieval functions above.
These are URLs that are used for examples throughout the package
reykjanes_lava_flow_url wi_hydro_url wi_landcover_url wi_leaf_off_url
reykjanes_lava_flow_url wi_hydro_url wi_landcover_url wi_leaf_off_url
Character strings of URLs
An object of class character
of length 1.
An object of class character
of length 1.
An object of class character
of length 1.
Use this function to convert the coordinates of a sf polygon object to a string of well known text. The output can be passed to an ArcGIS REST API to perform a spatial query.
format_polygon_coords(sf_obj) format_line_coords(sf_obj) format_multipoint_coords(sf_obj) format_point_coords(sf_obj) format_envelope_coords(sf_obj) format_coords(sf_obj, geom_type)
format_polygon_coords(sf_obj) format_line_coords(sf_obj) format_multipoint_coords(sf_obj) format_point_coords(sf_obj) format_envelope_coords(sf_obj) format_coords(sf_obj, geom_type)
sf_obj |
An sf object |
geom_type |
Either "points", "paths", or "rings". Choose wisely |
Spatial queries from an ArcGIS REST API require specific text inputs formatted in a way called well-known text (WKT). ArcGIS REST APIs have their own syntax for how the text is taken. These functions will format sf objects in the correct way to be able to make spatial queries from a ArcGIS REST API
String of well known text
mke_polygon_coords <- format_polygon_coords(mke_county)
mke_polygon_coords <- format_polygon_coords(mke_county)
Get Geometry Type
get_geometry_type(url)
get_geometry_type(url)
url |
A character string of a feature services URL |
A character string of the layers geometry type
## Not run: get_geometry_type(reykjanes_lava_flow_url) ## End(Not run)
## Not run: get_geometry_type(reykjanes_lava_flow_url) ## End(Not run)
This function retrieves image service layers from an ArcGIS
REST services API and returns them as a RasterStack
object
get_image_layer( url, sf_object = NULL, bbox = NULL, bbox_crs = NULL, token = "", clip_raster = TRUE, format = "png", transparent = TRUE, ... )
get_image_layer( url, sf_object = NULL, bbox = NULL, bbox_crs = NULL, token = "", clip_raster = TRUE, format = "png", transparent = TRUE, ... )
url |
A character string of the url for the layer to pull |
sf_object |
An |
bbox |
Vector of bounding box coordinates |
bbox_crs |
CRS for bbox (required if bbox is used) |
token |
A character string of the token (if needed) |
clip_raster |
Logical. Should the raster be clipped to contain only
the pixels that reside in the |
format |
The raster format desired. Default is "png" |
transparent |
Logical. Retrieve a raster with a transparent background (TRUE, default) or not (FALSE) |
... |
Additional arguments to pass to the ArcGIS REST API |
This is one of the core functions of the package. It retrieves image service
layers from an ArcGIS REST API designated by the URL. These layers require a
bounding box to query the map layer, which is either taken from the
sf_object
argument or optionally can be passed via the bbox
argument. Either sf_object
or bbox
are optional, but one of
them must be present.
All of the querying parameters are sent via a POST request to the URL, so
if there are issues with passing additional parameters via ...
first determine how they fit into the POST request and make adjustments as
needed. This syntax can be tricky if you're not used to it.
A "RasterStack" object
## Not run: wi_leaf_off_layer <- get_image_layer(wi_leaf_off_url, wis_poly) plot_layer(wi_leaf_off_layer, outline_poly = wis_poly) ## End(Not run)
## Not run: wi_leaf_off_layer <- get_image_layer(wi_leaf_off_url, wis_poly) plot_layer(wi_leaf_off_layer, outline_poly = wis_poly) ## End(Not run)
Used internally to pull HTML for a layer's web page so that the call
doesn't have to be made twice in get_geometry_type
if the
url provided there is for a raster layer.
get_layer_html(url)
get_layer_html(url)
url |
Character. The URL of the web page |
A character string of the HTML body
This function retrieves metadata for a layer.
get_layer_info(url, token = "")
get_layer_info(url, token = "")
url |
A character string of the url for the layer to pull |
token |
A character string of the token (if needed) |
A list of metadata fields
## Not run: # lava flows on Reykjanes (pr. 'rake-yah-ness') peninsula in Iceland lava_flows_info <- get_layer_info(reykjanes_lava_flow_url) ## End(Not run)
## Not run: # lava flows on Reykjanes (pr. 'rake-yah-ness') peninsula in Iceland lava_flows_info <- get_layer_info(reykjanes_lava_flow_url) ## End(Not run)
Raster layers are accompanied with legends to identify what the colors mean. This function retrieves those legend values and returns them as a data.frame with the associated RGB color values. This will likely be most useful for plotting and analysis of map layers.
get_layer_legend(url)
get_layer_legend(url)
url |
A URL to a Map or Image Service layer |
A data.frame with two columns (color, values) and the number of rows equal to the number of values in a layer
## Not run: get_layer_legend(wi_landcover_url) ## End(Not run)
## Not run: get_layer_legend(wi_landcover_url) ## End(Not run)
These functions are wrappers around get_spatial_layer
that are
specialized for querying by a spatial layer. They will make a POST request
to the query URL which returns data (if available) based on the appropriate
spatial feature (geometry
) and relationship (sp_rel
).
get_layer_by_poly(url, geometry, sp_rel = "contains", ...) get_layer_by_line(url, geometry, sp_rel = "intersects", ...) get_layer_by_point(url, geometry, sp_rel = "intersects", ...) get_layer_by_multipoint(url, geometry, sp_rel = "intersects", ...) get_layer_by_envelope(url, geometry, sp_rel = "intersects", ...) get_layer_by_spatial( url, geometry, geom_type, sp_ref = NULL, sp_rel = "intersects", ... )
get_layer_by_poly(url, geometry, sp_rel = "contains", ...) get_layer_by_line(url, geometry, sp_rel = "intersects", ...) get_layer_by_point(url, geometry, sp_rel = "intersects", ...) get_layer_by_multipoint(url, geometry, sp_rel = "intersects", ...) get_layer_by_envelope(url, geometry, sp_rel = "intersects", ...) get_layer_by_spatial( url, geometry, geom_type, sp_ref = NULL, sp_rel = "intersects", ... )
url |
A character string of the url for the layer to pull |
geometry |
An |
sp_rel |
Character. The type of relationship to query by. Possible options include "intersects", "contains", and "crosses" |
... |
Additional arguements to pass to |
geom_type |
A character of the geometry type to be used. This param is
automatically specified in all |
sp_ref |
The spatial reference value |
An object of class "sf" of the appropriate layer
## Not run: mke_waters <- get_layer_by_poly(wi_hydro_url, mke_county) ## End(Not run)
## Not run: mke_waters <- get_layer_by_poly(wi_hydro_url, mke_county) ## End(Not run)
This function retrieves map service layers from an ArcGIS
REST services API and returns them as a RasterLayer
object
get_map_layer( url, sf_object = NULL, bbox = NULL, bbox_crs = NULL, token = "", clip_raster = TRUE, format = "png", transparent = TRUE, add_legend = TRUE, ... )
get_map_layer( url, sf_object = NULL, bbox = NULL, bbox_crs = NULL, token = "", clip_raster = TRUE, format = "png", transparent = TRUE, add_legend = TRUE, ... )
url |
A character string of the url for the layer to pull |
sf_object |
An |
bbox |
Vector of bounding box coordinates |
bbox_crs |
CRS for bbox (required if bbox is used) |
token |
A character string of the token (if needed) |
clip_raster |
Logical. Should the raster be clipped to contain only
the pixels that reside in the |
format |
The raster format desired. Default is "png" |
transparent |
Logical. Retrieve a raster with a transparent background (TRUE, default) or not (FALSE) |
add_legend |
Logical. Pull legend and match to color values (TRUE, default) or not (FALSE) |
... |
Additional arguments to pass to the ArcGIS REST API |
This is one of the core functions of the package. It retrieves map service
layers from an ArcGIS REST API designated by the URL. These layers require a
bounding box to query the map layer, which is either taken from the
sf_object
argument or optionally can be passed via the bbox
argument. Either sf_object
or bbox
are optional, but one of
them must be present.
All of the querying parameters are sent via a POST request to the URL, so
if there are issues with passing additional parameters via ...
first determine how they fit into the POST request and make adjustments as
needed. This syntax can be tricky if you're not used to it.
A "RasterLayer" object
## Not run: wi_landcover<- get_map_layer(wi_landcover_url, wis_poly) plot_layer(wi_landcover, outline_poly = wis_poly) ## End(Not run)
## Not run: wi_landcover<- get_map_layer(wi_landcover_url, wis_poly) plot_layer(wi_landcover, outline_poly = wis_poly) ## End(Not run)
This is an internal function to pull raster layers from either a map service
or an image service of an ArcGIS REST API. This function is the engine that
drives get_map_layer
and get_image_layer
get_raster_layer( url, sf_object = NULL, bbox = NULL, bbox_crs = NULL, token = "", clip_raster = TRUE, format = "png", transparent = TRUE, export_type = "map", add_legend = FALSE, ... )
get_raster_layer( url, sf_object = NULL, bbox = NULL, bbox_crs = NULL, token = "", clip_raster = TRUE, format = "png", transparent = TRUE, export_type = "map", add_legend = FALSE, ... )
url |
A character string of the url for the layer to pull |
sf_object |
An |
bbox |
Vector of bounding box coordinates |
bbox_crs |
CRS for bbox (required if bbox is used) |
token |
A character string of the token (if needed) |
clip_raster |
Logical. Should the raster be clipped to contain only
the pixels that reside in the |
format |
The raster format desired. Default is "png" |
transparent |
Logical. Retrieve a raster with a transparent background (TRUE, default) or not (FALSE) |
export_type |
Character. Either "map" or "image" for the respective service layer desired |
add_legend |
Logical. Pull legend and match to color values (TRUE, default) or not (FALSE) |
... |
Additional arguments to pass to the ArcGIS REST API |
An object of type RasterLayer
if export_type = "map"
or
an object of type RasterStack
if export_type = "image"
This family of functions is meant to pull attributes from a particular service or layer hosted on an ArcGIS REST API. If the service is an ImageServer or MapServer, then the behavior will be slightly different than for a Feature Layer (see details).
get_service_type(url, ...)
get_service_type(url, ...)
url |
A character string of a valid layer URL |
... |
Only used internally, but html can be passed |
get_service_type
will return the type of service or layer for the
respective URL (or html) that is passed to the function. For a feature layer
the function should return "feature_layer", for a Image or Map Server the
function will return "image" or "map", respectively.
get_geometry_type
will return the geometry type of feature service
layers housed on an ArcGIS REST API server. If a URL is provided that points
to a map or image layer the function will return an error (i.e. only
feature layers have geometry types).
get_supported_operations
will simply return a character vector that
lists the supported operations for url
.
A character string defining the layer type
## Not run: get_service_type(reykjanes_lava_flow_url) ## End(Not run)
## Not run: get_service_type(reykjanes_lava_flow_url) ## End(Not run)
Return CRS value of an sf object
get_sf_crs(sf_obj)
get_sf_crs(sf_obj)
sf_obj |
An object of class sf |
A numeric value referring to the coordinate reference system
get_sf_crs(iceland_poly)
get_sf_crs(iceland_poly)
This function retrieves spatial layers present in Feature Service layers of
an ArcGIS REST services API and returns them as an sf
object
get_spatial_layer( url, out_fields = c("*"), where = "1=1", token = "", sf_type = NULL, head = FALSE, ... )
get_spatial_layer( url, out_fields = c("*"), where = "1=1", token = "", sf_type = NULL, head = FALSE, ... )
url |
A character string of the url for the layer to pull |
out_fields |
A character string of the fields to pull for each layer |
where |
A character string of the where condition. Default is 1=1 |
token |
A character string of the token (if needed) |
sf_type |
A character string specifying the layer geometry to convert to sf ("esriGeometryPolygon", "esriGeometryPoint", "esriGeometryPolyline"), if NULL (default) the server will take its best guess |
head |
Logical or numeric. Limits the number of records returned from a
query. If TRUE, only the first 5 records will be returned. If numeric, then
the number of records specified in |
... |
Additional arguments to pass to the ArcGIS REST POST request (or associated internal functions used to query them) |
This is one of the core functions of this package. It retrieves spatial
layers from feature services of an ArcGIS REST API designated by the URL.
Additional querying features can be passed such as a SQL WHERE statement
(where
argument) or spatial queries as well as any other types of
queries that the ArcGIS REST API accepts (using ...
). However, for
easier spatial querying see get_layers_by_spatial
.
All of the querying parameters are sent via a POST request to the URL, so
if there are issues with passing additional parameters via ...
first determine how they fit into the POST request and make adjustments as
needed. This syntax can be tricky if you're not used to it.
An object of class "sf" of the appropriate layer
## Not run: # lava flows on Reykjanes (pr. 'rake-yah-ness') peninsula in Iceland lava_flows <- get_spatial_layer(reykjanes_lava_flow_url) plot_layer(lava_flows, outline_poly = reykjanes_poly) plot_layer(lava_flows, outline_poly = iceland_poly) ## End(Not run)
## Not run: # lava flows on Reykjanes (pr. 'rake-yah-ness') peninsula in Iceland lava_flows <- get_spatial_layer(reykjanes_lava_flow_url) plot_layer(lava_flows, outline_poly = reykjanes_poly) plot_layer(lava_flows, outline_poly = iceland_poly) ## End(Not run)
This function retrieves tables present in an ArcGIS REST services API and returns them as a data frame.
get_table_layer( url, out_fields = "*", where = "1=1", token = "", head = FALSE, ... )
get_table_layer( url, out_fields = "*", where = "1=1", token = "", head = FALSE, ... )
url |
A character string of the url for the layer to pull |
out_fields |
A character string of the fields to pull for each layer |
where |
A character string of the where condition. Default is 1=1 |
token |
A character string of the token (if needed) |
head |
Logical or numeric. Limits the number of records returned from a
query. If TRUE, only the first 5 records will be returned. If numeric, then
the number of records specified in |
... |
Additional arguments to pass to the ArcGIS REST POST request (or associated internal functions used to query them) |
This function retrieves tables from an ArcGIS REST API designated by the
URL. Additional querying features can be passed such as a SQL WHERE
statement (where
argument) as well as any other types of queries
that the ArcGIS REST API accepts (using ...
).
All of the querying parameters are sent via a POST request to the URL, so
if there are issues with passing additional parameters via ...
first determine how they fit into the POST request and make adjustments as
needed. This syntax can be tricky if you're not used to it.
A data frame of the appropriate layer
Colors provided by the legend do not always correspond exactly with the colors in the colortable of a RasterLayer object. They are usually pretty close, though, so this function finds the closest colors, maps them to the appropriate colors in the Raster* object, and applies that to the legend.
match_raster_colors(legend, x)
match_raster_colors(legend, x)
legend |
An object of class raster_legend as returned by
|
x |
A RasterLayer object as returned by |
Raster colors in x
are mapped to those in legend
by converting
the RGB hexadecimal values to a 3D vector of values for red, green and blue.
The closest values are then assigned using 3D Pythagorean theorem to compute
the distance among all colors. The minimum distance in three dimensional
space is the color in x
that gets mapped to the appropriate color in
legend
.
A raster_legend object with corrected colors to match those in
x
## Not run: wi_landcover <- get_map_layer(wi_landcover_url, wis_poly) legend <- get_layer_legend(wi_landcover_url) new_legend <- match_raster_colors(legend, wi_landcover_url) ## End(Not run)
## Not run: wi_landcover <- get_map_layer(wi_landcover_url, wis_poly) legend <- get_layer_legend(wi_landcover_url) new_legend <- match_raster_colors(legend, wi_landcover_url) ## End(Not run)
This function plots a spatial layer as returned from
get_spatial_layer
.
plot_layer(x, ...) plot_layer.sf( x, outline_poly = NULL, outline_size = 1.2, outline_color = "gray30", plot_pkg = "ggplot", ... )
plot_layer(x, ...) plot_layer.sf( x, outline_poly = NULL, outline_size = 1.2, outline_color = "gray30", plot_pkg = "ggplot", ... )
x |
An sf or Raster* object as returned from a
|
... |
Additional arguments to |
outline_poly |
Optional. An sf polygon to outline |
outline_size |
Numeric argument that controls width of parameter |
outline_color |
A character vector of a valid color |
plot_pkg |
Character. The plotting environment to use. Either "ggplot" (default) or "base" |
Either a ggplot
object, or simply plots x
if
plot_pkg = "base"
## Not run: plot_layer(iceland_poly) plot_layer(portage_county, outline_poly = wis_poly) ## End(Not run)
## Not run: plot_layer(iceland_poly) plot_layer(portage_county, outline_poly = wis_poly) ## End(Not run)
Plot a RasterBrick object
## S4 method for signature 'RasterBrick' plot_layer( x, outline_poly = NULL, outline_size = 1.2, outline_color = "gray30", plot_pkg = "ggplot", ... )
## S4 method for signature 'RasterBrick' plot_layer( x, outline_poly = NULL, outline_size = 1.2, outline_color = "gray30", plot_pkg = "ggplot", ... )
x |
An sf or Raster* object as returned from a
|
outline_poly |
Optional. An sf polygon to outline |
outline_size |
Numeric argument that controls width of parameter |
outline_color |
A character vector of a valid color |
plot_pkg |
Character. The plotting environment to use. Either "ggplot" (default) or "base" |
... |
Additional arguments to |
## Not run: wi_aerial <- get_map_layer(wi_leaf_off_url, wis_poly) plot_layer(wi_aerial, outline_poly = wis_poly) ## End(Not run)
## Not run: wi_aerial <- get_map_layer(wi_leaf_off_url, wis_poly) plot_layer(wi_aerial, outline_poly = wis_poly) ## End(Not run)
Plot a RasterLayer object
## S4 method for signature 'RasterLayer' plot_layer( x, outline_poly = NULL, outline_size = 1.2, outline_color = "gray30", legend = TRUE, plot_pkg = "ggplot", ... )
## S4 method for signature 'RasterLayer' plot_layer( x, outline_poly = NULL, outline_size = 1.2, outline_color = "gray30", legend = TRUE, plot_pkg = "ggplot", ... )
x |
An sf or Raster* object as returned from a
|
outline_poly |
Optional. An sf polygon to outline |
outline_size |
Numeric argument that controls width of parameter |
outline_color |
A character vector of a valid color |
legend |
Logical. Only valid when plotting RasterLayers
retrieved from |
plot_pkg |
Character. The plotting environment to use. Either "ggplot" (default) or "base" |
... |
Additional arguments to |
## Not run: wi_landcover <- get_map_layer(wi_landcover_url, wis_poly) plot_layer(wi_landcover, outline_poly = wis_poly) ## End(Not run)
## Not run: wi_landcover <- get_map_layer(wi_landcover_url, wis_poly) plot_layer(wi_landcover, outline_poly = wis_poly) ## End(Not run)
Plot a RasterStack object
## S4 method for signature 'RasterStack' plot_layer( x, outline_poly = NULL, outline_size = 1.2, outline_color = "gray30", plot_pkg = "ggplot", ... )
## S4 method for signature 'RasterStack' plot_layer( x, outline_poly = NULL, outline_size = 1.2, outline_color = "gray30", plot_pkg = "ggplot", ... )
x |
An sf or Raster* object as returned from a
|
outline_poly |
Optional. An sf polygon to outline |
outline_size |
Numeric argument that controls width of parameter |
outline_color |
A character vector of a valid color |
plot_pkg |
Character. The plotting environment to use. Either "ggplot" (default) or "base" |
... |
Additional arguments to |
## Not run: wi_aerial <- get_map_layer(wi_leaf_off_url, wis_poly) plot_layer(wi_aerial, outline_poly = wis_poly) ## End(Not run)
## Not run: wi_aerial <- get_map_layer(wi_leaf_off_url, wis_poly) plot_layer(wi_aerial, outline_poly = wis_poly) ## End(Not run)
Plot an sf object
## S4 method for signature 'sf' plot_layer( x, outline_poly = NULL, outline_size = 1.2, outline_color = "gray30", plot_pkg = "ggplot", ... )
## S4 method for signature 'sf' plot_layer( x, outline_poly = NULL, outline_size = 1.2, outline_color = "gray30", plot_pkg = "ggplot", ... )
x |
An sf or Raster* object as returned from a
|
outline_poly |
Optional. An sf polygon to outline |
outline_size |
Numeric argument that controls width of parameter |
outline_color |
A character vector of a valid color |
plot_pkg |
Character. The plotting environment to use. Either "ggplot" (default) or "base" |
... |
Additional arguments to |
## Not run: plot_layer(wis_poly) ## End(Not run)
## Not run: plot_layer(wis_poly) ## End(Not run)
This function is used internally by plot_layer
to convert a
Raster* object to a data.frame of colors for each pixel that can be used for
plotting with ggplot2
raster_colors(x)
raster_colors(x)
x |
A Raster* object |
A data.frame with 3 columns and length(raster_object)
rows.
Two of these columns are the x-y coordinates of each pixel, and one is a
value for color that can be used for plotting
## Not run: wi_landcover <- get_map_layer(wi_landcover_url, wis_poly) wi_landcover_data <- raster_colors(wi_landcover) head(wi_landcover_data) ## End(Not run)
## Not run: wi_landcover <- get_map_layer(wi_landcover_url, wis_poly) wi_landcover_data <- raster_colors(wi_landcover) head(wi_landcover_data) ## End(Not run)
This function is used internally by plot_layer
to convert a
RasterBrick object to a data.frame of colors for each pixel that can be used
for plotting with ggplot2. Note that this function assumes that the first
three bands in the RasterBrick objects are the RGB values and all additional
bands are ignored.
## S4 method for signature 'RasterBrick' raster_colors(x)
## S4 method for signature 'RasterBrick' raster_colors(x)
x |
A RasterBrick object |
A data.frame with 3 columns and length(raster_object)
rows
## Not run: wi_leaf_off_layer <- get_image_layer(wi_leaf_off_url, wis_poly) wi_leaf_off_data <- raster_colors(wi_leaf_off_layer) ## End(Not run)
## Not run: wi_leaf_off_layer <- get_image_layer(wi_leaf_off_url, wis_poly) wi_leaf_off_data <- raster_colors(wi_leaf_off_layer) ## End(Not run)
This function is used internally by plot_layer
to convert a
RasterLayer object to a data.frame of colors for each pixel that can be used
for plotting with ggplot2
## S4 method for signature 'RasterLayer' raster_colors(x)
## S4 method for signature 'RasterLayer' raster_colors(x)
x |
A RasterLayer object |
A data.frame with 3 columns and length(raster_object)
rows
## Not run: wi_landcover <- get_map_layer(wi_landcover_url, wis_poly) wi_landcover_data <- raster_colors(wi_landcover) ## End(Not run)
## Not run: wi_landcover <- get_map_layer(wi_landcover_url, wis_poly) wi_landcover_data <- raster_colors(wi_landcover) ## End(Not run)
This function is used internally by plot_layer
to convert a
RasterStack object to a data.frame of colors for each pixel that can be used
for plotting with ggplot2. Note that this function assumes that the first
three bands in the RasterStack objects are the RGB values and all additional
bands are ignored.
## S4 method for signature 'RasterStack' raster_colors(x)
## S4 method for signature 'RasterStack' raster_colors(x)
x |
A RasterStack object |
A data.frame with 3 columns and length(raster_object)
rows
## Not run: wi_leaf_off_layer <- get_image_layer(wi_leaf_off_url, wis_poly) wi_leaf_off_data <- raster_colors(wi_leaf_off_layer) ## End(Not run)
## Not run: wi_leaf_off_layer <- get_image_layer(wi_leaf_off_url, wis_poly) wi_leaf_off_data <- raster_colors(wi_leaf_off_layer) ## End(Not run)
These are sf polygons that are used for examples throughout the package
iceland_poly mke_county portage_county reykjanes_poly wis_counties wis_poly cook_creek_ws cook_creek_streams cook_creek_env mke_river poly_streams_contains poly_streams_crosses sugar_creek sugar_creek_env trout_hab_project_pt trout_hab_project_pts example_poly trout_hab_project_pts
iceland_poly mke_county portage_county reykjanes_poly wis_counties wis_poly cook_creek_ws cook_creek_streams cook_creek_env mke_river poly_streams_contains poly_streams_crosses sugar_creek sugar_creek_env trout_hab_project_pt trout_hab_project_pts example_poly trout_hab_project_pts
An object of class sf and data.frame:
An object of class sf
(inherits from data.frame
) with 1 rows and 3 columns.
An object of class sf
(inherits from data.frame
) with 1 rows and 3 columns.
An object of class sf
(inherits from data.frame
) with 1 rows and 2 columns.
An object of class sf
(inherits from data.frame
) with 72 rows and 3 columns.
An object of class sf
(inherits from data.frame
) with 1 rows and 2 columns.
An object of class sf
(inherits from data.frame
) with 1 rows and 7 columns.
An object of class sf
(inherits from tbl_df
, tbl
, data.frame
) with 5 rows and 3 columns.
An object of class sf
(inherits from tbl_df
, tbl
, data.frame
) with 10 rows and 3 columns.
An object of class sf
(inherits from tbl_df
, tbl
, data.frame
) with 5 rows and 5 columns.
An object of class sf
(inherits from data.frame
) with 1 rows and 28 columns.
An object of class sf
(inherits from data.frame
) with 4 rows and 28 columns.
An object of class sf
(inherits from data.frame
) with 7 rows and 28 columns.
An object of class sf
(inherits from data.frame
) with 15 rows and 28 columns.
An object of class sf
(inherits from data.frame
) with 1 rows and 11 columns.
An object of class sf
(inherits from data.frame
) with 4 rows and 11 columns.
An object of class sf
(inherits from data.frame
) with 1 rows and 1 columns.
An object of class sf
(inherits from data.frame
) with 4 rows and 11 columns.
ggplot2's map_data
and Wisconsin DNR ArcGIS REST API
These are raster objects that are used for examples throughout the package
wi_landcover wi_aerial_imagery
wi_landcover wi_aerial_imagery
An object of class RasterLayer
of dimension 400 x 400 x 1.
An object of class RasterBrick
of dimension 400 x 400 x 3.
Wisconsin DNR ArcGIS Image Server
These are simple wrapper functions for creating sf objects from points
sf_line(..., crs = 4326) sf_point(..., crs = 4326) sf_points(..., crs = 4326) sf_polygon(..., crs = 4326) sf_box(xmin, ymin, xmax, ymax, crs = 4326)
sf_line(..., crs = 4326) sf_point(..., crs = 4326) sf_points(..., crs = 4326) sf_polygon(..., crs = 4326) sf_box(xmin, ymin, xmax, ymax, crs = 4326)
... |
The coordinates of the object |
crs |
The coordinate reference system. Defaults to 4326 |
xmin , xmax , ymin , ymax
|
Corners for sf_box |
An sf object of the appropriate type
pt_a <- c(-90, 45) pt_b <- c(-89, 44) pt <- sf_points(pt_a) line <- sf_line(pt_a, pt_b)
pt_a <- c(-90, 45) pt_b <- c(-89, 44) pt <- sf_points(pt_a) line <- sf_line(pt_a, pt_b)
These data.frames are used to lookup and explain which spatial relation types go with different spatial queries.
sp_rel_valid sp_rel_lookup
sp_rel_valid sp_rel_lookup
sp_rel_valid
is a data.frame with 105 rows and 3 variables as
follows:
A feature class to be queried
The feature class used to do a spatial query
The spatial relationships that are valid for the feature class and query_feature_class combination
sp_rel_lookup
is a data.frame with 9 rows and 2 variables as
follows:
The spatial relationship being described
A description of the sp_rel
sp_rel_lookup explains the various different types of spatial relationships available through ArcGIS REST APIs. sp_rel_valid shows which spatial relationships are valid with different geometry types being queried and used to do spatial queries
sp_rel_valid–Independent tests done specifically by and for arcpullr
sp_rel_lookup – https://help.arcgis.com/en/webapi/wpf/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.SpatialRelationship.html
After typing "esriSpatialRelIntersects" into 4 to 5 functions, you'll get
pretty sick of typing that. This function serves to allow shorthand strings
to be passed to the sp_rel
arguments of the
get_layers_by_spatial
family of functions. For example, you can
pass "intersects" to this function and it will return
"esriSpatialRelIntersects"
sp_rel_xref(x)
sp_rel_xref(x)
x |
A character string. One of "contains", "crosses", "envelopeintersects", "indexintersects", "intersects", "overlaps", "relation", "touches", "within" |
The appropriately named ESRI version of x
. For example,
an x
value of "intersects" returns "esriSpatialRelIntersects"
sp_rel_xref("intersects")
sp_rel_xref("intersects")
This function will create a where statement that is compatible with
get_spatial_layer
). This statement can then be passed
to the where
argument in this function.
sql_where(..., rel_op = "=")
sql_where(..., rel_op = "=")
... |
Named objects to be queried by |
rel_op |
Character. The relational operator in the SQL clause (i.e. "=",
"IN", "NOT IN", etc.). If a single rel_op is provide with multiple ...
parameters then it will be recycled |
A character string that can be passed to the where argument of
get_spatial_layer
## Not run: wbics <- sql_where(WATERBODY_WBIC = c(805400, 804600), rel_op = "IN") lakes <- get_spatial_layer(wi_hydro_url, where = wbics) plot_layer(lakes) ## End(Not run)
## Not run: wbics <- sql_where(WATERBODY_WBIC = c(805400, 804600), rel_op = "IN") lakes <- get_spatial_layer(wi_hydro_url, where = wbics) plot_layer(lakes) ## End(Not run)
Check to see which spatial relation types are applicable to the feature classes being queried and the sf objects use do to a spatial query
valid_sp_rel(fc1, fc2, pull = TRUE)
valid_sp_rel(fc1, fc2, pull = TRUE)
fc1 |
Character. The feature class type being queried. Available options are "point", "multipoint", "line", or "area". |
fc2 |
Character. The geometry type of the sf object used to do a spatial query. Available options are "point", "multipoint", "line", or "area". |
pull |
Logical. Pull the available options (TRUE) or print all columns of the sp_rel_valid data.frame for the appropriate fc1 and fc2 |
Either a vector or filtered data.frame showing the appropriate sp_rels for the given feature classes
valid_sp_rel("line", "line")
valid_sp_rel("line", "line")