[R-sig-Geo] Incompatible geometry error with a .kml file using readOGR()

Roger Bivand Roger.Bivand at nhh.no
Sat Apr 5 15:54:32 CEST 2014


On Sat, 5 Apr 2014, remissssss wrote:

> Hello,
> I got difficulties with reading a kml file, using rgdal package on a linux
> OS. This file has been downloaded on the European Soil Database website (
> http://eusoils.jrc.ec.europa.eu/ESDB_Archive/ESDBv3/googleearth/index.cfm
> <http://eusoils.jrc.ec.europa.eu/ESDB_Archive/ESDBv3/googleearth/index.cfm>
> What does "Incompatible geometry" refer to? and how can I solve this pb
> without having to edit the .kml in a GIS software (if possible) ?

Thanks for providing enough information to reproduce (more or less, the 
KMZ file had to be uncompressed into a large KML file):

library(rgdal)
ogrListLayers("DOC.kml")
ogrInfo(dsn="DOC.kml", layer="EAWC_SUB:Subsoil easily avail.water capac.")

which shows:

Source: "DOC.kml", layer: "EAWC_SUB:Subsoil easily avail.water capac."
Driver: KML number of rows 6
Feature type: wkbGeometryCollection with 3 dimensions
Extent: (-10.56697 34.83962) - (31.58095 70.09262)
CRS: +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs
Number of fields: 2
          name type length typeName
1        Name    4      0   String
2 Description    4      0   String

This shows two problems: wkbGeometryCollection which cannot be read into 
any sp class, and potentially 3 dimensions, as only SpatialPoints may be 
3D (looking at the details in the unpacked file, the third dimension is 
spurious, and the geometries are Polygon or MultiPolygon). I didn't 
succeed in reading it into GRASS 6.4 either (using the same OGR library).

The underlying problem is that the real data source is:

http://eusoils.jrc.ec.europa.eu/ESDB_Archive/ESDB_Data_Distribution/ESDB_data.html

and is not free to download without other steps. The files made available 
are really only intended to be displayed in Google Earth. For data 
handling and analysis, either the provider should make files available in 
a more usable format, or at least improve the production of KMZ files so 
that they are not in the "catch-all" category. If the data are actually in 
3D vector form (a volume), very few applications can handle them. They do 
not appear to be volumes, as the Name: field has 6 values:

  High (140 - 190 mm/m)    :6195
  Low ( < 100 mm/m)        :3565
  Medium (100 - 140 mm/m)  :4117
  No data or not applicable:4191
  Very high ( > 190 mm/m)  :2673
  Very low ( ~ 0 mm/m)     :2067

(the counts are constituent polygons).

Using the OGR command line utility:

ogr2ogr -f "ESRI Shapefile" DOC.shp -explodecollections DOC.kml

I got a shapefile which may be similar to the input:

> ogrInfo("DOC.shp", "DOC")
Source: "DOC.shp", layer: "DOC"
Driver: ESRI Shapefile number of rows 22808
Feature type: wkbPolygon with 2 dimensions
Extent: (-10.56697 34.83962) - (31.58095 70.09262)
CRS: +proj=longlat +datum=WGS84 +no_defs
LDID: 87
Number of fields: 2
         name type length typeName
1       Name    4     80   String
2 Descriptio    4     80   String

but the geometries read into R are not valid (checked with GEOS), and 
cannot be plotted, so ogr2ogr hasn't managed to make fish of fish soup.

For analysis, you need the actual polygons in an appropriate format; you 
should approach the data provider and persuade them to open data access 
properly. Maybe they can be forced out of the fish soup, but it would be 
much easier if the fish had not been smashed up first. The GML and SHP 
representations of the same data are an order of magnitude smaller too, 
KMZ and KML are big space-wasters.

Hope this clarifies,

Roger


>
> Below my code :
>
>> library(rgdal)
> Loading required package: sp
> rgdal: version: 0.8-16, (SVN revision 498)
> Geospatial Data Abstraction Library extensions to R successfully loaded
> Loaded GDAL runtime: GDAL 1.10.0, released 2013/04/24
> Path to GDAL shared files: /usr/share/gdal/1.10
> Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
> Path to PROJ.4 shared files: (autodetected)
>
>> ogrListLayers("/windows/BDD_sol/BDD_esdb_kml/kml/EAWC_SUB.kml")
> [1] "EAWC_SUB:Subsoil easily avail.water capac."
>
>> readOGR(dsn="/windows/BDD_sol/BDD_esdb_kml/kml/EAWC_SUB.kml",layer="EAWC_SUB:Subsoil
>> easily avail.water capac.")
> OGR data source with driver: KML
> Source: "/windows/BDD_sol/BDD_esdb_kml/kml/EAWC_SUB.kml", layer:
> "EAWC_SUB:Subsoil easily avail.water capac."
> with 6 features and 2 fields
> Feature type: wkbGeometryCollection with 3 dimensions
> Error in readOGR(dsn = "/windows/BDD_sol/BDD_esdb_kml/kml/EAWC_SUB.kml",  :
>  *Incompatible geometry: 7*
> In addition: Warning messages:
> 1: In readOGR(dsn = "/windows/BDD_sol/BDD_esdb_kml/kml/EAWC_SUB.kml",  :
>  eType not chosen
> 2: In readOGR(dsn = "/windows/BDD_sol/BDD_esdb_kml/kml/EAWC_SUB.kml",  :
>  eType not chosen
> 3: In readOGR(dsn = "/windows/BDD_sol/BDD_esdb_kml/kml/EAWC_SUB.kml",  :
>  eType not chosen
> 4: In readOGR(dsn = "/windows/BDD_sol/BDD_esdb_kml/kml/EAWC_SUB.kml",  :
>  eType not chosen
> 5: In readOGR(dsn = "/windows/BDD_sol/BDD_esdb_kml/kml/EAWC_SUB.kml",  :
>  eType not chosen
> 6: In readOGR(dsn = "/windows/BDD_sol/BDD_esdb_kml/kml/EAWC_SUB.kml",  :
>  eType not chosen
>
> and some additional information about my R session :
>
>> sessionInfo()
> R version 3.1.0 beta (2014-03-28 r65330)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
> [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C
> [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8
> [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8
> [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C
> [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] rgdal_0.8-16 sp_1.0-14
>
> loaded via a namespace (and not attached):
> [1] grid_3.1.0      lattice_0.20-27 tools_3.1.0
>
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/Incompatible-geometry-error-with-a-kml-file-using-readOGR-tp7586135.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> 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, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list