Skip to content

how to create maps from topojson files and csv data?

4 messages · Barry Rowlingson, Miguel Fiandor Gutiérrez, Ahmadou Dicko

#
The geoJSON driver in gdal/ogr will read it from version 2 of OGR:

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

but I think that's very leading-edge (I seem to have v 1.10  on my system).

So the solution would seem to be to convert your topojson to something
that your gdal/ogr can handle, and then read it into R using the rgdal
package readOGR function. I'm having trouble finding a utility that
will do the conversion that way, since most people start from
something and convert it _to_ topojson for fast rendering! I think it
might be necessary to cruft something  together from various python or
javascript modules lying around the web,
Barry

On Sun, Dec 15, 2013 at 10:49 PM, Miguel Fiandor Guti?rrez
<mfiandor at gmail.com> wrote:
#
On a more positive note, topojson, like geojson, is just a JSON file,
so you can read it with any of the R JSON interface packages (I've
just read a us.json file using package:RJSONIO).

 The job is then to unweave the structure into something plottable.
topojson works by defining features as sequences of arcs, and arcs as
sequences of coordinates. The arcs are actually defined as a start
point and x-y offsets.

 With a whole load of array lookups (remembering that arc -342 is arc
342 in the reverse direction) you could write some R code to go from
topojson to SpatialPolygons.

 I'm loathe to do this at the moment since I suspect the functionality
to convert from topojson to shapefiles/geojson/some other standard
exists (apart from in ogr 2.0) and it would be easier to re-use that.

 Ooh, it takes me back to my reverse-engineering Arc/Info .e00 files...

Barry


On Mon, Dec 16, 2013 at 10:31 AM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote: