30 #include "ogr_srs_api.h"
33 #define xstr(s) str(s)
38 static const char *label =
"ERROR: ";
39 char newfmt[1024] = {0};
40 snprintf(newfmt, 1024,
"%s%s\n", label,
fmt);
42 vfprintf(stderr, newfmt, ap);
48 static const char *label =
"WARNING: ";
49 char newfmt[1024] = {0};
50 snprintf(newfmt, 1024,
"%s%s\n", label,
fmt);
52 vfprintf(stderr, newfmt, ap);
58 static const char *label =
"INFO: ";
59 char newfmt[1024] = {0};
60 snprintf(newfmt, 1024,
"%s%s\n", label,
fmt);
62 vfprintf(stderr, newfmt, ap);
82 for (i = 0; i < nbands; i++) {
84 if (
band == NULL)
continue;
96 array_range(
int min,
int max,
int step,
int **range, uint32_t *len) {
101 *len = (uint32_t) ((abs(max - min) + 1 + (step / 2)) / step);
102 *range =
rtalloc(
sizeof(
int) * *len);
105 for (i = min, j = 0; i <= max; i += step, j++)
108 else if (max < min) {
109 if (step > 0) step *= -1;
110 for (i = min, j = 0; i >= max; i += step, j++)
113 else if (min == max) {
146 const char *oldstr,
const char *newstr,
149 const char *tmp =
str;
153 int oldlen = strlen(oldstr);
154 int newlen = strlen(newstr);
158 while ((tmp = strstr(tmp, oldstr)) != NULL && found != limit)
159 found++, tmp += oldlen;
161 length = strlen(
str) + found * (newlen - oldlen);
163 rterror(
_(
"strreplace: Not enough memory"));
172 while ((limit-- > 0) && (tmp = strstr(tmp, oldstr)) != NULL) {
173 length = (tmp -
str);
175 strcpy(
result + (reslen += length), newstr);
192 for (j = strlen(
str) - 1; j >= 0; j--)
210 tmp =
rtalloc(
sizeof(
char) * (strlen(
str) + 1));
212 rterror(
_(
"strsplit: Not enough memory"));
217 if (!strlen(tmp) || !delimiter || !strlen(delimiter)) {
219 rtn = (
char **)
rtalloc(*n *
sizeof(
char *));
221 rterror(
_(
"strsplit: Not enough memory"));
224 rtn[0] = (
char *)
rtalloc(
sizeof(
char) * (strlen(tmp) + 1));
225 if (NULL == rtn[0]) {
226 rterror(
_(
"strsplit: Not enough memory"));
234 token = strtok(tmp, delimiter);
235 while (token != NULL) {
237 rtn = (
char **)
rtalloc(
sizeof(
char *));
240 rtn = (
char **)
rtrealloc(rtn, (*n + 1) *
sizeof(
char *));
243 rterror(
_(
"strsplit: Not enough memory"));
248 rtn[*n] = (
char *)
rtalloc(
sizeof(
char) * (strlen(token) + 1));
249 if (NULL == rtn[*n]) {
250 rterror(
_(
"strsplit: Not enough memory"));
254 strcpy(rtn[*n], token);
257 token = strtok(NULL, delimiter);
274 return (
char *) input;
277 while (isspace(*input))
281 ptr = ((
char *) input) + strlen(input);
282 while (isspace(*--ptr))
285 len = strlen(input) - offset + 1;
286 rtn =
rtalloc(
sizeof(
char) * len);
288 rterror(
_(
"trim: Not enough memory"));
291 strncpy(rtn, input, len);
306 return (
char *) input;
309 while (strchr(remove, *input) != NULL)
313 ptr = ((
char *) input) + strlen(input);
314 while (strchr(remove, *--ptr) != NULL)
317 len = strlen(input) - offset + 1;
318 rtn =
rtalloc(
sizeof(
char) * len);
320 rterror(
_(
"chartrim: Not enough memory"));
323 strncpy(rtn, input, len);
324 rtn[strlen(input) - offset] =
'\0';
333 "USAGE: raster2pgsql [<options>] <raster>[ <raster>[ ...]] [[<schema>.]<table>]\n"
334 " Multiple rasters can also be specified using wildcards (*,?).\n"
347 " -s <srid> Set the SRID field. Defaults to %d. If SRID not\n"
348 " provided or is %d, raster's metadata will be checked to\n"
349 " determine an appropriate SRID.\n"
352 " -b <band> Index (1-based) of band to extract from raster. For more\n"
353 " than one band index, separate with comma (,). Ranges can be\n"
354 " defined by separating with dash (-). If unspecified, all bands\n"
355 " of raster will be extracted.\n"
358 " -t <tile size> Cut raster into tiles to be inserted one per\n"
359 " table row. <tile size> is expressed as WIDTHxHEIGHT.\n"
360 " <tile size> can also be \"auto\" to allow the loader to compute\n"
361 " an appropriate tile size using the first raster and applied to\n"
365 " -P Pad right-most and bottom-most tiles to guarantee that all tiles\n"
366 " have the same width and height.\n"
369 " -R Register the raster as an out-of-db (filesystem) raster. Provided\n"
370 " raster should have absolute path to the file\n"
373 " (-d|a|c|p) These are mutually exclusive options:\n"
374 " -d Drops the table, then recreates it and populates\n"
375 " it with current raster data.\n"
376 " -a Appends raster into current table, must be\n"
377 " exactly the same table schema.\n"
378 " -c Creates a new table and populates it, this is the\n"
379 " default if you do not specify any options.\n"
380 " -p Prepare mode, only creates the table.\n"
383 " -f <column> Specify the name of the raster column\n"
386 " -F Add a column with the filename of the raster.\n"
389 " -n <column> Specify the name of the filename column. Implies -F.\n"
392 " -l <overview factor> Create overview of the raster. For more than\n"
393 " one factor, separate with comma(,). Overview table name follows\n"
394 " the pattern o_<overview factor>_<table>. Created overview is\n"
395 " stored in the database and is not affected by -R.\n"
398 " -q Wrap PostgreSQL identifiers in quotes.\n"
401 " -I Create a GIST spatial index on the raster column. The ANALYZE\n"
402 " command will automatically be issued for the created index.\n"
405 " -M Run VACUUM ANALYZE on the table of the raster column. Most\n"
406 " useful when appending raster to existing table with -a.\n"
409 " -C Set the standard set of constraints on the raster\n"
410 " column after the rasters are loaded. Some constraints may fail\n"
411 " if one or more rasters violate the constraint.\n"
412 " -x Disable setting the max extent constraint. Only applied if\n"
413 " -C flag is also used.\n"
414 " -r Set the constraints (spatially unique and coverage tile) for\n"
415 " regular blocking. Only applied if -C flag is also used.\n"
418 " -T <tablespace> Specify the tablespace for the new table.\n"
419 " Note that indices (including the primary key) will still use\n"
420 " the default tablespace unless the -X flag is also used.\n"
423 " -X <tablespace> Specify the tablespace for the table's new index.\n"
424 " This applies to the primary key and the spatial index if\n"
425 " the -I flag is used.\n"
428 " -N <nodata> NODATA value to use on bands without a NODATA value.\n"
431 " -k Keep empty tiles by skipping NODATA value checks for each raster band. \n"
434 " -E <endian> Control endianness of generated binary output of\n"
435 " raster. Use 0 for XDR and 1 for NDR (default). Only NDR\n"
436 " is supported at this time.\n"
439 " -V <version> Specify version of output WKB format. Default\n"
440 " is 0. Only 0 is supported at this time.\n"
443 " -e Execute each statement individually, do not use a transaction.\n"
446 " -Y <max_rows_per_copy> Use COPY statements instead of INSERT statements. \n"
447 " Optionally specify <max_rows_per_copy>; default 50 when not specified. \n"
451 " -G Print the supported GDAL raster formats.\n"
454 " -? Display this help screen.\n"
459 calc_tile_size(uint32_t dimX, uint32_t dimY,
int *tileX,
int *tileY)
461 uint32_t min_tile_size = 30;
462 uint32_t max_tile_size = 300;
464 for (uint8_t current_dimension = 0; current_dimension <= 1; current_dimension++)
466 uint32_t img_size = (current_dimension == 0) ? dimX : dimY;
467 uint32_t best_gap = max_tile_size;
468 uint32_t best_size = img_size;
470 if (img_size > max_tile_size)
472 for (uint32_t tile_size = max_tile_size; tile_size >= min_tile_size; tile_size--)
474 uint32_t gap = img_size % tile_size;
478 best_size = tile_size;
483 if (current_dimension == 0)
494 memset(info->
dim, 0,
sizeof(uint32_t) * 2);
501 memset(info->
gt, 0,
sizeof(
double) * 6);
502 memset(info->
tile_size, 0,
sizeof(
int) * 2);
507 if (info->
srs != NULL)
523 if (src->
srs != NULL) {
525 if (dst->
srs == NULL) {
526 rterror(
_(
"copy_rastinfo: Not enough memory"));
529 strcpy(dst->
srs, src->
srs);
531 memcpy(dst->
dim, src->
dim,
sizeof(uint32_t) * 2);
535 if (dst->
nband == NULL) {
536 rterror(
_(
"copy_rastinfo: Not enough memory"));
544 rterror(
_(
"copy_rastinfo: Not enough memory"));
552 rterror(
_(
"copy_rastinfo: Not enough memory"));
560 rterror(
_(
"copy_rastinfo: Not enough memory"));
568 rterror(
_(
"copy_rastinfo: Not enough memory"));
573 memcpy(dst->
gt, src->
gt,
sizeof(
double) * 6);
581 static uint8_t msg[6] = {0};
589 rtwarn(
_(
"Different number of bands found in the set of rasters being converted to PostGIS raster"));
596 if (
x->bandtype[i] != ref->
bandtype[i]) {
597 rtwarn(
_(
"Different pixel types found for band %d in the set of rasters being converted to PostGIS raster"), ref->
nband[i]);
607 rtwarn(
_(
"Different hasnodata flags found for band %d in the set of rasters being converted to PostGIS raster"), ref->
nband[i]);
616 if (!
x->hasnodata[i] && !ref->
hasnodata[i])
continue;
618 rtwarn(
_(
"Different NODATA values found for band %d in the set of rasters being converted to PostGIS raster"), ref->
nband[i]);
635 rterror(
_(
"diff_rastinfo: Could not allocate memory for raster alignment test"));
648 rterror(
_(
"diff_rastinfo: Could not run raster alignment test"));
653 rtwarn(
_(
"Raster with different alignment found in the set of rasters being converted to PostGIS raster"));
660 for (i = 0; i < 2; i++) {
662 rtwarn(
_(
"Different tile sizes found in the set of rasters being converted to PostGIS raster"));
676 config->
table = NULL;
685 config->
nband = NULL;
687 memset(config->
tile_size, 0,
sizeof(
int) * 2);
721 if (config->
schema != NULL)
723 if (config->
table != NULL)
758 for (i = 0; i <
buffer->length; i++) {
759 if (
buffer->line[i] != NULL)
775 for (i = 0; i <
buffer->length; i++) {
776 printf(
"%s\n",
buffer->line[i]);
782 dump_stringbuffer(
buffer);
783 rtdealloc_stringbuffer(
buffer, 0);
792 if (
buffer->line == NULL) {
793 rterror(
_(
"append_stringbuffer: Could not allocate memory for appending string to buffer"));
805 flush_stringbuffer(
buffer);
811 copy_from(
const char *schema,
const char *table,
const char *column,
812 const char *filename,
const char *file_column_name,
818 assert(table != NULL);
819 assert(column != NULL);
821 len = strlen(
"COPY () FROM stdin;") + 1;
823 len += strlen(schema);
824 len += strlen(table);
825 len += strlen(column);
826 if (filename != NULL)
827 len += strlen(
",") + strlen(file_column_name);
831 rterror(
_(
"copy_from: Could not allocate memory for COPY statement"));
834 sprintf(
sql,
"COPY %s%s (%s%s%s) FROM stdin;",
835 (schema != NULL ? schema :
""),
838 (filename != NULL ?
"," :
""),
839 (filename != NULL ? file_column_name :
"")
852 append_sql_to_buffer(
buffer, strdup(
"\\."));
859 const char *schema,
const char *table,
const char *column,
860 const char *filename,
const char *file_column_name,
861 int copy_statements,
int out_srid,
869 assert(table != NULL);
870 assert(column != NULL);
873 if (copy_statements) {
876 schema, table, column,
877 (file_column_name ? filename : NULL), file_column_name,
880 rterror(
_(
"insert_records: Could not add COPY statement to string buffer"));
886 if (filename != NULL)
891 len = strlen(tileset->
line[
x]) + 1;
893 if (filename != NULL)
894 len += strlen(fn) + 1;
898 rterror(
_(
"insert_records: Could not allocate memory for COPY statement"));
901 sprintf(
sql,
"%s%s%s",
903 (filename != NULL ?
"\t" :
""),
904 (filename != NULL ? fn :
"")
911 if (!copy_from_end(
buffer)) {
912 rterror(
_(
"process_rasters: Could not add COPY end statement to string buffer"));
919 len = strlen(
"INSERT INTO () VALUES (ST_Transform(''::raster,xxxxxxxxx));") + 1;
921 len += strlen(schema);
922 len += strlen(table);
923 len += strlen(column);
924 if (filename != NULL)
925 len += strlen(
",") + strlen(file_column_name);
928 if (filename != NULL)
935 sqllen += strlen(tileset->
line[
x]);
936 if (filename != NULL)
937 sqllen += strlen(
",''") + strlen(fn);
941 rterror(
_(
"insert_records: Could not allocate memory for INSERT statement"));
945 ptr += sprintf(
sql,
"INSERT INTO %s%s (%s%s%s) VALUES (",
946 (schema != NULL ? schema :
""),
949 (filename != NULL ?
"," :
""),
950 (filename != NULL ? file_column_name :
"")
953 ptr += sprintf(ptr,
"ST_Transform(");
955 ptr += sprintf(ptr,
"'%s'::raster",
959 ptr += sprintf(ptr,
", %d)", out_srid);
961 if (filename != NULL) {
962 ptr += sprintf(ptr,
",'%s'", fn);
964 ptr += sprintf(ptr,
");");
980 len = strlen(
"DROP TABLE IF EXISTS ;") + 1;
982 len += strlen(schema);
983 len += strlen(table);
987 rterror(
_(
"drop_table: Could not allocate memory for DROP TABLE statement"));
990 sprintf(
sql,
"DROP TABLE IF EXISTS %s%s;",
991 (schema != NULL ? schema :
""),
1002 const char *schema,
const char *table,
const char *column,
1003 const int file_column,
const char *file_column_name,
1004 const char *tablespace,
const char *idx_tablespace,
1010 assert(table != NULL);
1011 assert(column != NULL);
1013 len = strlen(
"CREATE TABLE (\"rid\" serial PRIMARY KEY, raster);") + 1;
1015 len += strlen(schema);
1016 len += strlen(table);
1017 len += strlen(column);
1019 len += strlen(
", text") + strlen(file_column_name);
1020 if (tablespace != NULL)
1021 len += strlen(
" TABLESPACE ") + strlen(tablespace);
1022 if (idx_tablespace != NULL)
1023 len += strlen(
" USING INDEX TABLESPACE ") + strlen(idx_tablespace);
1027 rterror(
_(
"create_table: Could not allocate memory for CREATE TABLE statement"));
1030 sprintf(
sql,
"CREATE TABLE %s%s (\"rid\" serial PRIMARY KEY%s%s,%s raster%s%s%s)%s%s;",
1031 (schema != NULL ? schema :
""),
1033 (idx_tablespace != NULL ?
" USING INDEX TABLESPACE " :
""),
1034 (idx_tablespace != NULL ? idx_tablespace :
""),
1036 (file_column ?
"," :
""),
1037 (file_column ? file_column_name :
""),
1038 (file_column ?
" text" :
""),
1039 (tablespace != NULL ?
" TABLESPACE " :
""),
1040 (tablespace != NULL ? tablespace :
"")
1050 const char *schema,
const char *table,
const char *column,
1051 const char *tablespace,
1056 char *_table = NULL;
1057 char *_column = NULL;
1059 assert(table != NULL);
1060 assert(column != NULL);
1066 len = strlen(
"CREATE INDEX \"__gist\" ON USING gist (st_convexhull());") + 1;
1068 len += strlen(schema);
1069 len += strlen(_table);
1070 len += strlen(_column);
1071 len += strlen(table);
1072 len += strlen(column);
1073 if (tablespace != NULL)
1074 len += strlen(
" TABLESPACE ") + strlen(tablespace);
1078 rterror(
_(
"create_index: Could not allocate memory for CREATE INDEX statement"));
1083 sprintf(
sql,
"CREATE INDEX ON %s%s USING gist (st_convexhull(%s))%s%s;",
1084 (schema != NULL ? schema :
""),
1087 (tablespace != NULL ?
" TABLESPACE " :
""),
1088 (tablespace != NULL ? tablespace :
"")
1100 const char *schema,
const char *table,
1106 assert(table != NULL);
1108 len = strlen(
"ANALYZE ;") + 1;
1110 len += strlen(schema);
1111 len += strlen(table);
1115 rterror(
_(
"analyze_table: Could not allocate memory for ANALYZE TABLE statement"));
1118 sprintf(
sql,
"ANALYZE %s%s;",
1119 (schema != NULL ? schema :
""),
1130 const char *schema,
const char *table,
1136 assert(table != NULL);
1138 len = strlen(
"VACUUM ANALYZE ;") + 1;
1140 len += strlen(schema);
1141 len += strlen(table);
1145 rterror(
_(
"vacuum_table: Could not allocate memory for VACUUM statement"));
1148 sprintf(
sql,
"VACUUM ANALYZE %s%s;",
1149 (schema != NULL ? schema :
""),
1159 add_raster_constraints(
1160 const char *schema,
const char *table,
const char *column,
1161 int regular_blocking,
int max_extent,
1168 char *_schema = NULL;
1169 char *_table = NULL;
1170 char *_column = NULL;
1172 assert(table != NULL);
1173 assert(column != NULL);
1176 if (schema != NULL) {
1195 len = strlen(
"SELECT AddRasterConstraints('','','',TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,TRUE,TRUE,TRUE,TRUE,FALSE);") + 1;
1196 if (_schema != NULL)
1197 len += strlen(_schema);
1198 len += strlen(_table);
1199 len += strlen(_column);
1203 rterror(
_(
"add_raster_constraints: Could not allocate memory for AddRasterConstraints statement"));
1206 sprintf(
sql,
"SELECT AddRasterConstraints('%s','%s','%s',TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,%s,TRUE,TRUE,TRUE,TRUE,%s);",
1207 (_schema != NULL ? _schema :
""),
1210 (regular_blocking ?
"TRUE" :
"FALSE"),
1211 (max_extent ?
"TRUE" :
"FALSE")
1214 if (_schema != NULL)
1225 add_overview_constraints(
1226 const char *ovschema,
const char *ovtable,
const char *ovcolumn,
1227 const char *schema,
const char *table,
const char *column,
1236 char *_ovschema = NULL;
1237 char *_ovtable = NULL;
1238 char *_ovcolumn = NULL;
1240 char *_schema = NULL;
1241 char *_table = NULL;
1242 char *_column = NULL;
1244 assert(ovtable != NULL);
1245 assert(ovcolumn != NULL);
1246 assert(table != NULL);
1247 assert(column != NULL);
1251 if (ovschema != NULL) {
1255 _tmp =
strreplace(_ovschema,
"'",
"''", NULL);
1262 _ovtable =
strreplace(_tmp,
"'",
"''", NULL);
1267 _ovcolumn =
strreplace(_tmp,
"'",
"''", NULL);
1271 if (schema != NULL) {
1290 len = strlen(
"SELECT AddOverviewConstraints('','','','','','',);") + 5;
1291 if (_ovschema != NULL)
1292 len += strlen(_ovschema);
1293 len += strlen(_ovtable);
1294 len += strlen(_ovcolumn);
1295 if (_schema != NULL)
1296 len += strlen(_schema);
1297 len += strlen(_table);
1298 len += strlen(_column);
1302 rterror(
_(
"add_overview_constraints: Could not allocate memory for AddOverviewConstraints statement"));
1305 sprintf(
sql,
"SELECT AddOverviewConstraints('%s','%s','%s','%s','%s','%s',%d);",
1306 (_ovschema != NULL ? _ovschema :
""),
1309 (_schema != NULL ? _schema :
""),
1315 if (_ovschema != NULL)
1320 if (_schema != NULL)
1332 GDALDatasetH hdsSrc;
1334 VRTSourcedRasterBandH hbandOv;
1335 double gtOv[6] = {0.};
1340 const char *ovtable = NULL;
1343 VRTSourcedRasterBandH hbandDst;
1344 int tile_size[2] = {0};
1345 int _tile_size[2] = {0};
1346 int ntiles[2] = {1, 1};
1349 double gt[6] = {0.};
1353 uint32_t hexlen = 0;
1355 hdsSrc = GDALOpenShared(config->
rt_file[idx], GA_ReadOnly);
1356 if (hdsSrc == NULL) {
1357 rterror(
_(
"build_overview: Could not open raster: %s"), config->
rt_file[idx]);
1362 memcpy(gtOv, info->
gt,
sizeof(
double) * 6);
1365 rterror(
_(
"build_overview: Invalid overview index: %d"), ovx);
1377 dimOv[0] = (int) (info->
dim[0] + (factor / 2)) / factor;
1378 dimOv[1] = (int) (info->
dim[1] + (factor / 2)) / factor;
1381 hdsOv = VRTCreate(dimOv[0], dimOv[1]);
1385 GDALSetProjection(hdsOv, info->
srs);
1391 GDALSetGeoTransform(hdsOv, gtOv);
1396 hbandOv = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsOv, j + 1);
1399 GDALSetRasterNoDataValue(hbandOv, info->
nodataval[j]);
1402 hbandOv, GDALGetRasterBand(hdsSrc, info->
nband[j]),
1404 info->
dim[0], info->
dim[1],
1407 "near", VRT_NODATA_UNSET
1412 VRTFlushCache(hdsOv);
1416 tile_size[0] = dimOv[0];
1420 tile_size[1] = dimOv[1];
1426 tile_size[0] != dimOv[0] &&
1427 tile_size[1] != dimOv[1]
1429 ntiles[0] = (dimOv[0] + tile_size[0] - 1) / tile_size[0];
1430 ntiles[1] = (dimOv[1] + tile_size[1] - 1) / tile_size[1];
1434 memcpy(
gt, gtOv,
sizeof(
double) * 6);
1438 for (ytile = 0; ytile < ntiles[1]; ytile++) {
1441 if (!config->
pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
1442 _tile_size[1] = dimOv[1] - (ytile * tile_size[1]);
1444 _tile_size[1] = tile_size[1];
1446 for (xtile = 0; xtile < ntiles[0]; xtile++) {
1453 if (!config->
pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
1454 _tile_size[0] = dimOv[0] - (xtile * tile_size[0]);
1456 _tile_size[0] = tile_size[0];
1459 GDALApplyGeoTransform(
1461 xtile * tile_size[0], ytile * tile_size[1],
1466 hdsDst = VRTCreate(_tile_size[0], _tile_size[1]);
1470 GDALSetProjection(hdsDst, info->
srs);
1471 GDALSetGeoTransform(hdsDst,
gt);
1476 hbandDst = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsDst, j + 1);
1479 GDALSetRasterNoDataValue(hbandDst, info->
nodataval[j]);
1482 hbandDst, GDALGetRasterBand(hdsOv, j + 1),
1483 xtile * tile_size[0], ytile * tile_size[1],
1484 _tile_size[0], _tile_size[1],
1486 _tile_size[0], _tile_size[1],
1487 "near", VRT_NODATA_UNSET
1492 VRTFlushCache(hdsDst);
1497 rterror(
_(
"build_overview: Could not convert VRT dataset to PostGIS raster"));
1510 rterror(
_(
"build_overview: Could not convert PostGIS raster to hex WKB"));
1516 append_stringbuffer(tileset, hex);
1522 if (!insert_records(
1528 rterror(
_(
"build_overview: Could not convert raster tiles into INSERT or COPY statements"));
1533 rtdealloc_stringbuffer(tileset, 0);
1545 GDALDatasetH hdsSrc;
1546 GDALRasterBandH hbandSrc;
1549 int ntiles[2] = {1, 1};
1550 int _tile_size[2] = {0, 0};
1555 double gt[6] = {0.};
1556 const char* pszProjectionRef = NULL;
1560 uint32_t numbands = 0;
1563 uint32_t hexlen = 0;
1567 hdsSrc = GDALOpenShared(config->
rt_file[idx], GA_ReadOnly);
1568 if (hdsSrc == NULL) {
1569 rterror(
_(
"convert_raster: Could not open raster: %s"), config->
rt_file[idx]);
1573 nband = GDALGetRasterCount(hdsSrc);
1575 rterror(
_(
"convert_raster: No bands found in raster: %s"), config->
rt_file[idx]);
1583 rterror(
_(
"convert_raster: Band %d not found in raster: %s"), config->
nband[i], config->
rt_file[idx]);
1590 pszProjectionRef = GDALGetProjectionRef(hdsSrc);
1591 if (pszProjectionRef != NULL && pszProjectionRef[0] !=
'\0') {
1592 info->
srs =
rtalloc(
sizeof(
char) * (strlen(pszProjectionRef) + 1));
1593 if (info->
srs == NULL) {
1594 rterror(
_(
"convert_raster: Could not allocate memory for storing SRS"));
1598 strcpy(info->
srs, pszProjectionRef);
1601 OGRSpatialReferenceH hSRS = OSRNewSpatialReference(NULL);
1602 if (OSRSetFromUserInput(hSRS, pszProjectionRef) == OGRERR_NONE) {
1603 const char* pszAuthorityName = OSRGetAuthorityName(hSRS, NULL);
1604 const char* pszAuthorityCode = OSRGetAuthorityCode(hSRS, NULL);
1606 pszAuthorityName != NULL &&
1607 strcmp(pszAuthorityName,
"EPSG") == 0 &&
1608 pszAuthorityCode != NULL
1610 info->
srid = atoi(pszAuthorityCode);
1613 OSRDestroySpatialReference(hSRS);
1618 rterror(
_(
"convert_raster: could not determine source srid, cannot transform to target srid %d"), config->
out_srid);
1624 if (GDALGetGeoTransform(hdsSrc, info->
gt) != CE_None) {
1625 rtinfo(
_(
"Using default geotransform matrix (0, 1, 0, 0, 0, -1) for raster: %s"), config->
rt_file[idx]);
1633 memcpy(
gt, info->
gt,
sizeof(
double) * 6);
1640 if (info->
nband == NULL) {
1641 rterror(
_(
"convert_raster: Could not allocate memory for storing band indices"));
1651 if (info->
nband == NULL) {
1652 rterror(
_(
"convert_raster: Could not allocate memory for storing band indices"));
1657 info->
nband[i] = i + 1;
1663 rterror(
_(
"convert_raster: Could not allocate memory for storing GDAL data type"));
1669 rterror(
_(
"convert_raster: Could not allocate memory for storing pixel type"));
1675 rterror(
_(
"convert_raster: Could not allocate memory for storing hasnodata flag"));
1681 rterror(
_(
"convert_raster: Could not allocate memory for storing nodata value"));
1691 info->
dim[0] = GDALGetRasterXSize(hdsSrc);
1692 info->
dim[1] = GDALGetRasterYSize(hdsSrc);
1698 hbandSrc = GDALGetRasterBand(hdsSrc, info->
nband[i]);
1701 info->
gdalbandtype[i] = GDALGetRasterDataType(hbandSrc);
1705 rterror(
_(
"convert_raster: The pixel type of band %d is a complex data type. PostGIS raster does not support complex data types"), i + 1);
1709 GDALGetBlockSize(hbandSrc, &naturalx, &naturaly);
1733 calc_tile_size((naturalx > 1) ? (uint32_t)naturalx : info->
dim[0],
1734 (naturaly > 1) ? (uint32_t)naturaly : info->
dim[1],
1763 rtwarn(
_(
"The size of each output tile may exceed 1 GB. Use -t to specify a reasonable tile size"));
1766 if (config->
outdb) {
1770 for (ytile = 0; ytile < ntiles[1]; ytile++) {
1772 if (!config->
pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
1773 _tile_size[1] = info->
dim[1] - (ytile * info->
tile_size[1]);
1777 for (xtile = 0; xtile < ntiles[0]; xtile++) {
1781 if (!config->
pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
1782 _tile_size[0] = info->
dim[0] - (xtile * info->
tile_size[0]);
1787 GDALApplyGeoTransform(
1796 rterror(
_(
"convert_raster: Could not create raster"));
1807 _tile_size[0], _tile_size[1],
1814 rterror(
_(
"convert_raster: Could not create offline band"));
1821 rterror(
_(
"convert_raster: Could not add offlineband to raster"));
1833 if (!tile_is_nodata)
1837 if (!hex && !tile_is_nodata)
1839 rterror(
_(
"convert_raster: Could not convert PostGIS raster to hex WKB"));
1844 if (!tile_is_nodata)
1845 append_stringbuffer(tileset, hex);
1849 if (!insert_records(
1855 rterror(
_(
"convert_raster: Could not convert raster tiles into INSERT or COPY statements"));
1859 rtdealloc_stringbuffer(tileset, 0);
1867 VRTSourcedRasterBandH hbandDst;
1870 for (ytile = 0; ytile < ntiles[1]; ytile++) {
1873 if (!config->
pad_tile && ntiles[1] > 1 && (ytile + 1) == ntiles[1])
1874 _tile_size[1] = info->
dim[1] - (ytile * info->
tile_size[1]);
1878 for (xtile = 0; xtile < ntiles[0]; xtile++) {
1886 if (!config->
pad_tile && ntiles[0] > 1 && (xtile + 1) == ntiles[0])
1887 _tile_size[0] = info->
dim[0] - (xtile * info->
tile_size[0]);
1892 GDALApplyGeoTransform(
1905 hdsDst = VRTCreate(_tile_size[0], _tile_size[1]);
1909 GDALSetProjection(hdsDst, info->
srs);
1910 GDALSetGeoTransform(hdsDst,
gt);
1915 hbandDst = (VRTSourcedRasterBandH) GDALGetRasterBand(hdsDst, i + 1);
1918 GDALSetRasterNoDataValue(hbandDst, info->
nodataval[i]);
1921 hbandDst, GDALGetRasterBand(hdsSrc, info->
nband[i]),
1923 _tile_size[0], _tile_size[1],
1925 _tile_size[0], _tile_size[1],
1926 "near", VRT_NODATA_UNSET
1931 VRTFlushCache(hdsDst);
1936 rterror(
_(
"convert_raster: Could not convert VRT dataset to PostGIS raster"));
1946 for (i = 0; i < numbands; i++) {
1953 if (!tile_is_nodata)
1957 if (!hex && !tile_is_nodata)
1959 rterror(
_(
"convert_raster: Could not convert PostGIS raster to hex WKB"));
1965 if (!tile_is_nodata)
1966 append_stringbuffer(tileset, hex);
1972 if (!insert_records(
1978 rterror(
_(
"convert_raster: Could not convert raster tiles into INSERT or COPY statements"));
1983 rtdealloc_stringbuffer(tileset, 0);
1998 assert(config != NULL);
1999 assert(config->
table != NULL);
2003 if (!append_sql_to_buffer(
buffer, strdup(
"BEGIN;"))) {
2004 rterror(
_(
"process_rasters: Could not add BEGIN statement to string buffer"));
2010 if (config->
opt ==
'd') {
2012 rterror(
_(
"process_rasters: Could not add DROP TABLE statement to string buffer"));
2019 rterror(
_(
"process_rasters: Could not add an overview's DROP TABLE statement to string buffer"));
2027 if (config->
opt !=
'a') {
2034 rterror(
_(
"process_rasters: Could not add CREATE TABLE statement to string buffer"));
2046 rterror(
_(
"process_rasters: Could not add an overview's CREATE TABLE statement to string buffer"));
2054 if (config->
opt !=
'p') {
2056 init_rastinfo(&refinfo);
2065 init_rastinfo(&rastinfo);
2066 init_stringbuffer(&tileset);
2069 if (!convert_raster(i, config, &rastinfo, &tileset,
buffer)) {
2070 rterror(
_(
"process_rasters: Could not process raster: %s"), config->
rt_file[i]);
2071 rtdealloc_rastinfo(&rastinfo);
2072 rtdealloc_stringbuffer(&tileset, 0);
2077 if (tileset.
length && !insert_records(
2084 rterror(
_(
"process_rasters: Could not convert raster tiles into INSERT or COPY statements"));
2085 rtdealloc_rastinfo(&rastinfo);
2086 rtdealloc_stringbuffer(&tileset, 0);
2090 rtdealloc_stringbuffer(&tileset, 0);
2093 flush_stringbuffer(
buffer);
2101 if (!build_overview(i, config, &rastinfo, j, &tileset,
buffer)) {
2102 rterror(
_(
"process_rasters: Could not create overview of factor %d for raster %s"), config->
overview[j], config->
rt_file[i]);
2103 rtdealloc_rastinfo(&rastinfo);
2104 rtdealloc_stringbuffer(&tileset, 0);
2108 if (tileset.
length && !insert_records(
2114 rterror(
_(
"process_rasters: Could not convert overview tiles into INSERT or COPY statements"));
2115 rtdealloc_rastinfo(&rastinfo);
2116 rtdealloc_stringbuffer(&tileset, 0);
2120 rtdealloc_stringbuffer(&tileset, 0);
2123 flush_stringbuffer(
buffer);
2129 copy_rastinfo(&refinfo, &rastinfo);
2131 diff_rastinfo(&rastinfo, &refinfo);
2135 rtdealloc_rastinfo(&rastinfo);
2138 rtdealloc_rastinfo(&refinfo);
2149 rterror(
_(
"process_rasters: Could not add CREATE INDEX statement to string buffer"));
2154 if (config->
opt !=
'p') {
2159 rterror(
_(
"process_rasters: Could not add ANALYZE statement to string buffer"));
2172 rterror(
_(
"process_rasters: Could not add an overview's CREATE INDEX statement to string buffer"));
2177 if (config->
opt !=
'p') {
2182 rterror(
_(
"process_rasters: Could not add an overview's ANALYZE statement to string buffer"));
2192 if (!add_raster_constraints(
2197 rterror(
_(
"process:rasters: Could not add AddRasterConstraints statement to string buffer"));
2203 if (!add_raster_constraints(
2208 rterror(
_(
"process_rasters: Could not add an overview's AddRasterConstraints statement to string buffer"));
2218 if (!add_overview_constraints(
2224 rterror(
_(
"process_rasters: Could not add an overview's AddOverviewConstraints statement to string buffer"));
2231 if (!append_sql_to_buffer(
buffer, strdup(
"END;"))) {
2232 rterror(
_(
"process_rasters: Could not add END statement to string buffer"));
2243 rterror(
_(
"process_rasters: Could not add VACUUM statement to string buffer"));
2253 rterror(
_(
"process_rasters: Could not add an overview's VACUUM statement to string buffer"));
2265 main(
int argc,
char **argv) {
2270 char **elements = NULL;
2272 GDALDriverH drv = NULL;
2279 setlocale (LC_ALL,
"");
2280 bindtextdomain (PACKAGE, LOCALEDIR);
2281 textdomain (PACKAGE);
2292 if (config == NULL) {
2293 rterror(
_(
"Could not allocate memory for loader configuration"));
2296 init_config(config);
2302 for (argit = 1; argit < argc; argit++) {
2306 if (
CSEQUAL(argv[argit],
"-s") && argit < argc - 1) {
2307 optarg = argv[++argit];
2308 ptr = strchr(optarg,
':');
2311 sscanf(optarg,
"%d", &config->
srid);
2312 sscanf(ptr,
"%d", &config->
out_srid);
2314 config->
srid = atoi(optarg);
2318 else if (
CSEQUAL(argv[argit],
"-b") && argit < argc - 1) {
2319 elements =
strsplit(argv[++argit],
",", &n);
2321 rterror(
_(
"Could not process -b"));
2322 rtdealloc_config(config);
2327 for (j = 0; j < n; j++) {
2328 char *t =
trim(elements[j]);
2329 char **minmax = NULL;
2339 if (!
array_range(atoi(minmax[0]), atoi(minmax[1]), 1, &range, &p)) {
2340 rterror(
_(
"Could not allocate memory for storing band indices"));
2341 for (l = 0; l < o; l++)
2344 for (j = 0; j < n; j++)
2348 rtdealloc_config(config);
2355 if (range == NULL) {
2356 rterror(
_(
"Could not allocate memory for storing band indices"));
2357 for (l = 0; l < o; l++)
2360 for (j = 0; j < n; j++)
2364 rtdealloc_config(config);
2373 if (config->
nband == NULL) {
2374 rterror(
_(
"Could not allocate memory for storing band indices"));
2376 for (l = 0; l < o; l++)
2379 for (j = 0; j < n; j++)
2383 rtdealloc_config(config);
2387 for (l = 0; l < p; l++, m++)
2388 config->
nband[m] = range[l];
2392 for (l = 0; l < o; l++)
2404 if (config->
nband[j] < 1) {
2405 rterror(
_(
"Band index %d must be greater than 0"), config->
nband[j]);
2406 rtdealloc_config(config);
2412 else if (
CSEQUAL(argv[argit],
"-t") && argit < argc - 1) {
2413 if (
CSEQUAL(argv[++argit],
"auto")) {
2418 elements =
strsplit(argv[argit],
"x", &n);
2420 rterror(
_(
"Could not process -t"));
2421 rtdealloc_config(config);
2425 for (j = 0; j < n; j++) {
2426 char *t =
trim(elements[j]);
2435 for (j = 0; j < 2; j++) {
2437 rterror(
_(
"Tile size must be greater than 0x0"));
2438 rtdealloc_config(config);
2445 else if (
CSEQUAL(argv[argit],
"-P")) {
2449 else if (
CSEQUAL(argv[argit],
"-R")) {
2453 else if (
CSEQUAL(argv[argit],
"-d")) {
2457 else if (
CSEQUAL(argv[argit],
"-a")) {
2461 else if (
CSEQUAL(argv[argit],
"-c")) {
2465 else if (
CSEQUAL(argv[argit],
"-p")) {
2469 else if (
CSEQUAL(argv[argit],
"-f") && argit < argc - 1) {
2470 const size_t len = (strlen(argv[++argit]) + 1);
2473 rterror(
_(
"Could not allocate memory for storing raster column name"));
2474 rtdealloc_config(config);
2480 else if (
CSEQUAL(argv[argit],
"-F")) {
2484 else if (
CSEQUAL(argv[argit],
"-n") && argit < argc - 1) {
2485 const size_t len = (strlen(argv[++argit]) + 1);
2488 rterror(
_(
"Could not allocate memory for storing filename column name"));
2489 rtdealloc_config(config);
2496 else if (
CSEQUAL(argv[argit],
"-l") && argit < argc - 1) {
2497 elements =
strsplit(argv[++argit],
",", &n);
2499 rterror(
_(
"Could not process -l"));
2500 rtdealloc_config(config);
2507 rterror(
_(
"Could not allocate memory for storing overview factors"));
2508 rtdealloc_config(config);
2511 for (j = 0; j < n; j++) {
2512 char *t =
trim(elements[j]);
2524 rtdealloc_config(config);
2530 else if (
CSEQUAL(argv[argit],
"-q")) {
2534 else if (
CSEQUAL(argv[argit],
"-I")) {
2538 else if (
CSEQUAL(argv[argit],
"-M")) {
2542 else if (
CSEQUAL(argv[argit],
"-C")) {
2546 else if (
CSEQUAL(argv[argit],
"-x")) {
2550 else if (
CSEQUAL(argv[argit],
"-r")) {
2554 else if (
CSEQUAL(argv[argit],
"-T") && argit < argc - 1) {
2555 const size_t len = (strlen(argv[++argit]) + 1);
2558 rterror(
_(
"Could not allocate memory for storing tablespace of new table"));
2559 rtdealloc_config(config);
2562 strncpy(config->
tablespace, argv[argit], len);
2565 else if (
CSEQUAL(argv[argit],
"-X") && argit < argc - 1) {
2566 const size_t len = (strlen(argv[++argit]) + 1);
2569 rterror(
_(
"Could not allocate memory for storing tablespace of new indices"));
2570 rtdealloc_config(config);
2576 else if (
CSEQUAL(argv[argit],
"-N") && argit < argc - 1) {
2578 config->
nodataval = atof(argv[++argit]);
2581 else if (
CSEQUAL(argv[argit],
"-k")) {
2585 else if (
CSEQUAL(argv[argit],
"-E") && argit < argc - 1) {
2586 config->
endian = atoi(argv[++argit]);
2590 else if (
CSEQUAL(argv[argit],
"-V") && argit < argc - 1) {
2591 config->
version = atoi(argv[++argit]);
2595 else if (
CSEQUAL(argv[argit],
"-e")) {
2599 else if (
CSEQUAL(argv[argit],
"-Y")) {
2602 if ( argit < argc - 1) {
2603 optarg = argv[argit + 1];
2604 if (atoi(optarg) > 0 ) {
2613 else if (
CSEQUAL(argv[argit],
"-G")) {
2614 uint32_t drv_count = 0;
2616 if (drv_set == NULL || !drv_count) {
2617 rterror(
_(
"Could not get list of available GDAL raster formats"));
2620 printf(
_(
"Supported GDAL raster formats:\n"));
2621 for (j = 0; j < drv_count; j++) {
2622 printf(
_(
" %s\n"), drv_set[j].long_name);
2631 rtdealloc_config(config);
2635 else if (
CSEQUAL(argv[argit],
"-?")) {
2637 rtdealloc_config(config);
2644 if (config->
rt_file == NULL) {
2645 rterror(
_(
"Could not allocate memory for storing raster files"));
2646 rtdealloc_config(config);
2650 len = strlen(argv[argit]) + 1;
2653 rterror(
_(
"Could not allocate memory for storing raster filename"));
2654 rtdealloc_config(config);
2663 rterror(
_(
"Invalid argument combination - cannot use -Y with -s FROM_SRID:TO_SRID"));
2674 rtdealloc_config(config);
2691 if (config->
schema == NULL) {
2692 rterror(
_(
"Could not allocate memory for storing schema name"));
2693 rtdealloc_config(config);
2700 if (config->
table == NULL) {
2701 rterror(
_(
"Could not allocate memory for storing table name"));
2702 rtdealloc_config(config);
2712 if (config->
table == NULL) {
2713 rterror(
_(
"Could not allocate memory for storing table name"));
2714 rtdealloc_config(config);
2722 if (config->
rt_file == NULL) {
2723 rterror(
_(
"Could not reallocate the memory holding raster names"));
2724 rtdealloc_config(config);
2736 drv = GDALIdentifyDriver(config->
rt_file[i], NULL);
2740 rtdealloc_config(config);
2748 rterror(
_(
"Could not allocate memory for cleaned raster filenames"));
2749 rtdealloc_config(config);
2758 rterror(
_(
"Could not allocate memory for cleaned raster filename"));
2759 rtdealloc_config(config);
2762 strcpy(file, config->
rt_file[i]);
2764 for (ptr = file + strlen(file); ptr > file; ptr--) {
2765 if (*ptr ==
'/' || *ptr ==
'\\') {
2773 rterror(
_(
"Could not allocate memory for cleaned raster filename"));
2774 rtdealloc_config(config);
2786 if (config->
table == NULL) {
2792 rterror(
_(
"Could not allocate memory for proxy table name"));
2793 rtdealloc_config(config);
2798 for (ptr = file + strlen(file); ptr > file; ptr--) {
2805 config->
table =
rtalloc(
sizeof(
char) * (strlen(file) + 1));
2806 if (config->
table == NULL) {
2807 rterror(
_(
"Could not allocate memory for proxy table name"));
2808 rtdealloc_config(config);
2811 strcpy(config->
table, file);
2819 rterror(
_(
"Could not allocate memory for default raster column name"));
2820 rtdealloc_config(config);
2830 rterror(
_(
"Could not allocate memory for default filename column name"));
2831 rtdealloc_config(config);
2843 if (config->
schema != NULL)
2845 if (config->
table != NULL)
2865 rterror(
_(
"Could not allocate memory for overview table names"));
2866 rtdealloc_config(config);
2871 sprintf(factor,
"%d", config->
overview[i]);
2875 rterror(
_(
"Could not allocate memory for overview table name"));
2876 rtdealloc_config(config);
2888 rtwarn(
_(
"The schema name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2894 rtwarn(
_(
"The table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2900 rtwarn(
_(
"The column name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2906 rtwarn(
_(
"The column name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2912 rtwarn(
_(
"The tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2918 rtwarn(
_(
"The index tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2926 rtwarn(
_(
"The overview table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
2938 if (config->
schema != NULL) {
2941 rterror(
_(
"Could not allocate memory for quoting schema name"));
2942 rtdealloc_config(config);
2946 sprintf(tmp,
"\"%s\".", config->
schema);
2950 if (config->
table != NULL) {
2951 tmp =
rtalloc(
sizeof(
char) * (strlen(config->
table) + 3));
2953 rterror(
_(
"Could not allocate memory for quoting table name"));
2954 rtdealloc_config(config);
2958 sprintf(tmp,
"\"%s\"", config->
table);
2960 config->
table = tmp;
2965 rterror(
_(
"Could not allocate memory for quoting raster column name"));
2966 rtdealloc_config(config);
2977 rterror(
_(
"Could not allocate memory for quoting raster column name"));
2978 rtdealloc_config(config);
2989 rterror(
_(
"Could not allocate memory for quoting tablespace name"));
2990 rtdealloc_config(config);
3001 rterror(
_(
"Could not allocate memory for quoting index tablespace name"));
3002 rtdealloc_config(config);
3014 rterror(
_(
"Could not allocate memory for quoting overview table name"));
3015 rtdealloc_config(config);
3032 rterror(
_(
"Could not allocate memory for output string buffer"));
3033 rtdealloc_config(config);
3036 init_stringbuffer(
buffer);
3039 if (!process_rasters(config,
buffer)) {
3040 rterror(
_(
"Unable to process rasters"));
3041 rtdealloc_stringbuffer(
buffer, 1);
3042 rtdealloc_config(config);
3046 flush_stringbuffer(
buffer);
3048 rtdealloc_stringbuffer(
buffer, 1);
3049 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,...)
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 rtinfo(const char *fmt,...)
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)
void rtwarn(const char *fmt,...)
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 void loader_rt_error_handler(const char *fmt, va_list ap)
static char * strreplace(const char *str, const char *oldstr, const char *newstr, int *count)
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)
static void rt_init_allocators(void)
static char * strtolower(char *str)
static void raster_destroy(rt_raster raster)
static void loader_rt_warning_handler(const char *fmt, va_list ap)
#define POSTGIS_GDAL_VERSION
#define POSTGIS_LIB_VERSION
uint32_t max_tiles_per_copy
max tiles per copy
GDALDataType * gdalbandtype