Hi all,
Could someone point me in the right direction.
I have limited python scripting experience but know a enough (to be dangerous).
This is what I want to do.
I have a shapefile which has duplicate objects based on an "ID".
Object1: ID1 + Owner1
Object2: ID1 + Owner2
Object3: ID1 + Owner3
in this example there are 3 objects with identical ID but with 3 different owners for the same object.
What I want to do is search through the shapefiles for all identical "ID", then update a new shapefile with :
Object1: ID1 + Owner1 + Owner2 + Owner3
The new shapefile would have 3 extra columns added for the Owner field to be updated to.
so I want 1 object only but keep the owner information in the row.
thanks,
Tim
Solved! Go to Solution.
Good question... I don't think so.
The Alter Field tool that was released not so lng ago only allows you to change the name and alias of an existing field. However, you could delete the field, after the empty output featureclass is created and add the field with the same name, but with a larger length. before you start inserting the information. The downside is that it will change the order of the fields and the way to construct the output row would be a little more complex.
If you don't mind the changed order of the fields, you could:
Thanks Xander.
That’s exactly what I did !
Thanks also to the other replies again and the different approaches.
You're welcome...
Tim,
You could use the feature class to feature class tool:
In the field map parameters right click on your owner field and extend the size. Once created delete your original feature class and rename your new one to the same as your old one
Regards
Anthony
What is the purpose of removing (and returning) the item from the dictionary just before you write it to the shapefile? I don't see the "tmp" variable used anywhere else.
tmp = dct.pop(p_id)
The reason is, when I ommit this, it wil write the equal amount of features to the output. Removing it from the dictionary will cause the condition on line 36 to return False (and not add an ID that has already been added).
If you need any additional explanation on the code, just let me know.
Kind regards, Xander
Thanks Xander, I see it now. I'm just trying to understand the code and your process.
So you are iterating through the fc_in rows and then checking if the current ID is in the dictionary before writing the data to fc_out. I was thinking it might be easier to iterate through the dictionary instead of fc_in so you wouldn't have to remove the dictionary item but then I don't know how you would find the correct row in fc_in to copy the data in the rest of the fields. Is there a way to do that? Seems like it could be a faster because you wouldn't have to touch every row of in_fc; you're done after checking every item in the dictionary.
I see your point. However, I'm using the da cursors which is rather fast. Using the dictionary as basis, you would have to extract the corresponding feature from fc_in. This would require creating a cursor with probably a where clause on oid to extract the feature you're interested in. I think this would create a script that perfoms slower than what I am doing...
Ah, yes, the where clause when you create the cursor! But then you would have to use a dynamic where clause and create a new cursor each time. I agree with you then, it would be silly to do that compared to just popping the item from the dictionary.
Thanks for the clarification Xander!