grass
grass copied to clipboard
[Bug] v.dissolve looses connection with database tables when running
Describe the bug When processing the vector map one of backend commands (seems to be v.reclass) change the database table name to map_somenumbersandchars (example map_ef0691c223f2_631@PERMANENT), after that following command (v.extract) can't find tables for the map.
To Reproduce Steps to reproduce the behavior:
- Take a vector with varchar column with duplicated values and several columns with double precision or integer values.
- Start dissolving this vector on varchar column v.dissolve (version grass 8.4) (aggregate_backend=sql)
- See error ERROR: There is no table connected to
Expected behavior A dissolved map should be written.
System description:
- Operating System: Docker with GRASS GIS (debian)
- GRASS GIS version 8.4.0
@geografin I can't reproduce the problem on GRASS 8.4.0 on Ubuntu 22.04, using aggregate_backend=sql.
Thanks for reporting this. Can you please provide the code to reproduce ideally using the NC SPM sample dataset or other public data? The code can be just copied commands from the GUI if you are using it (there is Copy button in the tool dialog).
v.dissolve input=over_geo column=subid aggregate_columns=a_length,a_source_elev,a_outlet_elev aggregate_methods=sum,max,min result_columns=LENGTH,SOURCE,OUTLET output=over_geo_diss --overwrite
This is the command that ends with error. The map taken is a simple rivers layers generated with r.stream.order and overlayed with subwatersheds vector with v.overlay.
I don't use GUI. I use bash linux with GRASS docker image (from main branch, the last one)
Sorry @geografin what I meant was a minimal reproducible example. @ecodiv was not able to reproduce it, so I'm looking for a way to get the same data and situation you have. Bash is definitively better starting point than GUI, so that's great. Can you try to run relevant commands with the NC SPM sample dataset and share these commands?
Well. So take NorthCarolina dataset (full) and reproduce (I copy some maps form the dataset, that are identical to mine by type):
g.copy vect=roadsmajor,streams_init --overwrite
g.copy vect=zipcodes_wake,geodata_subbasins --overwrite
v.overlay ainput=streams_init binput=geodata_subbasins operator=and atype=line output=over_geo --overwrite
v.db.addcolumn map=over_geo columns="subid VARCHAR(15),maindown VARCHAR(15)"
v.db.update map=over_geo column=subid query_column="CAST(b_ZIPCODE_ID AS varchar)" where="b_ZIPCODE_ID <> 'N/A'"
v.dissolve input=over_geo column=subid aggregate_columns=a_SHAPE_LEN aggregate_methods=sum result_columns=LENGTH output=over_geo_diss --overwrite --verbose
This results in error:
ERROR: There is no table connected to <over_geo_diss>. Run v.db.connect or
v.db.addtable first.
ERROR: A processing step failed. Check the above error messages and see the
following details:
Module run `v.db.addcolumn map=over_geo_diss layer=1 columns=LENGTH
DOUBLE` ended with an error.
The subprocess ended with a non-zero return code: 1. See errors
above the traceback or in the error output.
That is the error I am talking about. Use --verbose flag in the last command to see that the error is caused by v.reclass which creates a new database table.
@geografin I can confirm the example results in the reported error. The difference with what I tried is that here you want to dissolve line features, right?
@wenzeslaus The manual exclusively refers to polygon data. Is this function supposed to be able to dissolve line features?
...Is this function supposed to be able to dissolve line features?
Thanks for looking into this. I didn't dive into that and focused on the attribute aggregation, so I don't know from top of my head. The geometrical part is taken care of by v.reclass and v.extract, so you can check those. The lines in v.dissolve are:
gs.run_command(
"v.reclass",
input=input_vector,
output=tmpfile,
layer=layer,
column=column,
)
gs.run_command(
"v.extract",
flags="d",
input=tmpfile,
output=output,
type="area",
layer=layer,
)
...Is this function supposed to be able to dissolve line features?
Thanks for looking into this. I didn't dive into that and focused on the attribute aggregation, so I don't know from top of my head. The geometrical part is taken care of by v.reclass and v.extract, so you can check those. The lines in v.dissolve are:
gs.run_command( "v.reclass", input=input_vector, output=tmpfile, layer=layer, column=column, ) gs.run_command( "v.extract", flags="d", input=tmpfile, output=output, type="area", layer=layer, )
Without having tested it, the type="area" might be the problem?
Without having tested it, the type="area" might be the problem?
Haha, that sure looks like that! Maybe deleting it will do trick?
The difference with what I tried is that here you want to dissolve line features, right?
@ecodiv yes, right! And v.extract doesn't support aggregation by specific columns. So my task can't be done with GRASS.
The difference with what I tried is that here you want to dissolve line features, right?
@ecodiv yes, right! And v.extract doesn't support aggregation by specific columns. So my task can't be done with GRASS.
@geografin I think it can be used, see #3433
#3433 will be merged in following hours when the CI is done testing it. Thanks @ecodiv for the update!