30 #include "ogr_srs_api.h"
33 #define xstr(s) str(s)
41 static const char *label =
"ERROR: ";
42 char newfmt[1024] = {0};
43 snprintf(newfmt, 1024,
"%s%s\n", label,
fmt);
45 vfprintf(stderr, newfmt, ap);
54 static const char *label =
"WARNING: ";
55 char newfmt[1024] = {0};
56 snprintf(newfmt, 1024,
"%s%s\n", label,
fmt);
58 vfprintf(stderr, newfmt, ap);
67 static const char *label =
"INFO: ";
68 char newfmt[1024] = {0};
69 snprintf(newfmt, 1024,
"%s%s\n", label,
fmt);
71 vfprintf(stderr, newfmt, ap);
91 for (i = 0; i < nbands; i++) {
93 if (
band == NULL)
continue;
105 array_range(
int min,
int max,
int step,
int **range, uint32_t *len) {
110 *len = (uint32_t) ((abs(max - min) + 1 + (step / 2)) / step);
111 *range =
rtalloc(
sizeof(
int) * *len);
114 for (i = min, j = 0; i <= max; i += step, j++)
117 else if (max < min) {
118 if (step > 0) step *= -1;
119 for (i = min, j = 0; i >= max; i += step, j++)
122 else if (min == max) {
155 const char *oldstr,
const char *newstr,
158 const char *tmp =
str;
162 int oldlen = strlen(oldstr);
163 int newlen = strlen(newstr);
167 while ((tmp = strstr(tmp, oldstr)) != NULL && found != limit)
168 found++, tmp += oldlen;
170 length = (int)strlen(
str) + found * (newlen - oldlen);
172 rterror(
_(
"strreplace: Not enough memory"));
181 while ((limit-- > 0) && (tmp = strstr(tmp, oldstr)) != NULL) {
182 length = (tmp -
str);
184 strcpy(
result + (reslen += length), newstr);
201 for (j = strlen(
str) - 1; j >= 0; j--)
219 tmp =
rtalloc(
sizeof(
char) * (strlen(
str) + 1));
221 rterror(
_(
"strsplit: Not enough memory"));
226 if (!strlen(tmp) || !delimiter || !strlen(delimiter)) {
228 rtn = (
char **)
rtalloc(*n *
sizeof(
char *));
230 rterror(
_(
"strsplit: Not enough memory"));
233 rtn[0] = (
char *)
rtalloc(
sizeof(
char) * (strlen(tmp) + 1));
234 if (NULL == rtn[0]) {
235 rterror(
_(
"strsplit: Not enough memory"));
243 token = strtok(tmp, delimiter);
244 while (token != NULL) {
246 rtn = (
char **)
rtalloc(
sizeof(
char *));
249 rtn = (
char **)
rtrealloc(rtn, (*n + 1) *
sizeof(
char *));
252 rterror(
_(
"strsplit: Not enough memory"));
257 rtn[*n] = (
char *)
rtalloc(
sizeof(
char) * (strlen(token) + 1));
258 if (NULL == rtn[*n]) {
259 rterror(
_(
"strsplit: Not enough memory"));
263 strcpy(rtn[*n], token);
266 token = strtok(NULL, delimiter);
283 return (
char *) input;
286 while (isspace(*input))
290 ptr = ((
char *) input) + strlen(input);
291 while (isspace(*--ptr))
294 len = strlen(input) - offset + 1;
295 rtn =
rtalloc(
sizeof(
char) * len);
297 rterror(
_(
"trim: Not enough memory"));
300 strncpy(rtn, input, len);
315 return (
char *) input;
318 while (strchr(remove, *input) != NULL)
322 ptr = ((
char *) input) + strlen(input);
323 while (strchr(remove, *--ptr) != NULL)
326 len = strlen(input) - offset + 1;
327 rtn =
rtalloc(
sizeof(
char) * len);
329 rterror(
_(
"chartrim: Not enough memory"));
332 strncpy(rtn, input, len);
333 rtn[strlen(input) - offset] =
'\0';
342 "USAGE: raster2pgsql [<options>] <raster>[ <raster>[ ...]] [[<schema>.]<table>]\n"
343 " Multiple rasters can also be specified using wildcards (*,?).\n"
356 " -s <srid> Set the SRID field. Defaults to %d. If SRID not\n"
357 " provided or is %d, raster's metadata will be checked to\n"
358 " determine an appropriate SRID.\n"
361 " -b <band> Index (1-based) of band to extract from raster. For more\n"
362 " than one band index, separate with comma (,). Ranges can be\n"
363 " defined by separating with dash (-). If unspecified, all bands\n"
364 " of raster will be extracted.\n"
367 " -t <tile size> Cut raster into tiles to be inserted one per\n"
368 " table row. <tile size> is expressed as WIDTHxHEIGHT.\n"
369 " <tile size> can also be \"auto\" to allow the loader to compute\n"
370 " an appropriate tile size using the first raster and applied to\n"
374 " -P Pad right-most and bottom-most tiles to guarantee that all tiles\n"
375 " have the same width and height.\n"
378 " -R Register the raster as an out-of-db (filesystem) raster. Provided\n"
379 " raster should have absolute path to the file\n"
382 " (-d|a|c|p) These are mutually exclusive options:\n"
383 " -d Drops the table, then recreates it and populates\n"
384 " it with current raster data.\n"
385 " -a Appends raster into current table, must be\n"
386 " exactly the same table schema.\n"
387 " -c Creates a new table and populates it, this is the\n"
388 " default if you do not specify any options.\n"
389 " -p Prepare mode, only creates the table.\n"
392 " -f <column> Specify the name of the raster column\n"
395 " -F Add a column with the filename of the raster.\n"
398 " -n <column> Specify the name of the filename column. Implies -F.\n"
401 " -l <overview factor> Create overview of the raster. For more than\n"
402 " one factor, separate with comma(,). Overview table name follows\n"
403 " the pattern o_<overview factor>_<table>. Created overview is\n"
404 " stored in the database and is not affected by -R.\n"
407 " -q Wrap PostgreSQL identifiers in quotes.\n"
410 " -I Create a GIST spatial index on the raster column. The ANALYZE\n"
411 " command will automatically be issued for the created index.\n"
414 " -M Run VACUUM ANALYZE on the table of the raster column. Most\n"
415 " useful when appending raster to existing table with -a.\n"
418 " -C Set the standard set of constraints on the raster\n"
419 " column after the rasters are loaded. Some constraints may fail\n"
420 " if one or more rasters violate the constraint.\n"
421 " -x Disable setting the max extent constraint. Only applied if\n"
422 " -C flag is also used.\n"
423 " -r Set the constraints (spatially unique and coverage tile) for\n"
424 " regular blocking. Only applied if -C flag is also used.\n"
427 " -T <tablespace> Specify the tablespace for the new table.\n"
428 " Note that indices (including the primary key) will still use\n"
429 " the default tablespace unless the -X flag is also used.\n"
432 " -X <tablespace> Specify the tablespace for the table's new index.\n"
433 " This applies to the primary key and the spatial index if\n"
434 " the -I flag is used.\n"
437 " -N <nodata> NODATA value to use on bands without a NODATA value.\n"
440 " -k Keep empty tiles by skipping NODATA value checks for each raster band. \n"
443 " -E <endian> Control endianness of generated binary output of\n"
444 " raster. Use 0 for XDR and 1 for NDR (default). Only NDR\n"
445 " is supported at this time.\n"
448 " -V <version> Specify version of output WKB format. Default\n"
449 " is 0. Only 0 is supported at this time.\n"
452 " -e Execute each statement individually, do not use a transaction.\n"
455 " -Y <max_rows_per_copy> Use COPY statements instead of INSERT statements. \n"
456 " Optionally specify <max_rows_per_copy>; default 50 when not specified. \n"
460 " -G Print the supported GDAL raster formats.\n"
463 " -? Display this help screen.\n"
468 calc_tile_size(uint32_t dimX, uint32_t dimY,
int *tileX,
int *tileY)
470 uint32_t min_tile_size = 30;
471 uint32_t max_tile_size = 300;
473 for (uint8_t current_dimension = 0; current_dimension <= 1; current_dimension++)
475 uint32_t img_size = (current_dimension == 0) ? dimX : dimY;
476 uint32_t best_gap = max_tile_size;
477 uint32_t best_size = img_size;
479 if (img_size > max_tile_size)
481 for (uint32_t tile_size = max_tile_size; tile_size >= min_tile_size; tile_size--)
483 uint32_t gap = img_size % tile_size;
487 best_size = tile_size;
492 if (current_dimension == 0)
503 memset(info->
dim, 0,
sizeof(uint32_t) * 2);
510 memset(info->
gt, 0,
sizeof(
double) * 6);
511 memset(info->
tile_size, 0,
sizeof(
int) * 2);
516 if (info->
srs != NULL)
532 if (src->
srs != NULL) {
534 if (dst->
srs == NULL) {
535 rterror(
_(
"copy_rastinfo: Not enough memory"));
538 strcpy(dst->
srs, src->
srs);
540 memcpy(dst->
dim, src->
dim,
sizeof(uint32_t) * 2);
544 if (dst->
nband == NULL) {
545 rterror(
_(
"copy_rastinfo: Not enough memory"));
553 rterror(
_(
"copy_rastinfo: Not enough memory"));
561 rterror(
_(
"copy_rastinfo: Not enough memory"));
569 rterror(
_(
"copy_rastinfo: Not enough memory"));
577 rterror(
_(
"copy_rastinfo: Not enough memory"));
582 memcpy(dst->
gt, src->
gt,
sizeof(
double) * 6);
590 static uint8_t msg[6] = {0};
598 rtwarn(
_(
"Different number of bands found in the set of rasters being converted to PostGIS raster"));
605 if (
x->bandtype[i] != ref->
bandtype[i]) {
606 rtwarn(
_(
"Different pixel types found for band %d in the set of rasters being converted to PostGIS raster"), ref->
nband[i]);
616 rtwarn(
_(
"Different hasnodata flags found for band %d in the set of rasters being converted to PostGIS raster"), ref->
nband[i]);
625 if (!
x->hasnodata[i] && !ref->
hasnodata[i])
continue;
627 rtwarn(
_(
"Different NODATA values found for band %d in the set of rasters being converted to PostGIS raster"), ref->
nband[i]);
644 rterror(
_(
"diff_rastinfo: Could not allocate memory for raster alignment test"));
657 rterror(
_(
"diff_rastinfo: Could not run raster alignment test"));
662 rtwarn(
_(
"Raster with different alignment found in the set of rasters being converted to PostGIS raster"));
669 for (i = 0; i < 2; i++) {
671 rtwarn(
_(
"Different tile sizes found in the set of rasters being converted to PostGIS raster"));
685 config->
table = NULL;
694 config->
nband = NULL;
696 memset(config->
tile_size, 0,
sizeof(
int) * 2);
730 if (config->
schema != NULL)
732 if (config->
table != NULL)
767 for (i = 0; i <
buffer->length; i++) {
768 if (
buffer->line[i] != NULL)
784 for (i = 0; i <
buffer->length; i++) {
785 printf(
"%s\n",
buffer->line[i]);
791 dump_stringbuffer(
buffer);
792 rtdealloc_stringbuffer(
buffer, 0);
801 if (
buffer->line == NULL) {
802 rterror(
_(
"append_stringbuffer: Could not allocate memory for appending string to buffer"));
814 flush_stringbuffer(
buffer);
820 copy_from(
const char *schema,
const char *table,
const char *column,
821 const char *filename,
const char *file_column_name,
827 assert(table != NULL);
828 assert(column != NULL);
830 len = strlen(
"COPY () FROM stdin;") + 1;
832 len += strlen(schema);
833 len += strlen(table);
834 len += strlen(column);
835 if (filename != NULL)
836 len += strlen(
",") + strlen(file_column_name);
840 rterror(
_(
"copy_from: Could not allocate memory for COPY statement"));
843 sprintf(
sql,
"COPY %s%s (%s%s%s) FROM stdin;",
844 (schema != NULL ? schema :
""),
847 (filename != NULL ?
"," :
""),
848 (filename != NULL ? file_column_name :
"")
861 append_sql_to_buffer(
buffer, strdup(
"\\."));
868 const char *schema,
const char *table,
const char *column,
869 const char *filename,
const char *file_column_name,
870 int copy_statements,
int out_srid,
878 assert(table != NULL);
879 assert(column != NULL);
882 if (copy_statements) {
885 schema, table, column,
886 (file_column_name ? filename : NULL), file_column_name,
889 rterror(
_(
"insert_records: Could not add COPY statement to string buffer"));
895 if (filename != NULL)
900 len = strlen(tileset->
line[
x]) + 1;
902 if (filename != NULL)
903 len += strlen(fn) + 1;
907 rterror(
_(
"insert_records: Could not allocate memory for COPY statement"));
910 sprintf(
sql,
"%s%s%s",
912 (filename != NULL ?
"\t" :
""),
913 (filename != NULL ? fn :
"")
920 if (!copy_from_end(
buffer)) {
921 rterror(
_(
"process_rasters: Could not add COPY end statement to string buffer"));
928 len = strlen(
"INSERT INTO () VALUES (ST_Transform(''::raster,xxxxxxxxx));") + 1;
930 len += strlen(schema);
931 len += strlen(table);
932 len += strlen(column);
933 if (filename != NULL)
934 len += strlen(
",") + strlen(file_column_name);
937 if (filename != NULL)
944 sqllen += strlen(tileset->
line[
x]);
945 if (filename != NULL)
946 sqllen += strlen(
",''") + strlen(fn);
950 rterror(
_(
"insert_records: Could not allocate memory for INSERT statement"));
954 ptr += sprintf(
sql,
"INSERT INTO %s%s (%s%s%s) VALUES (",
955 (schema != NULL ? schema :
""),
958 (filename != NULL ?
"," :
""),
959 (filename != NULL ? file_column_name :
"")
962 ptr += sprintf(ptr,
"ST_Transform(");
964 ptr += sprintf(ptr,
"'%s'::raster",
968 ptr += sprintf(ptr,
", %d)", out_srid);
970 if (filename != NULL) {
971 ptr += sprintf(ptr,
",'%s'", fn);
973 ptr += sprintf(ptr,
");");
989 len = strlen(
"DROP TABLE IF EXISTS ;") + 1;
991 len += strlen(schema);
992 len += strlen(table);
996 rterror(
_(
"drop_table: Could not allocate memory for DROP TABLE statement"));
999 sprintf(
sql,
"DROP TABLE IF EXISTS %s%s;",
1000 (schema != NULL ? schema :
""),
1011 const char *schema,
const char *table,
const char *column,
1012 const int file_column,
const char *file_column_name,
1013 const char *tablespace,
const char *idx_tablespace,
1019 assert(table != NULL);
1020 assert(column != NULL);
1022 len = strlen(
"CREATE TABLE (\"rid\" serial PRIMARY KEY, raster);") + 1;
1024 len += strlen(schema);
1025 len += strlen(table);
1026 len += strlen(column);
1028 len += strlen(
", text") + strlen(file_column_name);
1029 if (tablespace != NULL)
1030 len += strlen(
" TABLESPACE ") + strlen(tablespace);
1031 if (idx_tablespace != NULL)
1032 len += strlen(
" USING INDEX TABLESPACE ") + strlen(idx_tablespace);
1036 rterror(
_(
"create_table: Could not allocate memory for CREATE TABLE statement"));
1039 sprintf(
sql,
"CREATE TABLE %s%s (\"rid\" serial PRIMARY KEY%s%s,%s raster%s%s%s)%s%s;",
1040 (schema != NULL ? schema :
""),
1042 (idx_tablespace != NULL ?
" USING INDEX TABLESPACE " :
""),
1043 (idx_tablespace != NULL ? idx_tablespace :
""),
1045 (file_column ?
"," :
""),
1046 (file_column ? file_column_name :
""),
1047 (file_column ?
" text" :
""),
1048 (tablespace != NULL ?
" TABLESPACE " :
""),
1049 (tablespace != NULL ? tablespace :
"")
1059 const char *schema,
const char *table,
const char *column,
1060 const char *tablespace,
1065 char *_table = NULL;
1066 char *_column = NULL;
1068 assert(table != NULL);
1069 assert(column != NULL);
1075 len = strlen(
"CREATE INDEX \"__gist\" ON USING gist (st_convexhull());") + 1;
1077 len += strlen(schema);
1078 len += strlen(_table);
1079 len += strlen(_column);
1080 len += strlen(table);
1081 len += strlen(column);
1082 if (tablespace != NULL)
1083 len += strlen(
" TABLESPACE ") + strlen(tablespace);
1087 rterror(
_(
"create_index: Could not allocate memory for CREATE INDEX statement"));
1092 sprintf(
sql,
"CREATE INDEX ON %s%s USING gist (st_convexhull(%s))%s%s;",
1093 (schema != NULL ? schema :
""),
1096 (tablespace != NULL ?
" TABLESPACE " :
""),
1097 (tablespace != NULL ? tablespace :
"")
1109 const char *schema,
const char *table,
1115 assert(table != NULL);
1117 len = strlen(
"ANALYZE ;") + 1;
1119 len += strlen(schema);
1120 len += strlen(table);
1124 rterror(
_(
"analyze_table: Could not allocate memory for ANALYZE TABLE statement"));
1127 sprintf(
sql,
"ANALYZE %s%s;",
1128 (schema != NULL ? schema :
""),
1139 const char *schema,
const char *table,
1145 assert(table != NULL);
1147 len = strlen(
"VACUUM ANALYZE ;") + 1;
1149 len += strlen(schema);
1150 len += strlen(table);
1154 rterror(
_(
"vacuum_table: Could not allocate memory for VACUUM statement"));
1157 sprintf(
sql,
"VACUUM ANALYZE %s%s;",
1158 (schema != NULL ? schema :
""),
1168 add_raster_constraints(
1169 const char *schema,
const char *table,
const char *column,
1170 int regular_blocking,
int max_extent,
1177 char *_schema = NULL;
1178 char *_table = NULL;
1179 char *_column = NULL;
1181 assert(table != NULL);
1182 assert(column != NULL);
1185 if (schema != NULL) {
1204 len = strlen(
"SELECT AddRasterConstraints('','','',TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,TRUE,TRUE,TRUE,TRUE,FALSE);") + 1;
1205 if (_schema != NULL)
1206 len += strlen(_schema);
1207 len += strlen(_table);
1208 len += strlen(_column);
1212 rterror(
_(
"add_raster_constraints: Could not allocate memory for AddRasterConstraints statement"));
1215 sprintf(
sql,
"SELECT AddRasterConstraints('%s','%s','%s',TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,%s,TRUE,TRUE,TRUE,TRUE,%s);",
1216 (_schema != NULL ? _schema :
""),
1219 (regular_blocking ?
"TRUE" :
"FALSE"),
1220 (max_extent ?
"TRUE" :
"FALSE")
1223 if (_schema != NULL)
1234 add_overview_constraints(
1235 const char *ovschema,
const char *ovtable,
const char *ovcolumn,
1236 const char *schema,
const char *table,
const char *column,
1245 char *_ovschema = NULL;
1246 char *_ovtable = NULL;
1247 char *_ovcolumn = NULL;
1249 char *_schema = NULL;
1250 char *_table = NULL;
1251 char *_column = NULL;
1253 assert(ovtable != NULL);
1254 assert(ovcolumn != NULL);
1255 assert(table != NULL);
1256 assert(column != NULL);
1260 if (ovschema != NULL) {
1264 _tmp =
strreplace(_ovschema,
"'",
"''", NULL);
1271 _ovtable =
strreplace(_tmp,
"'",
"''", NULL);
1276 _ovcolumn =
strreplace(_tmp,
"'",
"''", NULL);
1280 if (schema != NULL) {
1299 len = strlen(
"SELECT AddOverviewConstraints('','','','','','',);") + 5;
1300 if (_ovschema != NULL)
1301 len += strlen(_ovschema);
1302 len += strlen(_ovtable);
1303 len += strlen(_ovcolumn);
1304 if (_schema != NULL)
1305 len += strlen(_schema);
1306 len += strlen(_table);
1307 len += strlen(_column);
1311 rterror(
_(
"add_overview_constraints: Could not allocate memory for AddOverviewConstraints statement"));
1314 sprintf(
sql,
"SELECT AddOverviewConstraints('%s','%s','%s','%s','%s','%s',%d);",
1315 (_ovschema != NULL ? _ovschema :
""),
1318 (_schema != NULL ? _schema :
""),
1324 if (_ovschema != NULL)
1329 if (_schema != NULL)
1341 GDALDatasetH hdsSrc;
1343 VRTSourcedRasterBandH hbandOv;
1344 double gtOv[6] = {0.};
1349 const char *ovtable = NULL;
1352 VRTSourcedRasterBandH hbandDst;
1353 int tile_size[2] = {0};
1354 int _tile_size[2] = {0};
1355 int ntiles[2] = {1, 1};
1358 double gt[6] = {0.};
1362 uint32_t hexlen = 0;
1364 hdsSrc = GDALOpenShared(config->
rt_file[idx], GA_ReadOnly);
1365 if (hdsSrc == NULL) {
1366 rterror(
_(
"build_overview: Could not open raster: %s"), config->
rt_file[idx]);
1371 memcpy(gtOv, info->
gt,
sizeof(
double) * 6);
1374 rterror(
_(
"build_overview: Invalid overview index: %d"), ovx);
1386 dimOv[0] = (int) (info->
dim[0] + (factor / 2)) / factor;
1387 dimOv[1] = (int) (info->
dim[1] + (factor / 2)) / factor;
1390 hdsOv = VRTCreate(dimOv[0], dimOv[1]);
1394 GDALSetProjection(hdsOv, info->
srs);
1400 GDALSetGeoTransform(hdsOv, gtOv);
1405 hbandOv = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsOv, j + 1);
1408 GDALSetRasterNoDataValue(hbandOv, info->
nodataval[j]);
1411 hbandOv, GDALGetRasterBand(hdsSrc, info->
nband[j]),
1413 info->
dim[0], info->
dim[1],
1416 "near", VRT_NODATA_UNSET
1421 VRTFlushCache(hdsOv);
1425 tile_size[0] = dimOv[0];
1429 tile_size[1] = dimOv[1];
1435 tile_size[0] != dimOv[0] &&
1436 tile_size[1] != dimOv[1]
1438 ntiles[0] = (dimOv[0] + tile_size[0] - 1) / tile_size[0];
1439 ntiles[1] = (dimOv[1] + tile_size[1] - 1) / tile_size[1];
1443 memcpy(
gt, gtOv,
sizeof(
double) * 6);
1447 for (ytile = 0; ytile < ntiles[1]; ytile++) {
1450 if (!config->
pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
1451 _tile_size[1] = dimOv[1] - (ytile * tile_size[1]);
1453 _tile_size[1] = tile_size[1];
1455 for (xtile = 0; xtile < ntiles[0]; xtile++) {
1462 if (!config->
pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
1463 _tile_size[0] = dimOv[0] - (xtile * tile_size[0]);
1465 _tile_size[0] = tile_size[0];
1468 GDALApplyGeoTransform(
1470 xtile * tile_size[0], ytile * tile_size[1],
1475 hdsDst = VRTCreate(_tile_size[0], _tile_size[1]);
1479 GDALSetProjection(hdsDst, info->
srs);
1480 GDALSetGeoTransform(hdsDst,
gt);
1485 hbandDst = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsDst, j + 1);
1488 GDALSetRasterNoDataValue(hbandDst, info->
nodataval[j]);
1491 hbandDst, GDALGetRasterBand(hdsOv, j + 1),
1492 xtile * tile_size[0], ytile * tile_size[1],
1493 _tile_size[0], _tile_size[1],
1495 _tile_size[0], _tile_size[1],
1496 "near", VRT_NODATA_UNSET
1501 VRTFlushCache(hdsDst);
1506 rterror(
_(
"build_overview: Could not convert VRT dataset to PostGIS raster"));
1519 rterror(
_(
"build_overview: Could not convert PostGIS raster to hex WKB"));
1525 append_stringbuffer(tileset, hex);
1531 if (!insert_records(
1537 rterror(
_(
"build_overview: Could not convert raster tiles into INSERT or COPY statements"));
1542 rtdealloc_stringbuffer(tileset, 0);
1554 GDALDatasetH hdsSrc;
1555 GDALRasterBandH hbandSrc;
1558 int ntiles[2] = {1, 1};
1559 int _tile_size[2] = {0, 0};
1564 double gt[6] = {0.};
1565 const char* pszProjectionRef = NULL;
1569 uint32_t numbands = 0;
1572 uint32_t hexlen = 0;
1576 hdsSrc = GDALOpenShared(config->
rt_file[idx], GA_ReadOnly);
1577 if (hdsSrc == NULL) {
1578 rterror(
_(
"convert_raster: Could not open raster: %s"), config->
rt_file[idx]);
1582 nband = GDALGetRasterCount(hdsSrc);
1584 rterror(
_(
"convert_raster: No bands found in raster: %s"), config->
rt_file[idx]);
1592 rterror(
_(
"convert_raster: Band %d not found in raster: %s"), config->
nband[i], config->
rt_file[idx]);
1599 pszProjectionRef = GDALGetProjectionRef(hdsSrc);
1600 if (pszProjectionRef != NULL && pszProjectionRef[0] !=
'\0') {
1601 info->
srs =
rtalloc(
sizeof(
char) * (strlen(pszProjectionRef) + 1));
1602 if (info->
srs == NULL) {
1603 rterror(
_(
"convert_raster: Could not allocate memory for storing SRS"));
1607 strcpy(info->
srs, pszProjectionRef);
1610 OGRSpatialReferenceH hSRS = OSRNewSpatialReference(NULL);
1611 if (OSRSetFromUserInput(hSRS, pszProjectionRef) == OGRERR_NONE) {
1612 const char* pszAuthorityName = OSRGetAuthorityName(hSRS, NULL);
1613 const char* pszAuthorityCode = OSRGetAuthorityCode(hSRS, NULL);
1615 pszAuthorityName != NULL &&
1616 strcmp(pszAuthorityName,
"EPSG") == 0 &&
1617 pszAuthorityCode != NULL
1619 info->
srid = atoi(pszAuthorityCode);
1622 OSRDestroySpatialReference(hSRS);
1627 rterror(
_(
"convert_raster: could not determine source srid, cannot transform to target srid %d"), config->
out_srid);
1633 if (GDALGetGeoTransform(hdsSrc, info->
gt) != CE_None) {
1634 rtinfo(
_(
"Using default geotransform matrix (0, 1, 0, 0, 0, -1) for raster: %s"), config->
rt_file[idx]);
1642 memcpy(
gt, info->
gt,
sizeof(
double) * 6);
1649 if (info->
nband == NULL) {
1650 rterror(
_(
"convert_raster: Could not allocate memory for storing band indices"));
1660 if (info->
nband == NULL) {
1661 rterror(
_(
"convert_raster: Could not allocate memory for storing band indices"));
1666 info->
nband[i] = i + 1;
1672 rterror(
_(
"convert_raster: Could not allocate memory for storing GDAL data type"));
1678 rterror(
_(
"convert_raster: Could not allocate memory for storing pixel type"));
1684 rterror(
_(
"convert_raster: Could not allocate memory for storing hasnodata flag"));
1690 rterror(
_(
"convert_raster: Could not allocate memory for storing nodata value"));
1700 info->
dim[0] = GDALGetRasterXSize(hdsSrc);
1701 info->
dim[1] = GDALGetRasterYSize(hdsSrc);
1707 hbandSrc = GDALGetRasterBand(hdsSrc, info->
nband[i]);
1710 info->
gdalbandtype[i] = GDALGetRasterDataType(hbandSrc);
1714 rterror(
_(
"convert_raster: The pixel type of band %d is a complex data type. PostGIS raster does not support complex data types"), i + 1);
1718 GDALGetBlockSize(hbandSrc, &naturalx, &naturaly);
1742 calc_tile_size((naturalx > 1) ? (uint32_t)naturalx : info->
dim[0],
1743 (naturaly > 1) ? (uint32_t)naturaly : info->
dim[1],
1772 rtwarn(
_(
"The size of each output tile may exceed 1 GB. Use -t to specify a reasonable tile size"));
1775 if (config->
outdb) {
1779 for (ytile = 0; ytile < ntiles[1]; ytile++) {
1781 if (!config->
pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
1782 _tile_size[1] = info->
dim[1] - (ytile * info->
tile_size[1]);
1786 for (xtile = 0; xtile < ntiles[0]; xtile++) {
1790 if (!config->
pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
1791 _tile_size[0] = info->
dim[0] - (xtile * info->
tile_size[0]);
1796 GDALApplyGeoTransform(
1805 rterror(
_(
"convert_raster: Could not create raster"));
1816 _tile_size[0], _tile_size[1],
1823 rterror(
_(
"convert_raster: Could not create offline band"));
1830 rterror(
_(
"convert_raster: Could not add offlineband to raster"));
1842 if (!tile_is_nodata)
1846 if (!hex && !tile_is_nodata)
1848 rterror(
_(
"convert_raster: Could not convert PostGIS raster to hex WKB"));
1853 if (!tile_is_nodata)
1854 append_stringbuffer(tileset, hex);
1858 if (!insert_records(
1864 rterror(
_(
"convert_raster: Could not convert raster tiles into INSERT or COPY statements"));
1868 rtdealloc_stringbuffer(tileset, 0);
1876 VRTSourcedRasterBandH hbandDst;
1879 for (ytile = 0; ytile < ntiles[1]; ytile++) {
1882 if (!config->
pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
1883 _tile_size[1] = info->
dim[1] - (ytile * info->
tile_size[1]);
1887 for (xtile = 0; xtile < ntiles[0]; xtile++) {
1895 if (!config->
pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
1896 _tile_size[0] = info->
dim[0] - (xtile * info->
tile_size[0]);
1901 GDALApplyGeoTransform(
1914 hdsDst = VRTCreate(_tile_size[0], _tile_size[1]);
1918 GDALSetProjection(hdsDst, info->
srs);
1919 GDALSetGeoTransform(hdsDst,
gt);
1924 hbandDst = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsDst, i + 1);
1927 GDALSetRasterNoDataValue(hbandDst, info->
nodataval[i]);
1930 hbandDst, GDALGetRasterBand(hdsSrc, info->
nband[i]),
1932 _tile_size[0], _tile_size[1],
1934 _tile_size[0], _tile_size[1],
1935 "near", VRT_NODATA_UNSET
1940 VRTFlushCache(hdsDst);
1945 rterror(
_(
"convert_raster: Could not convert VRT dataset to PostGIS raster"));
1955 for (i = 0; i < numbands; i++) {
1962 if (!tile_is_nodata)
1966 if (!hex && !tile_is_nodata)
1968 rterror(
_(
"convert_raster: Could not convert PostGIS raster to hex WKB"));
1974 if (!tile_is_nodata)
1975 append_stringbuffer(tileset, hex);
1981 if (!insert_records(
1987 rterror(
_(
"convert_raster: Could not convert raster tiles into INSERT or COPY statements"));
1992 rtdealloc_stringbuffer(tileset, 0);
2007 assert(config != NULL);
2008 assert(config->
table != NULL);
2012 if (!append_sql_to_buffer(
buffer, strdup(
"BEGIN;"))) {
2013 rterror(
_(
"process_rasters: Could not add BEGIN statement to string buffer"));
2019 if (config->
opt ==
'd') {
2021 rterror(
_(
"process_rasters: Could not add DROP TABLE statement to string buffer"));
2028 rterror(
_(
"process_rasters: Could not add an overview's DROP TABLE statement to string buffer"));
2036 if (config->
opt !=
'a') {
2043 rterror(
_(
"process_rasters: Could not add CREATE TABLE statement to string buffer"));
2055 rterror(
_(
"process_rasters: Could not add an overview's CREATE TABLE statement to string buffer"));
2063 if (config->
opt !=
'p') {
2065 init_rastinfo(&refinfo);
2074 init_rastinfo(&rastinfo);
2075 init_stringbuffer(&tileset);
2078 if (!convert_raster(i, config, &rastinfo, &tileset,
buffer)) {
2079 rterror(
_(
"process_rasters: Could not process raster: %s"), config->
rt_file[i]);
2080 rtdealloc_rastinfo(&rastinfo);
2081 rtdealloc_stringbuffer(&tileset, 0);
2086 if (tileset.
length && !insert_records(
2093 rterror(
_(
"process_rasters: Could not convert raster tiles into INSERT or COPY statements"));
2094 rtdealloc_rastinfo(&rastinfo);
2095 rtdealloc_stringbuffer(&tileset, 0);
2099 rtdealloc_stringbuffer(&tileset, 0);
2102 flush_stringbuffer(
buffer);
2110 if (!build_overview(i, config, &rastinfo, j, &tileset,
buffer)) {
2111 rterror(
_(
"process_rasters: Could not create overview of factor %d for raster %s"), config->
overview[j], config->
rt_file[i]);
2112 rtdealloc_rastinfo(&rastinfo);
2113 rtdealloc_stringbuffer(&tileset, 0);
2117 if (tileset.
length && !insert_records(
2123 rterror(
_(
"process_rasters: Could not convert overview tiles into INSERT or COPY statements"));
2124 rtdealloc_rastinfo(&rastinfo);
2125 rtdealloc_stringbuffer(&tileset, 0);
2129 rtdealloc_stringbuffer(&tileset, 0);
2132 flush_stringbuffer(
buffer);
2138 copy_rastinfo(&refinfo, &rastinfo);
2140 diff_rastinfo(&rastinfo, &refinfo);
2144 rtdealloc_rastinfo(&rastinfo);
2147 rtdealloc_rastinfo(&refinfo);
2158 rterror(
_(
"process_rasters: Could not add CREATE INDEX statement to string buffer"));
2163 if (config->
opt !=
'p') {
2168 rterror(
_(
"process_rasters: Could not add ANALYZE statement to string buffer"));
2181 rterror(
_(
"process_rasters: Could not add an overview's CREATE INDEX statement to string buffer"));
2186 if (config->
opt !=
'p') {
2191 rterror(
_(
"process_rasters: Could not add an overview's ANALYZE statement to string buffer"));
2201 if (!add_raster_constraints(
2206 rterror(
_(
"process:rasters: Could not add AddRasterConstraints statement to string buffer"));
2212 if (!add_raster_constraints(
2217 rterror(
_(
"process_rasters: Could not add an overview's AddRasterConstraints statement to string buffer"));
2227 if (!add_overview_constraints(
2233 rterror(
_(
"process_rasters: Could not add an overview's AddOverviewConstraints statement to string buffer"));
2240 if (!append_sql_to_buffer(
buffer, strdup(
"END;"))) {
2241 rterror(
_(
"process_rasters: Could not add END statement to string buffer"));
2252 rterror(
_(
"process_rasters: Could not add VACUUM statement to string buffer"));
2262 rterror(
_(
"process_rasters: Could not add an overview's VACUUM statement to string buffer"));
2274 main(
int argc,
char **argv) {
2279 char **elements = NULL;
2281 GDALDriverH drv = NULL;
2288 setlocale (LC_ALL,
"");
2289 bindtextdomain (PACKAGE, LOCALEDIR);
2290 textdomain (PACKAGE);
2301 if (config == NULL) {
2302 rterror(
_(
"Could not allocate memory for loader configuration"));
2305 init_config(config);
2311 for (argit = 1; argit < argc; argit++) {
2315 if (
CSEQUAL(argv[argit],
"-s") && argit < argc - 1) {
2316 optarg = argv[++argit];
2317 ptr = strchr(optarg,
':');
2320 sscanf(optarg,
"%d", &config->
srid);
2321 sscanf(ptr,
"%d", &config->
out_srid);
2323 config->
srid = atoi(optarg);
2327 else if (
CSEQUAL(argv[argit],
"-b") && argit < argc - 1) {
2328 elements =
strsplit(argv[++argit],
",", &n);
2330 rterror(
_(
"Could not process -b"));
2331 rtdealloc_config(config);
2336 for (j = 0; j < n; j++) {
2337 char *t =
trim(elements[j]);
2338 char **minmax = NULL;
2348 if (!
array_range(atoi(minmax[0]), atoi(minmax[1]), 1, &range, &p)) {
2349 rterror(
_(
"Could not allocate memory for storing band indices"));
2350 for (l = 0; l < o; l++)
2353 for (j = 0; j < n; j++)
2357 rtdealloc_config(config);
2364 if (range == NULL) {
2365 rterror(
_(
"Could not allocate memory for storing band indices"));
2366 for (l = 0; l < o; l++)
2369 for (j = 0; j < n; j++)
2373 rtdealloc_config(config);
2382 if (config->
nband == NULL) {
2383 rterror(
_(
"Could not allocate memory for storing band indices"));
2385 for (l = 0; l < o; l++)
2388 for (j = 0; j < n; j++)
2392 rtdealloc_config(config);
2396 for (l = 0; l < p; l++, m++)
2397 config->
nband[m] = range[l];
2401 for (l = 0; l < o; l++)
2413 if (config->
nband[j] < 1) {
2414 rterror(
_(
"Band index %d must be greater than 0"), config->
nband[j]);
2415 rtdealloc_config(config);
2421 else if (
CSEQUAL(argv[argit],
"-t") && argit < argc - 1) {
2422 if (
CSEQUAL(argv[++argit],
"auto")) {
2427 elements =
strsplit(argv[argit],
"x", &n);
2429 rterror(
_(
"Could not process -t"));
2430 rtdealloc_config(config);
2434 for (j = 0; j < n; j++) {
2435 char *t =
trim(elements[j]);
2444 for (j = 0; j < 2; j++) {
2446 rterror(
_(
"Tile size must be greater than 0x0"));
2447 rtdealloc_config(config);
2454 else if (
CSEQUAL(argv[argit],
"-P")) {
2458 else if (
CSEQUAL(argv[argit],
"-R")) {
2462 else if (
CSEQUAL(argv[argit],
"-d")) {
2466 else if (
CSEQUAL(argv[argit],
"-a")) {
2470 else if (
CSEQUAL(argv[argit],
"-c")) {
2474 else if (
CSEQUAL(argv[argit],
"-p")) {
2478 else if (
CSEQUAL(argv[argit],
"-f") && argit < argc - 1) {
2479 const size_t len = (strlen(argv[++argit]) + 1);
2482 rterror(
_(
"Could not allocate memory for storing raster column name"));
2483 rtdealloc_config(config);
2489 else if (
CSEQUAL(argv[argit],
"-F")) {
2493 else if (
CSEQUAL(argv[argit],
"-n") && argit < argc - 1) {
2494 const size_t len = (strlen(argv[++argit]) + 1);
2497 rterror(
_(
"Could not allocate memory for storing filename column name"));
2498 rtdealloc_config(config);
2505 else if (
CSEQUAL(argv[argit],
"-l") && argit < argc - 1) {
2506 elements =
strsplit(argv[++argit],
",", &n);
2508 rterror(
_(
"Could not process -l"));
2509 rtdealloc_config(config);
2516 rterror(
_(
"Could not allocate memory for storing overview factors"));
2517 rtdealloc_config(config);
2520 for (j = 0; j < n; j++) {
2521 char *t =
trim(elements[j]);
2533 rtdealloc_config(config);
2539 else if (
CSEQUAL(argv[argit],
"-q")) {
2543 else if (
CSEQUAL(argv[argit],
"-I")) {
2547 else if (
CSEQUAL(argv[argit],
"-M")) {
2551 else if (
CSEQUAL(argv[argit],
"-C")) {
2555 else if (
CSEQUAL(argv[argit],
"-x")) {
2559 else if (
CSEQUAL(argv[argit],
"-r")) {
2563 else if (
CSEQUAL(argv[argit],
"-T") && argit < argc - 1) {
2564 const size_t len = (strlen(argv[++argit]) + 1);
2567 rterror(
_(
"Could not allocate memory for storing tablespace of new table"));
2568 rtdealloc_config(config);
2571 strncpy(config->
tablespace, argv[argit], len);
2574 else if (
CSEQUAL(argv[argit],
"-X") && argit < argc - 1) {
2575 const size_t len = (strlen(argv[++argit]) + 1);
2578 rterror(
_(
"Could not allocate memory for storing tablespace of new indices"));
2579 rtdealloc_config(config);
2585 else if (
CSEQUAL(argv[argit],
"-N") && argit < argc - 1) {
2587 config->
nodataval = atof(argv[++argit]);
2590 else if (
CSEQUAL(argv[argit],
"-k")) {
2594 else if (
CSEQUAL(argv[argit],
"-E") && argit < argc - 1) {
2595 config->
endian = atoi(argv[++argit]);
2599 else if (
CSEQUAL(argv[argit],
"-V") && argit < argc - 1) {
2600 config->
version = atoi(argv[++argit]);
2604 else if (
CSEQUAL(argv[argit],
"-e")) {
2608 else if (
CSEQUAL(argv[argit],
"-Y")) {
2611 if ( argit < argc - 1) {
2612 optarg = argv[argit + 1];
2613 if (atoi(optarg) > 0 ) {
2622 else if (
CSEQUAL(argv[argit],
"-G")) {
2623 uint32_t drv_count = 0;
2625 if (drv_set == NULL || !drv_count) {
2626 rterror(
_(
"Could not get list of available GDAL raster formats"));
2629 printf(
_(
"Supported GDAL raster formats:\n"));
2630 for (j = 0; j < drv_count; j++) {
2631 printf(
_(
" %s\n"), drv_set[j].long_name);
2640 rtdealloc_config(config);
2644 else if (
CSEQUAL(argv[argit],
"-?")) {
2646 rtdealloc_config(config);
2653 if (config->
rt_file == NULL) {
2654 rterror(
_(
"Could not allocate memory for storing raster files"));
2655 rtdealloc_config(config);
2659 len = strlen(argv[argit]) + 1;
2662 rterror(
_(
"Could not allocate memory for storing raster filename"));
2663 rtdealloc_config(config);
2672 rterror(
_(
"Invalid argument combination - cannot use -Y with -s FROM_SRID:TO_SRID"));
2683 rtdealloc_config(config);
2700 if (config->
schema == NULL) {
2701 rterror(
_(
"Could not allocate memory for storing schema name"));
2702 rtdealloc_config(config);
2709 if (config->
table == NULL) {
2710 rterror(
_(
"Could not allocate memory for storing table name"));
2711 rtdealloc_config(config);
2721 if (config->
table == NULL) {
2722 rterror(
_(
"Could not allocate memory for storing table name"));
2723 rtdealloc_config(config);
2731 if (config->
rt_file == NULL) {
2732 rterror(
_(
"Could not reallocate the memory holding raster names"));
2733 rtdealloc_config(config);
2745 drv = GDALIdentifyDriver(config->
rt_file[i], NULL);
2749 rtdealloc_config(config);
2757 rterror(
_(
"Could not allocate memory for cleaned raster filenames"));
2758 rtdealloc_config(config);
2767 rterror(
_(
"Could not allocate memory for cleaned raster filename"));
2768 rtdealloc_config(config);
2771 strcpy(file, config->
rt_file[i]);
2773 for (ptr = file + strlen(file); ptr > file; ptr--) {
2774 if (*ptr ==
'/' || *ptr ==
'\\') {
2782 rterror(
_(
"Could not allocate memory for cleaned raster filename"));
2783 rtdealloc_config(config);
2795 if (config->
table == NULL) {
2801 rterror(
_(
"Could not allocate memory for proxy table name"));
2802 rtdealloc_config(config);
2807 for (ptr = file + strlen(file); ptr > file; ptr--) {
2814 config->
table =
rtalloc(
sizeof(
char) * (strlen(file) + 1));
2815 if (config->
table == NULL) {
2816 rterror(
_(
"Could not allocate memory for proxy table name"));
2817 rtdealloc_config(config);
2820 strcpy(config->
table, file);
2828 rterror(
_(
"Could not allocate memory for default raster column name"));
2829 rtdealloc_config(config);
2839 rterror(
_(
"Could not allocate memory for default filename column name"));
2840 rtdealloc_config(config);
2852 if (config->
schema != NULL)
2854 if (config->
table != NULL)
2874 rterror(
_(
"Could not allocate memory for overview table names"));
2875 rtdealloc_config(config);
2880 sprintf(factor,
"%d", config->
overview[i]);
2884 rterror(
_(
"Could not allocate memory for overview table name"));
2885 rtdealloc_config(config);
2897 rtwarn(
_(
"The schema name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2903 rtwarn(
_(
"The table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2909 rtwarn(
_(
"The column name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2915 rtwarn(
_(
"The column name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2921 rtwarn(
_(
"The tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2927 rtwarn(
_(
"The index tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2935 rtwarn(
_(
"The overview table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2947 if (config->
schema != NULL) {
2950 rterror(
_(
"Could not allocate memory for quoting schema name"));
2951 rtdealloc_config(config);
2955 sprintf(tmp,
"\"%s\".", config->
schema);
2959 if (config->
table != NULL) {
2960 tmp =
rtalloc(
sizeof(
char) * (strlen(config->
table) + 3));
2962 rterror(
_(
"Could not allocate memory for quoting table name"));
2963 rtdealloc_config(config);
2967 sprintf(tmp,
"\"%s\"", config->
table);
2969 config->
table = tmp;
2974 rterror(
_(
"Could not allocate memory for quoting raster column name"));
2975 rtdealloc_config(config);
2986 rterror(
_(
"Could not allocate memory for quoting raster column name"));
2987 rtdealloc_config(config);
2998 rterror(
_(
"Could not allocate memory for quoting tablespace name"));
2999 rtdealloc_config(config);
3010 rterror(
_(
"Could not allocate memory for quoting index tablespace name"));
3011 rtdealloc_config(config);
3023 rterror(
_(
"Could not allocate memory for quoting overview table name"));
3024 rtdealloc_config(config);
3041 rterror(
_(
"Could not allocate memory for output string buffer"));
3042 rtdealloc_config(config);
3045 init_stringbuffer(
buffer);
3048 if (!process_rasters(config,
buffer)) {
3049 rterror(
_(
"Unable to process rasters"));
3050 rtdealloc_stringbuffer(
buffer, 1);
3051 rtdealloc_config(config);
3055 flush_stringbuffer(
buffer);
3057 rtdealloc_stringbuffer(
buffer, 1);
3058 rtdealloc_config(config);
char result[OUT_DOUBLE_BUFFER_SIZE]
int main(int argc, char *argv[])
#define SRID_UNKNOWN
Unknown SRID value.
void * default_rt_allocator(size_t size)
The default memory/logging handlers installed by lwgeom_install_default_allocators()
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
rt_pixtype rt_util_gdal_datatype_to_pixtype(GDALDataType gdt)
Convert GDALDataType to rt_pixtype.
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
void void rtinfo(const char *fmt,...) __attribute__((format(printf
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
char * rt_raster_to_hexwkb(rt_raster raster, int outasin, uint32_t *hexwkbsize)
Return this raster in HEXWKB form (null-terminated hex)
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
void default_rt_deallocator(void *mem)
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
void rt_band_destroy(rt_band band)
Destroy a raster band.
void * rtrealloc(void *mem, size_t size)
uint16_t rt_raster_get_num_bands(rt_raster raster)
rt_band rt_band_new_offline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t bandNum, const char *path)
Create an out-db rt_band.
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
void rtdealloc(void *mem)
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
int rt_band_get_ownsdata_flag(rt_band band)
Return 0 (FALSE) or non-zero (TRUE) indicating if rt_band is responsible for managing the memory for ...
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
void * default_rt_reallocator(void *mem, size_t size)
void rt_set_handlers(rt_allocator allocator, rt_reallocator reallocator, rt_deallocator deallocator, rt_message_handler error_handler, rt_message_handler info_handler, rt_message_handler warning_handler)
This function is called when the PostgreSQL backend is taking care of the memory and we want to use p...
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Datum buffer(PG_FUNCTION_ARGS)
static char * strreplace(const char *str, const char *oldstr, const char *newstr, int *count)
static void loader_rt_warning_handler(const char *fmt, va_list ap) __attribute__((format(printf
static char ** strsplit(const char *str, const char *delimiter, uint32_t *n)
static int array_range(int min, int max, int step, int **range, uint32_t *len)
static char * chartrim(const char *input, char *remove)
static char * trim(const char *input)
static void loader_rt_info_handler(const char *fmt, va_list ap) __attribute__((format(printf
static void rt_init_allocators(void)
static char * strtolower(char *str)
static void raster_destroy(rt_raster raster)
static void loader_rt_error_handler(const char *fmt, va_list ap) __attribute__((format(printf
#define POSTGIS_GDAL_VERSION
#define POSTGIS_LIB_VERSION
uint32_t max_tiles_per_copy
max tiles per copy
GDALDataType * gdalbandtype