modifyGeoJSON
from osgeo import ogr
import json
from geojson import loads, dumps, Feature, FeatureCollection
from shapely.geometry import shape, Point, LineString
'''
shp_driver = ogr.GetDriverByName('ESRI Shapefile')
shp_dataset = shp_driver.Open(r'../geodata/schools.shp')
shp_layer = shp_dataset.GetLayer()
shp_srs = shp_layer.GetSpatialRef()
'''
filePathNE = r'D:/Project/JavaScript/LeafletJS/WebGISDemoAngularJS/data/ne.geojson'
filePathRegion = r'D:/Project/JavaScript/LeafletJS/WebGISDemoAngularJS/data/region.geojson'
def readGeoJSONFileToGeoJSON(jsonfile):
with open(jsonfile) as jsonFile:
jsonStr = jsonFile.read()
featureCollection = loads(jsonStr)
#print(dumps(featureCollection))
return featureCollection
def readGeoJSONFileToJSONObject(jsonfile):
with open(jsonfile) as jsonFile:
jsonObject = json.load(jsonFile)
return jsonObject
#
def JSONObjectToShape(jsonObject):
geometryList = []
for feature in jsonObject['features']:
#将GeoJSON中的Geometry转化成shapely(Geos)中的Geometry
# create shapely shape from geojson
shapeObj = shape(feature['geometry'])
geometryList.append(shapeObj)
#feature['geometry'] = None
return geometryList
jsonObjectNE = readGeoJSONFileToJSONObject(filePathNE)
geometryNEList = JSONObjectToShape(jsonObjectNE)
jsonObjectRegion = readGeoJSONFileToJSONObject(filePathRegion)
geometryRegionList = JSONObjectToShape(jsonObjectRegion)
for indexRegion, region in enumerate(geometryRegionList):
for indexNE, ne in enumerate(geometryNEList):
isIntersect = region.intersects(ne)
if isIntersect:
featureNE = jsonObjectNE['features'][indexNE]
featureRegion = jsonObjectRegion['features'][indexRegion]
featureNE['properties']['region'] = featureRegion['properties']['name']
#if hasattr(featureRegion['properties'], 'count'):
if featureRegion['properties'].get('count', None) is not None:
featureRegion['properties']['count'] = featureRegion['properties']['count'] + ',' + str(featureNE['properties']['count'])
else:
featureRegion['properties']['count'] = str(featureNE['properties']['count'])
print(json.dumps(jsonObjectRegion))
modifyGeoJSON的更多相关文章
随机推荐
- Linux 系统资源管理-top-cpu
- vue 自动化部署 jenkins 篇
前端项目打包部署,以前都是手工运行打包命令,打包结束后压缩,然后上传到服务器上解压部署.这种重复性的工作,确实有点让人烦,而且效率也不高. 本文基于 vue 的前端项目. GitHub 的代码仓库,简 ...
- [EXP]Jenkins 2.150.2 - Remote Command Execution (Metasploit)
## # This module requires Metasploit: https://metasploit.com/download # Current source: https://gith ...
- 为什么我们喜欢用 sigmoid 这类 S 型非线性变换?
本文整理自 @老师木 的一条图片新浪微博,从另一个角度给出为何采用 sigmoid 函数作非线性变换的解释. 为什么我们喜欢用 sigmoid 这类 S 型非线性变换?
- A Painless Q-learning Tutorial (一个 Q-learning 算法的简明教程)
本文是对 http://mnemstudio.org/path-finding-q-learning-tutorial.htm 的翻译,共分两部分,第一部分为中文翻译,第二部分为英文原文.翻译 ...
- 21天打造分布式爬虫-urllib库(一)
1.1.urlopen函数的用法 #encoding:utf-8 from urllib import request res = request.urlopen("https://www. ...
- Android多线程编程<一>Android中启动子线程的方法
我们知道在Android中,要更新UI只能在UI主线程去更新,而不允许在子线程直接去操作UI,但是很多时候,很多耗时的工作都交给子线程去实现,当子线程执行完这些耗时的工作后,我们希望去修改 ...
- 六:理解控件的运行机制(例:基于WebControl命名空间的控件)
Control类的Render方法在WebControl类中被被分成三部分1:RenderBeginTag,呈现标签的开始2:RenderContents,呈现标签的内容3:RenderEndTag, ...
- 从零开始学 Web 之 移动Web(七)Bootstrap
大家好,这里是「 从零开始学 Web 系列教程 」,并在下列地址同步更新...... github:https://github.com/Daotin/Web 微信公众号:Web前端之巅 博客园:ht ...
- 十余年软件开发经历,经验总结和程序一览(涉及Socket、WPF、vc++、CAD、图像、GIS)
前言 本文主要介绍我开发的几款软件产品,大概介绍一下功能.可以让读者了解本人的开发能力,所擅长的方面.有相关开发需求可以联系作者. 本人开发软件多年,从事的行业也多种多样:自然接触了不同的业务,开发了 ...