I am trying to handle string (non-geometry) duplicates in a large attribute table of a shapefile without having to convert to gdb and back or connect to a postgres db. I need to be able to use a count function for my query. I'd prefer not creating an output file, but rather simply updating the file itself. I've looked at the cursors but I cannot seem to accomplish what I need to with them. I essentially need to get a count for duplicates, do a comparison, and then accordingly append values of one field with the values of another field.
(This uses neither
ArcGIS but it might be a useful approach.)
One alternative approach could be to read the
dbf part of the shapfile into
R (using the
foreign package). Then install and load the package
sqldf, which provides full SQL functionality. So long as you do not reorder or change the number of rows you can write out a new
dbf file which will work^ with your shapefile.
^although I imagine it is possible to break the shapefile in certain circumstances I have not done this yet using this approach.
If OGR doesn't do what you want and the data you wish to change are across columns (fields) and not rows (records) with suitable care you can use any tool which understands DBF, which should any db tool worth it's salt, including Access/Excel. Something to watch for, especially with Excel, are silent reformatting of date/time fields, and truncation of total records (Excel has max row limit, and may or may not say something about it). Always work on a copy, validate the results, and never delete, add or re-order rows when using a non-spatial dbf tool.
If you install pywin32, you can query your .dbf files with any Jet compatible SQL query and access the results in a RecordSet from Python. You can run an aggregate function like count, nested query, update query, etc or output to another dbf. In my experience, the dbf file name must be 8.3 compiant.