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的更多相关文章

随机推荐

  1. 聚簇索引(clustered index )和非聚簇索引(secondary index)的区别

    这两个名字虽然都叫做索引,但这并不是一种单独的索引类型,而是一种数据存储方式.对于聚簇索引存储来说,行数据和主键B+树存储在一起,辅助键B+树只存储辅助键和主键,主键和非主键B+树几乎是两种类型的树. ...

  2. 《机器学习实战(基于scikit-learn和TensorFlow)》第二章内容的学习心得

    请支持正版图书, 购买链接 下方内容里面很多链接需要我们***,请大家自备梯子,实在不会再请留言,节约彼此时间. 源码在底部,请自行获取,谢谢! 当开始着手进行一个端到端的机器学习项目,大致需要以下几 ...

  3. Spark Graphx

    Graphx    概述        Spark GraphX是一个分布式图处理框架,它是基于Spark平台提供对图计算和图挖掘简洁易用的而丰富的接口,极大的方便了对分布式图处理的需求.       ...

  4. 课程四(Convolutional Neural Networks),第一周(Foundations of Convolutional Neural Networks) —— 0.Learning Goals

    Learning Goals Understand the convolution operation Understand the pooling operation Remember the vo ...

  5. Java访问文件夹中文件的递归遍历代码Demo

    上代码: import java.io.File; /* * 需求:对指定目录进行所有内容的列出(包含子目录中的内容) * 也可以理解为 深度遍历. */ public class FindAllFi ...

  6. Java第三方支付接入案例(支付宝)

    开源项目链接 Kitty 开源权限管理系统 项目地址:https://gitee.com/liuge1988/kitty 演示地址:http://139.196.87.48:9002/kitty 用户 ...

  7. Http怎么处理长连接

    http协议中有和keep alive特性,这个在http1.1中有, 可以保持浏览器和服务器之间保持着长连接,http本身是无连接的协议, 通过tcp实现数据的传输,处理长连接要注意什么时候数据服务 ...

  8. 获取访问者的IP地址

    function getIp() { $realip = NULL; if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ipArray = explode( ...

  9. docker常用命令记录

    Docker官方镜像中心:https://hub.docker.com/explore/ 参考:慕课网docker视频教程 https://www.imooc.com/video/14625 1.启动 ...

  10. c# DataSet转换为Json

    /// <summary> /// DataSet转换为Json /// </summary> /// <param name="dataSet"&g ...