栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Python中合并两个GEOJSON多边形

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Python中合并两个GEOJSON多边形

这就是我如何使用functools中的包/模块json,geojson,shapely,pyproj和partial做到这一点的方法:

import jsonimport geojsonfrom functools import partialimport pyprojimport shapely.geometryimport shapely.ops# reading into two geojson objects, in a GCS (WGS84)with open('file1.json') as geojson1:    poly1_geojson = json.load(geojson1)with open('file2.json') as geojson2:    poly2_geojson = json.load(geojson2)# pulling out the polygonspoly1 = shapely.geometry.asShape(poly1_geojson['features'][2]['geometry'])poly2 = shapely.geometry.asShape(poly2_geojson['features'][2]['geometry'])# checking to make sure they registered as polygonsprint poly1.geom_typeprint poly2.geom_type# merging the polygons - they are feature collections, containing a point, a polyline, and a polygon - I extract the polygon# for my purposes, they overlap, so merging produces a single polygon rather than a list of polygonsmergedPolygon = poly1.union(poly2)# using geojson module to convert from WKT back into GeoJSON formatgeojson_out = geojson.Feature(geometry=mergedPolygon, properties={})# outputting the updated geojson file - for mapping/storage in its GCS formatwith open('Merged_Polygon.json', 'w') as outfile:    json.dump(geojson_out.geometry, outfile, indent=3, encoding="utf-8")outfile.close()# reprojecting the merged polygon to determine the correct area# it is a polygon covering much of the US, and dervied form USGS data, so using Albers Equal Areaproject = partial(    pyproj.transform,    pyproj.Proj(init='epsg:4326'),    pyproj.Proj(init='epsg:5070'))mergedPolygon_proj = shapely.ops.transform(project,mergedPolygon)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/514582.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号