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的更多相关文章
随机推荐
- 从零开始学习渗透Node.js应用程序
本文来源于i春秋学院,未经允许严禁转载 0x01 介绍 简单的说 Node.js 就是运行在服务端的 JavaScript.Node.js 是一个基于Chrome JavaScript 运行时建立的一 ...
- JavaScript控制页码的显示与隐藏
前端页面开发分页显示功能时,一般都要求使用自定义的页码样式,直接用网上分页插件就比较麻烦了,这里记录一下工作中总结的一个比较简单通用的控制页码显示与隐藏的的js代码. 首先是使用时需要自己根据自己具体 ...
- SVN 客户端 TortoiseSVN 的安装和使用
关于 参考博客:TortoiseSVN新人使用指南 TortoiseSVN 是一个 Apache Subversion(SVN)客户端,实现为Windows外壳扩展.它直观且易于使用,因为它不需要Su ...
- 学生成绩管理系统(C++指针、链表、文件及面向对象的运用)
学生成绩管理系统 功能页面显示: 实现源码: #include<iostream> #include<fstream> #include<cstring> # ...
- JAVA实现调用微信js-sdk扫一扫
喜欢的朋友可以关注下. 已经很久没有给大家分享一片技术文章了,今天抽了点时间来,给大家说一说如何调用微信提供的扫一扫接口. 前提: 需要申请一个公众号:申请公众号需要的资料我就不说了,去申请微信会提示 ...
- 2-3 用组件改写Todolist案例
编写组件来改写2-2的Todolist案例
- win10 store 无法连接网络(原创)
当你试过所有的解决攻略 都无效时,那么使用这个教程 关闭以下的蓝色框里的
- 写在19年初的后端社招面试经历(两年经验): 蚂蚁 头条 PingCAP
去年(18年)年底想出来看看机会,最后很幸运地拿到了 PingCAP,今日头条的 offer 以及蚂蚁金服的口头 offer.想着可以总结一下经验,分享一下自己这一段"骑驴找马"过 ...
- app自动化测试中的相关api
这个说的api即python自动化测试中经常会使用到的一些api,具体如下: 1.find_element_by_id/find_elements_by_id 定位元素api,使用方法如下: driv ...
- tcp 三次握手 四次挥手
TCP协议中的三次握手和四次挥手 建立TCP需要三次握手才能建立,而断开连接则需要四次挥手. 三次握手,建立连接 首先Client发送连接请求报文,Server端接收连接后回复ACK报文,并为这次连接 ...