shpwrite是个开源的js包,依靠node来导出shp文件。但是原生js有些问题,无法导出多个面的shp文件,需要自行修改源代码。

源码下载地址:https://github.com/hwbllmnn/shp-write/tree/maintenance

这里我在补充一下,源码中获取面点的集合是三维数组,所以在创建geojson的时候需要这么写:"coordinates": [[[[],[],[]....]]]  (其实这种就属于多面的写法,但是源码中并不支持MultiPolygon)

导出代码

var shpwrite = require('shp-write');

// (optional) set names for feature types and zipped folder
var options = {
    folder: 'myshapes',
    types: {
        point: 'mypoints',
        polygon: 'mypolygons',
        line: 'mylines'
    }
}
// a GeoJSON bridge for features
shpwrite.download({
    type: 'FeatureCollection',
    features: [
        {
            type: 'Feature',
            geometry: {
                type: 'Point',
                coordinates: [0, 0]
            },
            properties: {
                name: 'Foo'
            }
        },
        {
            type: 'Feature',
            geometry: {
                type: 'Point',
                coordinates: [0, 10]
            },
            properties: {
                name: 'Bar'
            }
        }
    ]
}, options);

遗留问题:导出的dbf属性表中文乱码,还在解决中。

补:解决方法:解决shp-write导出shp属性表中文乱码问题_shp数据乱码_巧克力曲奇的博客-CSDN博客

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐