首页 > 解决方案 > 如何解决 Geojson 到 shapefile 的转换错误?

问题描述

我正在尝试将 geojson 文件转换为 shapefile。我正在使用 geojson2shape 方法,但是当我运行下面的代码时,我收到了这个错误。我也通过 npm install ogr2ogr 安装了 ogr2ogr,但我有错误。我该如何解决这个错误?

var geojson2shape = require('geojson2shape')
// a shapefile is actually multiple files. geojson2shape will output a zipped version if specified.
var zip = true
geojson2shape(__dirname+'/polygon.geojson', __dirname+'/polygon.shp',zip, function(err){
  if(err) throw err

  console.log('success');

})
Command failed: ogr2ogr -f "ESRI Shapefile" C:\upload2/output/out.shp C:\upload2/Files/imgUploader_1577252750283_AC127138-5645-497D-AF51-3F4EA12E20C5.geojson -overwrite -lco ENCODING=UTF-8
'ogr2ogr' is not recognized as an internal or external command

标签: node.jsgeojsonshapefileogr

解决方案


ogr2ogr 是一个“本机应用程序”。npm 中名为 ogr2ggr的包只是对本机工具的一种包装,如文档中所述:

ogr2ogr 需要命令行工具 ogr2ogr - gdal 安装页面。我们建议使用最新的稳定版本。

因此,要使用geojson2shape甚至 npm ,请ogr2ogr 按照在系统中安装 gdal/ogr2ogr 的说明进行操作,并确保ogr2ogr二进制文件位于PATH


推荐阅读