GIS常用npm包:GeoJSON文件合并与元素过滤\属性过滤\图形合并

文章介绍了如何使用@mapbox/geojson-merge进行GeoJSON文件的合并,以及在浏览器端的应用。此外,提到了turf.js库的filter功能用于GeoJSON特征属性过滤,还讨论了其他过滤和图形处理的npm包,如feature-filter和geojson-dissolve。
摘要由CSDN通过智能技术生成

GeoJSON文件合并

普通的geoJSON文件合并,只需geojson-merge插件就够了,@mapbox/geojson-merge - npm

  • mergeFeatureCollectionStream 合并文件

    Merge GeoJSON files containing GeoJSON FeatureCollections into a single stream of a FeatureCollection as a JSON string.

  • merge 合并GeoJSON数组

    Merge a series of GeoJSON objects into one FeatureCollection containing all features in all files. The objects can be any valid GeoJSON root object, including FeatureCollection, Feature, and Geometry types.

合并文件,官网的案例

var geojsonMerge = require('@mapbox/geojson-merge'); 
var mergedStream = geojsonMerge.mergeFeatureCollectionStream(['features.geojson','others.geojson']) 
mergedStream.pipe(process.stdout);

在浏览器端,需要导入文件,fileReader读取文件,获取json,再合并

var geojsonMerge = require('@mapbox/geojson-merge')
let features = []
// Todo push jgeoJSON
let jsonObject = geojsonMerge.merge(features)

GeoJSON过滤

GeoJSON一feature properties过滤

turf-filter - npm

turf.filter(features, key, value)

var features = turf.featurecollection([
 turf.point([-72.581777, 44.260875], {species: 'oak'}),
 turf.point([-72.570018, 44.260691], {species: 'birch'}),
 turf.point([-72.576284, 44.257925], {species: 'oak'}),
 turf.point([-72.56916, 44.254605], {species: 'redwood'}),
 turf.point([-72.581691, 44.24858], {species: 'maple'}),
 turf.point([-72.583837, 44.255773], {species: 'oak'})
]);

var key = 'species';
var value = 'oak';
 
var filtered = turf.filter(features, key, value);

这个过滤比较简单,feature-filter-geojson - npm

可以增加过滤规则,具体还是看官方文档。在浏览器端,其实用第一个就好

var ff = require('feature-filter');
var filter = [
    "all",
    ["==", "class", "street_limited"],
    ["<=", "admin_level", 3],
    ["!=", "$type", "Polygon"]
]
var testFilter = ff(filter);
let feature = GeoJSONObject
testFilter(feature);

geojson-filter - npm,这个也是一样的,但是推荐用第一个

geojson-dissolve

GeoJSON 里面的点线面合并为Multi(point/linestring/polygon)

Dissolve contiguous GeoJSON (Multi)LineStrings and (Multi)Polygons into single units.

说实话,这个实际项目,我目前还没有用到。

merge polygon 合并多边形

merge-simple-polygons:merge-simple-polygons - npm

Merge two (adjacent) simple polygons into another simple polygon.

Takes two arrays of vertex IDs, each spanning a planar polygon and returns:

  • false if the given polygons share no vertices

  • null if there would be more than one resulting simple polygon (if the two given polygons share either exactly one vertex, which would result in two polygons or multiple egdes that are not connected, which would result in a polygon with a "hole")

  • a list of vertex IDs forming the merged polygon

const mergePolygons = require('merge-simple-polygons')
 
const polygonA = ['a', 'b', 'c', 'd', 'e']
const polygonB = ['e', 'a', 'g', 'h', 'i', 'd']
const polygonC = mergePolygons(polygonA, polygonB)
console.log(polygonC) // ['a', 'b', 'c', 'd', 'i', 'h', 'g']
 
const polygonD = ['a', 'b', 'c']
const polygonE = ['d', 'e', 'f']
console.log(mergePolygons(polygonD, polygonE)) // false
 
const polygonF = ['a', 'b', 'c', 'd', 'e']
const polygonG = ['a', 'b', 'f', 'e', 'd', 'g']
console.log(mergePolygons(polygonF, polygonG)) // null

这个,turfjs Turf.js | Advanced Geospatial Analysis

其他GIS数据转 GeoJSON

Turn your geo data into GeoJSON.

转载本站文章《GIS常用npm包:GeoJSON文件合并与元素过滤\属性过滤\图形合并》,
请注明出处:GIS常用npm包:GeoJSON文件合并与元素过滤\属性过滤\图形合并 - WebGIS网页地图开发笔记手札 - 周陆军的个人网站

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值