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的更多相关文章
随机推荐
- 字符串拼接时使用StringBuffer还是StringBuilder?
StringBuffer.StringBuilder和String一样,也用来代表字符串.String类是不可变类,任何对String的改变都 会引发新的String对象的生成:StringBuffe ...
- Tomcat 在 Linux 上的安装和配置
一.文件上传 先上传tomcat安装文件到Linux服务器 二.解压安装 使用以下命令解压安装包 .tar.gz 解压成功会生成一个文件夹 tomcat服务器运行时是需要JDK支持的,所以必须先安装好 ...
- JavaScript学习之路-语法
版权声明:未经博主允许不得转载 在JavaScript中如何写语法呢?这里你可以去看一些教学文档来得快一些,这里不介绍,有点基础的也可以复习一下. //定义变量并赋值 var a; //定义变量 va ...
- apk文件md5校验之用好压对下载服务器测试[测试篇]
往往稍微有点规模的公司,都会有一个独立下载服务器,那么,我还是简单说一下下载服务器的原理吧,首先后台上传文件或软件,然后web服务器通过定时脚本检测,如有变化,则将文件同步出去到下载服务器,源站数据库 ...
- LeetCode--No.003 Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters Total Accepted: 167158 Total Submissions: 735821 Diff ...
- js中数字直接点方法会报错,如1.toString()
Number(11).toString() "11" var num = 111; undefined num.toString() "111" .toStri ...
- python 使用PyInstaller将程序打包
PyInstaller可以用来打包python应用程序,打包完的程序就可以在没有安装Python解释器的机器上运行了.类似于C#窗体程序使用Setup Factory 9 Trial进行打包. 安装: ...
- ArrayList的实现原理
ArrayList的线性复杂度是1.想确定一个数据,直接通过索引进行访问.实际上这个过程和数组是非常相似的.ArrayList在整个使用过程中,如果想要高效操作,最好设置一个数组的大小.在个数固定的情 ...
- oracle无法启动asm实例记录
首先查看asm进程ps aux|grep asmasm进程没起进行下面操作su - gridsrvctl start asmexit查看ora进程ps aux|grep oraora进程没起进行下面操 ...
- Gradle 大杂烩
1. 什么是Gradle Gradle是一个项目构建工具,目前支持Java.Groovy.Kotlin.Scala.构建脚本使用Groovy或Kotlin,目前一般用Groovy. 2. Gradle ...