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
1 2 3
Argument pass to
Argument pass to
Double greater than 0. Units are in Km. Default
This function generates a grid from
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
mappol. Finally, the returned object is a
help(spTransform) for more details)
is applied for transformation of mappol into a metric projection
(by default web mercator, epsg:3857).
help(gSimplify) for more details)
is applied for simplify geometry of transformed polygon in order
to reduce computation time and memory size.
help(bbox) for more details) is applied to
extract the bounding box of the transformed and simplify
help(spDists) for more details) is applied
for distances calculation.
floor is applied for rounding options.
help(GridTopology) for more details)
is applied to generate the grid. Then,
is applied to transform the
GridTopology object into
for more details) is applied to extract the grid's cells that intersects
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
SpatialPolygonsDataFrame object. It includes all the polygons
that form the grid. Data slot contains the identifiers for each cells.
Enrique Del Callejo Canal ([email protected]), based on implemented algortihms in web platform SPECIES (see References).
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.