[R-sig-Geo] writeOGR: ID field for exporting a KML file

Mauricio Zambrano-Bigiarini mauricio.zambrano at jrc.ec.europa.eu
Thu May 24 16:35:43 CEST 2012


Dear list,

I'm trying to export a point shapefile into a KML file by using the 
'writeOGR' function of the 'rgdal' package.

Everything works fine, except that I'm not able to select the field to 
be used for labelling the KML points from the table of the original 
shapefile.

I'm able to select the ID field to be used in the KML file by using the 
'ogr2ogr' program of GDAL, but I would like to be able to do the same 
directly within R with the 'writeOGR' function.

Below you can find a reproducible example:

---------------- START ---------------------
require(rgdal)

# creating the initial shapefile for the example
cities <- readOGR(system.file("vectors", package = "rgdal")[1], "cities")

writeOGR(cities, "cities.shp", "cities", driver="ESRI Shapefile")


OGRstring <- paste("ogr2ogr -f KML ", "cities.kml", " ", "cities.shp", " 
-dsco NameField=COUNTRY", sep = "")
system(OGRstring)

---------------- END ---------------------

I would like to achieve the same final KML file, but using:

   writeOGR(cities, dsn="cities2.kml", layer="cities", driver="KML" )


but I don't know how to pass the " -dsco NameField=COUNTRY" argument to 
the 'writeOGR' function.


Any help will be very much appreciated.


  sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-redhat-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_GB.utf8       LC_NUMERIC=C
  [3] LC_TIME=en_GB.utf8        LC_COLLATE=en_GB.utf8
  [5] LC_MONETARY=en_GB.utf8    LC_MESSAGES=en_GB.utf8
  [7] LC_PAPER=C                LC_NAME=C
  [9] LC_ADDRESS=C              LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.utf8 LC_IDENTIFICATION=C

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

other attached packages:
[1] rgdal_0.7-11 sp_0.9-99

loaded via a namespace (and not attached):
[1] grid_2.15.0    lattice_0.20-6 tools_2.15.0




Thanks in advance,

Mauricio Zambrano-Bigiarini

-- 
====================================================
Water Resources Unit
Institute for Environment and Sustainability (IES)
Joint Research Centre (JRC), European Commission
webinfo    : http://floods.jrc.ec.europa.eu/
====================================================
DISCLAIMER:\ "The views expressed are purely those of th...{{dropped:11}}



More information about the R-sig-Geo mailing list