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. JavaScript的BOM编程,事件-第4章

    目标 BOM编程 window和document对象 window对象的属性和方法 document对象的属性和方法 JavaScript中对象的分类 浏览器对象:window对象 window对象, ...

  2. 架构书籍推荐:Java中高级、架构师值得一读!

    上周我们免费送出了6本关于Python的重量级技术书籍,推出后反响特别强烈,有一个和最后一名仅差了一个赞,不过我们还是额外加送了一本送给这位朋友,以资鼓励,从另一面也可以看出Java程序猿对Pytho ...

  3. Android 源码分析01_AsyncTask

    [参考文献] http://blog.csdn.net/singwhatiwanna/article/details/17596225 /* * Copyright (C) 2008 The Andr ...

  4. Apache Commons Beanutils 二 (动态Bean - DynaBeans)

    相关背景 上一篇介绍了PropertyUtils的用法,PropertyUtils主要是在不修改bean结构的前提下,动态访问bean的属性: 但是有时候,我们会经常希望能够在不定义一个Java类的前 ...

  5. Log4Net使用详解1

    log4net是一个功能著名的开源日志记录组件.利用log4net可以方便地将日志信息记录到文件.控制台.Windows事件日志和数据库(包括MS SQL Server, Access, Oracle ...

  6. Spring Boot + Spring Cloud 实现权限管理系统 后端篇(二十四):权限控制(Shiro 注解)

    在线演示 演示地址:http://139.196.87.48:9002/kitty 用户名:admin 密码:admin 技术背景 当前,我们基于导航菜单的显示和操作按钮的禁用状态,实现了页面可见性和 ...

  7. Maven的assembly插件实现自定义打包部署(包含依赖jar包)

    微服务必备 优点: 1.可以直接导入依赖jar包 2.可以添加插件启动 .sh 文件 3.插件的配置以及微服务的统一打包方式 1.首先我们需要在pom.xml中配置maven的assembly插件 & ...

  8. Go HTTP服务器

    HTTP HandleFunc的简单使用 package main import ( "log" "net/http" ) func main() { //注册 ...

  9. Delphi常用快捷键

    delphi是我学编程时的入门语言,用过一年多的时光,个人对它还是挺喜欢的.现在用的少了,一些快捷键和语法也有些遗忘了,这里对delphi的快捷键做个总结,留个纪念.嘿嘿,不知道还有多少人还用着这门语 ...

  10. Scala面向对象编程与类型系统

    Scala支持面向对象编程, 其面向对象特性与Java有共同之处并添加了很多新的特性. 类定义 scala使用class关键字定义类: class MyComplex(real0:Double, im ...