Exemplo n.º 1
0
    def demote_gndb_rec(self, gndb_ufi,gndb_uni):
        '''
        retrieves a gndb record to external dataset in order to demote its NT field

        inputs:
            gndb_ufi: have to retrieve the row before it can be processed or
            appended; a cursor will query and search

        outputs:
            the row object, which will be appended to the external feature class 
        '''
        try:
            sc = SearchCursor(self.path+'/'+self.name2,"\"UFI\" = %d" % gndb_ufi)

            row_vals = {}
            row = sc.next()
            while row:
                # skip variant names
                if row.getValue('NT')=='N':
                    for field in ListFields(self.path+'/'+self.name2)[1:-1]:
                        row_vals[field.name] = row.getValue(field.name)
                        row_vals["NT"]='V'
                        row_vals['USID1']='FILE_MAINTENANCE'
                                    
                row = sc.next()
            
            del sc
            return row_vals
        except Exception:
            print gndb_ufi, type(gndb_ufi)
Exemplo n.º 2
0
    def getGNDBRecords(self, name):
        ''' iterates through the GNDB dataset and holds pertinent info from one record
            at a time.
        '''
        try:      
            d0 = time.clock()
            sc = SearchCursor(name)
            row = sc.next()
            
            while row:
                rec = []
                rec.append(row.getValue('UFI'))
                rec.append(row.getValue('FULL_NAME'))
                rec.append(row.getValue('LON'))
                rec.append(row.getValue('LAT'))
                rec.append(row.getValue('DSG'))
                rec.append(row.getValue('UNI'))
                rec.append(row.getValue('NT'))

                yield rec
                row = sc.next()

        except Exception, e:
            print "Error."
            e = sys.exc_info()
            log_file = open("H:/Programming/PyErrorLog.txt", 'a')
            log_file.write(str(datetime.datetime.now().time()) + "\n")
            log_file.write(str(e[0]) + "\n")
            log_file.write(str(e[1]) + "\n")
            traceback.print_tb(e[2],None,log_file)
            log_file.write('\n')
            log_file.close()
Exemplo n.º 3
0
 def __init__(self,
              outFile,
              featureClass,
              fileType,
              includeGeometry,
              first=True):
     self.outFile = outFile
     self.fileType = fileType
     #first we set put the local variables we'll need
     [self.shp, self.shpType] = getShp(featureClass)
     self.fields = listFields(featureClass)
     self.oid = getOID(self.fields)
     sr = SpatialReference()
     sr.loadFromString(wgs84)
     #the search cursor
     self.rows = SearchCursor(featureClass, "", sr)
     #don't want the shape field showing up as a property
     del self.fields[self.shp]
     self.first = first
     self.status = statusMessage(featureClass)
     #define the correct geometry function if we're exporting geometry
     self.parseGeo = getParseFunc(self.shpType, includeGeometry)
     self.i = 0
     if fileType == "geojson":
         self.parse = self.parseGeoJSON
     elif fileType == "csv":
         self.parse = self.parseCSV
     elif fileType == "json":
         self.parse = self.parseJSON
     elif fileType == "sqlite":
         self.parse = self.parseSqlite
Exemplo n.º 4
0
from os import path
from arcpy import SearchCursor

# base_dir ="C:\Users\scoblem\Documents\ArcGIS\~NGP\GeoDatabase\NGP_Master_Rev_01.gdb"
base_dir ="C:\Users\scoblem\Documents\ArcGIS\~NGP\Layers\NGP_Pipeline_RevD.gdb"
feature_class = "Placemarks\Points"
fc = path.join(base_dir, feature_class)

cursor = SearchCursor(fc)

def make_list():
    field_values = list()
    for row in cursor:
        field_values.append(row.getValue('Name'))
    return field_values

def get_duplicates(field_values):
    duplicate_values = list()
    for value in field_values:
        if field_values.count(value) > 1: duplicate_values.append(value)
    duplicate_values.sort()
    return duplicate_values

def get_unique(field_values):
    unique_values = list()
    for value in field_values:
        if field_values.count(value) == 1: unique_values.append(value)
    unique_values.sort()
    return unique_values

def print_attr():
Exemplo n.º 5
0
    def proximitySearch(self, name2):
        try:
            proxFile = 'H:/proxFile.txt'
            pF = open(proxFile,'w')
            
            count= 1
            d0 = time.clock()
            self.name2 = os.path.basename(name2)
            self.path2 = os.path.dirname(name2)
            if self.path != self.path2:
                if Exists(self.path+'/'+self.name2) == False:
                    FeatureClassToGeodatabase_conversion(self.path2+'/'+\
                                                           self.name2,self.path)
                    
            factory = aFactory()
            self.obj2 = factory.newOne(self.name2)

            c1 = GetCount_management(self.path+'/'+self.name).getOutput(0)
            
            ### search cursor for external dataset
            
            sc = SearchCursor(self.path+'/'+self.name)
            rowZ = sc.next()
            self.namePairs = []
            while rowZ:
                # gather relevant info for each value in the external dataset
                if count == c1:     # once the cursor is at the end of the set...
                    break           # ...exit the loop
                ufi = rowZ.getValue('UFI')
                nym = rowZ.getValue('FULL_NAME')
                lat = rowZ.getValue('LAT')
                lon = rowZ.getValue('LON')
                dsg = rowZ.getValue('DSG')
                if rowZ.getValue('GENERIC'):
                    generic = True
                else:
                    generic = False
                nt = rowZ.getValue('NT')

                rec = self.getGNDBRecords(name2)
                r = rec.next()      # GNDB record: [UFI, Name, Lon, Lat, Dsg, UNI, NT]

                if count % 10 == 0:
                    print count

                while r:                    
                    try:
                        # don't consider proximate features if they're not the same type

                        ########################
                        # handle dsg codes separately
    
                        d = self.handle_dsg(dsg, r[4])
                        if d == None:
                            r = rec.next()
                            continue
                                                                       
                        #
                        ########################
                        
                        #following lines converts to radians
                        lonDB,latDB,lonEx,latEx = map(radians,[r[2],r[3],lon,lat])

                        # get X,Y pairs distance, in km
                        distLon = (lonDB - lonEx)
                        distLat = (latDB - latEx)
                        a = sin(distLat/2)**2+cos(latEx)*cos(latDB)*sin(distLon/2)**2
                        c = 2 * asin(sqrt(a))
                        km = 6367*c
                    
                        threshold = 5
                        pF.write('%s (%s): %s (%s) == %0.5f\n' % (r[1].strip().encode('utf8'),r[4].encode('utf8')\
                                                                  ,nym.strip().encode('utf8'),dsg.encode('utf8'),km))
                        if km < threshold:
                            # store GNDB UFI, GNDB Name, External UFI...,
                            # External Name, GNDB UNI, generic, NT
                            pairInfo = [r[0],r[1].strip(),ufi,nym.strip(),r[5],generic, nt]
                            self.namePairs.append(pairInfo)
                        r = rec.next()
                            
                    except StopIteration: 
                        rowZ = sc.next()
                        count += 1
                        break

            del sc
     
            print "Proximity search complete."
            pF.close()
            print len(self.namePairs),'pairs found within %d km.\n' % threshold
            d1 = time.clock()
            delta = d1-d0
            print "%s took %f s to complete." % (sys._getframe().f_code.co_name,\
                                               delta)
            return self.namePairs # returns list of (GNDBUFI, GNDBName, exUFI, exName, GNDB_UNI) tuples  
            
        except Exception, e:
            print "Error."
            e = sys.exc_info()
            log_file = open("H:/Programming/PyErrorLog.txt", 'a')
            log_file.write(str(datetime.datetime.now().time()) + "\n")
            log_file.write(str(e[0]) + "\n")
            log_file.write(str(e[1]) + "\n")
            traceback.print_tb(e[2],None,log_file)
            log_file.write('\n')
            log_file.close()
Exemplo n.º 6
0
#written by Kyle 10/11/12
# Description
# Create Domain, select distinct values in field, append to domain, and assign domain to field

#
from arcpy import SearchCursor, TableToTable_conversion, TableToDomain_management, env, AssignDomainToField_management, RegisterWithGeodatabase_management
env.overwriteOutput = 1

fcName = r'Database Connections\Collect16_SDE.sde\Collect16.sde.CIIMS_CROSSINGDATA_DOMAINVAL'
DomainGDB = r'C:\temp\CrossingDomainTables.gdb'
DataTable = r'Database Connections\Collect16_SDE.sde\Collect16.SDE.CIIMS_CROSSINGDATA'
EnterpriseGDB = r'Database Connections\Collect16_SDE.sde'
fldName = 'CrossingData'

#RegisterWithGeodatabase_management(EnterpriseGDB+r"/Collect16.sde.CIIMS_CROSSINGDATA_DOMAINVAL")

myList = set([row.getValue(fldName) for row in SearchCursor(fcName, fields=fldName)]) 
print myList

for attrib in myList:
    sels = str(fldName.strip())+" = '"+ attrib+"'"
    print sels
    outname = 'd'+str(attrib)
    print outname
    TableToTable_conversion(fcName,DomainGDB,outname,sels)
    TableToDomain_management(DomainGDB+"/"+outname,"DESCRIPTIONS","DESCRIPTIONS",EnterpriseGDB, outname, attrib, "REPLACE")
    AssignDomainToField_management(DataTable, attrib, outname, subtype_code="")
print "All Cansys Domains copied to temp mdb as coded text values"        
Exemplo n.º 7
0
    Delete_management(outws)

CreateFileGDB_management(r"\\gisdata\arcgis\GISdata\KDOT\BTP\CANSYSTEST",
                         "AASHTOPROC.gdb")

if Exists(outfinal):
    Delete_management(outfinal)

CreateFileGDB_management(r"\\gisdata\arcgis\GISdata\KDOT\BTP\CANSYSTEST",
                         "AASHTOROUTES.gdb")

FeatureClassToFeatureClass_conversion(routelyr, outws, "USRoutes",
                                      "NE_UNIQUE LIKE 'U%'", "#")

routelyr = outws + "/USroutes"
rows = SearchCursor(routelyr)

for row in rows:
    print(row.getValue(IDfield))
    idc = str(row.getValue(IDfield)).replace("-", "_")
    print idc
    rfcx = str(row.getValue(IDfield)) + "_SRND"
    rfc = str(rfcx).replace("-", "_")
    print str(rfc)
    MakeFeatureLayer_management(
        routelyr, rfc, IDfield + " LIKE '" + row.getValue(IDfield) + "'")
    FeatureClassToGeodatabase_conversion(rfc, outws)
    FeatureVerticesToPoints_management(rfc, outws + "/" + idc + "_VP", "ALL")
    LocateFeaturesAlongRoutes_lr(outws + "/" + idc + "_VP", rfc, IDfield,
                                 "0 DecimalDegrees",
                                 outws + "/" + idc + "_CPT",