Example #1
0
def idFromTable(infc, outfc, inField, outIdField, outPrefixField):
	tab.copy(infc, outfc)
	tables = rd.tables()
	arcpy.management.AddField(tables[outfc], outIdField, 'TEXT')
	arcpy.management.AddField(tables[outfc], outPrefixField, 'TEXT')

	with arcpy.da.UpdateCursor(tables[outfc], (inField, outIdField, outPrefixField)) as cursor:
		for row in cursor:
			inSplit =  row[0].split('[')[1].split(']')[-2]
			fid = None
			prefix = None
			if 'CD' in inSplit:
				fid = inSplit.split('CD')[1]
				fid = fid[0:2] + fid[4:]
				fid = fid[0:4]
				prefix = 'CD'
			elif 'CCS' in inSplit:
				fid = inSplit.split('CCS')[1]
				fid = fid[0:2] + fid[4:]
				prefix = 'CCS'
			elif 'CAR' in inSplit:
				fid = inSplit.split('CAR')[1]
				prefix = 'CAR'
			elif 'PR' in inSplit:
				fid = inSplit.split('PR')[1]
				prefix = 'PR'
			else:
				fid = inSplit
				prefix = 'CO'
			
			# print fid
			row[1] = fid
			row[2] = prefix
			cursor.updateRow(row)
Example #2
0
def fcToTable(inFc, inTab, outFc, columns, idField, fieldPrimary, fieldSecondary):
	fc.copy(inFc, outFc)
	fcs = rd.featureClasses()
	tables = rd.tables()
	for c in sorted(columns):
		arcpy.management.AddField(fcs[outFc], c, 'FLOAT')
	col = columns.keys()	
	col.append(idField)

	with arcpy.da.UpdateCursor(fcs[outFc], col) as fcCursor:
		# print fcCursor.fields
		for fcRow in fcCursor:
			if fieldSecondary == '':
				with arcpy.da.SearchCursor(inTab, ['id', fieldPrimary, 'value']) as tabCursor:
					for tabRow in sorted(tabCursor):
						# Match Feature Class ID to table ID
						#print str(fcRow[-1][0:2]) 
						if str(fcRow[-1]) == str(tabRow[0]):
							for i in range(len(col)-1):
								if columns[col[i]] == tabRow[1]:
									if tabRow[2] != 'x':
										fcRow[i] = tabRow[2]
										#print tabRow[2]
									else:
										fcRow[i] = -1
										#print tabRow[2]
									fcCursor.updateRow(fcRow)
			else:
				with arcpy.da.SearchCursor(inTab, ['id', fieldPrimary, fieldSecondary, 'value']) as tabCursor:
					for tabRow in tabCursor:
						# Match Feature Class ID to table ID
						if str(fcRow[-1]) == str(tabRow[0]):
							for i in range(len(col)-1):
								if columns[col[i]] == tabRow[1] + ' (' + tabRow[2] + ')':
									if tabRow[3] != 'x':
										fcRow[i] = tabRow[3]
									else:
										fcRow[i] = -1
									fcCursor.updateRow(fcRow)
			#fcCursor.updateRow(fcRow)
Example #3
0
def fieldsFromTable(tab, tableName, fieldPrimary, fieldSecondary):
	tables = rd.tables()
	firstRowFlag = True
	attributes = {}
	prefix = 'at'
	i = 0
	if fieldSecondary == '':
		with arcpy.da.SearchCursor(tables[tab], ['id', fieldPrimary]) as cursor:
			for row in sorted(cursor, key=itemgetter(0)):
				if firstRowFlag:
					ref = row[0]
					fid = 'tc' + str(i).zfill(2) 
					attributes[fid] = row[1]
					i+=1
					firstRowFlag = False
				elif ref == row[0]:
					fid = 'tc' + str(i).zfill(2) 
					attributes[fid] = row[1]
					i+=1
				else:
					break
			
			t.writeToFile(tab[:9] + '.xml', tableName, attributes)
	else: 
		with arcpy.da.SearchCursor(tables[tab], ['id', fieldPrimary, fieldSecondary]) as cursor:
			for row in sorted(cursor, key=itemgetter(0)):
				if firstRowFlag:
					ref = row[0]
					fid = 'tc' + str(i).zfill(2) 
					attributes[fid] = row[1] + ' (' + row[2] + ')'
					i+=1
					firstRowFlag = False
				elif ref == row[0]:
					fid = 'tc' + str(i).zfill(2) 
					attributes[fid] = row[1] + ' (' + row[2] + ')'
					i+=1
				else:
					break
			
			t.writeToFile(tab[:9] + '.xml', tableName, attributes)
	return attributes
Example #4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Publish.py: Main script for geoprocessing tasks"""

__appname__ = "Main.py"
__author__ = "Keith E. Davey"
__email__ = "*****@*****.**"
__version__ = "0.1"
__license__ = "GNU GPL 3.0"

###########
# Modules #
###########
import arcpy, time
from DatabaseWorkspace import *
import FeatureClass as fc
import Table as tab
import Print as p
import RegisterData as rd
import Extract as e
import Analysis as a
import Join as j
import Log as l
import traceback

from Mailer import mail
from Zip import createZipFile

try:
	tables = rd.tables()
	featureClasses = rd.featureClasses()
Example #5
0
def tables():
	tables = rd.tables()
	print "\nTables:"
	for tab in tables:
		print tab + ': ' + tables[tab]
Example #6
0
def featureClasses():
	featureClasses = rd.featureClasses()
	print "\nFeature Classes:"
	for fc in featureClasses:
		print fc + ': ' + featureClasses[fc]