2

I have a dataset of block-level census data that I clipped to an Illinois State Senate district. To update the data (e.g. for population) I'm applying an area multiplier, i.e taking the area of each attribute after and dividing it by the area before and applying the percentage to each field. Since I wasn't aware of how to do a geoprocessing clip that would also clip data I'm left editing the table manually

My question is: how do I batch multiply columns against one column? I have 100 columns of data I need to multiply against a percentage contained in an aptly named proportion column. Can this be done through a model in ArcGis, or through a Python script in the Field Calculator? I have both QGIS and a demo license of ArcGis available.

1

You should be able to write this in a python scripting using an update cursor fairly easily.

import arcpy
tablename = "c:\temp\*NAMEOFYOURTABLE*"
fieldvalues = ['fieldname1','fieldname2','fieldname3'......'fieldnameX']

cur = arcpy.UpdateCursor(tablename)
for row in cur:
    sourcevalue = row.getValue('*name of field where source value coming from*')
    for f in fieldvalues:
        row.setValue(f, sourcevalue)
    cur.updateRow(row)
  • I'm a novice when it comes to Python--and that's saying essentially I know it exists and can deduce the syntax from what I know about objects and methods from my also basic knowledge of javascript. Is firstvalue / secondvalue the actual syntax (since it's not enclosed in asterisks?) And is there any way to loop this to run across all the fields by say, separating the names of the first fields with ','s and then doing the same for the setValue method? Would they correspond? – Grant Malcolm Oct 11 '13 at 22:51
  • ...and, another basic question: where would I write the script? In the field calculator? Where is the Python console built into QGIS? – Grant Malcolm Oct 11 '13 at 23:00
  • You could write this script into Python IDLE (C:\Python26\ArcGIS10.0\pythonw.exe) and run it from there. I have edited the code above to be more comprehensive for what you are looking for. The fieldvalues are a python list of fieldnames you want to calculate. The sourcevalue is coming from the field you want to pull the value from - i.e. the source value. This is a ArcGIS python script and will not work for QGIS. – dklassen Oct 17 '13 at 16:12
  • Thanks for this dklassen. However, I believe this replaces the field array with the source value. I need to multiply a float against each value in the sequence. It's set up right for that it seemed to me, so I just added in the operation to multiply the defined f against sourcevalue. Didn't work. Can you come through again on this for me? Am I wrong? It'd be a huge help...Thanks. – Grant Malcolm Oct 23 '13 at 9:12
  • Let me understand this, you want to have COLUMN_A = COLUMN_B * a float number? or do you just want Column_A = Column_A * a float number? – dklassen Oct 23 '13 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.