当前位置:网站首页>GDAL + ogr learning
GDAL + ogr learning
2022-04-23 18:00:00 【Be happy to study today】
GDAL+OGR Study
Every time you write code, use Arcpy You have to switch back python2, so much trouble , So let's learn gdal+ogr.
gdal Libraries installed
direct cmd Write pip intsall gdal Will report a mistake

Open the link gdal Library Download , according to python Version download the package of the corresponding version , My version is python3.9+64 position , Download on demand .


take wheel Copy the file to the corresponding folder and run again pip install Installation successful .
Use OGR Filter data
They are Gaud POI surface type The structure and POIshp type Structure


Will use the... Contained in the form POI The type is right shp Inside POI Type
#-*- coding:utf-8 -*-
#2022.2.10
'''
Put the statistics in the table poi Screening , Then select... In the designated area poi Category
'''
import time
import pandas as pd
from osgeo import ogr
import os
def identify(poistr,selectpoilist):
if poistr.split(';')[2] in selectpoilist:
return 1
else:
return 0
def selectpoi(poitype,lyr):
n = lyr.GetFeatureCount()
print(" common ",n," strip poi data ")
# Add fields
defn = lyr.GetLayerDefn()
fieldIndex = defn.GetFieldIndex('selectid')
if fieldIndex < 0:
# Add fields
lyr.CreateField( # Add a layer selectid Field
ogr.FieldDefn('selectid', ogr.OFTInteger,SetPrecision(3))
)
fieldIndex2 = defn.GetFieldIndex('selectid')
if fieldIndex2 > 0:
print(" Field created successfully :", fieldIndex)
m = 0
starttime = time.time()
for feat in lyr:
name = feat.GetField('name')
type = feat.GetField('type')
# Calculation r Value to determine whether to select ,>0 Then choose , yes 0 You don't choose
if (type.count("|")>0):
r=0
for i in range(0,type.count("|")):
r =r+identify(type.split('|')[i],poitype)
else:
r=identify(type,poitype)
if r>0:
feat.SetField('selectid', 1) # Set the value of the field
else:
feat.SetField('selectid', 0) # Set the value of the field
lyr.SetFeature(feat)
m=m+1
print(" Running page ",m," Data ",feat.GetField('selectid'),name,type)
if m==n:
break;
endtime = time.time()
print(" Total running time ",endtime-starttime)
if __name__=="__main__":
# Read POI Type table
datapath = r'E:\WHDATA\region_data\jianghan_district\database'
poifilename = "./ Sub category POI.xlsx"
poitype = pd.read_excel(poifilename)
type = poitype[' Subclass '].to_list()
# Read Jianghan District POIshp data
in_poishp = os.path.join(datapath,"poi.shp")
outpath = os.path.join(datapath,"poi_select.shp")
ds = ogr.Open(in_poishp,1)#1 Said to write ,0 Indicates read-only
lyr = ds.GetLayer()
selectpoi(type,lyr)
版权声明
本文为[Be happy to study today]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230545528278.html
边栏推荐
- Go的Gin框架学习
- Leak detection and vacancy filling (VIII)
- Compilation principle first set follow set select set prediction analysis table to judge whether the symbol string conforms to the grammar definition (with source code!!!)
- Arithmetic expression
- I / O multiplexing and its related details
- Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
- Timestamp to formatted date
- 高德地图搜索、拖拽 查询地址
- An example of linear regression based on tensorflow
- Cross domain settings of Chrome browser -- including new and old versions
猜你喜欢
![Click Cancel to return to the previous page and modify the parameter value of the previous page, let pages = getcurrentpages() let prevpage = pages [pages. Length - 2] / / the data of the previous pag](/img/ed/4d61ce34f830209f5adbddf9165676.png)
Click Cancel to return to the previous page and modify the parameter value of the previous page, let pages = getcurrentpages() let prevpage = pages [pages. Length - 2] / / the data of the previous pag

C# 的数据流加密与解密

JS forms the items with the same name in the array object into the same array according to the name

C#的随机数生成

SystemVerilog (VI) - variable

Chrome浏览器的跨域设置----包含新老版本两种设置

.105Location

2022 Jiangxi Photovoltaic Exhibition, China distributed Photovoltaic Exhibition, Nanchang solar energy utilization Exhibition

cv_ Solution of mismatch between bridge and opencv

Halo open source project learning (II): entity classes and data tables
随机推荐
Go对文件操作
Go language JSON package usage
587. 安装栅栏 / 剑指 Offer II 014. 字符串中的变位词
Solving the problem of displaying too many unique values in ArcGIS partition statistics failed
2022 Shanghai safety officer C certificate operation certificate examination question bank and simulation examination
C1小笔记【任务训练篇二】
Transfer learning of five categories of pictures based on VGg
Go's gin framework learning
[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)
JS implementation private attribute
Click Cancel to return to the previous page and modify the parameter value of the previous page, let pages = getcurrentpages() let prevpage = pages [pages. Length - 2] / / the data of the previous pag
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
Flask项目的部署详解
Eigen learning summary
JS interview question: FN call. call. call. Call (FN2) parsing
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
Gaode map search, drag and drop query address
Error in created hook: "referenceerror:" promise "undefined“
油猴网站地址