[GRASS-user] How to replace some vector & DB features, keep attributes
Ken Mankoff
mankoff at gmail.com
Mon Jan 15 07:48:26 PST 2024
Hi Maris,
On 2024-01-15 at 02:10 -08, Maris Nartiss <maris.gis at gmail.com> wrote...
> v.edit tool=catadd/catdel is the thing you are looking for. Delete old
> geometry, delete category of new geometry (if there is one), set old
> cat value to the new geometry.
Thank you for the suggestion. I don't need cat to be the same. I'm deleting ~100 cats (old vector lines) and replacing with only one new one anyway.
More importantly, in my simplified example I neglected to mention that although I want to keep some attributes, I don't want to keep all. There are several old attributes that are no longer relevant for this one manually created line.
I was going to create the new line (as below) and then in a for loop:
for a in attr1 attr2 attr3 attr4; do # attrs I want to keep or copy
# db.select statement to get attr1 value from $old_cat
# db.execute sql='UPDATE test set a = $att where cat=$new_cat
done
Alternatively, if I follow your advice, then I'd need to:
for a in attr1 attr2 attr3 attr4; do # attrs I want to delete
# db.execute sql='UPDATE test set $attr = NULL where cat=$new_cat
done
So... is this looping method correct, or is there some SQL statement that will copy attr1,attr2,attrn from row x (defined by an ID or cat) to row y?
Thanks,
-k.
>> I'd like to replace multiple vector lines with ID == 42 with one new
>> one, and keep the attributes (date, year, name) from one of the
>> replaced/removed lines.
>>
>> I'm able to create my one new line with:
>>
>>
>> I'm not sure how to copy over the relevant attributes from one of the
>> lines (first, last, doesn't matter) that has the relevant ID.
>>
>> Once I do that, I think I know how to delete the lines I don't want,
>> but I'm not sure I'm doing it correct. It seems I have to run two
>> commands to delete the lines from both the vectors (when displaying)
>> and the database (when querying). I'm doing this:
>>
>> v.edit map=test tool=delete where="ID == 42" db.execute sql="DELETE
>> FROM test WHERE ID == 42"
>>
>> Can anyone help with the middle step?
>>
>> Thanks,
>>
More information about the grass-user
mailing list