Select to view content in your preferred language

Best approach at continually updating data

3861
14
Jump to solution
04-18-2016 08:33 AM
AdrianWelsh
MVP Honored Contributor

Hi Everyone,

I am hoping to generate some ideas on how I should best handle a weekly update of some GIS data, particularly the attributes.

This seems simple enough but I wanted to see what other’s thought. I am working on a project where we have some parcels and each one has a status (with like 9 different options). Each week, we update this status with a new status, but only when it needs updating. The parcels have unique identifiers.

We get this info in the form of an Excel sheet (with the unique parcel number and the new status, etc.). So far, I have been manually updating each parcel’s status with the new status since this is the quick and dirty way, but I want to find a more automated solution.

Based on this vague information, what are your thoughts on the most efficient way of handling this?

Thanks!

(to shorten this post, I’ll put some thoughts in a reply below)

0 Kudos
14 Replies
AdrianWelsh
MVP Honored Contributor

Wes, I love over complications! This code is great! Thanks for sharing. I'll have to tinker around with it some and come up with some added complications!

0 Kudos
TedKowal
Regular Contributor II

--- LOL ---

Excel VLookup is soooooooo much more simple.   Guess I am a minimalist.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Well, why bother using all those ArcGIS/arcpy tools? You can just manipulate the Excel through Python.

AdrianWelsh
MVP Honored Contributor

Alright Wes Miller​, I finally was able to get back to this. I attempted to over-complicate but said "screw it" on the domains.

After some quality checking, this seemed to work really well, but I wanted to share my code to see how I can improve things. This is what I have:

#import modules
import arcpy
from time import strftime

# start the timer...
print 'Start Script: ' + strftime('%Y-%m-%d %H:%M:%S')

# identify variables for feature class and table
workspace = 'C:/Users/AWelsh/Documents/2016/' + \
            '15019-MWN-SR68_Bangerter to 12600 South (11203)/' +\
            '11203-RedwoodRd-Bangerter-to-126S/' +\
            '11203-RedwoodRd-Bangerter-to-126S.gdb'

fcParcels = 'Parcel_SpatialJoin_3_JoinTable_FIX'
tblParcels = 'ParcelTable_20160519'

# set the workspace environment to our workspace
arcpy.env.workspace = workspace

# identify fields used for updating
fieldsParcels = ['PARCEL_NUMBER', 'PARTIAL_SUBMITTAL', 'SUBMITTALSCHEDULE',
                'COUNTY_TAX_ID_NO', 'RW_Sheet', 'SQUARE_FEET_OF_TAKE',
                'SQUARE_FEET_PERP_EASE', 'SQUARE_FEET_TEMP_EASE',
                'RISK_MITIGATION', 'Status']

# Here is what we're going to do:
# One-by-one, check each row in the Feature Class against
# each row in the Table, and update if there are changes...

# first, it helps to "zero" out the arrays and counter
fcrow = ['','','','','','','','','','']
tblrow = ['','','','','','','','','','']
counter = 0

# putting this all in a try-catch statement to catch any errors
try:

    with arcpy.da.SearchCursor(tblParcels, fieldsParcels) as tblCursor:
        for tblrow in tblCursor:
            with arcpy.da.UpdateCursor(fcParcels, fieldsParcels) as fcCursor:
                fcrow = ['','','','','','','','','','']
                # ...need to zero out the row again...
                for fcrow in fcCursor:
                    if (str(tblrow[0]) == str(fcrow[0])
                        and str(tblrow[3]) == str(fcrow[3])):
                        fcrow[1] = tblrow[1]
                        fcrow[2] = tblrow[2]
                        fcrow[4] = tblrow[4]
                        fcrow[5] = tblrow[5]
                        fcrow[6] = tblrow[6]
                        fcrow[7] = tblrow[7]
                        fcrow[8] = tblrow[8]
                        fcrow[9] = tblrow[9]
                        print('Parcel ' + str(fcrow[0]) + ' was updated.')
                        fcCursor.updateRow(fcrow)
                        counter = counter + 1
                        continue

# except statement to catch the errors
except Exception:
    e =sys.exc_info()[1]
    print(e.args[0])
    arcpy.AddError(e.args[0])
except arcpy.ExcecuteError:
    print(arcpy.GetMessages(2))

# how many rows were updated?
print 'Updated ' + str(counter) + ' rows.'
# end the timer...
print 'Finshed Script: ' + strftime('%Y-%m-%d %H:%M:%S')
0 Kudos
WesMiller
Regular Contributor III

If it does what you need it to do, go with it. You may have gotten a lot more speed using a table join and calculate field tools.

0 Kudos