View source: R/generatePolygonSamplePoints.R
generatePolygonSamplePoints | R Documentation |
Generate a set of sample points within a polygon. Given an input polygon, create a set of sample points within the polygon. Multi-part polygons are allowed but the number of sample points will be distributed over the parts.
generatePolygonSamplePoints(
inputPolygons,
IDColumnLabel = "",
appendAttributes = FALSE,
columnNameID = "",
pattern = "hexagonal",
polyBuffer = -1,
gridSpacing = 5000,
offset = c(0.5, 0.5),
count = -1,
perturb = FALSE,
perturbMultiplier = 0.5,
minArea = -1,
seedColumnLabel = "",
seed = -1,
verbose = 0
)
inputPolygons |
|
IDColumnLabel |
Character: Name of the column in the |
appendAttributes |
Logical: if TRUE, the fields for the |
columnNameID |
Character: Name for the identifier field in the set of sample points.
If not specified, the name will be |
pattern |
Character indicating the desired sample pattern. |
polyBuffer |
Distance to reduce the size of the polygon(s) by applying |
gridSpacing |
Desired grid size passed to |
offset |
Position of the regular sample grid in the unit cell |
count |
Desired number of sample points. You may not actually get back |
perturb |
Logical: If TRUE, point locations are randomly moved from the location
generated by |
perturbMultiplier |
Multiplier > 0 used to adjust locations generated
by |
minArea |
Minimum area for polygons used to create sample points. This is the total
area covered by the feature so it might include several polygons. The area is evaluated
before and after the |
seedColumnLabel |
Character: Name of the column in |
seed |
Seed for the random number generator to be applied before any sample
generation (outside the loop used to generate sample locations for each polygon in
|
verbose |
if > 0, output status information every |
There are 3 potential interactions between gridSpacing
and count
:
Both have values > 0: gridSpacing
controls the sample point spacing. If the number of
sample points exceeds count
, the set of points is sampled to produce count
points.
count
> 0; gridSpacing
= -1: point spacing is computed using count
and the polygon
area.
count
= -1; gridSpacing
> 0: gridSpacing
controls the sample point spacing and
you get all sample points.
The number of sample points may not exactly match count
due to irregularities in the
the polygon. If count
is between 0 and 1, it is interpreted as the proportion of the
sample points that should be returned. For example, if you want a 10 percent sample of the points
located on a 100 meter grid, set count = 0.1
and gridSpacing = 100
.
If you perturb the locations without using a polyBuffer
, you can end up with points outside
the polygon. The final set of sample points is intersected with the original polygon
so the points outside the polygon are eliminated. However, this final clipping operation
can mess up the count
(number of sample points). This may not be a problem
when gridSpacing
and count
have values (not = -1) because the sampling to reduce the number
of points (if needed) occurs after the clipping operation.
One caution with polyBuffer
:
If you specify a value for polyBuffer
larger than the width of a polygon, you can essentially remove the
polygon so you end up with no sample points. This is especially a problem when you have
project polygons made up of several parts and some of the parts are small. Units for the buffer are
the same as the horizontal units for the input feature so you shouldn't use data in LON-LAT with units
of degrees.
You can call this function with multiple polygons to generate a set of sample points for
each polygon. Each set will have count
points (at least the logic tries to generate count
points).
A set of sample point locations attributed with X, Y, and an identifier created
using either IDColumnLabel
and the sequential point number (when IDColumnLabel
is specified) or just the sequential point number (when IDColumnLabel
is not
specified) and all columns from the inputPolygons
data frame. The return type
will be determined by the type of inputPolygons
. If inputPolygons
is
a Spatial*
type, the return will be a SpatialPointsDataFrame
object and
if inputPolygons
is a simple features (sf)
type, the return will be a
simple features (sf)
type.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.