-
Notifications
You must be signed in to change notification settings - Fork 8
Description
It seems that exporting a raster layer from the GRASS GIS database disregards the mapset's region (see example below). Accessing this important GRASS GIS feature would be very convenient, e.g. in aligning multiple raster layers that were accessed with the GDAL driver.
Would it be possible to add a 'dataset open' option that sets a GRASS GIS region? Various options of g.region might be used for this purpose; the most useful probably being region (sufficient to use a GRASS GIS region) and the manual settings n, s, e, w and res.
Example of mismatching region settings between r.out.gdal and gdalwarp
$ grass
Starting GRASS GIS...
__________ ___ __________ _______________
/ ____/ __ \/ | / ___/ ___/ / ____/ _/ ___/
/ / __/ /_/ / /| | \__ \\_ \ / / __ / / \__ \
/ /_/ / _, _/ ___ |___/ /__/ / / /_/ // / ___/ /
\____/_/ |_/_/ |_/____/____/ \____/___//____/
Welcome to GRASS GIS 8.3.2
GRASS GIS homepage: https://grass.osgeo.org
This version running through: Bash Shell (/bin/bash)
Help is available with the command: g.manual -i
See the licence terms with: g.version -c
See citation options with: g.version -x
Start the GUI with: g.gui wxpython
When ready to quit enter: exit
GRASS nc_basic_spm_grass7/PERMANENT:~ > g.region region=state_500m
GRASS nc_basic_spm_grass7/PERMANENT:~ >
GRASS nc_basic_spm_grass7/PERMANENT:~ > g.region -p
projection: 99 (Lambert Conformal Conic)
zone: 0
datum: nad83
ellipsoid: a=6378137 es=0.006694380022900787
north: 320000
south: 8000
west: 120000
east: 934000
nsres: 500
ewres: 500
rows: 624
cols: 1628
cells: 1015872
GRASS nc_basic_spm_grass7/PERMANENT:~ >
GRASS nc_basic_spm_grass7/PERMANENT:~ > r.out.gdal input=elevation output=elevation_grass.tif 2> /dev/null
GRASS nc_basic_spm_grass7/PERMANENT:~ >
GRASS nc_basic_spm_grass7/PERMANENT:~ > gdalwarp /home/floris/grassdata/nc_basic_spm_grass7/PERMANENT/cellhd/elevation elevation_gdal.tif 2> /dev/null
Copying color table from /home/floris/grassdata/nc_basic_spm_grass7/PERMANENT/cellhd/elevation to new file.
Creating output file that is 1500P x 1350L.
Processing /home/floris/grassdata/nc_basic_spm_grass7/PERMANENT/cellhd/elevation [1/1] : 0Using internal nodata values (e.g. nan) for image /home/floris/grassdata/nc_basic_spm_grass7/PERMANENT/cellhd/elevation.
Copying nodata values from source /home/floris/grassdata/nc_basic_spm_grass7/PERMANENT/cellhd/elevation to destination elevation_gdal.tif.
...10...20...30...40...50...60...70...80...90...100 - done.
GRASS nc_basic_spm_grass7/PERMANENT:~ >
GRASS nc_basic_spm_grass7/PERMANENT:~ >
GRASS nc_basic_spm_grass7/PERMANENT:~ > gdalinfo -nomd elevation_grass.tif | tail -11
Origin = (120000.000000000000000,320000.000000000000000)
Pixel Size = (500.000000000000000,-500.000000000000000)
Corner Coordinates:
Upper Left ( 120000.000, 320000.000) ( 84d28' 4.38"W, 36d30'46.34"N)
Lower Left ( 120000.000, 8000.000) ( 84d16'57.51"W, 33d42'16.78"N)
Upper Right ( 934000.000, 320000.000) ( 75d22'30.17"W, 36d34'51.69"N)
Lower Right ( 934000.000, 8000.000) ( 75d29'52.75"W, 33d46'13.90"N)
Center ( 527000.000, 164000.000) ( 79d54'26.85"W, 35d13'30.03"N)
Band 1 Block=1628x1 Type=Float32, ColorInterp=Gray
Description = elevation
NoData Value=nan
GRASS nc_basic_spm_grass7/PERMANENT:~ >
GRASS nc_basic_spm_grass7/PERMANENT:~ >
GRASS nc_basic_spm_grass7/PERMANENT:~ > gdalinfo -nomd elevation_gdal.tif | tail -11
Data axis to CRS axis mapping: 1,2
Origin = (630000.000000000000000,228500.000000000000000)
Pixel Size = (10.000000000000000,-10.000000000000000)
Corner Coordinates:
Upper Left ( 630000.000, 228500.000) ( 78d46'27.41"W, 35d48'34.59"N)
Lower Left ( 630000.000, 215000.000) ( 78d46'28.63"W, 35d41'16.54"N)
Upper Right ( 645000.000, 228500.000) ( 78d36'29.89"W, 35d48'33.08"N)
Lower Right ( 645000.000, 215000.000) ( 78d36'32.01"W, 35d41'15.03"N)
Center ( 637500.000, 221750.000) ( 78d41'29.49"W, 35d44'54.91"N)
Band 1 Block=1500x1 Type=Float32, ColorInterp=Palette
NoData Value=nan
GRASS nc_basic_spm_grass7/PERMANENT:~ >
exit
Done.
Goodbye from GRASS GIS
Motivation:
In R the GRASS GIS interface is provided by package {rgrass}, which in turn uses the {terra} package for reading & writing with GDAL. In the {rgrass} package we intend to (re-)implement the GDAL-GRASS driver to access layers in order to avoid the extra r.out.gdal or v.out.ogr steps that cause extra overhead. (https://github.com/rsbivand/rgrass/issues/75)
System specs:
$ ogrinfo --version
GDAL 3.8.4, released 2024/02/08
$
$ apt policy libgdal-grass
libgdal-grass:
Installed: 1:1.0.2-7+jammy3
Candidate: 1:1.0.2-7+jammy3
Version table:
*** 1:1.0.2-7+jammy3 500
500 http://ppa.launchpad.net/ubuntugis/ubuntugis-unstable/ubuntu jammy/main amd64 Packages
100 /var/lib/dpkg/status
3.4.1-3 500
500 http://ftp.belnet.be/ubuntu jammy/universe amd64 Packages
$
$ inxi -Sxxx
System:
Host: xxx Kernel: 5.15.0-112-generic x86_64 bits: 64 compiler: gcc
v: 11.4.0 Desktop: Cinnamon 6.0.4 tk: GTK 3.24.33 wm: muffin vt: 7
dm: LightDM 1.30.0 Distro: Linux Mint 21.3 Virginia
base: Ubuntu 22.04 jammy