[R-sig-Geo] how to create maps from topojson files and csv data?
Barry Rowlingson
b.rowlingson at lancaster.ac.uk
Mon Dec 16 13:01:56 CET 2013
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:
> 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,
>
> From there its straightforward SpatialPolygonsDataFrame stuff.
>
> Barry
>
> On Sun, Dec 15, 2013 at 10:49 PM, Miguel Fiandor Gutiérrez
> <mfiandor at gmail.com> wrote:
>> Hi,
>>
>> I do have some maps in topojson format, and I would like to display data on
>> them that i have in .CSVs and access database. So far I play with them with
>> d3.js,<http://transparenciadecuentaspublicas.es/2012/madrid/gastos-personales>but
>> i'd like to learn too with R.
>> My question is not about the csv or db to data frame or similar, is how to
>> display any data variable with this kind of map files, I have not found
>> literature about it. Yes, each region of the map has its own id code.
>>
>> The output will end on a pdf file or website, but as soon as I can print
>> the map or export it it would be enough.
>>
>> Thanks
>>
>> Miguel Fiandor
>>
>> [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list