[R-sig-Geo] import kml with readOGR

Roger Bivand Roger.Bivand at nhh.no
Wed Apr 16 20:57:06 CEST 2014


On Wed, 16 Apr 2014, Gabriele Cozzi wrote:

> Hi,
>
> my understanding is that the second argument correspond to the kml layer
> name, which is not necessarily the file name. However it is in my case, I
> suppose (think).
>
>> From opening my file with a text editor I get:
> <Document><name>Sarikamis.kml</name>

Try first OGRListLayers(dsn=) to list the layer(s) actually seen by the 
software. Also use setwd() first to give the file name, if you are unsure 
of its name. Once OGRListLayers() runs correctly, you will have 
confirmation of the dsn=, and a listing of recognised layer= value(s).

Hope this clarifies,

Roger

>
> The two arguments should correspond to the arguments:
> dsn= data source name
> layer= layer name
>
>
> Gabriele
>
>
>
> On Wed, Apr 16, 2014 at 7:21 PM, Frede Aakmann T??gersen <frtog at vestas.com>wrote:
>
>>  Hi
>>
>> I'm not close to my R right now. Can you explain to me what you think your
>> second argument to readORG does?
>>
>> Br. Frede
>>
>>
>> Sendt fra Samsung mobil
>>
>>
>> -------- Oprindelig meddelelse --------
>> Fra: Gabriele Cozzi
>> Dato:16/04/2014 19.11 (GMT+01:00)
>> Til: r-sig-geo
>> Emne: [R-sig-Geo] import iml with readOGR
>>
>> Dear all,
>>
>> I am trying to import a kml (polygon) into R following the suggestions
>> from:
>>
>> http://gis.stackexchange.com/questions/58131/how-to-efficiently-read-a-kml-file-into-r
>>
>> and
>> https://stat.ethz.ch/pipermail/r-sig-geo/2010-May/008355.html
>>
>>
>> the code I run is the following:
>>
>> S <- readOGR(???~/Documents/Sarikamis.kml", "Sarikamis???)
>> and I also tried:
>> S <- readOGR(???~/Documents/Sarikamis.kml", ???Sarikamis.kml???)
>>
>> but I get the usual error:
>> Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv =
>> use_iconv) :
>>   Cannot open file
>>
>>
>> When I open the kml file using a text editor it reads as below (in blue),
>> which makes me think that the kml file name is ???Sarikamis??? and the string
>> is ???Document/Sarikamis.kml???. But obviously I am doing something wrong, but
>> I can???t understand what.
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="
>> http://www.google.com/kml/ext/2.2" xmlns:kml="
>> http://www.opengis.net/kml/2.2"
>> xmlns:atom="http://www.w3.org/2005/Atom">
>> <Document>
>> <name>Sarikamis.kml</name>
>> <StyleMap id="msn_ylw-pushpin">
>> <Pair>
>> <key>normal</key>
>> <styleUrl>#sn_ylw-pushpin</styleUrl>
>> </Pair>
>> <Pair>
>> <key>highlight</key>
>> <styleUrl>#sh_ylw-pushpin</styleUrl>
>>                        ......
>>                         ......
>>
>>
>> Any advice is highly appreciated!
>>
>> I am running R 3.0.3 for Mac
>>
>>
>> Best,
>> Gabriele
>>
>>
>> --
>> Gabriele Cozzi
>> Postdoctoral Research Associate
>> Population Ecology Research Group
>> http://www.popecol.org
>>
>> Zurich University
>> Institute of Evolutionary Biology and Environmental Studies
>> Winterthurerstr. 190
>> 8057 Zurich - Switzerland
>> E-mail: gabriele.cozzi at uzh.ch
>> Phone: +41(0)44 635 49 12
>> Fax: +41(0)16355711
>> http://www.ieu.uzh.ch
>>
>>         [[alternative HTML version deleted]]
>>
>>
>
>
>

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