/*
* $Id$
*
- * PostGIS Raster loader
+ * PostGIS raster loader
* http://trac.osgeo.org/postgis/wiki/WKTRaster
*
* Copyright 2001-2003 Refractions Research Inc.
lwgeom_install_default_allocators();
}
+static void
+loader_rt_error_handler(const char *fmt, va_list ap) {
+ static const char *label = "ERROR: ";
+ char newfmt[1024] = {0};
+ snprintf(newfmt, 1024, "%s%s\n", label, fmt);
+ newfmt[1023] = '\0';
+ vfprintf(stderr, newfmt, ap);
+ va_end(ap);
+}
+
+static void
+loader_rt_warning_handler(const char *fmt, va_list ap) {
+ static const char *label = "WARNING: ";
+ char newfmt[1024] = {0};
+ snprintf(newfmt, 1024, "%s%s\n", label, fmt);
+ newfmt[1023] = '\0';
+ vfprintf(stderr, newfmt, ap);
+ va_end(ap);
+}
+
+static void
+loader_rt_info_handler(const char *fmt, va_list ap) {
+ static const char *label = "INFO: ";
+ char newfmt[1024] = {0};
+ snprintf(newfmt, 1024, "%s%s\n", label, fmt);
+ newfmt[1023] = '\0';
+ vfprintf(stderr, newfmt, ap);
+ va_end(ap);
+}
+
void rt_init_allocators(void) {
- rt_install_default_allocators();
+ rt_set_handlers(
+ default_rt_allocator,
+ default_rt_reallocator,
+ default_rt_deallocator,
+ loader_rt_error_handler,
+ loader_rt_info_handler,
+ loader_rt_warning_handler
+ );
}
static void
length = strlen(str) + found * (newlen - oldlen);
if ((result = (char *) rtalloc(length + 1)) == NULL) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("strreplace: Not enough memory"));
found = -1;
}
else {
/* copy str to tmp as strtok will mangle the string */
tmp = rtalloc(sizeof(char) * (strlen(str) + 1));
if (NULL == tmp) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("strsplit: Not enough memory"));
return NULL;
}
strcpy(tmp, str);
*n = 1;
rtn = (char **) rtalloc(*n * sizeof(char *));
if (NULL == rtn) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("strsplit: Not enough memory"));
return NULL;
}
rtn[0] = (char *) rtalloc(sizeof(char) * (strlen(tmp) + 1));
if (NULL == rtn[0]) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("strsplit: Not enough memory"));
return NULL;
}
strcpy(rtn[0], tmp);
rtn = (char **) rtrealloc(rtn, (*n + 1) * sizeof(char *));
}
if (NULL == rtn) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("strsplit: Not enough memory"));
return NULL;
}
rtn[*n] = NULL;
rtn[*n] = (char *) rtalloc(sizeof(char) * (strlen(token) + 1));
if (NULL == rtn[*n]) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("strsplit: Not enough memory"));
return NULL;
}
rtn = rtalloc(sizeof(char) * (strlen(input) - offset + 1));
if (NULL == rtn) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("trim: Not enough memory"));
return NULL;
}
strncpy(rtn, input, strlen(input) - offset);
rtn = rtalloc(sizeof(char) * (strlen(input) - offset + 1));
if (NULL == rtn) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("chartrim: Not enough memory"));
return NULL;
}
strncpy(rtn, input, strlen(input) - offset);
if (src->srs != NULL) {
dst->srs = rtalloc(sizeof(char) * (strlen(src->srs) + 1));
if (dst->srs == NULL) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("copy_rastinfo: Not enough memory"));
return 0;
}
strcpy(dst->srs, src->srs);
if (src->nband_count && src->nband != NULL) {
dst->nband = rtalloc(sizeof(int) * src->nband_count);
if (dst->nband == NULL) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("copy_rastinfo: Not enough memory"));
return 0;
}
memcpy(dst->nband, src->nband, sizeof(int) * src->nband_count);
if (src->gdalbandtype != NULL) {
dst->gdalbandtype = rtalloc(sizeof(GDALDataType) * src->nband_count);
if (dst->gdalbandtype == NULL) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("copy_rastinfo: Not enough memory"));
return 0;
}
memcpy(dst->gdalbandtype, src->gdalbandtype, sizeof(GDALDataType) * src->nband_count);
if (src->bandtype != NULL) {
dst->bandtype = rtalloc(sizeof(rt_pixtype) * src->nband_count);
if (dst->bandtype == NULL) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("copy_rastinfo: Not enough memory"));
return 0;
}
memcpy(dst->bandtype, src->bandtype, sizeof(rt_pixtype) * src->nband_count);
if (src->hasnodata != NULL) {
dst->hasnodata = rtalloc(sizeof(int) * src->nband_count);
if (dst->hasnodata == NULL) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("copy_rastinfo: Not enough memory"));
return 0;
}
memcpy(dst->hasnodata, src->hasnodata, sizeof(int) * src->nband_count);
if (src->nodataval != NULL) {
dst->nodataval = rtalloc(sizeof(double) * src->nband_count);
if (dst->nodataval == NULL) {
- fprintf(stderr, _("Not enough memory\n"));
+ rterror(_("copy_rastinfo: Not enough memory"));
return 0;
}
memcpy(dst->nodataval, src->nodataval, sizeof(double) * src->nband_count);
!msg[0] &&
x->nband_count != ref->nband_count
) {
- fprintf(stderr, _("WARNING: Different number of bands found in the set of rasters being converted to PostGIS Raster\n"));
+ rtwarn(_("Different number of bands found in the set of rasters being converted to PostGIS raster"));
msg[0]++;
}
if (!msg[1]) {
for (i = 0; i < ref->nband_count; i++) {
if (x->bandtype[i] != ref->bandtype[i]) {
- fprintf(stderr, _("WARNING: Different pixel types found for band %d in the set of rasters being converted to PostGIS Raster\n"), ref->nband[i]);
+ rtwarn(_("Different pixel types found for band %d in the set of rasters being converted to PostGIS raster"), ref->nband[i]);
msg[1]++;
}
}
if (!msg[2]) {
for (i = 0; i < ref->nband_count; i++) {
if (x->hasnodata[i] != ref->hasnodata[i]) {
- fprintf(stderr, _("WARNING: Different hasnodata flags found for band %d in the set of rasters being converted to PostGIS Raster\n"), ref->nband[i]);
+ rtwarn(_("Different hasnodata flags found for band %d in the set of rasters being converted to PostGIS raster"), ref->nband[i]);
msg[2]++;
}
}
for (i = 0; i < ref->nband_count; i++) {
if (!x->hasnodata[i] && !ref->hasnodata[i]) continue;
if (FLT_NEQ(x->hasnodata[i], ref->hasnodata[i])) {
- fprintf(stderr, _("WARNING: Different NODATA values found for band %d in the set of rasters being converted to PostGIS Raster\n"), ref->nband[i]);
+ rtwarn(_("Different NODATA values found for band %d in the set of rasters being converted to PostGIS raster"), ref->nband[i]);
msg[3]++;
}
}
if (!msg[4]) {
for (i = 0; i < 6; i++) {
if (FLT_NEQ(x->gt[i], ref->gt[i])) {
- fprintf(stderr, _("WARNING: Different geotransform matrices found in the set of rasters being converted to PostGIS Raster\n"));
+ rtwarn(_("Different geotransform matrices found in the set of rasters being converted to PostGIS raster"));
msg[4]++;
break;
}
if (!msg[5]) {
for (i = 0; i < 2; i++) {
if (FLT_NEQ(x->tile_size[i], ref->tile_size[i])) {
- fprintf(stderr, _("WARNING: Different tile sizes found in the set of rasters being converted to PostGIS Raster\n"));
+ rtwarn(_("Different tile sizes found in the set of rasters being converted to PostGIS raster"));
msg[5]++;
break;
}
buffer->line = rtrealloc(buffer->line, sizeof(char *) * buffer->length);
if (buffer->line == NULL) {
- fprintf(stderr, _("Could not allocate memory for appending string to buffer\n"));
+ rterror(_("append_stringbuffer: Could not allocate memory for appending string to buffer"));
return 0;
}
buffer->line[buffer->length - 1] = NULL;
buffer->line[buffer->length - 1] = rtalloc(sizeof(char) * (strlen(str) + 1));
if (buffer->line[buffer->length - 1] == NULL) {
- fprintf(stderr, _("Could not allocate memory for appending string to buffer\n"));
+ rterror(_("append_stringbuffer: Could not allocate memory for appending string to buffer"));
return 0;
}
strcpy(buffer->line[buffer->length - 1], str);
sql = rtalloc(sizeof(char) * len);
if (sql == NULL) {
- fprintf(stderr, _("Could not allocate memory for COPY statement\n"));
+ rterror(_("insert_records: Could not allocate memory for COPY statement"));
return 0;
}
sprintf(sql, "%s%s%s",
sql = rtalloc(sizeof(char) * sqllen);
if (sql == NULL) {
- fprintf(stderr, _("Could not allocate memory for INSERT statement\n"));
+ rterror(_("insert_records: Could not allocate memory for INSERT statement"));
return 0;
}
sprintf(sql, "INSERT INTO %s%s (%s%s) VALUES ('%s'::raster%s%s%s);",
sql = rtalloc(sizeof(char) * len);
if (sql == NULL) {
- fprintf(stderr, _("Could not allocate memory for DROP TABLE statement\n"));
+ rterror(_("drop_table: Could not allocate memory for DROP TABLE statement"));
return 0;
}
sprintf(sql, "DROP TABLE IF EXISTS %s%s;",
sql = rtalloc(sizeof(char) * len);
if (sql == NULL) {
- fprintf(stderr, _("Could not allocate memory for CREATE TABLE statement\n"));
+ rterror(_("create_table: Could not allocate memory for CREATE TABLE statement"));
return 0;
}
sprintf(sql, "CREATE TABLE %s%s (\"rid\" serial PRIMARY KEY,%s raster%s)%s%s%s%s;",
sql = rtalloc(sizeof(char) * len);
if (sql == NULL) {
- fprintf(stderr, _("Could not allocate memory for COPY statement\n"));
+ rterror(_("copy_from: Could not allocate memory for COPY statement"));
return 0;
}
sprintf(sql, "COPY %s%s (%s%s) FROM stdin;",
sql = rtalloc(sizeof(char) * len);
if (sql == NULL) {
- fprintf(stderr, _("Could not allocate memory for CREATE INDEX statement\n"));
+ rterror(_("create_index: Could not allocate memory for CREATE INDEX statement"));
rtdealloc(_table);
rtdealloc(_column);
return 0;
sql = rtalloc(sizeof(char) * len);
if (sql == NULL) {
- fprintf(stderr, _("Could not allocate memory for ANALYZE TABLE statement\n"));
+ rterror(_("analyze_table: Could not allocate memory for ANALYZE TABLE statement"));
return 0;
}
sprintf(sql, "ANALYZE %s%s;",
sql = rtalloc(sizeof(char) * len);
if (sql == NULL) {
- fprintf(stderr, _("Could not allocate memory for VACUUM statement\n"));
+ rterror(_("vacuum_table: Could not allocate memory for VACUUM statement"));
return 0;
}
sprintf(sql, "VACUUM ANALYZE %s%s;",
sql = rtalloc(sizeof(char) * len);
if (sql == NULL) {
- fprintf(stderr, _("Could not allocate memory for AddRasterConstraints statement\n"));
+ rterror(_("add_raster_constraints: Could not allocate memory for AddRasterConstraints statement"));
return 0;
}
sprintf(sql, "SELECT AddRasterConstraints('%s','%s','%s',TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,%s,TRUE,TRUE,TRUE,TRUE,%s);",
sql = rtalloc(sizeof(char) * len);
if (sql == NULL) {
- fprintf(stderr, _("Could not allocate memory for AddOverviewConstraints statement\n"));
+ rterror(_("add_overview_constraints: Could not allocate memory for AddOverviewConstraints statement"));
return 0;
}
sprintf(sql, "SELECT AddOverviewConstraints('%s','%s','%s','%s','%s','%s',%d);",
hdsSrc = GDALOpenShared(config->rt_file[idx], GA_ReadOnly);
if (hdsSrc == NULL) {
- fprintf(stderr, _("Could not open raster: %s\n"), config->rt_file[idx]);
+ rterror(_("build_overview: Could not open raster: %s"), config->rt_file[idx]);
return 0;
}
memcpy(gtOv, info->gt, sizeof(double) * 6);
if (ovx >= config->overview_count) {
- fprintf(stderr, _("Invalid overview index: %d\n"), ovx);
+ rterror(_("build_overview: Invalid overview index: %d"), ovx);
return 0;
}
factor = config->overview[ovx];
/* factor must be within valid range */
if (factor < MINOVFACTOR || factor > MAXOVFACTOR) {
- fprintf(stderr, _("Overview factor %d is not between %d and %d\n"), factor, MINOVFACTOR, MAXOVFACTOR);
+ rterror(_("build_overview: Overview factor %d is not between %d and %d"), factor, MINOVFACTOR, MAXOVFACTOR);
return 0;
}
/* convert VRT dataset to rt_raster */
rast = rt_raster_from_gdal_dataset(hdsDst);
if (rast == NULL) {
- fprintf(stderr, _("Could not convert VRT dataset to rt_raster\n"));
+ rterror(_("build_overview: Could not convert VRT dataset to PostGIS raster"));
GDALClose(hdsDst);
return 0;
}
hex = rt_raster_to_hexwkb(rast, &hexlen);
raster_destroy(rast);
+ if (hex == NULL) {
+ rterror(_("build_overview: Could not convert PostGIS raster to hex WKB"));
+ GDALClose(hdsDst);
+ return 0;
+ }
+
/* add hexwkb to tileset */
append_stringbuffer(tileset, hex);
(config->file_column ? config->rt_filename[idx] : NULL), config->copy_statements,
tileset, buffer
)) {
- fprintf(stderr, _("Could not convert raster tiles into INSERT or COPY statements\n"));
+ rterror(_("build_overview: Could not convert raster tiles into INSERT or COPY statements"));
GDALClose(hdsSrc);
return 0;
}
hdsSrc = GDALOpenShared(config->rt_file[idx], GA_ReadOnly);
if (hdsSrc == NULL) {
- fprintf(stderr, _("Could not open raster: %s\n"), config->rt_file[idx]);
+ rterror(_("convert_raster: Could not open raster: %s"), config->rt_file[idx]);
return 0;
}
nband = GDALGetRasterCount(hdsSrc);
if (!nband) {
- fprintf(stderr, _("No bands found in raster: %s\n"), config->rt_file[idx]);
+ rterror(_("convert_raster: No bands found in raster: %s"), config->rt_file[idx]);
GDALClose(hdsSrc);
return 0;
}
/* check that bands specified are available */
for (i = 0; i < config->nband_count; i++) {
if (config->nband[i] > nband) {
- fprintf(stderr, _("Band %d not found in raster: %s\n"), config->nband[i], config->rt_file[idx]);
+ rterror(_("convert_raster: Band %d not found in raster: %s"), config->nband[i], config->rt_file[idx]);
GDALClose(hdsSrc);
return 0;
}
if (pszProjectionRef != NULL && pszProjectionRef[0] != '\0') {
info->srs = rtalloc(sizeof(char) * (strlen(pszProjectionRef) + 1));
if (info->srs == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing SRS\n"));
+ rterror(_("convert_raster: Could not allocate memory for storing SRS"));
GDALClose(hdsSrc);
return 0;
}
/* record geotransform matrix */
if (GDALGetGeoTransform(hdsSrc, info->gt) != CE_None) {
- fprintf(stderr, _("Using default geotransform matrix (0, 1, 0, 0, 0, -1) for raster: %s\n"), config->rt_file[idx]);
+ rtinfo(_("Using default geotransform matrix (0, 1, 0, 0, 0, -1) for raster: %s"), config->rt_file[idx]);
info->gt[0] = 0;
info->gt[1] = 1;
info->gt[2] = 0;
info->nband_count = config->nband_count;
info->nband = rtalloc(sizeof(int) * info->nband_count);
if (info->nband == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing band indices\n"));
+ rterror(_("convert_raster: Could not allocate memory for storing band indices"));
GDALClose(hdsSrc);
return 0;
}
info->nband_count = nband;
info->nband = rtalloc(sizeof(int) * info->nband_count);
if (info->nband == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing band indices\n"));
+ rterror(_("convert_raster: Could not allocate memory for storing band indices"));
GDALClose(hdsSrc);
return 0;
}
/* initialize parameters dependent on nband */
info->gdalbandtype = rtalloc(sizeof(GDALDataType) * info->nband_count);
if (info->gdalbandtype == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing GDAL data type\n"));
+ rterror(_("convert_raster: Could not allocate memory for storing GDAL data type"));
GDALClose(hdsSrc);
return 0;
}
info->bandtype = rtalloc(sizeof(rt_pixtype) * info->nband_count);
if (info->bandtype == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing pixel type\n"));
+ rterror(_("convert_raster: Could not allocate memory for storing pixel type"));
GDALClose(hdsSrc);
return 0;
}
info->hasnodata = rtalloc(sizeof(int) * info->nband_count);
if (info->hasnodata == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing hasnodata flag\n"));
+ rterror(_("convert_raster: Could not allocate memory for storing hasnodata flag"));
GDALClose(hdsSrc);
return 0;
}
info->nodataval = rtalloc(sizeof(double) * info->nband_count);
if (info->nodataval == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing nodata value\n"));
+ rterror(_("convert_raster: Could not allocate memory for storing nodata value"));
GDALClose(hdsSrc);
return 0;
}
/* complex data type? */
if (GDALDataTypeIsComplex(info->gdalbandtype[i])) {
- fprintf(stderr, _("The pixel type of band %d is a complex data type. PostGIS Raster does not support complex data types\n"), i + 1);
+ rterror(_("convert_raster: The pixel type of band %d is a complex data type. PostGIS raster does not support complex data types"), i + 1);
GDALClose(hdsSrc);
return 0;
}
/* create raster object */
rast = rt_raster_new(info->tile_size[0], info->tile_size[1]);
if (rast == NULL) {
- fprintf(stderr, _("Could not create raster\n"));
+ rterror(_("convert_raster: Could not create raster"));
return 0;
}
config->rt_file[idx]
);
if (band == NULL) {
- fprintf(stderr, _("Could not create offline band\n"));
+ rterror(_("convert_raster: Could not create offline band"));
raster_destroy(rast);
return 0;
}
/* add band to raster */
if (rt_raster_add_band(rast, band, rt_raster_get_num_bands(rast)) == -1) {
- fprintf(stderr, _("Could not add offlineband to raster\n"));
+ rterror(_("convert_raster: Could not add offlineband to raster"));
rt_band_destroy(band);
raster_destroy(rast);
return 0;
hex = rt_raster_to_hexwkb(rast, &hexlen);
raster_destroy(rast);
+ if (hex == NULL) {
+ rterror(_("convert_raster: Could not convert PostGIS raster to hex WKB"));
+ return 0;
+ }
+
/* add hexwkb to tileset */
append_stringbuffer(tileset, hex);
(config->file_column ? config->rt_filename[idx] : NULL), config->copy_statements,
tileset, buffer
)) {
- fprintf(stderr, _("Could not convert raster tiles into INSERT or COPY statements\n"));
+ rterror(_("convert_raster: Could not convert raster tiles into INSERT or COPY statements"));
return 0;
}
/* convert VRT dataset to rt_raster */
rast = rt_raster_from_gdal_dataset(hdsDst);
if (rast == NULL) {
- fprintf(stderr, _("Could not convert VRT dataset to PostGIS raster\n"));
+ rterror(_("convert_raster: Could not convert VRT dataset to PostGIS raster"));
GDALClose(hdsDst);
return 0;
}
hex = rt_raster_to_hexwkb(rast, &hexlen);
raster_destroy(rast);
+ if (hex == NULL) {
+ rterror(_("convert_raster: Could not convert PostGIS raster to hex WKB"));
+ GDALClose(hdsDst);
+ return 0;
+ }
+
/* add hexwkb to tileset */
append_stringbuffer(tileset, hex);
(config->file_column ? config->rt_filename[idx] : NULL), config->copy_statements,
tileset, buffer
)) {
- fprintf(stderr, _("Could not convert raster tiles into INSERT or COPY statements\n"));
+ rterror(_("convert_raster: Could not convert raster tiles into INSERT or COPY statements"));
GDALClose(hdsSrc);
return 0;
}
if (config->transaction) {
if (!append_sql_to_buffer(buffer, "BEGIN;")) {
- fprintf(stderr, _("Could not add BEGIN statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add BEGIN statement to string buffer"));
return 0;
}
}
/* drop table */
if (config->opt == 'd') {
if (!drop_table(config->schema, config->table, buffer)) {
- fprintf(stderr, _("Could not add DROP TABLE statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add DROP TABLE statement to string buffer"));
return 0;
}
if (config->overview_count) {
for (i = 0; i < config->overview_count; i++) {
if (!drop_table(config->schema, config->overview_table[i], buffer)) {
- fprintf(stderr, _("Could not add an overview's DROP TABLE statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add an overview's DROP TABLE statement to string buffer"));
return 0;
}
}
config->tablespace, config->idx_tablespace,
buffer
)) {
- fprintf(stderr, _("Could not add CREATE TABLE statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add CREATE TABLE statement to string buffer"));
return 0;
}
config->tablespace, config->idx_tablespace,
buffer
)) {
- fprintf(stderr, _("Could not add an overview's CREATE TABLE statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add an overview's CREATE TABLE statement to string buffer"));
return 0;
}
}
(config->file_column ? config->rt_filename[i] : NULL),
buffer
)) {
- fprintf(stderr, _("Could not add COPY statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add COPY statement to string buffer"));
rtdealloc_rastinfo(&rastinfo);
rtdealloc_stringbuffer(&tileset, 0);
return 0;
/* convert raster */
if (!convert_raster(i, config, &rastinfo, &tileset, buffer)) {
- fprintf(stderr, _("Could not process raster: %s\n"), config->rt_file[i]);
+ rterror(_("process_rasters: Could not process raster: %s"), config->rt_file[i]);
rtdealloc_rastinfo(&rastinfo);
rtdealloc_stringbuffer(&tileset, 0);
return 0;
(config->file_column ? config->rt_filename[i] : NULL), config->copy_statements,
&tileset, buffer
)) {
- fprintf(stderr, _("Could not convert raster tiles into INSERT or COPY statements\n"));
+ rterror(_("process_rasters: Could not convert raster tiles into INSERT or COPY statements"));
rtdealloc_rastinfo(&rastinfo);
rtdealloc_stringbuffer(&tileset, 0);
return 0;
rtdealloc_stringbuffer(&tileset, 0);
if (config->copy_statements && !copy_from_end(buffer)) {
- fprintf(stderr, _("Could not add COPY end statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add COPY end statement to string buffer"));
rtdealloc_rastinfo(&rastinfo);
return 0;
}
(config->file_column ? config->rt_filename[i] : NULL),
buffer
)) {
- fprintf(stderr, _("Could not add COPY statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add COPY statement to string buffer"));
rtdealloc_rastinfo(&rastinfo);
rtdealloc_stringbuffer(&tileset, 0);
return 0;
}
if (!build_overview(i, config, &rastinfo, j, &tileset, buffer)) {
- fprintf(stderr, _("Could not create overview of factor %d for raster %s\n"), config->overview[j], config->rt_file[i]);
+ rterror(_("process_rasters: Could not create overview of factor %d for raster %s"), config->overview[j], config->rt_file[i]);
rtdealloc_rastinfo(&rastinfo);
rtdealloc_stringbuffer(&tileset, 0);
return 0;
(config->file_column ? config->rt_filename[i] : NULL), config->copy_statements,
&tileset, buffer
)) {
- fprintf(stderr, _("Could not convert overview tiles into INSERT or COPY statements\n"));
+ rterror(_("process_rasters: Could not convert overview tiles into INSERT or COPY statements"));
rtdealloc_rastinfo(&rastinfo);
rtdealloc_stringbuffer(&tileset, 0);
return 0;
if (config->copy_statements) {
if (!copy_from_end(buffer)) {
- fprintf(stderr, _("Could not add COPY end statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add COPY end statement to string buffer"));
rtdealloc_rastinfo(&rastinfo);
return 0;
}
config->idx_tablespace,
buffer
)) {
- fprintf(stderr, _("Could not add CREATE INDEX statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add CREATE INDEX statement to string buffer"));
return 0;
}
config->schema, config->table,
buffer
)) {
- fprintf(stderr, _("Could not add ANALYZE statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add ANALYZE statement to string buffer"));
return 0;
}
}
config->idx_tablespace,
buffer
)) {
- fprintf(stderr, _("Could not add an overview's CREATE INDEX statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add an overview's CREATE INDEX statement to string buffer"));
return 0;
}
config->schema, config->overview_table[i],
buffer
)) {
- fprintf(stderr, _("Could not add an overview's ANALYZE statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add an overview's ANALYZE statement to string buffer"));
return 0;
}
}
config->regular_blocking, config->max_extent,
buffer
)) {
- fprintf(stderr, _("Could not add AddRasterConstraints statement to string buffer\n"));
+ rterror(_("process:rasters: Could not add AddRasterConstraints statement to string buffer"));
return 0;
}
config->regular_blocking, config->max_extent,
buffer
)) {
- fprintf(stderr, _("Could not add an overview's AddRasterConstraints statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add an overview's AddRasterConstraints statement to string buffer"));
return 0;
}
}
config->overview[i],
buffer
)) {
- fprintf(stderr, _("Could not add an overview's AddOverviewConstraints statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add an overview's AddOverviewConstraints statement to string buffer"));
return 0;
}
}
if (config->transaction) {
if (!append_sql_to_buffer(buffer, "END;")) {
- fprintf(stderr, _("Could not add END statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add END statement to string buffer"));
return 0;
}
}
config->schema, config->table,
buffer
)) {
- fprintf(stderr, _("Could not add VACUUM statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add VACUUM statement to string buffer"));
return 0;
}
config->schema, config->overview_table[i],
buffer
)) {
- fprintf(stderr, _("Could not add an overview's VACUUM statement to string buffer\n"));
+ rterror(_("process_rasters: Could not add an overview's VACUUM statement to string buffer"));
return 0;
}
}
/* initialize config */
config = rtalloc(sizeof(RTLOADERCFG));
if (config == NULL) {
- fprintf(stderr, _("Could not allocate memory for loader configuration\n"));
+ rterror(_("Could not allocate memory for loader configuration"));
exit(1);
}
init_config(config);
else if (CSEQUAL(argv[i], "-b") && i < argc - 1) {
elements = strsplit(argv[++i], ",", &n);
if (n < 1) {
- fprintf(stderr, _("Could not process -b.\n"));
+ rterror(_("Could not process -b"));
rtdealloc_config(config);
exit(1);
}
minmax = strsplit(t, "-", &o);
if (o == 2) {
if (!array_range(atoi(minmax[0]), atoi(minmax[1]), 1, &range, &p)) {
- fprintf(stderr, _("Could not allocate memory for storing band indices\n"));
+ rterror(_("Could not allocate memory for storing band indices"));
for (l = 0; l < o; l++)
rtdealloc(minmax[l]);
rtdealloc(minmax);
p = 1;
range = rtalloc(sizeof(int));
if (range == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing band indices\n"));
+ rterror(_("Could not allocate memory for storing band indices"));
for (l = 0; l < o; l++)
rtdealloc(minmax[l]);
rtdealloc(minmax);
config->nband_count += p;
config->nband = rtrealloc(config->nband, sizeof(int) * config->nband_count);
if (config->nband == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing band indices\n"));
+ rterror(_("Could not allocate memory for storing band indices"));
rtdealloc(range);
for (l = 0; l < o; l++)
rtdealloc(minmax[l]);
for (j = 0; j < config->nband_count; j++) {
if (config->nband[j] < 1) {
- fprintf(stderr, _("Band index %d must be greater than 0\n"), config->nband[j]);
+ rterror(_("Band index %d must be greater than 0"), config->nband[j]);
rtdealloc_config(config);
exit(1);
}
else if (CSEQUAL(argv[i], "-t") && i < argc - 1) {
elements = strsplit(argv[++i], "x", &n);
if (n != 2) {
- fprintf(stderr, _("Could not process -t.\n"));
+ rterror(_("Could not process -t"));
rtdealloc_config(config);
exit(1);
}
for (j = 0; j < 2; j++) {
if (config->tile_size[j] < 1) {
- fprintf(stderr, _("Tile size must be greater than 0x0\n"));
+ rterror(_("Tile size must be greater than 0x0"));
rtdealloc_config(config);
exit(1);
}
else if (CSEQUAL(argv[i], "-f") && i < argc - 1) {
config->raster_column = rtalloc(sizeof(char) * (strlen(argv[++i]) + 1));
if (config->raster_column == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing raster column name\n"));
+ rterror(_("Could not allocate memory for storing raster column name"));
rtdealloc_config(config);
exit(1);
}
else if (CSEQUAL(argv[i], "-l") && i < argc - 1) {
elements = strsplit(argv[++i], ",", &n);
if (n < 1) {
- fprintf(stderr, _("Could not process -l.\n"));
+ rterror(_("Could not process -l"));
rtdealloc_config(config);
exit(1);
}
config->overview_count = n;
config->overview = rtalloc(sizeof(int) * n);
if (config->overview == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing overview factors\n"));
+ rterror(_("Could not allocate memory for storing overview factors"));
rtdealloc_config(config);
exit(1);
}
for (j = 0; j < config->overview_count; j++) {
if (config->overview[j] < MINOVFACTOR || config->overview[j] > MAXOVFACTOR) {
- fprintf(stderr, _("Overview factor %d is not between %d and %d\n"), config->overview[j], MINOVFACTOR, MAXOVFACTOR);
+ rterror(_("Overview factor %d is not between %d and %d"), config->overview[j], MINOVFACTOR, MAXOVFACTOR);
rtdealloc_config(config);
exit(1);
}
else if (CSEQUAL(argv[i], "-T") && i < argc - 1) {
config->tablespace = rtalloc(sizeof(char) * (strlen(argv[++i]) + 1));
if (config->tablespace == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing tablespace of new table\n"));
+ rterror(_("Could not allocate memory for storing tablespace of new table"));
rtdealloc_config(config);
exit(1);
}
else if (CSEQUAL(argv[i], "-X") && i < argc - 1) {
config->idx_tablespace = rtalloc(sizeof(char) * (strlen(argv[++i]) + 1));
if (config->idx_tablespace == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing tablespace of new indices\n"));
+ rterror(_("Could not allocate memory for storing tablespace of new indices"));
rtdealloc_config(config);
exit(1);
}
uint32_t drv_count = 0;
rt_gdaldriver drv_set = rt_raster_gdal_drivers(&drv_count, 0);
if (drv_set == NULL || !drv_count) {
- fprintf(stderr, _("Could not get list of available GDAL raster formats\n"));
+ rterror(_("Could not get list of available GDAL raster formats"));
}
else {
- fprintf(stderr, _("Available GDAL raster formats:\n"));
+ printf(_("Available GDAL raster formats:\n"));
for (j = 0; j < drv_count; j++) {
- fprintf(stderr, _(" %s\n"), drv_set[j].long_name);
+ printf(_(" %s\n"), drv_set[j].long_name);
rtdealloc(drv_set[j].short_name);
rtdealloc(drv_set[j].long_name);
config->rt_file_count++;
config->rt_file = (char **) rtrealloc(config->rt_file, sizeof(char *) * config->rt_file_count);
if (config->rt_file == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing raster files\n"));
+ rterror(_("Could not allocate memory for storing raster files"));
rtdealloc_config(config);
exit(1);
}
config->rt_file[config->rt_file_count - 1] = rtalloc(sizeof(char) * (strlen(argv[i]) + 1));
if (config->rt_file[config->rt_file_count - 1] == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing raster filename\n"));
+ rterror(_("Could not allocate memory for storing raster filename"));
rtdealloc_config(config);
exit(1);
}
/* no files provided */
if (!config->rt_file_count) {
- fprintf(stderr, _("No raster provided.\n"));
+ rterror(_("No raster provided"));
rtdealloc_config(config);
exit(1);
}
if (ptr) {
config->schema = rtalloc(sizeof(char) * (strlen(config->rt_file[config->rt_file_count - 1]) + 1));
if (config->schema == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing schema name\n"));
+ rterror(_("Could not allocate memory for storing schema name"));
rtdealloc_config(config);
exit(1);
}
config->table = rtalloc(sizeof(char) * strlen(config->rt_file[config->rt_file_count - 1]));
if (config->table == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing table name\n"));
+ rterror(_("Could not allocate memory for storing table name"));
rtdealloc_config(config);
exit(1);
}
else {
config->table = rtalloc(sizeof(char) * strlen(config->rt_file[config->rt_file_count - 1]) + 1);
if (config->table == NULL) {
- fprintf(stderr, _("Could not allocate memory for storing table name\n"));
+ rterror(_("Could not allocate memory for storing table name"));
rtdealloc_config(config);
exit(1);
}
rtdealloc(config->rt_file[--(config->rt_file_count)]);
config->rt_file = (char **) rtrealloc(config->rt_file, sizeof(char *) * config->rt_file_count);
if (config->rt_file == NULL) {
- fprintf(stderr, _("Could not reallocate the memory holding raster names\n"));
+ rterror(_("Could not reallocate the memory holding raster names"));
rtdealloc_config(config);
exit(1);
}
fp = fopen(config->rt_file[i], "rb");
if (fp == NULL) {
- fprintf(stderr, _("Unable to read raster file: %s\n"), config->rt_file[i]);
+ rterror(_("Unable to read raster file: %s"), config->rt_file[i]);
rtdealloc_config(config);
exit(1);
}
/* process each file for just the filename */
config->rt_filename = (char **) rtalloc(sizeof(char *) * config->rt_file_count);
if (config->rt_filename == NULL) {
- fprintf(stderr, _("Could not allocate memory for cleaned raster filenames\n"));
+ rterror(_("Could not allocate memory for cleaned raster filenames"));
rtdealloc_config(config);
exit(1);
}
file = rtalloc(sizeof(char) * (strlen(config->rt_file[i]) + 1));
if (file == NULL) {
- fprintf(stderr, _("Could not allocate memory for cleaned raster filename\n"));
+ rterror(_("Could not allocate memory for cleaned raster filename"));
rtdealloc_config(config);
exit(1);
}
config->rt_filename[i] = rtalloc(sizeof(char) * (strlen(ptr) + 1));
if (config->rt_filename[i] == NULL) {
- fprintf(stderr, _("Could not allocate memory for cleaned raster filename\n"));
+ rterror(_("Could not allocate memory for cleaned raster filename"));
rtdealloc_config(config);
exit(1);
}
file = rtalloc(sizeof(char) * (strlen(config->rt_filename[0]) + 1));
if (file == NULL) {
- fprintf(stderr, _("Could not allocate memory for proxy table name\n"));
+ rterror(_("Could not allocate memory for proxy table name"));
rtdealloc_config(config);
exit(1);
}
config->table = rtalloc(sizeof(char) * (strlen(file) + 1));
if (config->table == NULL) {
- fprintf(stderr, _("Could not allocate memory for proxy table name\n"));
+ rterror(_("Could not allocate memory for proxy table name"));
rtdealloc_config(config);
exit(1);
}
if (config->raster_column == NULL) {
config->raster_column = rtalloc(sizeof(char) * (strlen("rast") + 1));
if (config->raster_column == NULL) {
- fprintf(stderr, _("Could not allocate memory for default raster column name\n"));
+ rterror(_("Could not allocate memory for default raster column name"));
rtdealloc_config(config);
exit(1);
}
char factor[4];
config->overview_table = rtalloc(sizeof(char *) * config->overview_count);
if (config->overview_table == NULL) {
- fprintf(stderr, _("Could not allocate memory for overview table names\n"));
+ rterror(_("Could not allocate memory for overview table names"));
rtdealloc_config(config);
exit(1);
}
config->overview_table[i] = rtalloc(sizeof(char) * (strlen("o__") + strlen(factor) + strlen(config->table) + 1));
if (config->overview_table[i] == NULL) {
- fprintf(stderr, _("Could not allocate memory for overview table name\n"));
+ rterror(_("Could not allocate memory for overview table name"));
rtdealloc_config(config);
exit(1);
}
****************************************************************************/
if (config->schema != NULL && strlen(config->schema) > MAXNAMELEN) {
- fprintf(stderr, _("The schema name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d).\n"),
+ rtwarn(_("The schema name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
config->schema,
MAXNAMELEN
);
}
if (config->table != NULL && strlen(config->table) > MAXNAMELEN) {
- fprintf(stderr, _("The table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d).\n"),
+ rtwarn(_("The table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
config->table,
MAXNAMELEN
);
}
if (config->raster_column != NULL && strlen(config->raster_column) > MAXNAMELEN) {
- fprintf(stderr, _("The column name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d).\n"),
+ rtwarn(_("The column name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
config->raster_column,
MAXNAMELEN
);
}
if (config->tablespace != NULL && strlen(config->tablespace) > MAXNAMELEN) {
- fprintf(stderr, _("The tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d).\n"),
+ rtwarn(_("The tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
config->tablespace,
MAXNAMELEN
);
}
if (config->idx_tablespace != NULL && strlen(config->idx_tablespace) > MAXNAMELEN) {
- fprintf(stderr, _("The index tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d).\n"),
+ rtwarn(_("The index tablespace name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
config->idx_tablespace,
MAXNAMELEN
);
if (config->overview_count) {
for (i = 0; i < config->overview_count; i++) {
if (strlen(config->overview_table[i]) > MAXNAMELEN) {
- fprintf(stderr, _("The overview table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d).\n"),
+ rtwarn(_("The overview table name \"%s\" may exceed the maximum string length permitted for PostgreSQL identifiers (%d)"),
config->overview_table[i],
MAXNAMELEN
);
if (config->schema != NULL) {
tmp = rtalloc(sizeof(char) * (strlen(config->schema) + 4));
if (tmp == NULL) {
- fprintf(stderr, _("Could not allocate memory for quoting schema name\n"));
+ rterror(_("Could not allocate memory for quoting schema name"));
rtdealloc_config(config);
exit(1);
}
if (config->table != NULL) {
tmp = rtalloc(sizeof(char) * (strlen(config->table) + 3));
if (tmp == NULL) {
- fprintf(stderr, _("Could not allocate memory for quoting table name\n"));
+ rterror(_("Could not allocate memory for quoting table name"));
rtdealloc_config(config);
exit(1);
}
if (config->raster_column != NULL) {
tmp = rtalloc(sizeof(char) * (strlen(config->raster_column) + 3));
if (tmp == NULL) {
- fprintf(stderr, _("Could not allocate memory for quoting raster column name\n"));
+ rterror(_("Could not allocate memory for quoting raster column name"));
rtdealloc_config(config);
exit(1);
}
if (config->tablespace != NULL) {
tmp = rtalloc(sizeof(char) * (strlen(config->tablespace) + 3));
if (tmp == NULL) {
- fprintf(stderr, _("Could not allocate memory for quoting tablespace name\n"));
+ rterror(_("Could not allocate memory for quoting tablespace name"));
rtdealloc_config(config);
exit(1);
}
if (config->idx_tablespace != NULL) {
tmp = rtalloc(sizeof(char) * (strlen(config->idx_tablespace) + 3));
if (tmp == NULL) {
- fprintf(stderr, _("Could not allocate memory for quoting index tablespace name\n"));
+ rterror(_("Could not allocate memory for quoting index tablespace name"));
rtdealloc_config(config);
exit(1);
}
for (i = 0; i < config->overview_count; i++) {
tmp = rtalloc(sizeof(char) * (strlen(config->overview_table[i]) + 3));
if (tmp == NULL) {
- fprintf(stderr, _("Could not allocate memory for quoting overview table name\n"));
+ rterror(_("Could not allocate memory for quoting overview table name"));
rtdealloc_config(config);
exit(1);
}
/* initialize string buffer */
buffer = rtalloc(sizeof(STRINGBUFFER));
if (buffer == NULL) {
- fprintf(stderr, _("Could not allocate memory for output string buffer\n"));
+ rterror(_("Could not allocate memory for output string buffer"));
rtdealloc_config(config);
exit(1);
}
/* pass off to processing function */
if (!process_rasters(config, buffer)) {
- fprintf(stderr, _("Unable to process rasters\n"));
+ rterror(_("Unable to process rasters"));
rtdealloc_stringbuffer(buffer, 1);
rtdealloc_config(config);
exit(1);