Convert spatial data files to GeoJSON from various formats.

Share:

Description

The web option uses the Ogre web API. Ogre currently has an output size limit of 15MB. See here http://ogre.adc4gis.com/ for info on the Ogre web API. The local option uses the function writeOGR from the package rgdal.

Note that for Shapefiles, GML, MapInfo, and VRT, you need to send zip files to Ogre. For other file types (.bna, .csv, .dgn, .dxf, .gxt, .txt, .json, .geojson, .rss, .georss, .xml, .gmt, .kml, .kmz) you send the actual file with that file extension.

If you're having trouble rendering geoJSON files, ensure you have a valid geoJSON file by running it through a geoJSON linter http://geojsonlint.com/.

Usage

1
2
file_to_geojson(input, method = "web", output = ".", parse = FALSE,
  encoding = "CP1250", verbose = FALSE, ...)

Arguments

input

The file being uploaded, path to the file on your machine.

method

One of web or local. Matches on partial strings.

output

Destination for output geojson file. Defaults to current working directory

parse

(logical) To parse geojson to data.frame like structures if possible. Default: FALSE

encoding

(character) The encoding passed to readOGR. Default: CP1250

verbose

(logical) Printing of readOGR progress. Default: FALSE

...

Additional parameters passed to readOGR

Details

You can use a web interface called Ogre, or do conversions locally using the rgdal package.

Examples

 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
## Not run: 
file <- system.file("examples", "norway_maple.kml", package = "geojsonio")

# KML type file - using the web method
file_to_geojson(input=file, method='web', output='kml_web')
## read into memory
file_to_geojson(input=file, method='web', output = ":memory:")
file_to_geojson(input=file, method='local', output = ":memory:")

# KML type file - using the local method
file_to_geojson(input=file, method='local', output='kml_local')

# Shp type file - using the web method - input is a zipped shp bundle
file <- system.file("examples", "bison.zip", package = "geojsonio")
file_to_geojson(file, method='web', output='shp_web')

# Shp type file - using the local method - input is the actual .shp file
file <- system.file("examples", "bison.zip", package = "geojsonio")
dir <- tempdir()
unzip(file, exdir = dir)
list.files(dir)
shpfile <- file.path(dir, "bison-Bison_bison-20130704-120856.shp")
file_to_geojson(shpfile, method='local', output='shp_local')

# Neighborhoods in the US
## beware, this is a long running example
# url <- 'http://www.nws.noaa.gov/geodata/catalog/national/data/ci08au12.zip'
# out <- file_to_geojson(input=url, method='web', output='cities')

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.