1.要素描述属性获得
#coding=utf8 import arcpy import os import sys import math from arcpy.sa import * #获得基本描述,获得要素图层属性 def getFLayerinfo(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("{0:<20s}{1}".format("nameString: ",desc.nameString)) arcpy.AddMessage("{0:<20s}{1}".format("Where Clause: " , desc.whereClause)) arcpy.AddMessage("{0:<20s}{1}".format("Feature class type: " , desc.featureClass.featureType)) if hasattr(desc, "FIDSet"): arcpy.AddMessage("{0:<20s}{1}".format("FIDSet: " , desc.FIDSet)) if hasattr(desc, "dataElement"): arcpy.AddMessage("{0:<20s}{1}".format("dataElement: ",desc.dataElement)) #获得基本描述 def getdescinfo(): desc = arcpy.Describe(inFeature) if desc.childrenExpanded: for child in desc.children: arcpy.AddMessage(u" %s = %s" % (child.name, child.dataType)) arcpy.AddMessage("baseName="+desc.baseName) arcpy.AddMessage("catalogPath="+desc.catalogPath) arcpy.AddMessage("dataElementType="+desc.dataElementType) arcpy.AddMessage("dataType="+desc.dataType) if desc.dataType=="FeatureLayer": arcpy.AddMessage("inFeature是图层") getFLayerinfo() elif desc.dataType=="FeatureClass": arcpy.AddMessage("inFeature是要素类") arcpy.AddMessage("extension="+desc.extension) arcpy.AddMessage("file="+desc.file) arcpy.AddMessage("name="+desc.name) arcpy.AddMessage("path="+desc.path) arcpy.AddMessage("fullPropsRetrieved="+str(desc.fullPropsRetrieved)) arcpy.AddMessage("metadataRetrieved="+str(desc.metadataRetrieved)) #获得要素信息 def getFeatureInfo(): desc = arcpy.Describe(inFeature) ptype = desc.shapeType #获得类型 if ptype=="Point": arcpy.AddMessage(u""+inFeature+"是点") elif ptype=="Multipoint": arcpy.AddMessage(u""+inFeature+"是多点") elif ptype=="Polyline": arcpy.AddMessage(u""+inFeature+"是线") elif ptype=="Polygon": arcpy.AddMessage(u""+inFeature+"是面") arcpy.AddMessage(u"类型:"+ptype) #点,线,面 "Point", "Multipoint", "Polyline", "Polygon" arcpy.AddMessage(u"要素类型:"+desc.featureType) #"Simple", "Annotation", "Dimension if desc.featureType=="Annotation": arcpy.AddMessage(u""+inFeature+"是注记") if desc.hasZ==True: arcpy.AddMessage(u""+inFeature+"是3d") else: arcpy.AddMessage(u""+inFeature+"是2d") def Main(): getdescinfo() getFeatureInfo() getFLayerinfo() inFeature=arcpy.GetParameterAsText(0) Main()
2.数据集和坐标系信息属性获得
#coding=utf8 import arcpy import os import sys import math from arcpy.sa import * def getbandinfo(band1): desc = arcpy.Describe(band1) arcpy.AddMessage("Height: %d" % desc.height) arcpy.AddMessage("Width: %d" % desc.width) arcpy.AddMessage("Integer Raster: %s" % desc.isInteger) arcpy.AddMessage("noDataValue: %s" % desc.noDataValue) arcpy.AddMessage(u"Y方向分辨率: %s" % desc.meanCellHeight) arcpy.AddMessage(u"X方向分辨率: %s" % desc.meanCellWidth) arcpy.AddMessage("pixelType: %s" % desc.pixelType) arcpy.AddMessage("primaryField: %d" % desc.primaryField) arcpy.AddMessage("tableType: %s" % desc.tableType) ## U1 —1 bit ## U2 —2 bits ## U4 —4 bits ## U8 —Unsigned 8 bit integers ## S8 —8 bit integers ## U16 —Unsigned 16 bit integers ## S16 —16 bit integers ## U32 —Unsigned 32 bit integers ## S32 —32 bit integers ## F32 —Single precision floating point ## F64 —Double precision floating point #获得栅格数据集的信息 def getRasterDataset(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("Band Count: %d" % desc.bandCount) arcpy.AddMessage("Compression Type: %s" % desc.compressionType) arcpy.AddMessage("Raster Format: %s" % desc.format) arcpy.AddMessage("Raster sensorType: %s" % desc.sensorType) arcpy.AddMessage("Raster permanent: " + str(desc.permanent)) band1=inFeature+os.sep+"Band_1" getbandinfo(band1) #获得基本描述,获得要素图层属性 def getFLayerinfo(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("{0:<20s}{1}".format("nameString: ",desc.nameString)) arcpy.AddMessage("{0:<20s}{1}".format("Where Clause: " , desc.whereClause)) arcpy.AddMessage("{0:<20s}{1}".format("Feature class type: " , desc.featureClass.featureType)) if hasattr(desc, "FIDSet"): arcpy.AddMessage("{0:<20s}{1}".format("FIDSet: " , desc.FIDSet)) #获得基本描述 def getdescinfo(): desc = arcpy.Describe(inFeature) if desc.childrenExpanded: for child in desc.children: arcpy.AddMessage(" %s = %s" % (child.name, child.dataType)) arcpy.AddMessage("baseName="+desc.baseName) arcpy.AddMessage("catalogPath="+desc.catalogPath) arcpy.AddMessage("dataElementType="+desc.dataElementType) arcpy.AddMessage("dataType="+desc.dataType) ##FeatureClass — ##FeatureDataset — ## ##LasDataset — ##Layer — ##FeatureLayer — ##Map ##MosaicDataset — ## ##RasterBand — ##RasterCatalog — ##RasterDataset — ##RelationshipClass — ##RepresentationClass — ##SchematicDataset — ##Style — ##Table — ##Terrain — ##Text — ##Tin — ##Tool — ##Toolbox ##Topology if desc.dataType=="FeatureLayer": arcpy.AddMessage(inFeature+"是图层") getFLayerinfo() elif desc.dataType=="FeatureClass": getFeatureInfo() arcpy.AddMessage(inFeature+"是要素类") elif desc.dataType=="RasterDataset": arcpy.AddMessage(inFeature+"是栅格数据集") getRasterDataset() arcpy.AddMessage("extension="+desc.extension) arcpy.AddMessage("file="+desc.file) arcpy.AddMessage("name="+desc.name) arcpy.AddMessage("path="+desc.path) arcpy.AddMessage("fullPropsRetrieved="+str(desc.fullPropsRetrieved)) arcpy.AddMessage("metadataRetrieved="+str(desc.metadataRetrieved)) #获得要素信息 def getFeatureInfo(): desc = arcpy.Describe(inFeature) ptype = desc.shapeType #获得类型 if ptype=="Point": arcpy.AddMessage(u""+inFeature+"是点") elif ptype=="Multipoint": arcpy.AddMessage(u""+inFeature+"是多点") elif ptype=="Polyline": arcpy.AddMessage(u""+inFeature+"是线") elif ptype=="Polygon": arcpy.AddMessage(u""+inFeature+"是面") arcpy.AddMessage(u"类型:"+ptype) #点,线,面 "Point", "Multipoint", "Polyline", "Polygon" arcpy.AddMessage(u"要素类型:"+desc.featureType) #"Simple", "Annotation", "Dimension if desc.featureType=="Annotation": arcpy.AddMessage(u""+inFeature+"是注记") if desc.hasZ==True: arcpy.AddMessage(u""+inFeature+"是3d") else: arcpy.AddMessage(u""+inFeature+"是2d") #获得数据集信息 def getDatasetInfo(): desc = arcpy.Describe(inFeature) arcpy.AddMessage(u"Dataset Type: {0}".format(desc.datasetType)) arcpy.AddMessage(u"canVersion: {0}".format(desc.canVersion)) if hasattr(desc,"isArchived"): arcpy.AddMessage(u"isArchived: {0}".format(desc.isArchived)) arcpy.AddMessage(u"ZExtent: {0}".format(desc.ZExtent)) pextent=desc.extent #范围信息 arcpy.AddMessage("Extent: XMin: {0}, XMax: {1}, YMin: {2}, YMax: {3}".format( pextent.XMin, pextent.XMax, pextent.YMin, pextent.YMax)) #坐标系信息 sr=desc.spatialReference if hasattr(sr,"GCS"): arcpy.AddMessage(u"sr.GCS.name: {0}".format(sr.GCS.name)) arcpy.AddMessage(u"sr.XYTolerance: {0}".format(sr.XYTolerance)) arcpy.AddMessage(u"sr.abbreviation: {0}".format(sr.abbreviation)) arcpy.AddMessage(u"sr.alias: {0}".format(sr.alias)) arcpy.AddMessage(u"sr.domain: {0}".format(sr.domain)) arcpy.AddMessage(u"sr.factoryCode: {0}".format(sr.factoryCode)) arcpy.AddMessage(u"sr.name: {0}".format(sr.name)) arcpy.AddMessage(u"sr.remarks: {0}".format(sr.remarks)) arcpy.AddMessage(u"sr.remarks: {0}".format(sr.remarks)) arcpy.AddMessage(u"sr.type: {0}".format(sr.type)) arcpy.AddMessage(u"sr.PCSCode: {0}".format(sr.PCSCode)) arcpy.AddMessage(u"sr.PCSName: {0}".format(sr.PCSName)) arcpy.AddMessage(u"sr.centralMeridian: {0}".format(sr.centralMeridian)) arcpy.AddMessage(u"sr.centralParallel: {0}".format(sr.centralParallel)) arcpy.AddMessage(u"sr.projectionCode: {0}".format(sr.projectionCode)) arcpy.AddMessage(u"sr.projectionName: {0}".format(sr.projectionName)) arcpy.AddMessage(u"sr.datumCode: {0}".format(sr.datumCode)) arcpy.AddMessage(u"sr.datumName: {0}".format(sr.datumName)) arcpy.AddMessage(u"sr.semiMajorAxis: {0}".format(sr.semiMajorAxis)) arcpy.AddMessage(u"sr.semiMinorAxis: {0}".format(sr.semiMinorAxis)) arcpy.AddMessage(u"sr.spheroidCode: {0}".format(sr.spheroidCode)) arcpy.AddMessage(u"sr.spheroidName: {0}".format(sr.spheroidName)) def Main(): getdescinfo() getDatasetInfo() inFeature=arcpy.GetParameterAsText(0) Main()
3.栅格属性获得
#coding=utf8 import arcpy import os import sys import math from arcpy.sa import * def getbandinfo(band1): desc = arcpy.Describe(band1) arcpy.AddMessage("Height: %d" % desc.height) arcpy.AddMessage("Width: %d" % desc.width) arcpy.AddMessage("Integer Raster: %s" % desc.isInteger) arcpy.AddMessage("noDataValue: %s" % desc.noDataValue) arcpy.AddMessage(u"Y方向分辨率: %s" % desc.meanCellHeight) arcpy.AddMessage(u"X方向分辨率: %s" % desc.meanCellWidth) arcpy.AddMessage("pixelType: %s" % desc.pixelType) arcpy.AddMessage("primaryField: %d" % desc.primaryField) arcpy.AddMessage("tableType: %s" % desc.tableType) ## U1 —1 bit ## U2 —2 bits ## U4 —4 bits ## U8 —Unsigned 8 bit integers ## S8 —8 bit integers ## U16 —Unsigned 16 bit integers ## S16 —16 bit integers ## U32 —Unsigned 32 bit integers ## S32 —32 bit integers ## F32 —Single precision floating point ## F64 —Double precision floating point #获得栅格数据集的信息 def getRasterDataset(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("Band Count: %d" % desc.bandCount) arcpy.AddMessage("Compression Type: %s" % desc.compressionType) arcpy.AddMessage("Raster Format: %s" % desc.format) arcpy.AddMessage("Raster sensorType: %s" % desc.sensorType) arcpy.AddMessage("Raster permanent: " + str(desc.permanent)) band1=inFeature+os.sep+"Band_1" getbandinfo(band1) #获得基本描述,获得要素图层属性 def getFLayerinfo(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("{0:<20s}{1}".format("nameString: ",desc.nameString)) arcpy.AddMessage("{0:<20s}{1}".format("Where Clause: " , desc.whereClause)) arcpy.AddMessage("{0:<20s}{1}".format("Feature class type: " , desc.featureClass.featureType)) if hasattr(desc, "FIDSet"): arcpy.AddMessage("{0:<20s}{1}".format("FIDSet: " , desc.FIDSet)) #获得基本描述 def getdescinfo(): desc = arcpy.Describe(inFeature) if desc.childrenExpanded: for child in desc.children: arcpy.AddMessage(" %s = %s" % (child.name, child.dataType)) arcpy.AddMessage("baseName="+desc.baseName) arcpy.AddMessage("catalogPath="+desc.catalogPath) arcpy.AddMessage("dataElementType="+desc.dataElementType) arcpy.AddMessage("dataType="+desc.dataType) ##FeatureClass — ##FeatureDataset — ## ##LasDataset — ##Layer — ##FeatureLayer — ##Map ##MosaicDataset — ## ##RasterBand — ##RasterCatalog — ##RasterDataset — ##RelationshipClass — ##RepresentationClass — ##SchematicDataset — ##Style — ##Table — ##Terrain — ##Text — ##Tin — ##Tool — ##Toolbox ##Topology if desc.dataType=="FeatureLayer": arcpy.AddMessage(inFeature+"是图层") getFLayerinfo() elif desc.dataType=="FeatureClass": getFeatureInfo() arcpy.AddMessage(inFeature+"是要素类") elif desc.dataType=="RasterDataset": arcpy.AddMessage(inFeature+"是栅格数据集") getRasterDataset() arcpy.AddMessage("extension="+desc.extension) arcpy.AddMessage("file="+desc.file) arcpy.AddMessage("name="+desc.name) arcpy.AddMessage("path="+desc.path) arcpy.AddMessage("fullPropsRetrieved="+str(desc.fullPropsRetrieved)) arcpy.AddMessage("metadataRetrieved="+str(desc.metadataRetrieved)) #获得要素信息 def getFeatureInfo(): desc = arcpy.Describe(inFeature) ptype = desc.shapeType #获得类型 if ptype=="Point": arcpy.AddMessage(u""+inFeature+"是点") elif ptype=="Multipoint": arcpy.AddMessage(u""+inFeature+"是多点") elif ptype=="Polyline": arcpy.AddMessage(u""+inFeature+"是线") elif ptype=="Polygon": arcpy.AddMessage(u""+inFeature+"是面") arcpy.AddMessage(u"类型:"+ptype) #点,线,面 "Point", "Multipoint", "Polyline", "Polygon" arcpy.AddMessage(u"要素类型:"+desc.featureType) #"Simple", "Annotation", "Dimension if desc.featureType=="Annotation": arcpy.AddMessage(u""+inFeature+"是注记") if desc.hasZ==True: arcpy.AddMessage(u""+inFeature+"是3d") else: arcpy.AddMessage(u""+inFeature+"是2d") def Main(): getdescinfo() inFeature=arcpy.GetParameterAsText(0) Main()
4.表和字段信息信息获得
#coding=utf8 import arcpy import os import sys import math from arcpy.sa import * def getbandinfo(band1): desc = arcpy.Describe(band1) arcpy.AddMessage("Height: %d" % desc.height) arcpy.AddMessage("Width: %d" % desc.width) arcpy.AddMessage("Integer Raster: %s" % desc.isInteger) arcpy.AddMessage("noDataValue: %s" % desc.noDataValue) arcpy.AddMessage(u"Y方向分辨率: %s" % desc.meanCellHeight) arcpy.AddMessage(u"X方向分辨率: %s" % desc.meanCellWidth) arcpy.AddMessage("pixelType: %s" % desc.pixelType) arcpy.AddMessage("primaryField: %d" % desc.primaryField) arcpy.AddMessage("tableType: %s" % desc.tableType) ## U1 —1 bit ## U2 —2 bits ## U4 —4 bits ## U8 —Unsigned 8 bit integers ## S8 —8 bit integers ## U16 —Unsigned 16 bit integers ## S16 —16 bit integers ## U32 —Unsigned 32 bit integers ## S32 —32 bit integers ## F32 —Single precision floating point ## F64 —Double precision floating point #获得栅格数据集的信息 def getRasterDataset(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("Band Count: %d" % desc.bandCount) arcpy.AddMessage("Compression Type: %s" % desc.compressionType) arcpy.AddMessage("Raster Format: %s" % desc.format) arcpy.AddMessage("Raster sensorType: %s" % desc.sensorType) arcpy.AddMessage("Raster permanent: " + str(desc.permanent)) band1=inFeature+os.sep+"Band_1" getbandinfo(band1) #获得基本描述,获得要素图层属性 def getFLayerinfo(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("{0:<20s}{1}".format("nameString: ",desc.nameString)) arcpy.AddMessage("{0:<20s}{1}".format("Where Clause: " , desc.whereClause)) arcpy.AddMessage("{0:<20s}{1}".format("Feature class type: " , desc.featureClass.featureType)) if hasattr(desc, "FIDSet"): arcpy.AddMessage("{0:<20s}{1}".format("FIDSet: " , desc.FIDSet)) def getTableView(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("Table View Name: " + desc.nameString) arcpy.AddMessage("Where Clause: " + desc.whereClause) arcpy.AddMessage("Table Name: " + desc.name) #获得基本描述 def getdescinfo(): desc = arcpy.Describe(inFeature) if desc.childrenExpanded: for child in desc.children: arcpy.AddMessage(" %s = %s" % (child.name, child.dataType)) arcpy.AddMessage("baseName="+desc.baseName) arcpy.AddMessage("catalogPath="+desc.catalogPath) arcpy.AddMessage("dataElementType="+desc.dataElementType) arcpy.AddMessage("dataType="+desc.dataType) ##FeatureClass — ##FeatureDataset — ## ##LasDataset — ##Layer — ##FeatureLayer — ##Map ##MosaicDataset — ## ##RasterBand — ##RasterCatalog — ##RasterDataset — ##RelationshipClass — ##RepresentationClass — ##SchematicDataset — ##Style — ##Table — ##Terrain — ##Text — ##Tin — ##Tool — ##Toolbox ##Topology if desc.dataType=="FeatureLayer": arcpy.AddMessage(inFeature+"是图层") getFLayerinfo() elif desc.dataType=="FeatureClass": getFeatureInfo() arcpy.AddMessage(inFeature+"是要素类") elif desc.dataType=="RasterDataset": arcpy.AddMessage(inFeature+"是栅格数据集") getRasterDataset() elif desc.dataType=="TableView": getTableView() arcpy.AddMessage("extension="+desc.extension) arcpy.AddMessage("file="+desc.file) arcpy.AddMessage("name="+desc.name) arcpy.AddMessage("path="+desc.path) arcpy.AddMessage("fullPropsRetrieved="+str(desc.fullPropsRetrieved)) arcpy.AddMessage("metadataRetrieved="+str(desc.metadataRetrieved)) #获得要素信息 def getFeatureInfo(): desc = arcpy.Describe(inFeature) ptype = desc.shapeType #获得类型 if ptype=="Point": arcpy.AddMessage(u""+inFeature+"是点") elif ptype=="Multipoint": arcpy.AddMessage(u""+inFeature+"是多点") elif ptype=="Polyline": arcpy.AddMessage(u""+inFeature+"是线") elif ptype=="Polygon": arcpy.AddMessage(u""+inFeature+"是面") arcpy.AddMessage(u"类型:"+ptype) #点,线,面 "Point", "Multipoint", "Polyline", "Polygon" arcpy.AddMessage(u"要素类型:"+desc.featureType) #"Simple", "Annotation", "Dimension if desc.featureType=="Annotation": arcpy.AddMessage(u""+inFeature+"是注记") if desc.hasZ==True: arcpy.AddMessage(u""+inFeature+"是3d") else: arcpy.AddMessage(u""+inFeature+"是2d") #获得数据集信息 def getDatasetInfo(): desc = arcpy.Describe(inFeature) arcpy.AddMessage(u"Dataset Type: {0}".format(desc.datasetType)) arcpy.AddMessage(u"canVersion: {0}".format(desc.canVersion)) if hasattr(desc,"isArchived"): arcpy.AddMessage(u"isArchived: {0}".format(desc.isArchived)) arcpy.AddMessage(u"ZExtent: {0}".format(desc.ZExtent)) pextent=desc.extent #范围信息 arcpy.AddMessage("Extent: XMin: {0}, XMax: {1}, YMin: {2}, YMax: {3}".format( pextent.XMin, pextent.XMax, pextent.YMin, pextent.YMax)) #坐标系信息 sr=desc.spatialReference if hasattr(sr,"GCS"): arcpy.AddMessage(u"sr.GCS.name: {0}".format(sr.GCS.name)) arcpy.AddMessage(u"sr.XYTolerance: {0}".format(sr.XYTolerance)) arcpy.AddMessage(u"sr.abbreviation: {0}".format(sr.abbreviation)) arcpy.AddMessage(u"sr.alias: {0}".format(sr.alias)) arcpy.AddMessage(u"sr.domain: {0}".format(sr.domain)) arcpy.AddMessage(u"sr.factoryCode: {0}".format(sr.factoryCode)) arcpy.AddMessage(u"sr.name: {0}".format(sr.name)) arcpy.AddMessage(u"sr.remarks: {0}".format(sr.remarks)) arcpy.AddMessage(u"sr.remarks: {0}".format(sr.remarks)) arcpy.AddMessage(u"sr.type: {0}".format(sr.type)) arcpy.AddMessage(u"sr.PCSCode: {0}".format(sr.PCSCode)) arcpy.AddMessage(u"sr.PCSName: {0}".format(sr.PCSName)) arcpy.AddMessage(u"sr.centralMeridian: {0}".format(sr.centralMeridian)) arcpy.AddMessage(u"sr.centralParallel: {0}".format(sr.centralParallel)) arcpy.AddMessage(u"sr.projectionCode: {0}".format(sr.projectionCode)) arcpy.AddMessage(u"sr.projectionName: {0}".format(sr.projectionName)) arcpy.AddMessage(u"sr.datumCode: {0}".format(sr.datumCode)) arcpy.AddMessage(u"sr.datumName: {0}".format(sr.datumName)) arcpy.AddMessage(u"sr.semiMajorAxis: {0}".format(sr.semiMajorAxis)) arcpy.AddMessage(u"sr.semiMinorAxis: {0}".format(sr.semiMinorAxis)) arcpy.AddMessage(u"sr.spheroidCode: {0}".format(sr.spheroidCode)) arcpy.AddMessage(u"sr.spheroidName: {0}".format(sr.spheroidName)) def getTableinfo(): desc = arcpy.Describe(inFeature) if hasattr(desc,"hasOID"): arcpy.AddMessage(u"hasOID: {0}".format(desc.hasOID)) if desc.hasOID: arcpy.AddMessage(u"OIDFieldName: {0}".format(desc.OIDFieldName)) for field in desc.fields: arcpy.AddMessage("name=%-22s aliasName=%s baseName=%s type=%s length=%d precision=%d scale=%d" % (field.name, field.aliasName, field.baseName, field.type,field.length,field.precision,field.scale)) indexes = arcpy.ListIndexes(inFeature) # Iterate through the list of indexes for index in indexes: # Print index properties arcpy.AddMessage("Name: {0}".format(index.name)) arcpy.AddMessage(" Type : {0}".format(index.isAscending)) arcpy.AddMessage(" Scale : {0}".format(index.isUnique)) arcpy.AddMessage(" Number of fields: {0} {1}".format(len(index.fields),index.fields[0].name)) for field in index.fields: arcpy.AddMessage("idx==================name=%-22s aliasName=%s baseName=%s type=%s length=%d precision=%d scale=%d" % (field.name, field.aliasName, field.baseName, field.type,field.length,field.precision,field.scale)) def Main(): getdescinfo() getDatasetInfo() getTableinfo() inFeature=arcpy.GetParameterAsText(0) Main()
5.工作空间属性
#coding=utf8 import arcpy import os import sys import math from arcpy.sa import * def getbandinfo(band1): desc = arcpy.Describe(band1) arcpy.AddMessage("Height: %d" % desc.height) arcpy.AddMessage("Width: %d" % desc.width) arcpy.AddMessage("Integer Raster: %s" % desc.isInteger) arcpy.AddMessage("noDataValue: %s" % desc.noDataValue) arcpy.AddMessage(u"Y方向分辨率: %s" % desc.meanCellHeight) arcpy.AddMessage(u"X方向分辨率: %s" % desc.meanCellWidth) arcpy.AddMessage("pixelType: %s" % desc.pixelType) arcpy.AddMessage("primaryField: %d" % desc.primaryField) arcpy.AddMessage("tableType: %s" % desc.tableType) ## U1 —1 bit ## U2 —2 bits ## U4 —4 bits ## U8 —Unsigned 8 bit integers ## S8 —8 bit integers ## U16 —Unsigned 16 bit integers ## S16 —16 bit integers ## U32 —Unsigned 32 bit integers ## S32 —32 bit integers ## F32 —Single precision floating point ## F64 —Double precision floating point #获得栅格数据集的信息 def getRasterDataset(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("Band Count: %d" % desc.bandCount) arcpy.AddMessage("Compression Type: %s" % desc.compressionType) arcpy.AddMessage("Raster Format: %s" % desc.format) arcpy.AddMessage("Raster sensorType: %s" % desc.sensorType) arcpy.AddMessage("Raster permanent: " + str(desc.permanent)) band1=inFeature+os.sep+"Band_1" getbandinfo(band1) #获得基本描述,获得要素图层属性 def getFLayerinfo(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("{0:<20s}{1}".format("nameString: ",desc.nameString)) arcpy.AddMessage("{0:<20s}{1}".format("Where Clause: " , desc.whereClause)) arcpy.AddMessage("{0:<20s}{1}".format("Feature class type: " , desc.featureClass.featureType)) if hasattr(desc, "FIDSet"): arcpy.AddMessage("{0:<20s}{1}".format("FIDSet: " , desc.FIDSet)) def getTableView(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("Table View Name: " + desc.nameString) arcpy.AddMessage("Where Clause: " + desc.whereClause) arcpy.AddMessage("Table Name: " + desc.name) def getWorkspace(): desc = arcpy.Describe(inFeature) arcpy.AddMessage("%-24s %s" % ("Connection String:", desc.connectionString)) arcpy.AddMessage("%-24s %s" % ("release:", desc.release)) arcpy.AddMessage("%-24s %s" % ("currentRelease:", desc.currentRelease)) arcpy.AddMessage("%-24s %s" % ("WorkspaceFactoryProgID:", desc.workspaceFactoryProgID)) arcpy.AddMessage("%-24s %s" % ("Workspace Type:", desc.workspaceType)) # Print Connection properties # cp = desc.connectionProperties if cp!=None: if hasattr(cp,"server"): arcpy.AddMessage(" Database Connection Properties:") arcpy.AddMessage("%-12s %s" % (" Server:", cp.server)) arcpy.AddMessage( "%-12s %s" % (" Instance:", cp.instance)) arcpy.AddMessage( "%-12s %s" % (" Database:", cp.database)) arcpy.AddMessage("%-12s %s" % (" User:", cp.user)) arcpy.AddMessage( "%-12s %s" % (" Version:", cp.version)) # Print workspace domain names" # domains = desc.domains for domain in domains: arcpy.AddMessage( " " + domain) arcpy.AddMessage( " Domains:") domains =arcpy.da.ListDomains(inFeature) for domain in domains: arcpy.AddMessage( " " + domain.name) if domain.domainType == 'CodedValue': coded_values = domain.codedValues for val, desc in coded_values.iteritems(): arcpy.AddMessage('{0} : {1}'.format(val, desc)) elif domain.domainType == 'Range': arcpy.AddMessage('Min: {0}'.format(domain.range[0])) arcpy.AddMessage('Max: {0}'.format(domain.range[1])) def getTopology(): desc = arcpy.Describe(inFeature) arcpy.AddMessage( "%-27s %s" % ("ClusterTolerance:", desc.clusterTolerance)) arcpy.AddMessage( "%-27s %s" % ("ZClusterTolerance:", desc.ZClusterTolerance)) arcpy.AddMessage( "%-27s %s" % ("FeatureClassNames:", desc.featureClassNames)) arcpy.AddMessage( "%-27s %s" % ("MaximumGeneratedErrorCount:", desc.maximumGeneratedErrorCount)) #获得基本描述 def getdescinfo(): desc = arcpy.Describe(inFeature) if desc.childrenExpanded: for child in desc.children: arcpy.AddMessage(" %s = %s" % (child.name, child.dataType)) arcpy.AddMessage("baseName="+desc.baseName) arcpy.AddMessage("catalogPath="+desc.catalogPath) arcpy.AddMessage("dataElementType="+desc.dataElementType) arcpy.AddMessage("dataType="+desc.dataType) ##FeatureClass — ##FeatureDataset — ## ##LasDataset — ##Layer — ##FeatureLayer — ##Map ##MosaicDataset — ## ##RasterBand — ##RasterCatalog — ##RasterDataset — ##RelationshipClass — ##RepresentationClass — ##SchematicDataset — ##Style — ##Table — ##Terrain — ##Text — ##Tin — ##Tool — ##Toolbox ##Topology if desc.dataType=="FeatureLayer": arcpy.AddMessage(inFeature+"是图层") getFLayerinfo() elif desc.dataType=="FeatureClass": getFeatureInfo() arcpy.AddMessage(inFeature+"是要素类") elif desc.dataType=="RasterDataset": arcpy.AddMessage(inFeature+"是栅格数据集") getRasterDataset() elif desc.dataType=="TableView": getTableView() elif desc.dataType=="Workspace": getWorkspace() elif desc.dataType=="Topology": getTopology() arcpy.AddMessage("extension="+desc.extension) arcpy.AddMessage("file="+desc.file) arcpy.AddMessage("name="+desc.name) arcpy.AddMessage("path="+desc.path) arcpy.AddMessage("fullPropsRetrieved="+str(desc.fullPropsRetrieved)) arcpy.AddMessage("metadataRetrieved="+str(desc.metadataRetrieved)) #获得要素信息 def getFeatureInfo(): desc = arcpy.Describe(inFeature) ptype = desc.shapeType #获得类型 if ptype=="Point": arcpy.AddMessage(u""+inFeature+"是点") elif ptype=="Multipoint": arcpy.AddMessage(u""+inFeature+"是多点") elif ptype=="Polyline": arcpy.AddMessage(u""+inFeature+"是线") elif ptype=="Polygon": arcpy.AddMessage(u""+inFeature+"是面") arcpy.AddMessage(u"类型:"+ptype) #点,线,面 "Point", "Multipoint", "Polyline", "Polygon" arcpy.AddMessage(u"要素类型:"+desc.featureType) #"Simple", "Annotation", "Dimension if desc.featureType=="Annotation": arcpy.AddMessage(u""+inFeature+"是注记") if desc.hasZ==True: arcpy.AddMessage(u""+inFeature+"是3d") else: arcpy.AddMessage(u""+inFeature+"是2d") #获得数据集信息 def getDatasetInfo(): desc = arcpy.Describe(inFeature) if not hasattr(inFeature,"datasetType"): return arcpy.AddMessage(u"Dataset Type: {0}".format(desc.datasetType)) arcpy.AddMessage(u"canVersion: {0}".format(desc.canVersion)) if hasattr(desc,"isArchived"): arcpy.AddMessage(u"isArchived: {0}".format(desc.isArchived)) arcpy.AddMessage(u"ZExtent: {0}".format(desc.ZExtent)) pextent=desc.extent #范围信息 arcpy.AddMessage("Extent: XMin: {0}, XMax: {1}, YMin: {2}, YMax: {3}".format( pextent.XMin, pextent.XMax, pextent.YMin, pextent.YMax)) #坐标系信息 sr=desc.spatialReference if hasattr(sr,"GCS"): arcpy.AddMessage(u"sr.GCS.name: {0}".format(sr.GCS.name)) arcpy.AddMessage(u"sr.XYTolerance: {0}".format(sr.XYTolerance)) arcpy.AddMessage(u"sr.abbreviation: {0}".format(sr.abbreviation)) arcpy.AddMessage(u"sr.alias: {0}".format(sr.alias)) arcpy.AddMessage(u"sr.domain: {0}".format(sr.domain)) arcpy.AddMessage(u"sr.factoryCode: {0}".format(sr.factoryCode)) arcpy.AddMessage(u"sr.name: {0}".format(sr.name)) arcpy.AddMessage(u"sr.remarks: {0}".format(sr.remarks)) arcpy.AddMessage(u"sr.remarks: {0}".format(sr.remarks)) arcpy.AddMessage(u"sr.type: {0}".format(sr.type)) arcpy.AddMessage(u"sr.PCSCode: {0}".format(sr.PCSCode)) arcpy.AddMessage(u"sr.PCSName: {0}".format(sr.PCSName)) arcpy.AddMessage(u"sr.centralMeridian: {0}".format(sr.centralMeridian)) arcpy.AddMessage(u"sr.centralParallel: {0}".format(sr.centralParallel)) arcpy.AddMessage(u"sr.projectionCode: {0}".format(sr.projectionCode)) arcpy.AddMessage(u"sr.projectionName: {0}".format(sr.projectionName)) arcpy.AddMessage(u"sr.datumCode: {0}".format(sr.datumCode)) arcpy.AddMessage(u"sr.datumName: {0}".format(sr.datumName)) arcpy.AddMessage(u"sr.semiMajorAxis: {0}".format(sr.semiMajorAxis)) arcpy.AddMessage(u"sr.semiMinorAxis: {0}".format(sr.semiMinorAxis)) arcpy.AddMessage(u"sr.spheroidCode: {0}".format(sr.spheroidCode)) arcpy.AddMessage(u"sr.spheroidName: {0}".format(sr.spheroidName)) def getTableinfo(): desc = arcpy.Describe(inFeature) if hasattr(desc,"hasOID"): arcpy.AddMessage(u"hasOID: {0}".format(desc.hasOID)) if desc.hasOID: arcpy.AddMessage(u"OIDFieldName: {0}".format(desc.OIDFieldName)) for field in desc.fields: arcpy.AddMessage("name=%-22s aliasName=%s baseName=%s type=%s length=%d precision=%d scale=%d" % (field.name, field.aliasName, field.baseName, field.type,field.length,field.precision,field.scale)) indexes = arcpy.ListIndexes(inFeature) # Iterate through the list of indexes for index in indexes: # Print index properties arcpy.AddMessage("Name: {0}".format(index.name)) arcpy.AddMessage(" Type : {0}".format(index.isAscending)) arcpy.AddMessage(" Scale : {0}".format(index.isUnique)) arcpy.AddMessage(" Number of fields: {0}".format(len(index.fields))) def Main(): getdescinfo() getDatasetInfo() getTableinfo() inFeature=arcpy.GetParameterAsText(0) Main()
6.设置字段的属性域
#coding=utf8 import arcpy import os import sys import math #删除属性域 def deldomains(inFeature,domainname): fields = arcpy.ListFields(inFeature) for field in fields: if field.domain.upper()==domainname.upper(): arcpy.RemoveDomainFromField_management(inFeature,field.name) #获得一个数据的工作空间 def getWorkspace(inFeature): desc = arcpy.Describe(inFeature) path=desc.path.lower() if path.endswith(".mdb") or path.endswith(".gdb"): return path if os.path.isdir(path):#shp return path outPath, outFC = os.path.split(path) return outPath def getdomainsList(inWorkspace): desc = arcpy.Describe(inWorkspace) return desc.domains def Main(): inWorkspace=getWorkspace(inFeature) arcpy.AddMessage("inWorkspace="+inWorkspace) desc = arcpy.Describe(inWorkspace) if desc.workspaceType!="LocalDatabase": arcpy.AddMessage("inWorkspace="+inWorkspace+"不是数据库的数据") return domainsList=getdomainsList(inWorkspace) arcpy.AddMessage("codeField=type"+str(type(codeField))) #code=codeField #decode('unicode_escape').decode('utf-8') #decode('unicode_escape') .encode('utf-8') if domainsList: idx=domainsList.index(codeField) if idx>-1: deldomains(inFeature,codeField) arcpy.DeleteDomain_management(inWorkspace, codeField) arcpy.TableToDomain_management(byTable,codeField,nameField,inWorkspace,codeField,nameField,update_option="APPEND") arcpy.AssignDomainToField_management(inFeature,inField,codeField) inFeature=arcpy.GetParameterAsText(0) inField=arcpy.GetParameterAsText(1) byTable=arcpy.GetParameterAsText(2) codeField=arcpy.GetParameterAsText(3) arcpy.AddMessage("codeField="+codeField) nameField=arcpy.GetParameterAsText(4) arcpy.AddMessage("nameField="+nameField) Main()
#coding=utf8
import arcpy
import os
import sys
import math
#删除属性域
def deldomains(inFeature,domainname):
fields = arcpy.ListFields(inFeature)
for field in fields:
if field.domain.upper()==domainname.upper():
arcpy.RemoveDomainFromField_management(inFeature,field.name)
#获得一个数据的工作空间
def getWorkspace(inFeature):
desc = arcpy.Describe(inFeature)
path=desc.path.lower()
if path.endswith(".mdb") or path.endswith(".gdb"):
return path
if os.path.isdir(path):#shp
return path
outPath, outFC = os.path.split(path)
return outPath
def getdomainsList(inWorkspace):
desc = arcpy.Describe(inWorkspace)
return desc.domains
def Main():
inWorkspace=getWorkspace(inFeature)
arcpy.AddMessage("inWorkspace="+inWorkspace)
desc = arcpy.Describe(inWorkspace)
if desc.workspaceType!="LocalDatabase":
arcpy.AddMessage("inWorkspace="+inWorkspace+"不是数据库的数据")
return
domainsList=getdomainsList(inWorkspace)
arcpy.AddMessage("codeField=type"+str(type(codeField)))
#code=codeField #decode('unicode_escape').decode('utf-8') #decode('unicode_escape') .encode('utf-8')
if domainsList:
idx=domainsList.index(codeField)
if idx>-1:
deldomains(inFeature,codeField)
arcpy.DeleteDomain_management(inWorkspace, codeField)
arcpy.TableToDomain_management(byTable,codeField,nameField,inWorkspace,codeField,nameField,update_option="APPEND")
arcpy.AssignDomainToField_management(inFeature,inField,codeField)
inFeature=arcpy.GetParameterAsText(0)
inField=arcpy.GetParameterAsText(1)
byTable=arcpy.GetParameterAsText(2)
codeField=arcpy.GetParameterAsText(3)
arcpy.AddMessage("codeField="+codeField)
nameField=arcpy.GetParameterAsText(4)
arcpy.AddMessage("nameField="+nameField)
Main()