| geojson_write.SpatialRings {geojsonio} | R Documentation |
## S3 method for class 'SpatialRings' geojson_write( input, lat = NULL, lon = NULL, geometry = "point", group = NULL, file = "myfile.geojson", overwrite = TRUE, precision = NULL, convert_wgs84 = FALSE, crs = NULL, ... ) ## S3 method for class 'SpatialRingsDataFrame' geojson_write( input, lat = NULL, lon = NULL, geometry = "point", group = NULL, file = "myfile.geojson", overwrite = TRUE, precision = NULL, convert_wgs84 = FALSE, crs = NULL, ... ) ## S3 method for class 'SpatialCollections' geojson_write( input, lat = NULL, lon = NULL, geometry = "point", group = NULL, file = "myfile.geojson", overwrite = TRUE, precision = NULL, convert_wgs84 = FALSE, crs = NULL, ... )
input |
Input list, data.frame, spatial class, or sf class.
Inputs can also be dplyr |
lat |
(character) Latitude name. The default is |
lon |
(character) Longitude name. The default is |
geometry |
(character) One of point (Default) or polygon. |
group |
(character) A grouping variable to perform grouping for polygons - doesn't apply for points |
file |
(character) A path and file name (e.g., myfile), with the
|
overwrite |
(logical) Overwrite the file given in |
precision |
desired number of decimal places for the coordinates in the geojson file. Using fewer decimal places can decrease file sizes (at the cost of precision). |
convert_wgs84 |
Should the input be converted to the
standard CRS for GeoJSON (https://tools.ietf.org/html/rfc7946)
(geographic coordinate reference
system, using the WGS84 datum, with longitude and latitude units of decimal
degrees; EPSG: 4326). Default is |
crs |
The CRS of the input if it is not already defined. This can be
an epsg code as a four or five digit integer or a valid proj4 string. This
argument will be ignored if |
... |
Further args passed on to internal functions. For Spatial*
classes, data.frames,
regular lists, and numerics, it is passed through to
|
Due to the retirement of rgeos and maptools in 2023, the following functions are now defunct. They will be removed entirely in the future.
At the moment, there is no replacement for these functions that uses the newer geos package (or any alternative for maptools). If you'd be interested in contributing replacements, please feel free to contribute a pull request!
## Not run:
# From SpatialRings
library(rgeos)
r1 <- Ring(cbind(x = c(1, 1, 2, 2, 1), y = c(1, 2, 2, 1, 1)), ID = "1")
r2 <- Ring(cbind(x = c(1, 1, 2, 2, 1), y = c(1, 2, 2, 1, 1)), ID = "2")
r1r2 <- SpatialRings(list(r1, r2))
geojson_write(r1r2)
# From SpatialRingsDataFrame
dat <- data.frame(id = c(1, 2), value = 3:4)
r1r2df <- SpatialRingsDataFrame(r1r2, data = dat)
geojson_write(r1r2df)
# From SpatialCollections
library("sp")
poly1 <- Polygons(list(Polygon(cbind(c(-100, -90, -85, -100), c(40, 50, 45, 40)))), "1")
poly2 <- Polygons(list(Polygon(cbind(c(-90, -80, -75, -90), c(30, 40, 35, 30)))), "2")
poly <- SpatialPolygons(list(poly1, poly2), 1:2)
coordinates(us_cities) <- ~ long + lat
dat <- SpatialCollections(points = us_cities, polygons = poly)
geojson_write(dat)
## End(Not run)