Skip to main content
deleted 19 characters in body; edited title
Source Link
GforGIS
  • 3.3k
  • 4
  • 22
  • 39

update one shapefile attribute table with values from another dbf tabletable

I try to explain here what I am trying to do:

I have one shapefile and one independent dbf table with the same fields. In the dbf table all the fields are populated but in the shapefile attribute table just one, lets name it "OneField". What I want to do is to check that the values from "OneField"(Shapefile) are the same as the values in "OneField"(dbf table) and if so, to populate the remaining empty fields in the shapefile attribute table with the ones in the independent dbf table.

At the moment I am trying just to copy the values from the independent dbf table to the shapefile attribute table but I am stuck.(when I run this code I get a message that pythonwin stopped working and nothing happens to the tables). Can you give me a hand please?

Here is the code:

import arcpy

table = "link/to/table.dbf"
fc = "link/to/shapefile.shp"

# Create a search cursor

rowsTable = arcpy.SearchCursor(table)

# Create an update cursor

rowsFc = arcpy.UpdateCursor(fc) 

for row in rowsTable:
    row = row.getValue("OneField")
    valueTable = row
    for row in rowsFc:
        row = row.setValue("OneField", valueTable)
        rowsFc.updateRow(row)
        row = rowsFc.next()
    row = rowsTable.next()    

del row, rowsFc, rowsTable

Thank you very much

update one shapefile attribute table with values from another dbf table

I try to explain here what I am trying to do:

I have one shapefile and one independent dbf table with the same fields. In the dbf table all the fields are populated but in the shapefile attribute table just one, lets name it "OneField". What I want to do is to check that the values from "OneField"(Shapefile) are the same as the values in "OneField"(dbf table) and if so, to populate the remaining empty fields in the shapefile attribute table with the ones in the independent dbf table.

At the moment I am trying just to copy the values from the independent dbf table to the shapefile attribute table but I am stuck.(when I run this code I get a message that pythonwin stopped working and nothing happens to the tables). Can you give me a hand please?

Here is the code:

import arcpy

table = "link/to/table.dbf"
fc = "link/to/shapefile.shp"

# Create a search cursor

rowsTable = arcpy.SearchCursor(table)

# Create an update cursor

rowsFc = arcpy.UpdateCursor(fc) 

for row in rowsTable:
    row = row.getValue("OneField")
    valueTable = row
    for row in rowsFc:
        row = row.setValue("OneField", valueTable)
        rowsFc.updateRow(row)
        row = rowsFc.next()
    row = rowsTable.next()    

del row, rowsFc, rowsTable

Thank you very much

update one shapefile attribute table with values from another dbf table

I try to explain here what I am trying to do:

I have one shapefile and one independent dbf table with the same fields. In the dbf table all the fields are populated but in the shapefile attribute table just one, lets name it "OneField". What I want to do is to check that the values from "OneField"(Shapefile) are the same as the values in "OneField"(dbf table) and if so, to populate the remaining empty fields in the shapefile attribute table with the ones in the independent dbf table.

At the moment I am trying just to copy the values from the independent dbf table to the shapefile attribute table but I am stuck.(when I run this code I get a message that pythonwin stopped working and nothing happens to the tables). Can you give me a hand please?

Here is the code:

import arcpy

table = "link/to/table.dbf"
fc = "link/to/shapefile.shp"

# Create a search cursor

rowsTable = arcpy.SearchCursor(table)

# Create an update cursor

rowsFc = arcpy.UpdateCursor(fc) 

for row in rowsTable:
    row = row.getValue("OneField")
    valueTable = row
    for row in rowsFc:
        row = row.setValue("OneField", valueTable)
        rowsFc.updateRow(row)
        row = rowsFc.next()
    row = rowsTable.next()    

del row, rowsFc, rowsTable
Tweeted twitter.com/StackGIS/status/1253201983504343041
edited tags
Link
Brad Nesom
  • 17.4k
  • 2
  • 44
  • 68
formatted code tag; deleted 17 characters in body
Source Link
Brad Nesom
  • 17.4k
  • 2
  • 44
  • 68

I try to explain here what I am trying to do:

I have one shapefile and one independent dbf table with the same fields. In the dbf table all the fields are populated but in the shapefile attribute table just one, lets name it "OneField". Whaenter code heretWhat I want to do is to check that the values from "OneField"(Shapefile) are the same as the values in "OneField"(dbf table) and if so, to populate the remaining empty fields in the shapefile attribute table with the ones in the independent dbf table.

At the moment I am trying just to copy the values from the independent dbf table to the shapefile attribute table but I am stuck.(when I run this code I get a message that pythonwin stopped working and nothing happens to the tables). Can you give me a hand please?

Here is the code:

import arcpy

table = "link/to/table.dbf" fc = "link/to/shapefile.shp"

Create a search cursor

rowsTable = arcpy.SearchCursor(table)

Create an update cursor

rowsFc = arcpy.UpdateCursor(fc)

for row in rowsTable: row = row.getValue("OneField") valueTable = row for row in rowsFc: row = row.setValue("OneField", valueTable) rowsFc.updateRow(row) row = rowsFc.next() row = rowsTable.next()

del row, rowsFc, rowsTable

import arcpy

table = "link/to/table.dbf"
fc = "link/to/shapefile.shp"

# Create a search cursor

rowsTable = arcpy.SearchCursor(table)

# Create an update cursor

rowsFc = arcpy.UpdateCursor(fc) 

for row in rowsTable:
    row = row.getValue("OneField")
    valueTable = row
    for row in rowsFc:
        row = row.setValue("OneField", valueTable)
        rowsFc.updateRow(row)
        row = rowsFc.next()
    row = rowsTable.next()    

del row, rowsFc, rowsTable

Thank you very much

I try to explain here what I am trying to do:

I have one shapefile and one independent dbf table with the same fields. In the dbf table all the fields are populated but in the shapefile attribute table just one, lets name it "OneField". Whaenter code heret I want to do is to check that the values from "OneField"(Shapefile) are the same as the values in "OneField"(dbf table) and if so, to populate the remaining empty fields in the shapefile attribute table with the ones in the independent dbf table.

At the moment I am trying just to copy the values from the independent dbf table to the shapefile attribute table but I am stuck.(when I run this code I get a message that pythonwin stopped working and nothing happens to the tables). Can you give me a hand please?

Here is the code:

import arcpy

table = "link/to/table.dbf" fc = "link/to/shapefile.shp"

Create a search cursor

rowsTable = arcpy.SearchCursor(table)

Create an update cursor

rowsFc = arcpy.UpdateCursor(fc)

for row in rowsTable: row = row.getValue("OneField") valueTable = row for row in rowsFc: row = row.setValue("OneField", valueTable) rowsFc.updateRow(row) row = rowsFc.next() row = rowsTable.next()

del row, rowsFc, rowsTable

Thank you very much

I try to explain here what I am trying to do:

I have one shapefile and one independent dbf table with the same fields. In the dbf table all the fields are populated but in the shapefile attribute table just one, lets name it "OneField". What I want to do is to check that the values from "OneField"(Shapefile) are the same as the values in "OneField"(dbf table) and if so, to populate the remaining empty fields in the shapefile attribute table with the ones in the independent dbf table.

At the moment I am trying just to copy the values from the independent dbf table to the shapefile attribute table but I am stuck.(when I run this code I get a message that pythonwin stopped working and nothing happens to the tables). Can you give me a hand please?

Here is the code:

import arcpy

table = "link/to/table.dbf"
fc = "link/to/shapefile.shp"

# Create a search cursor

rowsTable = arcpy.SearchCursor(table)

# Create an update cursor

rowsFc = arcpy.UpdateCursor(fc) 

for row in rowsTable:
    row = row.getValue("OneField")
    valueTable = row
    for row in rowsFc:
        row = row.setValue("OneField", valueTable)
        rowsFc.updateRow(row)
        row = rowsFc.next()
    row = rowsTable.next()    

del row, rowsFc, rowsTable

Thank you very much

Source Link
Loading