42 static int initialized;
110 if (strcmp(p,
"none") == 0 ||
144 if (req_type != map_type)
149 data = GDALOpen(filename, GA_ReadOnly);
153 band = GDALGetRasterBand(data, band_num);
187 struct GDAL_Options opts;
188 struct Key_Value *projinfo, *projunits, *projepsg;
194 static void read_gdal_options(
void)
217 if (access(path, 0) != 0)
222 st->opts.ext =
G_store(p ? p :
"");
225 st->opts.format =
G_store(p ? p :
"GTiff");
263 if (st->projinfo && st->projunits)
271 sprintf(path,
"%s/%s%s", st->opts.dir, name, st->opts.ext);
281 gdal->
type = GDT_Byte;
285 gdal->
type = GDT_UInt16;
290 gdal->
type = GDT_Int32;
296 gdal->
type = GDT_Float32;
300 gdal->
type = GDT_Float64;
308 driver = GDALGetDriverByName(st->opts.format);
313 if (GDALGetMetadataItem(driver, GDAL_DCAP_CREATE,
NULL)) {
317 1, gdal->
type, st->opts.options);
319 G_fatal_error(
_(
"Unable to create <%s> dataset using <%s> driver"),
320 name, st->opts.format);
324 else if (GDALGetMetadataItem(driver, GDAL_DCAP_CREATECOPY,
NULL)) {
325 GDALDriverH mem_driver;
327 G_message(
_(
"Driver <%s> does not support direct writing. " 328 "Using MEM driver for intermediate dataset."),
331 mem_driver = GDALGetDriverByName(
"MEM");
336 GDALCreate(mem_driver,
"",
338 1, gdal->
type, st->opts.options);
340 G_fatal_error(
_(
"Unable to create <%s> dataset using memory driver"),
359 if (GDALSetGeoTransform(gdal->
data, transform) >= CE_Failure)
363 if (GDALSetProjection(gdal->
data, st->srswkt) == CE_Failure)
368 G_fatal_error(
_(
"Unable to create cell_misc/%s/gdal file"), name);
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);
432 G_warning(
_(
"Unable to create output file <%s> using driver <%s>"),
439 GDALClose(gdal->
data);
455 int x_off,
int y_off,
int x_size,
int y_size,
456 void *buffer,
int buf_x_size,
int buf_y_size,
457 GDALDataType buf_type,
int pixel_size,
460 return GDALRasterIO(band, rw_flag, x_off, y_off, x_size, y_size,
461 buffer, buf_x_size, buf_y_size, buf_type,
462 pixel_size, line_size);
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
struct Key_Value * G_get_projinfo(void)
Gets projection information for location.
CPLErr Rast_gdal_raster_IO(GDALRasterBandH, GDALRWFlag, int, int, int, int, void *, int, int, GDALDataType, int, int)
int Rast_close_gdal_write_link(struct GDAL_link *gdal)
Close existing GDAL link and write out data.
double west
Extent coordinates (west)
struct Key_Value * G_fread_key_value(FILE *)
Read key/values pairs from file.
void G_free(void *)
Free allocated memory.
char ** G_tokenize(const char *, const char *)
Tokenize string.
void Rast__init_window(void)
void G_initialize_done(int *)
struct Cell_head wr_window
struct Key_Value * G_get_projunits(void)
Gets units information for location.
void G_message(const char *,...) __attribute__((format(printf
double north
Extent coordinates (north)
struct GDAL_link * Rast_create_gdal_link(const char *name, RASTER_MAP_TYPE map_type)
Create GDAL settings for given raster map.
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
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...
FILE * G_fopen_old_misc(const char *, const char *, const char *, const char *)
open a database misc file for reading
const struct driver * driver
void G_set_key_value(const char *, const char *, struct Key_Value *)
Set value for given key.
FILE * G_fopen_old(const char *, const char *, const char *)
Open a database file for reading.
int G_fwrite_key_value(FILE *, const struct Key_Value *)
Write key/value pairs to file.
int cols
Number of columns for 2D data.
int G_is_initialized(int *)
FILE * G_fopen_new_misc(const char *, const char *, const char *)
open a new database misc file
double ns_res
Resolution - north to south cell size for 2D data.
const char * G_mapset(void)
Get current mapset name.
void G_warning(const char *,...) __attribute__((format(printf
void Rast_init_gdal(void)
Initialization.
const char * G_find_raster2(const char *, const char *)
Find a raster map (look but don't touch)
char * G_store(const char *)
Copy string to allocated memory.
void Rast_close_gdal_link(struct GDAL_link *gdal)
Close existing GDAL link.
struct Key_Value * G_create_key_value(void)
Allocate and initialize Key_Value structure.
double ew_res
Resolution - east to west cell size for 2D data.
int rows
Number of rows for 2D data.
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
void G_free_key_value(struct Key_Value *)
Free allocated Key_Value structure.
struct Key_Value * G_get_projepsg(void)
Gets EPSG information for the current location.
int G_make_mapset_object_group(const char *)
Create directory for group of elements of a given type.
struct GDAL_link * Rast_get_gdal_link(const char *name, const char *mapset)
Get GDAL link settings for given raster map.
const char * G_find_key_value(const char *, const struct Key_Value *)
Find given key (case sensitive)
RASTER_MAP_TYPE Rast_map_type(const char *, const char *)
Determine raster data type.