Skip to content

writeOGR(GeoJSON) to string instead of file

2 messages · Philip Greenwood, Roger Bivand

#
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?

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
#
On Wed, 6 Mar 2013, Philip Greenwood wrote:

            
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")