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. typescript handbook 学习笔记1

    概述 这是我学习typescript的笔记.写这个笔记的原因主要有2个,一个是熟悉相关的写法:另一个是理清其中一些晦涩的东西.供以后开发时参考,相信对其他人也有用. 学习typescript建议直接看 ...

  2. javascript 实现数据结构 - 队列

    队列是遵循FIFO(First In First Out,先进先出,也称为先来先服务)原则的一组有序的项.队列在尾部添加新元素,并从顶部移除元素.最新添加的元素必须排在队列的末尾. 1.构造函数构建队 ...

  3. 夜神模拟已开启,adb命令检测不了设备解决方法

    日常APP测试中,很难拥有多种机型和各种安卓版本的手机,此时可以借助模拟器. 命令返回结果只有 “List of devices attached”,即代表检测不了模拟器 最近在使用夜神模拟器的时候, ...

  4. java开发,年薪15W的你和年薪50W的他的差距

      在这个IT系统动辄就是上亿流量的时代,Java作为大数据时代应用最广泛的语言,诞生了一批又一批的新技术,包括HBase.Hadoop.MQ.Netty.SpringCloud等等 .   一些独角 ...

  5. 201. Orchard学习 一、基础

    一.项目介绍 Orchard是一个免费和开源的社区交流项目,致力于在ASP.NET平台开发应用程序和可重用性组件.它将创建用于ASP.Net应用和扩展的共享组件,以及修改这些组件以便使其应用于终端用户 ...

  6. flex和box-shadow一些兼容性问题

    html代码 <div class="creative-list"> <a class="creative-list-item"> &l ...

  7. redis linux(centos) 安装

    前言 redis 大家都使用过, 可以安装在windows下, 也可以安装在linux下, 一般还是linux下安装比较多. 这里来介绍一下redis在linux下的安装 一. 下载 https:// ...

  8. javascript的作用域和优先级

    变量的作用域是在定义时决定的,不是在运行时活动对象是在运行时决定的?如果就创建一个对象,使用完毕就完了,就使用json字面量的方式如果对象被反复创建,反复使用,就使用自定义的构造函数方式优先级内部变量 ...

  9. Vuejs的指令及组件用法总结

    vuejs介绍 Vue.js是当下很火的一个JavaScript MVVM库,它是以数据驱动和组件化的思想构建的.相比于Angular.js,Vue.js提供了更加简洁.更易于理解的API,使得我们能 ...

  10. scikit-learn入门导航

    scikit-learn是一个非常强大的机器学习库, 提供了很多常见机器学习算法的实现. scikit-learn可以通过pip进行安装: pip install -U scikit-learn 不过 ...