16 #include <grass/config.h>
17 #include <grass/gis.h>
18 #include <grass/glocale.h>
28 # if defined(__unix) || defined(__unix__)
36 static void CPL_STDCALL (*pGDALAllRegister)(void);
37 static void CPL_STDCALL (*pGDALClose)(GDALDatasetH);
38 static GDALRasterBandH CPL_STDCALL (*pGDALGetRasterBand)(GDALDatasetH,
int);
39 static GDALDatasetH CPL_STDCALL (*pGDALOpen)(
40 const char *pszFilename, GDALAccess eAccess);
41 static CPLErr CPL_STDCALL (*pGDALRasterIO)(
42 GDALRasterBandH hRBand, GDALRWFlag eRWFlag,
43 int nDSXOff,
int nDSYOff,
int nDSXSize,
int nDSYSize,
44 void * pBuffer,
int nBXSize,
int nBYSize,GDALDataType eBDataType,
45 int nPixelSpace,
int nLineSpace);
48 # if defined(__unix) && !defined(__unix__)
49 # define __unix__ __unix
52 static void *library_h;
54 static void *get_symbol(
const char *
name)
59 sym = dlsym(library_h, name);
62 sym = GetProcAddress((HINSTANCE) library_h, name);
71 static void try_load_library(
const char *name)
74 library_h = dlopen(name, RTLD_NOW);
77 library_h = LoadLibrary(name);
81 static void load_library(
void)
83 static const char *
const candidates[] = {
108 for (i = 0; candidates[i]; i++) {
109 try_load_library(candidates[i]);
117 static void init_gdal(
void)
122 pGDALAllRegister = get_symbol(
"_GDALAllRegister@0");
123 pGDALOpen = get_symbol(
"_GDALOpen@8");
124 pGDALClose = get_symbol(
"_GDALClose@4");
125 pGDALGetRasterBand = get_symbol(
"_GDALGetRasterBand@8");
126 pGDALRasterIO = get_symbol(
"_GDALRasterIO@48");
128 pGDALAllRegister = get_symbol(
"GDALAllRegister");
129 pGDALOpen = get_symbol(
"GDALOpen");
130 pGDALClose = get_symbol(
"GDALClose");
131 pGDALGetRasterBand = get_symbol(
"GDALGetRasterBand");
132 pGDALRasterIO = get_symbol(
"GDALRasterIO");
138 static void init_gdal(
void)
140 pGDALAllRegister = &GDALAllRegister;
141 pGDALOpen = &GDALOpen;
142 pGDALClose = &GDALClose;
143 pGDALGetRasterBand = &GDALGetRasterBand;
144 pGDALRasterIO = &GDALRasterIO;
154 static int initialized;
156 GDALRasterBandH band;
158 RASTER_MAP_TYPE req_type;
163 RASTER_MAP_TYPE map_type;
165 struct Key_Value *key_val;
199 if (strcmp(p,
"none") == 0)
216 req_type = CELL_TYPE;
219 req_type = FCELL_TYPE;
222 req_type = DCELL_TYPE;
228 if (req_type != map_type)
233 (*pGDALAllRegister)();
237 data = (*pGDALOpen)(filename, GA_ReadOnly);
241 band = (*pGDALGetRasterBand)(
data, band_num);
248 gdal = G_calloc(1,
sizeof(
struct GDAL_link));
265 (*pGDALClose)(gdal->data);
272 CPLErr G_gdal_raster_IO(
273 GDALRasterBandH band, GDALRWFlag rw_flag,
274 int x_off,
int y_off,
int x_size,
int y_size,
275 void *buffer,
int buf_x_size,
int buf_y_size, GDALDataType buf_type,
276 int pixel_size,
int line_size)
278 return (*pGDALRasterIO)(
279 band, rw_flag, x_off, y_off, x_size, y_size,
280 buffer, buf_x_size, buf_y_size, buf_type,
281 pixel_size, line_size);
char * G_find_key_value(const char *key, const struct Key_Value *kv)
Find given key.
void G_free(void *buf)
Free allocated memory.
char * G_store(const char *s)
Copy string to allocated memory.
struct Key_Value * G_fread_key_value(FILE *fd)
Read key/values pairs from file.
void G_set_d_null_value(DCELL *dcellVals, int numVals)
FILE * G_fopen_old_misc(const char *dir, const char *element, const char *name, const char *mapset)
open a database file for reading
char * G_find_cell2(const char *name, const char *mapset)
find a raster map (look but don't touch)
void G_close_gdal_link(struct GDAL_link *gdal)
struct GDAL_link * G_get_gdal_link(const char *name, const char *mapset)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
RASTER_MAP_TYPE G_raster_map_type(const char *name, const char *mapset)
Determine raster data type.