Thank you for your help, Francis. I actually would like to populate a new column with values that are calculated from other columns in the same attribute.
Another problem is: as I tried the code below, after I ran it. The attribute table will be emptied, all the rows are gone, only field name left. really weird I'd appreciate any advice you might give me. Jen On May 25, 1:35 am, Francis Markham <[email protected]> wrote: > I forgot to add this can just as easily be done using OGR with arcgis, but I > gave an arcgis example as your previous emails indicated you were using it. > > -F > > On 25 May 2010 15:34, Francis Markham <[email protected]> wrote: > > > Check out > >http://michalisavraam.org/2009/10/understanding-the-geoprocessor-prog... > > > I've modified the example there a little. For each row in the shapefile, > > it gets the value of field "foo" and squares it, saving the squared value > > back into the shapefile. > > > import arcgisscripting > > # Import the module provided by ESRI > > > gp = arcgisscripting.create(9.3) > > # Create the geoprocessor object > > > fcUpdate = gp.UpdateCursor(r"c:\data\testUpdate.shp") > > # Create an update cursor that points to the testUpadate.shp file. > > # The returned value fcUpdate is actually a rows object. > > > fcUpdate.Reset() > > # Reset the cursor to the rows object > > > fcRow = fcUpdate.Next() > > # Receive the first row > > > while fcRow: > > # get the "foo" field > > fooVal = fcRow.GetValue("foo") > > #square it and put it back > > newFooVal = fooVal * fooVal > > fcRow.SetValue("foo", newFooVal) > > > # Perform the update to the row > > fcUpdate.UpdateRow(fcRow) > > # Call the UpdateRow() method with the current row as a parameter > > > - F > > > On 25 May 2010 12:41, Jen <[email protected]> wrote: > > > > Is there a way that we can populate new fields in shapefile attribute > > > table with python? > > > > Or can we populate the new field in csv first, then convert the csv to > > > dbf. Finally replace the old dbf of the shapefile with the new dbf? > > > > I'd appreciate any advice you might give me. > > > > Sincerely > > > > Jen
