I have three polygon features of the same category in a larger vector layer from which I would like to create a center point (mean coordinate) that holds the same attributes as the three polygons. I would then like to delete the original polygon features and replace them with the new point in the larger vector layer.
Running the below commands finds me the center point, which, following the answer by Micha, can be connected to the attribute table of the polygons to hold the same data. However, during these steps the character columns are redefined as text columns, making it so that it can't be patched with the original vector layer as 'Length of string columns differ'. I thus need a way to avoid this transformation, or a way to transform the column-types back again. I will look into this last point, which I assume can be done by defining a new table and copying over the data - although that sounds like it should have a better solution.
# First extract the three polygons that have cat 1 v.extract input=vector_layer cats=1 output=polygons # Content of the attribute table v.db.select polygons cat|precision|method_con|measure_me|survey_yea|event|elev_minimum 1|3|tpDmg|gnss|2017||101.230186462402 # With corresponding column names and types v.info -c polygons Displaying column types/names for database connection of layer <1>: INTEGER|cat INTEGER|precision CHARACTER|method_con CHARACTER|measure_me INTEGER|survey_yea CHARACTER|event DOUBLE PRECISION|elev_minimum # Then find the center points of the individual polygons v.centerpoint input=polygons output=poly_center # These automatically hold an identical attribute table as the polygons v.info -c poly_center Displaying column types/names for database connection of layer <1>: INTEGER|cat INTEGER|precision CHARACTER|method_con CHARACTER|measure_me INTEGER|survey_yea CHARACTER|event DOUBLE PRECISION|elev_minimum v.db.select poly_center cat|precision|method_con|measure_me|survey_yea|event|elev_minimum 1|3|tpDmg|gnss|2017||101.230186462402 # Then find the center point of the three polygon center points v.centerpoint input=poly_center output=centerpoint # This point does not have an attribute table. # Add attribute table and join with that of the poly_center points v.db.addtable centerpoint v.db.join centerpoint column=cat other_column=cat other_table=poly_center # The data itself is the same v.db.select centerpoint cat|precision|method_con|measure_me|survey_yea|event|elev_minimum 1|3|tpDmg|gnss|2017||101.230186462402 # However, the 'character' columns (all of length 254) # have been redefined as 'text' columns of length 1000. v.info -c centerpoint Displaying column types/names for database connection of layer <1>: INTEGER|cat INTEGER|precision TEXT|method_con TEXT|measure_me INTEGER|survey_yea TEXT|event DOUBLE PRECISION|elev_minimum # Delete the three polygons from the larger vector layer db.execute sql="DELETE FROM vector_layer WHERE cat = 1" # Attempt to patch the centerpoint to the larger vector layer v.patch -e input=vector_layer,centerpoint output=new_vect ERROR:Length of string columns differ
I am using GRASS GIS 7.6.1 on Windows 10. I am also open to a complete reworking of the steps taken, as they certainly might not be the best.