python27获取gdb里所有要素类及字段和别名

2024-04-15 19:58

本文主要是介绍python27获取gdb里所有要素类及字段和别名,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

#!/usr/bin/python
# -*- coding:utf-8 -*-import os
import arcpy
import json
import sys
reload(sys)
sys.setdefaultencoding('utf8')#Author By Kgdblist=[] #新建空白列表 
file_dir=r"C:\Users\Administrator\Desktop\test" #输入待合并GDB数据库所在的文件夹的路径
dirlist=os.listdir(file_dir) #获取 C:\\Desktop 下一层级目录的路径
for dir in dirlist: #循环dirlist列表if ".gdb" in dir: #如果路径名称中包含 .gdb 字符串gdblist.append(file_dir+"\\"+dir) #将待合并GDB数据库的路径添加到gdblist列表中
print(gdblist)
print("gdb number is:" +str(len(gdblist)))for gdb in gdblist: #循环待合并GDB数据库arcpy.env.workspace = gdb #将循环到的数据库作为工作空间datasets = arcpy.ListDatasets() #列出该数据库包含的要素数据集#考虑GDB中含要素集  if(len(datasets)!=0):for ds in datasets: #循环要素数据集print("------" + ds)  # 打印该要素数据集的名称fcs=arcpy.ListFeatureClasses(feature_dataset=ds) #获取该要素数据集下的所有要素类filePath= fileName + "\\" + str(ds)print(filePath)for fc in fcs: #循环该要素数据集下的所有要素类print("-------" + fc)  # 打印要素类名称便于查看进度cnt=arcpy.GetCount_management(fc).getOutput(0) #获取该要素类的要素总个数print fc," feature number is ",cnt#考虑GDB中不含要素集只有要素类else:print"feature_dataset is None! "   # 打印无要素集说明fcs=arcpy.ListFeatureClasses() #直接获取GDB下的所有要素类for fc in fcs: #循环所有要素类print("-------" + fc)  # 打印要素类名称便于查看进度cnt=int(arcpy.GetCount_management(fc).getOutput(0)) #获取该要素类的要素总个数print fc," feature number is ",cnt#遍历要素类的字段名fcfields =arcpy.ListFields(fc)for fcfield in fcfields:
#                print(fc,":","{0} is a type of {1} with a length of {2} and aliasname is {3} "
#                    .format(fcfield.name, fcfield.type, fcfield.length,fcfield.aliasName))fielddefinition = (fc,":","{0} is a type of {1} with a length of {2} and aliasname is {3} ".format(fcfield.name, fcfield.type, fcfield.length,fcfield.aliasName))#输出为txt           with codecs.open(file_dir + "/" + "DataStructureTable" +".txt", "a",encoding='utf-8') as fd:fd.write(json.dumps(fielddefinition,encoding='UTF-8', ensure_ascii=False) +'\n')

参考以下文章

https://blog.csdn.net/weixin_38415513/article/details/104762342
https://blog.csdn.net/gognzixiaobai666/article/details/113864222
https://www.cnblogs.com/pengwue/p/9382741.html
http://zhihu.geoscene.cn/article/4062
 

抛砖引玉,希望有大佬能优化下,将结果导出至excel。

这篇关于python27获取gdb里所有要素类及字段和别名的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/906781

相关文章

Android Environment 获取的路径问题

1. 以获取 /System 路径为例 /*** Return root of the "system" partition holding the core Android OS.* Always present and mounted read-only.*/public static @NonNull File getRootDirectory() {return DIR_ANDR

JS和jQuery获取节点的兄弟,父级,子级元素

原文转自http://blog.csdn.net/duanshuyong/article/details/7562423 先说一下JS的获取方法,其要比JQUERY的方法麻烦很多,后面以JQUERY的方法作对比。 JS的方法会比JQUERY麻烦很多,主要则是因为FF浏览器,FF浏览器会把你的换行也当最DOM元素。 <div id="test"><div></div><div></div

vcpkg子包路径批量获取

获取vcpkg 子包的路径,并拼接为set(CMAKE_PREFIX_PATH “拼接路径” ) import osdef find_directories_with_subdirs(root_dir):# 构建根目录下的 "packages" 文件夹路径root_packages_dir = os.path.join(root_dir, "packages")# 如果 "packages"

Weex入门教程之4,获取当前全局环境变量和配置信息(屏幕高度、宽度等)

$getConfig() 获取当前全局环境变量和配置信息。 Returns: config (object): 配置对象;bundleUrl (string): bundle 的 url;debug (boolean): 是否是调试模式;env (object): 环境对象; weexVersion (string): Weex sdk 版本;appName (string): 应用名字;

Collection的所有的方法演示

import java.util.ArrayList;import java.util.Collection;import java.util.Iterator;public class TestCollection {/*** @param args* Collection的所有的方法演示* 此程序没有使用泛型,所以可以添加任意类型* 以后如果写到泛型会补充这一方面的内容*/public s

Temu官方宣导务必将所有的点位材料进行检测-RSL资质检测

关于饰品类产品合规问题宣导: 产品法规RSL要求 RSL测试是根据REACH法规及附录17的要求进行测试。REACH法规是欧洲一项重要的法规,其中包含许多对化学物质进行限制的规定和高度关注物质。 为了确保珠宝首饰的安全性,欧盟REACH法规规定,珠宝首饰上架各大电商平台前必须进行RSLReport(欧盟禁限用化学物质检测报告)资质认证,以确保产品不含对人体有害的化学物质。 RSL-铅,

MFC中App,Doc,MainFrame,View各指针的互相获取

纸上得来终觉浅,为了熟悉获取方法,我建了个SDI。 首先说明这四个类的执行顺序是App->Doc->Main->View 另外添加CDialog类获得各个指针的方法。 多文档的获取有点小区别,有时间也总结一下。 //  App void CSDIApp::OnApp() {      //  App      //  Doc     CDocument *pD

android两种日志获取log4j

android   log4j 加载日志使用方法; 先上图: 有两种方式: 1:直接使用架包 加载(两个都要使用); 架包:android-logging-log4j-1.0.3.jar 、log4j-1.2.15.jar  (说明:也可以使用架包:log4j-1.2.17.jar)  2:对架包输入日志的二次封装使用; 1:直接使用 log4j 日志框架获取日志信息: A:配置 日志 文

17 通过ref代替DOM用来获取元素和组件的引用

重点 ref :官网给出的解释是: ref: 用于注册对元素或子组件的引用。引用将在父组件的$refs 对象下注册。如果在普通DOM元素上使用,则引用将是该元素;如果在子组件上使用,则引用将是组件实例: <!-- vm.$refs.p will be the DOM node --><p ref="p">hello</p><!-- vm.$refs.child will be the c

react笔记 8-19 事件对象、获取dom元素、双向绑定

1、事件对象event 通过事件的event对象获取它的dom元素 run=(event)=>{event.target.style="background:yellowgreen" //event的父级为他本身event.target.getAttribute("aid") //这样便获取到了它的自定义属性aid}render() {return (<div><h2>{