Rstudio中从KML提取坐标点
想从KML文件中导入坐标点
getwd()
library(classInt)
library(fpc)
library(leaflet)
library(maptools)
library(raster)
library(RColorBrewer)
library(rmarkdown)
library(sp)
library(spatstat)
library(rgeos)
LondonBorough<-readShapeSpatial("London_Borough_Excluding_MHW.shp")
qtm(LondonBorough)
summary(LondonBorough)
class(LondonBorough)
install.packages("rJava")
#stimulate operation of openstreetmap
if (Sys.info()['sysname'] == 'Darwin') {
libjvm <- paste0(system2('/usr/libexec/java_home',stdout = TRUE)[1],'/jre/lib/server/libjvm.dylib')
message (paste0('Load libjvm.dylib from: ',libjvm))
dyn.load(libjvm)
}
library(rJava)
library(OpenStreetMap)
library(rgdal)
data(simply_list.csv)
list<-read.csv("full_attributions_list.csv")
Borough <- readOGR(dsn="London_Borough_Excluding_MHW.shp")
ogrInfo(dsn="London_Borough_Excluding_MHW.shp", layer="London_Borough_Excluding_MHW")
crs(Borough)
ETRS89 <- "+init=epsg:25833"
proj4string(Borough) <- CRS(ETRS89)
plot(Borough)
attractions <- getKMLcoordinates(kmlfile="full_list.kml", ignoreAltitude=T)
summary(attractions)
crs(attractions)
attractionss_projection<-spTransform(attractions,CRS(ETRS89))
plot(Borough, lwd=0.7, border="grey40")
plot(attractions,add=TRUE,pch=16,col='red')
然后报错是
> attractionss_projection<-spTransform(attractions,CRS(ETRS89))
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘spTransform’ for signature ‘"list", "CRS"’
以及继续尝试plot的报错
> plot(attractions,add=TRUE,pch=16,col='red')
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
但是KML坐标可以在Google map上看到的 除了坐标系不一样不知道问题在哪里
summary出来是这样
> summary(attractions)
Length Class Mode
[1,] 2 -none- numeric
[2,] 2 -none- numeric
[3,] 2 -none- numeric
[4,] 2 -none- numeric
[5,] 2 -none- numeric
[6,] 2 -none- numeric
[7,] 2 -none- numeric
[8,] 2 -none- numeric
[9,] 2 -none- numeric
在values里面也是可以看到两个值的
求问大神们要怎么改QAQ