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[] = {
110 for (i = 0; candidates[i]; i++) {
111 try_load_library(candidates[i]);
113 G_debug(3,
"found %s", candidates[i]);
121 static void init_gdal(
void)
125 # if defined(_WIN32) && !defined(_WIN64)
126 pGDALAllRegister = get_symbol(
"_GDALAllRegister@0");
127 pGDALOpen = get_symbol(
"_GDALOpen@8");
128 pGDALClose = get_symbol(
"_GDALClose@4");
129 pGDALGetRasterBand = get_symbol(
"_GDALGetRasterBand@8");
130 pGDALRasterIO = get_symbol(
"_GDALRasterIO@48");
132 pGDALAllRegister = get_symbol(
"GDALAllRegister");
133 pGDALOpen = get_symbol(
"GDALOpen");
134 pGDALClose = get_symbol(
"GDALClose");
135 pGDALGetRasterBand = get_symbol(
"GDALGetRasterBand");
136 pGDALRasterIO = get_symbol(
"GDALRasterIO");
142 static void init_gdal(
void)
144 pGDALAllRegister = &GDALAllRegister;
145 pGDALOpen = &GDALOpen;
146 pGDALClose = &GDALClose;
147 pGDALGetRasterBand = &GDALGetRasterBand;
148 pGDALRasterIO = &GDALRasterIO;
158 static int initialized;
160 GDALRasterBandH band;
162 RASTER_MAP_TYPE req_type;
167 RASTER_MAP_TYPE map_type;
169 struct Key_Value *key_val;
203 if (strcmp(p,
"none") == 0)
220 req_type = CELL_TYPE;
223 req_type = FCELL_TYPE;
226 req_type = DCELL_TYPE;
232 if (req_type != map_type)
237 (*pGDALAllRegister)();
241 data = (*pGDALOpen)(filename, GA_ReadOnly);
245 band = (*pGDALGetRasterBand)(
data, band_num);
252 gdal = G_calloc(1,
sizeof(
struct GDAL_link));
269 (*pGDALClose)(gdal->data);
276 CPLErr G_gdal_raster_IO(
277 GDALRasterBandH band, GDALRWFlag rw_flag,
278 int x_off,
int y_off,
int x_size,
int y_size,
279 void *buffer,
int buf_x_size,
int buf_y_size, GDALDataType buf_type,
280 int pixel_size,
int line_size)
282 return (*pGDALRasterIO)(
283 band, rw_flag, x_off, y_off, x_size, y_size,
284 buffer, buf_x_size, buf_y_size, buf_type,
285 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)
int G_debug(int level, const char *msg,...)
Print debugging message.
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.