createPolygon: Creates a polygon

View source: R/create_polygon.R

createPolygonR Documentation

Creates a polygon

Description

This function lets users create a polygon by point-and-click or directly retrieve polygon data.

Usage

createPolygon(countries, ...)

Arguments

countries

character string vector with country designations (names or ISO-codes).

...

Additional parameters:

  • regions numeric. Specifies the level of administrative borders. By default 0 for displaying only country borders.

  • region_ID character string vector with region IDs.

  • region_name character string vector with region names.

  • retrieve logical. If TRUE, the coordinates of the region or country are returned. No map will be drawn.

  • toponym_path character string. Path name for downloaded data.

Details

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.

Value

A data frame with the coordinates of the polygon.

Examples

## 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


toponym documentation built on April 13, 2026, 5:06 p.m.