OSGeo / grass

GRASS GIS - free and open-source geospatial processing engine
https://grass.osgeo.org
Other
855 stars 310 forks source link

[Bug] r.import doesn't resample when importing #4725

Closed mazingaro closed 5 days ago

mazingaro commented 5 days ago

Tested in GRASS 8.4 and grass script in python.

When importing a 16cm ortophoto and setting resolution="region",r.import doesn't resample the raster to the region's (1m). Also after setting resolution="value" and resolution_value=1, it doesn't work. The metadata is also a bit misleading, but it clearly shows that there are no resampling processes (no option for that with r.in.gdal if I understand well: so wrapping it with offering resampling seems odd).

g.region -p                                                                     
projection: 99 (Slovenia 1996 / Slovene National Grid)
zone:       0
datum:      towgs84=0,0,0,0,0,0,0
ellipsoid:  grs80
north:      81000
south:      62000
west:       499000
east:       510000
nsres:      1
ewres:      1
rows:       19000
cols:       11000
cells:      209000000

One of the python codes

gs.run_command('r.import',
               input='seznam_pof_rgb.vrt',
               output='pof',
               resolution='value', #same thing happens if resolution='region' and without resolution_value
               resolution_value='1',
               resample='bilinear',
               memory='30000',
               flags='o')

The metadata says it was imported with r.in.gdal (I understand that r.import is basically a wrapper around r.in.gdal), but the parameters for resampling can't be seen, as there are no such options in r.in.gdal. You can see as well the resolution of the imported raster.

r.info map=pof.2@PERMANENT                                                      
 +----------------------------------------------------------------------------+
 | Map:      pof.2@PERMANENT                Date: Wed Nov 20 13:28:41 2024    |
 | Mapset:   PERMANENT                      Login of Creator: alen            |
 | Project:  ...                                                         |
 | DataBase: .....                           |
 | Title:    pof.2                                                            |
 | Timestamp: none                                                            |
 |----------------------------------------------------------------------------|
 |                                                                            |
 |   Type of Map:  raster               Number of Categories: 0               |
 |   Data Type:    CELL                 Semantic label: (none)                |
 |   Rows:         118750                                                     |
 |   Columns:      68750                                                      |
 |   Total Cells:  8164062500                                                 |
 |        Projection: Slovenia 1996 / Slovene National Grid                   |
 |            N:      81000    S:      62000   Res:  0.16                     |
 |            E:     510000    W:     499000   Res:  0.16                     |
 |   Range of data:    min = 1  max = 254                                     |
 |                                                                            |
 |   Data Description:                                                        |
 |    generated by r.in.gdal                                                  |
 |                                                                            |
 |   Comments:                                                                |
 |    r.in.gdal -o -a -k input="somepath/se\   |
 |    znam_pof_rgb.vrt" output="pof" memory=30000 offset=0 num_digits=0       |
 |                                                                            |
 +----------------------------------------------------------------------------+
mazingaro commented 5 days ago

Eeeh, I understood after that this option is possible just when reprojecting.

neteler commented 5 days ago

@mazingaro Anything which should be better documented in the manual page?

mazingaro commented 5 days ago

@mazingaro Anything which should be better documented in the manual page?

Not really, I should take a deep breath or two before reading and do it slower :P

But generally, It would make sense to propose an enhancement to resample the imported rasters also without re-projection. @neteler is it a selfish request or you find it useful for the users?

echoix commented 5 days ago

Do you mean a standalone reproduction tool, like gdal warp, or on the fly reprojection, like QGIS?

mazingaro commented 5 days ago

Do you mean a standalone reproduction tool, like gdal warp, or on the fly reprojection, like QGIS?

I mean something as a flag withing the function, that allows you to resample it also if EPSG matches the project. In the background there is probably gdalwarp, so this could mean just using gdalwarp within the same projection.