我已经多次使用这个脚本,直到现在它运行良好。我目前在尝试写出形状文件时遇到错误。谁能告诉我这个错误的含义?我输入的形状文件似乎是一个普通的形状文件。此外,在我的代码中没有任何地方试图创建一个对象字段。
这是我收到的错误:
Writing layer MonroeMD14F0037_1' to data source N:\MonroeMD14F0037_1.shp' using driver ESRI Shapefile Creating field Ã_OBJECT failed.Error in CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options), :
Layer creation failed.In addition: Warning message:In CPL_write_ogr(obj, dsn, layer, driver, as.character(dataset_options), :GDAL Error 1: Failed to create field name 'Ã_OBJECT': cannot convert to ISO-8859-1
最佳答案
这个错误(CPL_write_ogr)似乎与数据类型有关。我今天遇到了同样的问题,我刚刚解决了。方法如下 - 我发现我的对象不是 sf 或 sfc,而是一个geometrycollection。必须将它重新变成一个简单的(多)多边形,然后它才能工作。
Simple feature collection with 1 feature and 4 fields
geometry type: GEOMETRYCOLLECTION
dimension: XY
bbox: xmin: 486390.1 ymin: 6044675 xmax: 487045.9 ymax: 6045202
projected CRS: WGS 84 / UTM zone 32N
通过使用以下方法从集合中提取它来创建一个 sf 多边形:
mydata2 <- st_collection_extract(mydata, "POLYGON")
然后我能够正确保存新文件,即...
st_write(mydata2, "mydata2.shp")
希望对您有所帮助!
关于r - 在 R 中写出形状文件时出现 CPL_write_ogr 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60454067/