我有一个脚本来创建一个KML格式的随机分布的方形多边形,它使用一个多边形作为输入,并且可以很好地工作。当我尝试从中创建用户定义的函数时出现问题。我使用readShapePoly()函数来读取shapefile,它在使用函数时效果很好。但是当创建函数时,应该将shapefile作为输入给出,它根本不会占用。它显示此错误消息
getinfo.shape(filen)出错:打开SHP文件时出错
我避免编写扩展,我确实有所有的扩展文件来创建shapefile。
使用它作为输入文件读取shapefile的脚本的一部分:
library(maptools)
library(sp)
library(ggplot2)
Polytokml <- function(shapefile_name){
###Input Files
file1 <- "shapefile_name"
Shape_file <- readShapePoly(file1) #requires maptools
return(Shape_file)
}
该函数已创建,但如果调用该函数则不起作用。
>Polytokml(HKH.shp)
Error in getinfo.shape(filen) : Error opening SHP file
这在函数中运行良好。
###Input Files
file1 <- "shapefile.shp"
Shape_file <- readShapePoly(file1) #requires maptools
这只是整个脚本中的一个示例,其中将不同的参数作为输入。所以为了简单起见我已经添加了脚本来读取现在出现问题的shapefile。如果不清楚,请告诉我。
提前非常感谢你:)