Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

85 lines (75 sloc) 2.853 kB
from arcpy import ListFields,Describe,SetProgressorLabel,SetProgressorPosition,GetCount_management, SetProgressor, AddMessage
from os.path import splitext
#utility functions we will call more then once
#takes the input feature class and returns a dict with
# the field name as key and field types as values
def listFields(featureClass):
fields=ListFields(featureClass)
out=dict()
for fld in fields:
out[fld.name]=fld.type
return out
#takes the input geometry object and returns
# a list of [name of shape field, name of shape type]
def getShp(shp):
desc = Describe(shp)
return [desc.ShapeFieldName,desc.shapeType.lower()]
#takes the fields object from above, tells you which is the OID
def getOID(fields):
for key, value in fields.items():
if value== u'OID':
return key
#for putting a % based status total up
class statusMessage:
def __init__(self,featureClass):
self.featureCount = int(GetCount_management(featureClass).getOutput(0))
SetProgressor("step", "Found {0} features".format(str(self.featureCount)), 0, 100,1)
AddMessage("Found "+str(self.featureCount)+" features")
self.percent = 0
self.current=0
def update(self):
self.current+=1
newPercent = int((self.current*100)/self.featureCount)
if newPercent != self.percent:
self.percent=newPercent
SetProgressorLabel("{0}% done".format(str(self.percent)))
SetProgressorPosition(self.percent)
#parse the properties, get rid of ones we don't want, i.e. null, or the shape
def parseProp(row,fields, shp):
out=dict()
for field in fields:
if (fields[field] != u'OID') and field.lower() not in ('shape_length','shape_area','shape.len','shape.length','shape_len','shape.area',shp.lower()) and row.getValue(field) is not None:
if fields[field] == "Date":
value = str(row.getValue(field).date())
elif fields[field] == "String":
value = row.getValue(field).strip()
else:
value = row.getValue(field)
if value != "":
out[field]=value
return out
def getExt(fileName):
split=splitext(fileName)
if split[1]:
return split[1][1:].lower()
else:
return False
def parseFieldType(name, esriType):
if esriType.lower() in ("text","string","date"):
return name+" text"
elif esriType.lower() in ("short","long"):
return name+" integer"
elif esriType.lower() in ("float","single","double"):
return name+" real"
else:
return name+" blob"
def zm(shp):
desc = Describe(shp)
return [desc.hasZ,desc.hasM]
def makeInter(n):
out = []
i = 0
while i<n:
i+=1
out.append("?")
return ",".join(out)
Jump to Line
Something went wrong with that request. Please try again.