42 static int initialized;
110 if (strcmp(p,
"none") == 0 ||
G_strcasecmp(p,
"nan") == 0 ||
129 #if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3, 7, 0)
148 if (req_type != map_type)
153 data = GDALOpen(filename, GA_ReadOnly);
157 band = GDALGetRasterBand(data, band_num);
180 struct GDAL_Options {
187 static struct state {
189 struct GDAL_Options opts;
190 struct Key_Value *projinfo, *projunits, *projepsg;
196 static void read_gdal_options(
void)
219 if (access(
path, 0) != 0)
227 st->opts.format =
G_store(p ? p :
"GTiff");
265 if (
st->projinfo &&
st->projunits)
273 sprintf(
path,
"%s/%s%s",
st->opts.dir,
name,
st->opts.ext);
283 gdal->
type = GDT_Byte;
287 gdal->
type = GDT_UInt16;
292 gdal->
type = GDT_Int32;
298 gdal->
type = GDT_Float32;
302 gdal->
type = GDT_Float64;
310 driver = GDALGetDriverByName(
st->opts.format);
315 if (GDALGetMetadataItem(
driver, GDAL_DCAP_CREATE,
NULL)) {
320 G_fatal_error(
_(
"Unable to create <%s> dataset using <%s> driver"),
325 else if (GDALGetMetadataItem(
driver, GDAL_DCAP_CREATECOPY,
NULL)) {
326 GDALDriverH mem_driver;
328 G_message(
_(
"Driver <%s> does not support direct writing. "
329 "Using MEM driver for intermediate dataset."),
332 mem_driver = GDALGetDriverByName(
"MEM");
338 1, gdal->
type,
st->opts.options);
341 _(
"Unable to create <%s> dataset using memory driver"),
name);
359 if (GDALSetGeoTransform(gdal->
data,
transform) >= CE_Failure)
363 if (GDALSetProjection(gdal->
data,
st->srswkt) == CE_Failure)
377 sprintf(buf,
"%.22g", gdal->
null_val);
380 sprintf(buf,
"%d", gdal->
type);
404 GDALClose(gdal->
data);
423 GDALDriverH src_drv = GDALGetDatasetDriver(gdal->
data);
425 if (
G_strcasecmp(GDALGetDriverShortName(src_drv),
"MEM") == 0) {
426 GDALDriverH dst_drv = GDALGetDriverByName(
st->opts.format);
431 G_warning(
_(
"Unable to create output file <%s> using driver <%s>"),
438 GDALClose(gdal->
data);
454 int y_off,
int x_size,
int y_size,
void *buffer,
455 int buf_x_size,
int buf_y_size,
456 GDALDataType buf_type,
int pixel_size,
int line_size)
458 return GDALRasterIO(band, rw_flag, x_off, y_off, x_size, y_size, buffer,
459 buf_x_size, buf_y_size, buf_type, pixel_size,
CPLErr Rast_gdal_raster_IO(GDALRasterBandH, GDALRWFlag, int, int, int, int, void *, int, int, GDALDataType, int, int)
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
void G_free(void *)
Free allocated memory.
struct Key_Value * G_get_projinfo(void)
Gets projection information for location.
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
struct Key_Value * G_get_projunits(void)
Gets units information for location.
void G_warning(const char *,...) __attribute__((format(printf
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
const char * G_find_key_value(const char *, const struct Key_Value *)
Find given key (case sensitive)
int G_fwrite_key_value(FILE *, const struct Key_Value *)
Write key/value pairs to file.
int G_make_mapset_object_group(const char *)
Create directory for group of elements of a given type.
const char * G_find_raster2(const char *, const char *)
Find a raster map (look but don't touch)
void G_free_key_value(struct Key_Value *)
Free allocated Key_Value structure.
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
const char * G_mapset(void)
Get current mapset name.
void G_set_key_value(const char *, const char *, struct Key_Value *)
Set value for given key.
struct Key_Value * G_fread_key_value(FILE *)
Read key/values pairs from file.
int G_is_initialized(int *)
void G_initialize_done(int *)
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
struct Key_Value * G_get_projepsg(void)
Gets EPSG information for the current location.
void G_message(const char *,...) __attribute__((format(printf
struct Key_Value * G_create_key_value(void)
Allocate and initialize Key_Value structure.
char * G_store(const char *)
Copy string to allocated memory.
char ** G_tokenize(const char *, const char *)
Tokenize string.
char * GPJ_grass_to_wkt2(const struct Key_Value *, const struct Key_Value *, const struct Key_Value *, int, int)
Converts a GRASS co-ordinate system representation to WKT style. EPSG code is preferred if available.
void Rast__init_window(void)
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
RASTER_MAP_TYPE Rast_map_type(const char *, const char *)
Determine raster data type.
const struct driver * driver
int Rast_close_gdal_write_link(struct GDAL_link *gdal)
Close existing GDAL link and write out data.
void Rast_close_gdal_link(struct GDAL_link *gdal)
Close existing GDAL link.
void Rast_init_gdal(void)
Initialization.
struct GDAL_link * Rast_create_gdal_link(const char *name, RASTER_MAP_TYPE map_type)
Create GDAL settings for given raster map.
struct GDAL_link * Rast_get_gdal_link(const char *name, const char *mapset)
Get GDAL link settings for given raster map.
double ew_res
Resolution - east to west cell size for 2D data.
double north
Extent coordinates (north)
double ns_res
Resolution - north to south cell size for 2D data.
int rows
Number of rows for 2D data.
int cols
Number of columns for 2D data.
double west
Extent coordinates (west)
struct Cell_head wr_window