Description Usage Arguments Details Value Author(s) References Examples
The function generates a grid from pseudo mercator or web Mercator
(epsg:3857) projection system. It is recommended to use metrics projection
to preserve areas. First, transform mappol into web Mercator projection.
Then, the distances between the four coordinates given by the bounding box
are calculated and divided by resolution argument to determine the number
of cells per direction. Finally, GridTopology
is applied
to generate the coordinates that create the final object of class
SpatialPolygonsDataFrame
.
1 2 3 |
mappol |
A |
keep.p4s |
Logical. If |
tol |
Argument pass to |
TP |
Argument pass to |
resolution |
Double greater than 0. Units are in Km. Default |
r.ceiling |
Logical. If |
g.int |
Logical. If |
pretty.int |
Logical ( |
This function generates a grid from SpatialPolygonsDataFrame
object. The main steps are: projection system transformation, geometry
simplification, bounding box extraction, distance calculation,
calculation of cells per direction (Longitude, Latitude), grid
topology creation, class reassignment of grid topology into
SpatialPolygons
object and compute the intersected polygons between
grid and mappol
. Finally, the returned object is a
SpatialPolygonsDataFrame
object.
spTransform
(see help(spTransform)
for more details)
is applied for transformation of mappol into a metric projection
(by default web mercator, epsg:3857).
gSimplify
(see help(gSimplify)
for more details)
is applied for simplify geometry of transformed polygon in order
to reduce computation time and memory size.
bbox
(see help(bbox)
for more details) is applied to
extract the bounding box of the transformed and simplify mappol
.
spDists
(see help(spDists)
for more details) is applied
for distances calculation. ceiling
and
floor
is applied for rounding options.
GridTopology
(see help(GridTopology)
for more details)
is applied to generate the grid. Then, as.SpatialPolygons.GridTopology
is applied to transform the GridTopology
object into
SpatialPolygonsDataFrame
.
Finally, gIntersects
(see help(gIntersects)
for more details) is applied to extract the grid's cells that intersects
mappol
. gContains
and gIntersection
(see help(gContains)
and help(gIntersection)
for more details)
is applied to extract the grid's cells that intersects mappol
and generate
a pretty visualization. The latter method may require considerable computing time
depending on the number of coordinates contained in the mappol
polygon.
A SpatialPolygonsDataFrame
object. It includes all the polygons
that form the grid. Data slot contains the identifiers for each cells.
Enrique Del Callejo Canal (edelcallejoc@gmail.com), based on implemented algortihms in web platform SPECIES (see References).
http://species.conabio.gob.mx/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | library(sp)
library(rgeos)
library(rgdal)
library(raster)
data(Mex0)
# Whithout pretty intersection
# Default resolution is 20 km.
system.time(Mex0.grd<-grd_build(Mex0))
plot(Mex0.grd)
plot(Mex0, add = TRUE)
# ggplot2 interaction
library(ggplot2)
library(mapproj)
ggplot(data = fortify(Mex0.grd), aes(x = long, y = lat, group = group)) +
geom_polygon(colour = "white") +
coord_quickmap()
# leaflet interaction
library(leaflet)
leaflet() %>%
addProviderTiles('OpenStreetMap.Mapnik',
options = providerTileOptions(noWrap = TRUE))%>%
addPolygons(data=Mex0.grd, stroke=TRUE, color = '#FFFFFF',
layerId = Mex0.grd@data$ID, weight = 1, opacity = 0.3,
fillColor = '#A9A9A9', fillOpacity = 0.6,
popup = row.names(Mex0.grd@data))
# With Pretty options
system.time(Mex0.grd.p<-grd_build(Mex0, pretty.int=TRUE))
plot(Mex0.grd.p)
# ggplot2 interaction
ggplot(data = fortify(Mex0.grd.p), aes(x = long, y = lat, group = group)) +
geom_polygon(colour = "white") +
coord_map(projection = "mercator")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.