五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

python arcpy練習(xí)之面要素重疊拓?fù)錂z查

發(fā)布日期:2022-01-03 02:30 | 文章來源:源碼中國

需求

有多個(gè)文件地理數(shù)據(jù)庫(gdb),數(shù)據(jù)庫內(nèi)有多個(gè)面要素類圖層,每個(gè)圖層不能有自重疊,也不能和其他圖層重疊。所以,需要為每個(gè)文件地理數(shù)據(jù)庫(gdb)進(jìn)行拓?fù)錂z查。

思路

1.在輸出文件夾下新建與輸入文件夾下同名的gdb。

2.在gdb內(nèi)新建要素類數(shù)據(jù)集。

3.在數(shù)據(jù)集內(nèi)創(chuàng)建拓?fù)洹?/p>

4.向拓?fù)渲刑砑右仡悺?/p>

5.添加拓?fù)湟?guī)則。

6.拓?fù)潋?yàn)證。

7.導(dǎo)出拓?fù)溴e(cuò)誤。

將需要拓?fù)涞膅db放入同一個(gè)文件夾下,用python代碼串連起來利用循環(huán)遍歷gdb便可以進(jìn)行批量拓?fù)淞恕?/p>

代碼

# -*- coding: gbk -*-
import os
import arcpy
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
arcpy.AddMessage(sys.getdefaultencoding())
arcpy.env.XYResolution = "0.0001 Meters" #設(shè)置XY分辨率
arcpy.env.XYTolerance = "0.001 Meters"#設(shè)置XY容差
def checkTopology(in_path, out_path):
 cout = 0
 fail = 0
 warning = 0
 fail_list = []
 warning_list = []
 arcpy.env.workspace = in_path
 workspaces = arcpy.ListWorkspaces("*", "ALL")
 for workspace in workspaces:
  arcpy.AddMessage("=" * 60)
  cout += 1
  arcpy.AddMessage(" (" + str(cout) + ") " + os.path.basename(workspace))
  arcpy.AddMessage("  ")
  try:
# 將每個(gè)gdb設(shè)為工作區(qū)
arcpy.env.workspace = workspace
fc_list = arcpy.ListFeatureClasses() #列出gdb內(nèi)的要素類圖層
in_fc_path_list = []
for fc in fc_list:
 in_fc_path_list.append(os.path.join(workspace,fc))
# 在輸出路徑out_path下新建gdb
gdb_name1 = os.path.basename(workspace)
result_gdb = os.path.join(out_path, gdb_name1)
if not arcpy.Exists(result_gdb):
 arcpy.AddMessage(" 新建 " + result_gdb + " ...")
 arcpy.CreateFileGDB_management(out_path, gdb_name1)
else:
 arcpy.AddWarning(result_gdb + " 已存在!")
 warning_list.append(result_gdb)
 warning += 1
 continue
arcpy.AddMessage(" 在 " + result_gdb + " 內(nèi)新建要素?cái)?shù)據(jù)集...")
dataset_name = "dataset"
dataset_path = os.path.join(result_gdb,dataset_name)
# 引用包含要應(yīng)用的空間參考的要素類或要素?cái)?shù)據(jù)集,
# 將in_fc_path_list[0]的坐標(biāo)作為要素?cái)?shù)據(jù)集的坐標(biāo),所以gdb內(nèi)的所有要素類應(yīng)該是統(tǒng)一坐標(biāo)
arcpy.CreateFeatureDataset_management(result_gdb, dataset_name, in_fc_path_list[0])
#導(dǎo)入要素類到數(shù)據(jù)集
arcpy.AddMessage(" 向 " + dataset_path + " 導(dǎo)入要素類圖層...")
arcpy.FeatureClassToGeodatabase_conversion(in_fc_path_list,dataset_path)
#在dataset數(shù)據(jù)內(nèi)創(chuàng)建拓?fù)?arcpy.AddMessage(" 創(chuàng)建拓?fù)?..")
topology_name = "topology"
topology_path = os.path.join(dataset_path, topology_name)
arcpy.CreateTopology_management(dataset_path, topology_name)
# 將導(dǎo)入dataset的要素類添加到拓?fù)渲?arcpy.AddMessage(" 向拓?fù)渲刑砑右仡?..")
dataset_fc_path_lsit = []  #數(shù)據(jù)集中的要素類絕對路徑列表
for ifc_name in fc_list:
 # 拼接數(shù)據(jù)集中的要素類絕對路徑
 dataset_fc_path = os.path.join(dataset_path,ifc_name)
 dataset_fc_path_lsit.append(dataset_fc_path)
 arcpy.AddFeatureClassToTopology_management(topology_path, dataset_fc_path, "1", "1")
arcpy.AddMessage(" 添加拓?fù)湟?guī)則...")
for i in range(len(dataset_fc_path_lsit)):
 fc_path1 = dataset_fc_path_lsit[i]
 #規(guī)則1:不能重疊
 arcpy.AddRuleToTopology_management(topology_path, "Must Not Overlap (Area)", fc_path1, "", "", "")
 for j in range(i + 1, len(dataset_fc_path_lsit)):
  fc_path2 = dataset_fc_path_lsit[j]
  # 規(guī)則2:不能重疊與其他要素類重疊
  arcpy.AddRuleToTopology_management(topology_path, "Must Not Overlap With (Area-Area)", fc_path1, "", fc_path2, "")
arcpy.AddMessage(" 拓?fù)潋?yàn)證...")
arcpy.ValidateTopology_management(topology_path, "Full_Extent")
arcpy.AddMessage(" 導(dǎo)出拓?fù)溴e(cuò)誤...")
arcpy.ExportTopologyErrors_management(topology_path, dataset_path, "topoError")
  except Exception as e:
arcpy.AddError(e.message)
arcpy.AddError(" " + os.path.basename(workspace) + " 失?。?)
fail_list.append(os.path.basename(workspace))
fail += 1
 arcpy.AddMessage('+' * 60)
 arcpy.AddMessage(u"  成功:" + str(cout - fail - warning) + u" 個(gè)!")
 if warning > 0:
  arcpy.AddWarning(u"  警告:" + str(warning) + u" 個(gè)! 如下:")
  arcpy.AddWarning("####" + '*' * 20)
  for fff in warning_list:
arcpy.AddWarning("  " + fff)
  arcpy.AddWarning("####" + '*' * 20)
 if fail > 0:
  arcpy.AddError(u"  失敗:" + str(fail) + u" 個(gè)! 如下:")
  arcpy.AddError("####" + '*' * 20)
  for ff in fail_list:
arcpy.AddError("  " + ff)
  arcpy.AddError("####" + '*' * 20)
 arcpy.AddMessage('+' * 60)
if __name__ == "__main__":
 in_path_globle = arcpy.GetParameterAsText(0)
 out_path_globe = arcpy.GetParameterAsText(1)
 checkTopology(in_path_globle,out_path_globe)

效果圖

總結(jié)

本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注本站的更多內(nèi)容!

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部