[R-sig-Geo] error for converting between KML and Shape file
b.rowlingson at lancaster.ac.uk
Thu Dec 10 21:41:33 CET 2009
On Thu, Dec 10, 2009 at 8:17 PM, rusers.sh <rusers.sh at gmail.com> wrote:
> Hi all,
> I try to use the readOGR and writeOGR in rgdal package to do the
> conversion KML and Shape files, but failed. Following is my codes for a
> simulated dataset.
> #generate a simulated point SHAPE file,its name is "pointexamle0" and save
> in "h:/example".
> pointsam<-SpatialPoints(data.frame(x,y), proj4string=CRS("+proj=longlat
> write.pointShape(coordinates(pointsam), df=as(pointsam, "data.frame"),
> #1. Conver SHAPE file to KML file
> importshp <- readOGR(dsn="h:/example",layer="pointexamle0") #correct
> proj4string(importshp)<-CRS("+proj=longlat +ellps=WGS84")
> #Error in writeOGR(obj = importshp, dsn = "h:/example", driver = "KML", :
> GDAL Error 4: Failed to create KML file h:/example.
The devil, as we say, is in the details (which for some reason are truncated!):
Working out which combination of dsn, layer, and driver (and
option) values give the desired output takes time and care, and is
constrained by the ability of drivers to write output; many ar
The parameters for writeOGR are:
writeOGR(object, fileName, layerName,driver="KML")
Here 'object' is your R Spatial Points/Poly/etc, 'fileName' is the
path (including filename) for your output KML, and 'layerName' is a
label that your layer will get in the KML - you'll see this in the
layer list in Google Earth, for example.
More information about the R-sig-Geo