For shapefile it has to be the name of the file without extension, so whatever you nominate as layer will be the file name, if you try to separate these by giving an explicit filename in dsn
then the layer
will be ignored.
u <- "http://geoportal.statistics.gov.uk/datasets/8edafbe3276d4b56aec60991cbddda50_2.geojson"
d <- rgdal::readOGR(u)
rgdal::writeOGR(d, dsn = ".", layer = "somelayer", driver = "ESRI Shapefile")
list.files(pattern = "shp$")
[1] "somelayer.shp"
rgdal
tells me it's simply the name of the file without extension:
rgdal::ogrListLayers(u)
[1] "8edafbe3276d4b56aec60991cbddda50_2"
attr(,"driver")
[1] "GeoJSON"
attr(,"nlayers")
[1] 1
As does sf
sf::st_layers(u)
Driver: GeoJSON
Available layers:
layer_name geometry_type features fields
1 8edafbe3276d4b56aec60991cbddda50_2 380 6
and vapour
vapour::vapour_layer_names(u)
[1] "8edafbe3276d4b56aec60991cbddda50_2"
and GDAL at the command line
system(sprintf("ogrinfo %s ", u))
INFO: Open of `http://geoportal.statistics.gov.uk/datasets/8edafbe3276d4b56aec60991cbddda50_2.geojson'
using driver `GeoJSON' successful.
1: 8edafbe3276d4b56aec60991cbddda50_2
For GeoJSON, it can be more complicated, since you can nominate your own layer name independently of the file name.
rgdal::writeOGR(d, "file.geojson", "layername", "GeoJSON")
rgdal::ogrListLayers("file.geojson")
[1] "layername"
attr(,"driver")
[1] "GeoJSON"
attr(,"nlayers")
[1] 1
Older versions of GDAL had a generic name, the new logic is described here:
Starting with GDAL 2.2, the layer name is built with the following
logic:
If a "name" member is found at the FeatureCollection level, it is
used. Otherwise if the filename is regular (ie not a URL with query
parameters), then the filename without extension and path is used as
the layer name. Otherwise OGRGeoJSON is used.