Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
根据ZevRoss的博客,我正在尝试使用传单包制作一张交互式地图。但是代码中有一个错误_R_Leaflet_Geojson - Fatal编程技术网

根据ZevRoss的博客,我正在尝试使用传单包制作一张交互式地图。但是代码中有一个错误

根据ZevRoss的博客,我正在尝试使用传单包制作一张交互式地图。但是代码中有一个错误,r,leaflet,geojson,R,Leaflet,Geojson,ZevRoss的博客如下: 出现错误的代码是: # ----- Write data to GeoJSON leafdat<-paste(downloaddir, "/", filename, ".geojson", sep="") writeOGR(subdat, leafdat, layer="", driver="GeoJSON") #----将数据写入GeoJSON leafdat即使您的计算机上已经有一个“d:”驱动器,并且您有写入该驱动器的权限,请尝试以下操作: ----

ZevRoss的博客如下:

出现错误的代码是:

# ----- Write data to GeoJSON
leafdat<-paste(downloaddir, "/", filename, ".geojson", sep="") 
writeOGR(subdat, leafdat, layer="", driver="GeoJSON")
#----将数据写入GeoJSON

leafdat即使您的计算机上已经有一个“d:”驱动器,并且您有写入该驱动器的权限,请尝试以下操作:

--------------------------------
leafdat leafdat
>“d:/传单/.geojson”
writeOGR(subdat,leafdat,layer=“”,driver=“GeoJSON”)
--------------------------------
然后,您可以在“d:/传单”上获得“.geojson”文件。将文件名“.geojson”更改为“County_2010ccensus_DP1.geojson”。

您可以使用传单包创建geojson:

library('leafletR')
Your_GeoJSON <- toGeoJSON(data=YourData, dest=getwd())
库(“传单”)

您的_GeoJSON我已经为这个神秘的错误寻找了一段时间的解决方案

最终,我在网上找到了这篇文章,澄清了问题并给出了解决方案

基本上,问题在于rgdal和Gdal之间的接口(Gdal改变了它们的工作方式,并且rgdal的最新版本还没有出现):

因此,以下代码将起作用:

writeOGR(spDf,'foo.geojson','spDf', driver='GeoJSON',check_exists = FALSE)

当然,如果在writeOGR位置已经有一个具有所选名称的geojson文件,它仍然会失败。

您的计算机上有
d:
驱动器吗?如果是,一个名为
传单的文件夹
?您好,我只是用相同的rgdal版本(在mac上)运行了代码,没有问题。正如@Pascal的逻辑所说,它可能与写入问题有关,而不是与R有关。您是否有权限写入D:/drive?也许试着写一个U盘?我重新测试了代码,似乎工作得很好。在原始代码中,通过粘贴destdir(您的代码有download dir)创建leafdat。与Pascal类似,我想知道您是否正在写入不存在的路径/文件夹。
writeOGR() calls ogrCheckExists("foo.geojson") to check first if the file exists before creating a new dataset.
In the 1.11 version the OGR GeoJSON driver will emit an error message that this file doesn't exists, whereas previous version didn't emit an error message. 
rgdal catches this error as a fatal one and doesn't go to the writing step. This should be fixed in rgdal.
Meanwhile you have an easy workaround : add check_exists = FALSE as a parameter to writeOGR()
writeOGR(spDf,'foo.geojson','spDf', driver='GeoJSON',check_exists = FALSE)