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的更多相关文章
随机推荐
- 如果你在it院校学习累了,你能干什么?
文章来源i春秋,未经允许不得转载 工具链接https://bbs.ichunqiu.com/portal.php 如果你在国内的it院校累了,有些厌倦了,你该怎么办? 分享一些joke以前 ...
- 第二十六节:复习Java语言基础-Java的概述,匿名对象,封装,构造函数
Java基础 Java语言概述 Java语言 语言 描述 javaee 企业版 javase 标准版 javame 小型版 JDK JDK(Java开发工具包) Java语言 语言 Java语言 Ja ...
- MySQL备份---lvm snapshot
正常安装(缺点要锁表) 1, 创建一个LV(逻辑卷) , 把MySQL的数据目录放到这个LV上 /var/lib/mysql 对这个LV做快照, 从快照备份数据 删除快照 非正常安装 1,创建LV 2 ...
- B - Red and Black 问题思考
红黑地板问题 There is a rectangular room, covered with square tiles. Each tile is colored either red or bl ...
- Django Rest Framework-介绍
什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中文翻译为"表征状态转移" RE ...
- 《Kubernetes权威指南》——Kubelet运行机制与安全机制
1 Kubelet运行机制 Kubenetes集群中的每个Node节点都会启动一个Kubelet服务进程用于处理Master下发到该节点的任务,管理Pod及其中的容器 Kubelet进程在API Se ...
- salesforce lightning零基础学习(十) Aura Js 浅谈三: $A、Action、Util篇
前两篇分别介绍了Component类以及Event类,此篇将会说一下 $A , Action以及 Util. 一. Action Action类通常用于和apex后台交互,设置参数,调用后台以及对结 ...
- 【awesome-dotnet-core-learning】(3)-Bogus-假数据生成器
[awesome-dotnet-core-learning](3)-Bogus-假数据生成器 简介 Bogus一个简单而强大的假数据生成器,用于C#,F#和VB.NET.从著名的faker.js移植过 ...
- solr源码分析之数据导入DataImporter追溯。
若要搜索的信息都是被存储在数据库里面的,但是solr不能直接搜数据库,所以只有借助Solr组件将要搜索的信息在搜索服务器上进行索引,然后在客户端供客户使用. 1. SolrDispatchFilter ...
- PHP多个进程同时写入同一个文件
flock (PHP 3 >= 3.0.7, PHP 4, PHP 5) flock -- 轻便的咨询文件锁定 说明 bool flock ( int handle, int operation ...