Learn R Programming

geojsonio (version 0.11.0)

geojson_write.SpatialRings: Deprecated functions from geojsonio

Description

[Defunct]

Usage

# S3 method for 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 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 SpatialCollections geojson_write( input, lat = NULL, lon = NULL, geometry = "point", group = NULL, file = "myfile.geojson", overwrite = TRUE, precision = NULL, convert_wgs84 = FALSE, crs = NULL, ... )

Arguments

input

Input list, data.frame, spatial class, or sf class. Inputs can also be dplyr tbl_df class since it inherits from data.frame

lat

(character) Latitude name. The default is NULL, and we attempt to guess.

lon

(character) Longitude name. The default is NULL, and we attempt to guess.

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 .geojson file extension. Default writes to current working directory.

overwrite

(logical) Overwrite the file given in file with input. Default: TRUE. If this param is FALSE and the file already exists, we stop with error message.

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 FALSE though this may change in a future package version. This will only work for sf or Spatial objects with a CRS already defined. If one is not defined but you know what it is, you may define it in the crs argument below.

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 convert_wgs84 is FALSE or the object already has a CRS.

...

Further args passed on to internal functions. For Spatial* classes, data.frames, regular lists, and numerics, it is passed through to sf::st_write(). For sf classes, geo_lists and json classes, it is passed through to jsonlite::toJSON().

Details

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!

Examples

Run this code
if (FALSE) {
# 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)
}

Run the code above in your browser using DataLab