[R-sig-Geo] writeOGR(GeoJSON) to string instead of file

Roger Bivand Roger.Bivand at nhh.no
Wed Mar 6 09:08:13 CET 2013


On Wed, 6 Mar 2013, Philip Greenwood wrote:

> Hi all,
>
> This is a re-post from a few weeks ago.
>
> I'm using writeOGR{rgdal} to a create GeoJSON temporary file then 
> reading the file and passing as a string in Java. It would be really 
> nice to avoid writing the temporary file, and have writeOGR return a 
> GeoJSON string.
>
> Is this possible?

See:

http://www.gdal.org/ogr/drv_geojson.html

which implies no. The write driver writes to a file as far as I can see, 
unless you try the VSI route, dsn="/vsistdout/", but that output goes 
straight to the console, not through R. If you can find a way to access 
this output stream, you may be lucky.

Roger

library(rgdal)
cities <- readOGR(system.file("vectors", package = "rgdal")[1], "cities")
writeOGR(cities[1:10,], "/vsistdout/", "cities", driver="GeoJSON")


>
> My project requires passing spatial data from R to Java, and then 
> storing data as GeoJSON. I'm using RServe to interface between R and 
> Java.
>
> Thanks.
>
> Philip Greenwood
>
> Geospatial and Analytics eEnabler
> Australian Urban Research Infrastructure Network (AURIN)
> 308 Doug McDonell Building, University of Melbourne
> Tel: +61-(0)3-9035-8549
> philip.greenwood at unimelb.edu.au
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list