View source: R/create_polygon.R
| createPolygon | R Documentation |
This function lets users create a polygon by point-and-click or directly retrieve polygon data.
createPolygon(countries, ...)
countries |
character string vector with country designations (names or ISO-codes). |
... |
Additional parameters:
|
Parameter countries accepts all designations found in country(query = "country table").
region_ID and region_name accepts region designations for the selected countries, which can be retrieved by country().
The function prioritizes any region_ID and ignores region_name if users provide both.
The matrix from country() listing all region designations may be incomplete as the geodata map data is incomplete in this regard. For mapping purposes, geodata is used throughout this package.
Parameter toponym_path accepts "pkgdir" for the package directory or a full, alternative path.
With toponymOptions(), users can specify the path for toponym and map data downloaded by this package across sessions. See help(toponymOptions).
In RGui, users exit the point selection by middle-clicking or right-clicking and then pressing stop.
In RStudio, users exit the point selection by pressing ESC or Finish in the top right corner of the plot. Users whose points are shifted away, are advised to set the zoom settings of RStudio and of their device to 100%:
Tools -> Global Options -> Appearance -> Zoom
This function uses the function spatstatLocator provided by the spatstat.utils package for the point-and-click functionality.
For further details on the point-and-click mechanism, please refer to the help page for spatstatLocator.
A data frame with the coordinates of the polygon.
## We recommend setting a persistent path for downloaded data by using toponymOptions()
## Users can always set the path manually when a function is used
## For illustration purposes in the following examples,
## 1. the path is manually set each time
## 2. and wrapped in donttest because data will be downloaded
## 3. or if(interactive) because it is interactive:
if(interactive()){
createPolygon("NA", region_ID = "NAM.7_1", toponym_path = tempdir())
# a plot of the region Ohangwena in Namibia appears.
# by point-and-click a polygon can be created
# upon completion, a data frame with the coordinates of the polygon returns
}
Ohangwena_polygon <- createPolygon(
"NA", region_ID = "NAM.7_1", retrieve = TRUE, toponym_path = tempdir())
# no plot appears
# the coordinates of the whole region are stored in the object named `Ohangwena_polygon`
# and can be used by other functions
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.