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.
#library(rgdal);library(maptools);ogrDrivers()
#generate a simulated point SHAPE file,its name is "pointexamle0" and save
in "h:/example".
x<-runif(5)*180;y<-runif(5)*90
pointsam<-SpatialPoints(data.frame(x,y), proj4string=CRS("+proj=longlat
+ellps=WGS84"))
write.pointShape(coordinates(pointsam), df=as(pointsam, "data.frame"),
file="h:/example/pointexamle0")

#1. Conver SHAPE file to KML file
importshp <- readOGR(dsn="h:/example",layer="pointexamle0") #correct
proj4string(importshp)<-CRS("+proj=longlat +ellps=WGS84")
writeOGR(obj=importshp,dsn="h:/example",driver="KML",layer="output")
 #????Errors
#Error in writeOGR(obj = importshp, dsn = "h:/example", driver = "KML",  :
          GDAL Error 4: Failed to create KML file h:/example.

#2. Conver KML file to SHAPE file
#I use the XTools Pro for ARCGIS to generate the KML file for the above
"pointexamle0" SHAPE file.Its name is "pointkml.kml" and save
in "h:/example".
importkml <- readOGR(dsn="h:/example",layer="pointkml")  #???Errors?
#in ogrInfo(dsn = dsn, layer = layer, input_field_name_encoding =
input_field_name_encoding) :
  Cannot open layer

writeOGR(obj=importkml,dsn="h:/example",driver="ESRI
Shapefile",layer="output2") #cannot have a try,maybe there is also errors.

  Does anybody know where i made a mistake to use these two functions?
Thanks a lot.

-- 
-----------------
Jane Chang
Queen's

	[[alternative HTML version deleted]]

