
Create a square polygon (block) based on input coordinates and size
MakeBlockPolygon.Rd
This function creates a square polygon (block) that contains the input coordinates.
The block is aligned to a grid defined by the size
parameter, with the coordinates
rounded to the nearest multiple of size
. The resulting polygon is returned as an sf
object.
Value
An sf
object representing the square polygon. The polygon is created in the
WGS 84 coordinate reference system (EPSG:4326).
Details
The function calculates the lower-left corner of the block by aligning the input coordinates
to a grid defined by the size
parameter. For example:
If
x = 5.2
,y = 10.7
, andsize = 1
, the lower-left corner will be at(5, 10)
.The block will extend from
(5, 10)
to(6, 11)
.If
x = 5.2
,y = 10.7
, andsize = 0.1
, the lower-left corner will be at(5.1, 10.6)
.The block will extend from
(5.1, 10.6)
to(5.2, 10.7)
.
The polygon is created with vertices in the following order:
Lower-left corner
(xll, yll)
Lower-right corner
(xll + size, yll)
Upper-right corner
(xll + size, yll + size)
Upper-left corner
(xll, yll + size)
Lower-left corner
(xll, yll)
(to close the polygon)
The resulting polygon is returned as an sf
object with a WGS 84 (EPSG:4326) coordinate
reference system.
Examples
# Create a 1x1 degree block including the point (5.2, 10.7) aligned to a 1x1 degree grid:
block <- MakeBlockPolygon(5.2, 10.7, 1)
print(block)
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POLYGON
#> Dimension: XY
#> Bounding box: xmin: 5 ymin: 10 xmax: 6 ymax: 11
#> Geodetic CRS: WGS 84
#> geometry
#> 1 POLYGON ((5 10, 6 10, 6 11,...
plot(block)
# Create a 0.25x0.25 degree block including the point (5.2, 10.7) aligned to a 0.25x0.25 degree grid:
block2 <- MakeBlockPolygon(5.2, 10.7, 0.25)
print(block2)
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POLYGON
#> Dimension: XY
#> Bounding box: xmin: 5 ymin: 10.5 xmax: 5.25 ymax: 10.75
#> Geodetic CRS: WGS 84
#> geometry
#> 1 POLYGON ((5 10.5, 5.25 10.5...
sf::st_centroid(block2)
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 5.125 ymin: 10.62501 xmax: 5.125 ymax: 10.62501
#> Geodetic CRS: WGS 84
#> geometry
#> 1 POINT (5.125 10.62501)