Skip to content

Issue with ogrInfo

7 messages · Daniel Marcelino, Barry Rowlingson, Roger Bivand

#
Dear all, I'm having the following issue when trying to read a
topographical json file:
The file is here
https://github.com/kjhealy/uk-elections/blob/master/maps/topo_wpc.json
Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding,
use_iconv = use_iconv,  :
  Cannot open file
5: .Call("ogrInfo", as.character(dsn), as.character(layer), PACKAGE = "rgdal")
4: ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv,
       swapAxisOrder = swapAxisOrder, require_geomType = require_geomType)
3: withCallingHandlers(expr, message = function(c)
invokeRestart("muffleMessage"))
2: suppressMessages(ogr_info <- ogrInfo(dsn = dsn, layer = layer,
       encoding = encoding, use_iconv = use_iconv, swapAxisOrder =
swapAxisOrder,
       require_geomType = require_geomType))
1: readOGR(dsn = "maps/topo_wpc.json", layer = "wpc")
R version 3.2.0 Patched (2015-04-19 r68207)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
Running under: OS X 10.8.5 (Mountain Lion)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] rgdal_0.9-2 sp_1.1-0

loaded via a namespace (and not attached):
 [1] MASS_7.3-40      colorspace_1.2-6 scales_0.2.4     plyr_1.8.1
 [5] tools_3.2.0      gtable_0.1.2     reshape2_1.4.1   Rcpp_0.11.5
 [9] ggplot2_1.0.1    grid_3.2.0       stringr_0.6.2    digest_0.6.8
[13] proto_0.3-10     munsell_0.4.2    lattice_0.20-31
#
On Sun, 10 May 2015, Daniel Marcelino wrote:

            
The file is not recognised by OGR either, so is probably not conforming to 
geojson expectations. It declares itself as HTML, but within github puts 
boundaries on a map background, so I think the file is trying to do much 
more than simply represent Welsh parliamentary constituencies.

Roger

  
    
#
On Sun, May 10, 2015 at 4:31 PM, Daniel Marcelino <dmarcelino at live.com> wrote:
That's a **topological**  (not topographical) geojson file. Instead
of recording each polygon separately, and thus duplicating common
boundaries, a topojson file stores all the line segments once, and
then defines polygons as which sequence of line segments draws the
polygon.

 I'm guessing your ogr library doesn't have topojson support. Does the
output of ogrDrivers() agree with me?

 Solution is usually "use gdal/ogr tools to convert to plain old
geojson (ogr2ogr)"


Barry
#
On Sun, May 10, 2015 at 6:12 PM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:

            
Actually that's a really stupid solution. If ogr2ogr can do it, you
need the support in the first place! Doh!

 You need a separate tool. Something here might help:

http://recology.info/2015/01/geojson-topojson-io/
#
On Sun, 10 May 2015, Barry Rowlingson wrote:

            
Right, but while the geojson driver does read topojson from 1.11, ogrinfo 
says no-go. On inspecting the file, it appears only to contain lost of 
links to other stuff and no geometries that I (or OGR) recognise. The 
geometries must be hidden in one of the links, but are not exposed.

Roger

  
    
#
If you go far enough into the file (which appears to be without line
breaks, so somewhere on line 1... You'll see:

"arcs":[[[7533,1255],[-1,8],[0,4],[2,3],[-1,8],[2,2],[-2,2],[-1,0],[-1,1] .....

which I think is the geometry (arcs have a start point and then x-y deltas).

I can read this file if I first convert to geojson using the command
line converter:

 $ topojson-geojson topo_wpc.json

which gives me wpc.json, and then in R:

 > d=readOGR("./wpc.json","OGRGeoJSON")
OGR data source with driver: GeoJSON
Source: "./wpc.json", layer: "OGRGeoJSON"
with 632 features and 3 fields
Feature type: wkbPolygon with 2 dimensions

Hmmmm

Barry
On Sun, May 10, 2015 at 6:38 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote:
#
On Mon, 11 May 2015, Barry Rowlingson wrote:

            
Support for geometries like these may be coming to OGR, I think curves 
were also discussed. Using the converter here seems the best way forward.

Roger