PostGIS  2.1.10dev-r@@SVN_REVISION@@
rt_api.h
Go to the documentation of this file.
1 /*
2  * $Id: rt_api.h 14705 2016-02-26 11:37:39Z pramsey $
3  *
4  * WKTRaster - Raster Types for PostGIS
5  * http://trac.osgeo.org/postgis/wiki/WKTRaster
6  *
7  * Copyright (C) 2011-2013 Regents of the University of California
8  * <bkpark@ucdavis.edu>
9  * Copyright (C) 2010-2011 Jorge Arevalo <jorge.arevalo@deimos-space.com>
10  * Copyright (C) 2010-2011 David Zwarg <dzwarg@azavea.com>
11  * Copyright (C) 2009-2011 Pierre Racine <pierre.racine@sbf.ulaval.ca>
12  * Copyright (C) 2009-2011 Mateusz Loskot <mateusz@loskot.net>
13  * Copyright (C) 2008-2009 Sandro Santilli <strk@keybit.net>
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software Foundation,
27  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28  *
29  */
30 
31 #ifndef RT_API_H_INCLUDED
32 #define RT_API_H_INCLUDED
33 
34 /* define the systems */
35 #if defined(__linux__) /* (predefined) */
36 #if !defined(LINUX)
37 #define LINUX
38 #endif
39 #if !defined(UNIX)
40 #define UNIX /* make sure this is defined */
41 #endif
42 #endif
43 
44 
45 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) /* seems to work like Linux... */
46 #if !defined(LINUX)
47 #define LINUX
48 #endif
49 #if !defined(UNIX)
50 #define UNIX /* make sure this is defined */
51 #endif
52 #endif
53 
54 #if defined(__MSDOS__)
55 #if !defined(MSDOS)
56 #define MSDOS /* make sure this is defined */
57 #endif
58 #endif
59 
60 #if defined(__WIN32__) || defined(__NT__) || defined(_WIN32)
61 #if !defined(WIN32)
62 #define WIN32
63 #endif
64 #if defined(__BORLANDC__) && defined(MSDOS) /* Borland always defines MSDOS */
65 #undef MSDOS
66 #endif
67 #endif
68 
69 #if defined(__APPLE__)
70 #if !defined(UNIX)
71 #define UNIX
72 #endif
73 #endif
74 
75 #if defined(sun) || defined(__sun)
76 #if !defined(UNIX)
77 #define UNIX
78 #endif
79 #endif
80 
81 /* if we are in Unix define stricmp to be strcasecmp and strnicmp to */
82 /* be strncasecmp. I'm not sure if all Unices have these, but Linux */
83 /* does. */
84 #if defined(UNIX)
85 #if !defined(HAVE_STRICMP)
86 #define stricmp strcasecmp
87 #endif
88 #if !defined(HAVE_STRNICMP)
89 #define strnicmp strncasecmp
90 #endif
91 #endif
92 
93 #include <stdlib.h> /* For size_t, srand and rand */
94 #include <stdint.h> /* For C99 int types */
95 #include <float.h> /* for FLT_EPSILON, DBL_EPSILON and float type limits */
96 #include <limits.h> /* for integer type limits */
97 #include <math.h>
98 
99 #include "lwgeom_geos.h"
100 #include "liblwgeom.h"
101 
102 #include "gdal_alg.h"
103 #include "gdal_frmts.h"
104 #include "gdal.h"
105 #include "gdalwarper.h"
106 #include "ogr_api.h"
107 #include "ogr_srs_api.h"
108 #include "cpl_vsi.h"
109 #include "cpl_conv.h"
110 #include "../../postgis_config.h"
111 #include "../raster_config.h"
112 
133 typedef struct rt_raster_t* rt_raster;
134 typedef struct rt_band_t* rt_band;
135 typedef struct rt_pixel_t* rt_pixel;
136 typedef struct rt_geomval_t* rt_geomval;
137 typedef struct rt_bandstats_t* rt_bandstats;
138 typedef struct rt_histogram_t* rt_histogram;
139 typedef struct rt_quantile_t* rt_quantile;
143 
144 typedef struct rt_iterator_t* rt_iterator;
146 
148 typedef struct rt_colormap_t* rt_colormap;
149 
150 /* envelope information */
151 typedef struct {
152  double MinX;
153  double MaxX;
154  double MinY;
155  double MaxY;
156 
157  double UpperLeftX;
158  double UpperLeftY;
159 } rt_envelope;
160 
165 /* function return error states */
166 typedef enum {
167  ES_NONE = 0, /* no error */
168  ES_ERROR = 1 /* generic error */
169 } rt_errorstate;
170 
171 /* Pixel types */
172 typedef enum {
173  PT_1BB=0, /* 1-bit boolean */
174  PT_2BUI=1, /* 2-bit unsigned integer */
175  PT_4BUI=2, /* 4-bit unsigned integer */
176  PT_8BSI=3, /* 8-bit signed integer */
177  PT_8BUI=4, /* 8-bit unsigned integer */
178  PT_16BSI=5, /* 16-bit signed integer */
179  PT_16BUI=6, /* 16-bit unsigned integer */
180  PT_32BSI=7, /* 32-bit signed integer */
181  PT_32BUI=8, /* 32-bit unsigned integer */
182  PT_32BF=10, /* 32-bit float */
183  PT_64BF=11, /* 64-bit float */
185 } rt_pixtype;
186 
187 typedef enum {
194 } rt_extenttype;
195 
204 typedef enum {
212 
216 typedef void* (*rt_allocator)(size_t size);
217 typedef void* (*rt_reallocator)(void *mem, size_t size);
218 typedef void (*rt_deallocator)(void *mem);
219 typedef void (*rt_message_handler)(const char* string, va_list ap);
220 
221 /*******************************************************************
222  * Functions that may be used by the raster core function's caller
223  * (for example: rt_pg functions, test functions, future loader/exporter)
224  *******************************************************************/
228 extern void rt_install_default_allocators(void);
229 
230 
235 extern void* rtalloc(size_t size);
236 extern void* rtrealloc(void* mem, size_t size);
237 extern void rtdealloc(void* mem);
238 
239 /******************************************************************/
240 
241 
245 void rterror(const char *fmt, ...);
246 void rtinfo(const char *fmt, ...);
247 void rtwarn(const char *fmt, ...);
248 
249 
253 void * default_rt_allocator(size_t size);
254 void * default_rt_reallocator(void * mem, size_t size);
255 void default_rt_deallocator(void * mem);
256 void default_rt_error_handler(const char * fmt, va_list ap);
257 void default_rt_warning_handler(const char * fmt, va_list ap);
258 void default_rt_info_handler(const char * fmt, va_list ap);
259 
260 
261 /* Debugging macros */
262 #if POSTGIS_DEBUG_LEVEL > 0
263 
264 /* Display a simple message at NOTICE level */
265 #define RASTER_DEBUG(level, msg) \
266  do { \
267  if (POSTGIS_DEBUG_LEVEL >= level) \
268  rtinfo("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__); \
269  } while (0);
270 
271 /* Display a formatted message at NOTICE level (like printf, with variadic arguments) */
272 #define RASTER_DEBUGF(level, msg, ...) \
273  do { \
274  if (POSTGIS_DEBUG_LEVEL >= level) \
275  rtinfo("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__, __VA_ARGS__); \
276  } while (0);
277 
278 #else
279 
280 /* Empty prototype that can be optimised away by the compiler for non-debug builds */
281 #define RASTER_DEBUG(level, msg) \
282  ((void) 0)
283 
284 /* Empty prototype that can be optimised away by the compiler for non-debug builds */
285 #define RASTER_DEBUGF(level, msg, ...) \
286  ((void) 0)
287 
288 #endif
289 
290 /*- memory context -------------------------------------------------------*/
291 
292 void rt_set_handlers(rt_allocator allocator, rt_reallocator reallocator,
293  rt_deallocator deallocator, rt_message_handler error_handler,
294  rt_message_handler info_handler, rt_message_handler warning_handler);
295 
296 
297 
298 /*- rt_pixtype --------------------------------------------------------*/
299 
307 int rt_pixtype_size(rt_pixtype pixtype);
308 
318 int rt_pixtype_alignment(rt_pixtype pixtype);
319 
320 /* Return human-readable name of pixel type */
321 const char* rt_pixtype_name(rt_pixtype pixtype);
322 
323 /* Return pixel type index from human-readable name */
324 rt_pixtype rt_pixtype_index_from_name(const char* pixname);
325 
333 double rt_pixtype_get_min_value(rt_pixtype pixtype);
334 
346  rt_pixtype pixtype,
347  double val, double refval,
348  int *isequal
349 );
350 
351 /*- rt_pixel ----------------------------------------------------------*/
352 
353 /*
354  * Convert an array of rt_pixel objects to two 2D arrays of value and NODATA.
355  * The dimensions of the returned 2D array are [Y][X], going by row Y and
356  * then column X.
357  *
358  * @param npixel : array of rt_pixel objects
359  * @param count : number of elements in npixel
360  * @param x : the column of the center pixel (0-based)
361  * @param y : the line of the center pixel (0-based)
362  * @param distancex : the number of pixels around the specified pixel
363  * along the X axis
364  * @param distancey : the number of pixels around the specified pixel
365  * along the Y axis
366  * @param value : pointer to pointer for 2D value array
367  * @param nodata : pointer to pointer for 2D NODATA array
368  * @param dimx : size of value and nodata along the X axis
369  * @param dimy : size of value and nodata along the Y axis
370  *
371  * @return ES_NONE on success, ES_ERROR on error
372  */
374  rt_pixel npixel, int count,
375  int x, int y,
376  uint16_t distancex, uint16_t distancey,
377  double ***value,
378  int ***nodata,
379  int *dimx, int *dimy
380 );
381 
382 /*- rt_band ----------------------------------------------------------*/
383 
404 rt_band rt_band_new_inline(
405  uint16_t width, uint16_t height,
406  rt_pixtype pixtype,
407  uint32_t hasnodata, double nodataval,
408  uint8_t* data
409 );
410 
430 rt_band rt_band_new_offline(
431  uint16_t width, uint16_t height,
432  rt_pixtype pixtype,
433  uint32_t hasnodata, double nodataval,
434  uint8_t bandNum, const char* path
435 );
436 
447 rt_band rt_band_duplicate(rt_band band);
448 
458 int rt_band_is_offline(rt_band band);
459 
468 const char* rt_band_get_ext_path(rt_band band);
469 
479 rt_errorstate rt_band_get_ext_band_num(rt_band band, uint8_t *bandnum);
480 
489 
497 uint16_t rt_band_get_width(rt_band band);
498 
506 uint16_t rt_band_get_height(rt_band band);
507 
517 int rt_band_get_ownsdata_flag(rt_band band);
518 
519 /* set ownsdata flag */
520 void rt_band_set_ownsdata_flag(rt_band band, int flag);
521 
529 void* rt_band_get_data(rt_band band);
530 
541 
547 void rt_band_destroy(rt_band band);
548 
556 int rt_band_get_hasnodata_flag(rt_band band);
557 
563 void rt_band_set_hasnodata_flag(rt_band band, int flag);
564 
573 rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag);
574 
582 int rt_band_get_isnodata_flag(rt_band band);
583 
594 rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted);
595 
604 rt_errorstate rt_band_get_nodata(rt_band band, double *nodata);
605 
626  rt_band band,
627  int x, int y,
628  void *vals, uint32_t len
629 );
630 
643  rt_band band,
644  int x, int y,
645  double val,
646  int *converted
647 );
648 
670  rt_band band,
671  int x, int y,
672  uint16_t len,
673  void **vals, uint16_t *nvals
674 );
675 
689  rt_band band,
690  int x, int y,
691  double *value,
692  int *nodata
693 );
694 
713  rt_band band,
714  int x, int y,
715  uint16_t distancex, uint16_t distancey,
716  int exclude_nodata_value,
717  rt_pixel *npixels
718 );
719 
732  rt_band band, int exclude_nodata_value,
733  double *searchset, int searchcount,
734  rt_pixel *pixels
735 );
736 
744 double rt_band_get_min_value(rt_band band);
745 
753 int rt_band_check_is_nodata(rt_band band);
754 
765 int rt_band_clamped_value_is_nodata(rt_band band, double val);
766 
781  rt_band band,
782  double val,
783  double *newval, int *corrected
784 );
785 
799 rt_bandstats rt_band_get_summary_stats(
800  rt_band band,
801  int exclude_nodata_value, double sample, int inc_vals,
802  uint64_t *cK, double *cM, double *cQ
803 );
804 
823 rt_histogram rt_band_get_histogram(
824  rt_bandstats stats,
825  int bin_count, double *bin_widths, int bin_widths_count,
826  int right, double min, double max,
827  uint32_t *rtn_count
828 );
829 
841 rt_quantile rt_band_get_quantiles(rt_bandstats stats,
842  double *quantiles, int quantiles_count, uint32_t *rtn_count);
843 
844 struct quantile_llist;
846  struct quantile_llist **list,
847  uint32_t list_count
848 );
849 
877 rt_quantile rt_band_get_quantiles_stream(
878  rt_band band,
879  int exclude_nodata_value, double sample,
880  uint64_t cov_count,
881  struct quantile_llist **qlls, uint32_t *qlls_count,
882  double *quantiles, int quantiles_count,
883  uint32_t *rtn_count
884 );
885 
900 rt_valuecount rt_band_get_value_count(
901  rt_band band, int exclude_nodata_value,
902  double *search_values, uint32_t search_values_count, double roundto,
903  uint32_t *rtn_total, uint32_t *rtn_count
904 );
905 
918 rt_band rt_band_reclass(
919  rt_band srcband, rt_pixtype pixtype,
920  uint32_t hasnodata, double nodataval,
921  rt_reclassexpr *exprset, int exprcount
922 );
923 
924 /*- rt_raster --------------------------------------------------------*/
925 
937 rt_raster rt_raster_new(uint32_t width, uint32_t height);
938 
949 rt_raster rt_raster_from_wkb(const uint8_t* wkb, uint32_t wkbsize);
950 
961 rt_raster rt_raster_from_hexwkb(const char* hexwkb, uint32_t hexwkbsize);
962 
972 uint8_t *rt_raster_to_wkb(rt_raster raster, int outasin, uint32_t *wkbsize);
973 
984 char *rt_raster_to_hexwkb(rt_raster raster, int outasin, uint32_t *hexwkbsize);
985 
996 void rt_raster_destroy(rt_raster raster);
997 
998 /* Get number of bands */
999 int rt_raster_get_num_bands(rt_raster raster);
1000 
1009 rt_band rt_raster_get_band(rt_raster raster, int bandNum);
1010 
1011 /* Get number of rows */
1012 uint16_t rt_raster_get_width(rt_raster raster);
1013 
1014 /* Get number of columns */
1015 uint16_t rt_raster_get_height(rt_raster raster);
1016 
1027 int rt_raster_add_band(rt_raster raster, rt_band band, int index);
1028 
1042  rt_raster raster,
1043  rt_pixtype pixtype,
1044  double initialvalue,
1045  uint32_t hasnodata, double nodatavalue,
1046  int index
1047 );
1048 
1058 void rt_raster_set_scale(rt_raster raster,
1059  double scaleX, double scaleY);
1060 
1068 double rt_raster_get_x_scale(rt_raster raster);
1069 
1077 double rt_raster_get_y_scale(rt_raster raster);
1078 
1088 void rt_raster_set_offsets(rt_raster raster,
1089  double x, double y);
1090 
1099 double rt_raster_get_x_offset(rt_raster raster);
1100 
1109 double rt_raster_get_y_offset(rt_raster raster);
1110 
1118 void rt_raster_set_skews(rt_raster raster,
1119  double skewX, double skewY);
1120 
1127 double rt_raster_get_x_skew(rt_raster raster);
1128 
1135 double rt_raster_get_y_skew(rt_raster raster);
1136 
1149 void rt_raster_get_phys_params(rt_raster rast,
1150  double *i_mag, double *j_mag, double *theta_i, double *theta_ij) ;
1151 
1167 void rt_raster_set_phys_params(rt_raster rast,
1168  double i_mag, double j_mag, double theta_i, double theta_ij) ;
1169 
1170 
1186 void rt_raster_calc_phys_params(double xscale,
1187  double xskew, double yskew, double yscale,
1188  double *i_mag, double *j_mag, double *theta_i, double *theta_ij) ;
1189 
1190 
1207 int rt_raster_calc_gt_coeff(double i_mag,
1208  double j_mag, double theta_i, double theta_ij,
1209  double *xscale, double *xskew, double *yskew, double *yscale) ;
1210 
1217 void rt_raster_set_srid(rt_raster raster, int32_t srid);
1218 
1225 int32_t rt_raster_get_srid(rt_raster raster);
1226 
1237  rt_raster raster,
1238  double *gt, double *igt
1239 );
1240 
1248  double *gt);
1249 
1258  double *gt);
1259 
1273  rt_raster raster,
1274  double xr, double yr,
1275  double* xw, double* yw,
1276  double *gt
1277 );
1278 
1292  rt_raster raster,
1293  double xw, double yw,
1294  double *xr, double *yr,
1295  double *igt
1296 );
1297 
1311 
1323  rt_raster raster,
1324  rt_envelope *env
1325 );
1326 
1341  rt_raster raster, int nband,
1342  LWGEOM **perimeter
1343 );
1344 
1345 /*
1346  * Compute skewed extent that covers unskewed extent.
1347  *
1348  * @param envelope : unskewed extent of type rt_envelope
1349  * @param skew : pointer to 2-element array (x, y) of skew
1350  * @param scale : pointer to 2-element array (x, y) of scale
1351  * @param tolerance : value between 0 and 1 where the smaller the tolerance
1352  * results in an extent approaching the "minimum" skewed extent.
1353  * If value <= 0, tolerance = 0.1. If value > 1, tolerance = 1.
1354  *
1355  * @return skewed raster who's extent covers unskewed extent, NULL on error
1356  */
1357 rt_raster
1359  rt_envelope extent,
1360  double *skew,
1361  double *scale,
1362  double tolerance
1363 );
1364 
1379 LWPOLY* rt_raster_pixel_as_polygon(rt_raster raster, int x, int y);
1380 
1394 rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface);
1395 
1413 rt_geomval
1415  rt_raster raster, int nband,
1416  int exclude_nodata_value,
1417  int * pnElements
1418 );
1419 
1426 void* rt_raster_serialize(rt_raster raster);
1427 
1436 rt_raster rt_raster_deserialize(void* serialized, int header_only);
1437 
1445 int rt_raster_is_empty(rt_raster raster);
1446 
1455 int rt_raster_has_band(rt_raster raster, int nband);
1456 
1472  rt_raster torast, rt_raster fromrast,
1473  int fromindex, int toindex
1474 );
1475 
1487 rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums,
1488  int count);
1489 
1499 rt_band rt_raster_replace_band(rt_raster raster, rt_band band,
1500  int index);
1501 
1510 rt_raster rt_raster_clone(rt_raster raster, uint8_t deep);
1511 
1524 uint8_t *rt_raster_to_gdal(rt_raster raster, const char *srs,
1525  char *format, char **options, uint64_t *gdalsize);
1526 
1536 rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc);
1537 
1554 GDALDatasetH rt_raster_to_gdal_mem(
1555  rt_raster raster,
1556  const char *srs,
1557  uint32_t *bandNums,
1558  int *excludeNodataValues,
1559  int count,
1560  GDALDriverH *rtn_drv, int *destroy_rtn_drv
1561 );
1562 
1570 rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds);
1571 
1602 rt_raster rt_raster_gdal_warp(
1603  rt_raster raster,
1604  const char *src_srs, const char *dst_srs,
1605  double *scale_x, double *scale_y,
1606  int *width, int *height,
1607  double *ul_xw, double *ul_yw,
1608  double *grid_xw, double *grid_yw,
1609  double *skew_x, double *skew_y,
1610  GDALResampleAlg resample_alg, double max_err);
1611 
1638 rt_raster rt_raster_gdal_rasterize(const unsigned char *wkb,
1639  uint32_t wkb_len, const char *srs,
1640  uint32_t num_bands, rt_pixtype *pixtype,
1641  double *init, double *value,
1642  double *nodata, uint8_t *hasnodata,
1643  int *width, int *height,
1644  double *scale_x, double *scale_y,
1645  double *ul_xw, double *ul_yw,
1646  double *grid_xw, double *grid_yw,
1647  double *skew_x, double *skew_y,
1648  char **options
1649 );
1650 
1668  rt_raster rast1, int nband1,
1669  rt_raster rast2, int nband2,
1670  int *intersects
1671 );
1672 
1690  rt_raster rast1, int nband1,
1691  rt_raster rast2, int nband2,
1692  int *overlaps
1693 );
1694 
1712  rt_raster rast1, int nband1,
1713  rt_raster rast2, int nband2,
1714  int *contains
1715 );
1716 
1734  rt_raster rast1, int nband1,
1735  rt_raster rast2, int nband2,
1736  int *contains
1737 );
1738 
1756  rt_raster rast1, int nband1,
1757  rt_raster rast2, int nband2,
1758  int *touches
1759 );
1760 
1778  rt_raster rast1, int nband1,
1779  rt_raster rast2, int nband2,
1780  int *covers
1781 );
1782 
1800  rt_raster rast1, int nband1,
1801  rt_raster rast2, int nband2,
1802  int *coveredby
1803 );
1804 
1824  rt_raster rast1, int nband1,
1825  rt_raster rast2, int nband2,
1826  double distance,
1827  int *dwithin
1828 );
1829 
1849  rt_raster rast1, int nband1,
1850  rt_raster rast2, int nband2,
1851  double distance,
1852  int *dfwithin
1853 );
1854 
1855 /*
1856  * Return ES_ERROR if error occurred in function.
1857  * Paramter aligned returns non-zero if two rasters are aligned
1858  *
1859  * @param rast1 : the first raster for alignment test
1860  * @param rast2 : the second raster for alignment test
1861  * @param *aligned : non-zero value if the two rasters are aligned
1862  * @param *reason : reason why rasters are not aligned
1863  *
1864  * @return ES_NONE if success, ES_ERROR if error
1865  */
1867  rt_raster rast1,
1868  rt_raster rast2,
1869  int *aligned, char **reason
1870 );
1871 
1872 /*
1873  * Return raster of computed extent specified extenttype applied
1874  * on two input rasters. The raster returned should be freed by
1875  * the caller
1876  *
1877  * @param rast1 : the first raster
1878  * @param rast2 : the second raster
1879  * @param extenttype : type of extent for the output raster
1880  * @param *rtnraster : raster of computed extent
1881  * @param *offset : 4-element array indicating the X,Y offsets
1882  * for each raster. 0,1 for rast1 X,Y. 2,3 for rast2 X,Y.
1883  *
1884  * @return ES_NONE if success, ES_ERROR if error
1885  */
1888  rt_raster rast1, rt_raster rast2,
1889  rt_extenttype extenttype,
1890  rt_raster *rtnraster, double *offset
1891 );
1892 
1931  rt_iterator itrset, uint16_t itrcount,
1932  rt_extenttype extenttype, rt_raster customextent,
1933  rt_pixtype pixtype,
1934  uint8_t hasnodata, double nodataval,
1935  uint16_t distancex, uint16_t distancey,
1936  void *userarg,
1937  int (*callback)(
1938  rt_iterator_arg arg,
1939  void *userarg,
1940  double *value,
1941  int *nodata
1942  ),
1943  rt_raster *rtnraster
1944 );
1945 
1957 rt_raster rt_raster_colormap(
1958  rt_raster raster, int nband,
1959  rt_colormap colormap
1960 );
1961 
1962 /*- utilities -------------------------------------------------------*/
1963 
1964 /*
1965  * rt_core memory functions
1966  */
1967 extern void *rtalloc(size_t size);
1968 extern void *rtrealloc(void *mem, size_t size);
1969 extern void rtdealloc(void *mem);
1970 
1971 /*
1972  * GDAL driver flags
1973  */
1974 
1975 #define GDAL_ENABLE_ALL "ENABLE_ALL"
1976 #define GDAL_DISABLE_ALL "DISABLE_ALL"
1977 #define GDAL_VSICURL "VSICURL"
1978 
1979 /* Set of functions to clamp double to int of different size
1980  */
1981 
1982 #if !defined(POSTGIS_RASTER_WARN_ON_TRUNCATION)
1983 #define POSTGIS_RASTER_WARN_ON_TRUNCATION 0
1984 #endif
1985 
1986 #define POSTGIS_RT_1BBMAX 1
1987 #define POSTGIS_RT_2BUIMAX 3
1988 #define POSTGIS_RT_4BUIMAX 15
1989 
1990 uint8_t
1991 rt_util_clamp_to_1BB(double value);
1992 
1993 uint8_t
1995 
1996 uint8_t
1998 
1999 int8_t
2001 
2002 uint8_t
2004 
2005 int16_t
2007 
2008 uint16_t
2010 
2011 int32_t
2013 
2014 uint32_t
2016 
2017 float
2018 rt_util_clamp_to_32F(double value);
2019 
2020 int
2022  double initialvalue,
2023  int32_t checkvalint, uint32_t checkvaluint,
2024  float checkvalfloat, double checkvaldouble,
2025  rt_pixtype pixtype
2026 );
2027 
2035 GDALResampleAlg
2036 rt_util_gdal_resample_alg(const char *algname);
2037 
2045 GDALDataType
2047 
2055 rt_pixtype
2056 rt_util_gdal_datatype_to_pixtype(GDALDataType gdt);
2057 
2058 /*
2059  get GDAL runtime version information
2060 */
2061 const char*
2062 rt_util_gdal_version(const char *request);
2063 
2064 /*
2065  computed extent type from c string
2066 */
2068 rt_util_extent_type(const char *name);
2069 
2070 /*
2071  convert the spatial reference string from a GDAL recognized format to either WKT or Proj4
2072 */
2073 char*
2074 rt_util_gdal_convert_sr(const char *srs, int proj4);
2075 
2076 /*
2077  is the spatial reference string supported by GDAL
2078 */
2079 int
2080 rt_util_gdal_supported_sr(const char *srs);
2081 
2092 rt_errorstate rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode);
2093 
2094 /*
2095  is GDAL configured correctly?
2096 */
2097 int
2099 
2100 /*
2101  register all GDAL drivers
2102 */
2103 int
2104 rt_util_gdal_register_all(int force_register_all);
2105 
2106 /*
2107  is the driver registered?
2108 */
2109 int
2110 rt_util_gdal_driver_registered(const char *drv);
2111 
2112 /*
2113  wrapper for GDALOpen and GDALOpenShared
2114 */
2115 GDALDatasetH
2116 rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared);
2117 
2118 void
2120  OGREnvelope env,
2121  rt_envelope *ext
2122 );
2123 
2124 void
2126  rt_envelope ext,
2127  OGREnvelope *env
2128 );
2129 
2130 LWPOLY *
2132  rt_envelope ext
2133 );
2134 
2135 int
2137  double *gt1,
2138  double *gt2
2139 );
2140 
2141 /* coordinates in RGB and HSV are floating point values between 0 and 1 */
2144  double rgb[3],
2145  double hsv[3]
2146 );
2147 
2148 /* coordinates in RGB and HSV are floating point values between 0 and 1 */
2151  double hsv[3],
2152  double rgb[3]
2153 );
2154 
2155 /*
2156  helper macros for consistent floating point equality checks
2157 */
2158 #define FLT_NEQ(x, y) (fabs(x - y) > FLT_EPSILON)
2159 #define FLT_EQ(x, y) (!FLT_NEQ(x, y))
2160 #define DBL_NEQ(x, y) (fabs(x - y) > DBL_EPSILON)
2161 #define DBL_EQ(x, y) (!DBL_NEQ(x, y))
2162 
2163 /*
2164  helper macro for symmetrical rounding
2165 */
2166 #define ROUND(x, y) (((x > 0.0) ? floor((x * pow(10, y) + 0.5)) : ceil((x * pow(10, y) - 0.5))) / pow(10, y))
2167 
2176  /*---[ 8 byte boundary ]---{ */
2177  uint32_t size; /* required by postgresql: 4 bytes */
2178  uint16_t version; /* format version (this is version 0): 2 bytes */
2179  uint16_t numBands; /* Number of bands: 2 bytes */
2180 
2181  /* }---[ 8 byte boundary ]---{ */
2182  double scaleX; /* pixel width: 8 bytes */
2183 
2184  /* }---[ 8 byte boundary ]---{ */
2185  double scaleY; /* pixel height: 8 bytes */
2186 
2187  /* }---[ 8 byte boundary ]---{ */
2188  double ipX; /* insertion point X: 8 bytes */
2189 
2190  /* }---[ 8 byte boundary ]---{ */
2191  double ipY; /* insertion point Y: 8 bytes */
2192 
2193  /* }---[ 8 byte boundary ]---{ */
2194  double skewX; /* skew about the X axis: 8 bytes */
2195 
2196  /* }---[ 8 byte boundary ]---{ */
2197  double skewY; /* skew about the Y axis: 8 bytes */
2198 
2199  /* }---[ 8 byte boundary ]--- */
2200  int32_t srid; /* Spatial reference id: 4 bytes */
2201  uint16_t width; /* pixel columns: 2 bytes */
2202  uint16_t height; /* pixel rows: 2 bytes */
2203 };
2204 
2205 /* NOTE: the initial part of this structure matches the layout
2206  * of data in the serialized form version 0, starting
2207  * from the numBands element
2208  */
2209 struct rt_raster_t {
2210  uint32_t size;
2211  uint16_t version;
2212 
2213  /* Number of bands, all share the same dimension
2214  * and georeference */
2215  uint16_t numBands;
2216 
2217  /* Georeference (in projection units) */
2218  double scaleX; /* pixel width */
2219  double scaleY; /* pixel height */
2220  double ipX; /* geo x ordinate of the corner of upper-left pixel */
2221  double ipY; /* geo y ordinate of the corner of bottom-right pixel */
2222  double skewX; /* skew about the X axis*/
2223  double skewY; /* skew about the Y axis */
2224 
2225  int32_t srid; /* spatial reference id */
2226  uint16_t width; /* pixel columns - max 65535 */
2227  uint16_t height; /* pixel rows - max 65535 */
2228  rt_band *bands; /* actual bands */
2229 
2230 };
2231 
2233  uint8_t bandNum; /* 0-based */
2234  char* path; /* internally owned */
2235  void *mem; /* loaded external band data, internally owned */
2236 };
2237 
2238 struct rt_band_t {
2240  int32_t offline;
2241  uint16_t width;
2242  uint16_t height;
2243  int32_t hasnodata; /* a flag indicating if this band contains nodata values */
2244  int32_t isnodata; /* a flag indicating if this band is filled only with
2245  nodata values. flag CANNOT be TRUE if hasnodata is FALSE */
2246  double nodataval; /* int will be converted ... */
2247  int8_t ownsdata; /* 0, externally owned. 1, internally owned. only applies to data.mem */
2248 
2249  rt_raster raster; /* reference to parent raster */
2250 
2251  union {
2252  void* mem; /* actual data, externally owned */
2253  struct rt_extband_t offline;
2254  } data;
2255 
2256 };
2257 
2258 struct rt_pixel_t {
2259  int x; /* column */
2260  int y; /* line */
2261 
2262  uint8_t nodata;
2263  double value;
2264 
2266 };
2267 
2268 /* polygon as LWPOLY with associated value */
2271  double val;
2272 };
2273 
2274 /* summary stats of specified band */
2276  double sample;
2277  uint32_t count;
2278 
2279  double min;
2280  double max;
2281  double sum;
2282  double mean;
2283  double stddev;
2284 
2285  double *values;
2286  int sorted; /* flag indicating that values is sorted ascending by value */
2287 };
2288 
2289 /* histogram bin(s) of specified band */
2291  uint32_t count;
2292  double percent;
2293 
2294  double min;
2295  double max;
2296 
2297  int inc_min;
2298  int inc_max;
2299 };
2300 
2301 /* quantile(s) of the specified band */
2303  double quantile;
2304  double value;
2305  uint32_t has_value;
2306 };
2307 
2308 /* listed-list structures for rt_band_get_quantiles_stream */
2310  uint8_t algeq; /* AL-GEQ (1) or AL-GT (0) */
2311  double quantile;
2312  uint64_t tau; /* position in sequence */
2313 
2314  struct quantile_llist_element *head; /* H index 0 */
2315  struct quantile_llist_element *tail; /* H index last */
2316  uint32_t count; /* # of elements in H */
2317 
2318  /* faster access to elements at specific intervals */
2320  uint32_t index_max; /* max # of elements in index */
2321 
2322  uint64_t sum1; /* N1H */
2323  uint64_t sum2; /* N2H */
2324 };
2325 
2327  double value;
2328  uint32_t count;
2329 
2332 };
2333 
2336  uint32_t index;
2337 };
2338 
2339 /* number of times a value occurs */
2341  double value;
2342  uint32_t count;
2343  double percent;
2344 };
2345 
2346 /* reclassification expression */
2349  double min;
2350  double max;
2351  int inc_min; /* include min */
2352  int inc_max; /* include max */
2353  int exc_min; /* exceed min */
2354  int exc_max; /* exceed max */
2355  } src, dst;
2356 };
2357 
2358 /* raster iterator */
2360  rt_raster raster;
2361  uint16_t nband; /* 0-based */
2362  uint8_t nbnodata; /* no band = treat as NODATA */
2363 };
2364 
2365 /* callback argument from raster iterator */
2367  /* # of rasters, Z-axis */
2368  uint16_t rasters;
2369  /* # of rows, Y-axis */
2370  uint32_t rows;
2371  /* # of columns, X-axis */
2372  uint32_t columns;
2373 
2374  /* axis order: Z,X,Y */
2375  /* individual pixel values */
2376  double ***values;
2377  /* 0,1 value of nodata flag */
2378  int ***nodata;
2379 
2380  /* X,Y of pixel from each input raster */
2381  int **src_pixel;
2382 
2383  /* X,Y of pixel from output raster */
2384  int dst_pixel[2];
2385 };
2386 
2387 /* gdal driver information */
2389  int idx;
2390  char *short_name;
2391  char *long_name;
2393 };
2394 
2395 /* raster colormap entry */
2398  double value;
2399  uint8_t color[4]; /* RGBA */
2400 };
2401 
2403  enum {
2407  } method;
2408 
2409  int ncolor;
2410  uint16_t nentry;
2411  rt_colormap_entry entry;
2412 };
2413 
2414 #endif /* RT_API_H_INCLUDED */
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
Definition: rt_api.c:9339
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
Definition: rt_api.c:1636
struct rt_valuecount_t * rt_valuecount
Definition: rt_api.h:140
Datum coveredby(PG_FUNCTION_ARGS)
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_api.c:2302
uint8_t rt_util_clamp_to_8BUI(double value)
Definition: rt_api.c:109
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_api.c:445
rt_errorstate rt_pixel_set_to_array(rt_pixel npixel, int count, int x, int y, uint16_t distancex, uint16_t distancey, double ***value, int ***nodata, int *dimx, int *dimy)
Definition: rt_api.c:1341
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_api.c:5677
uint8_t rt_util_clamp_to_4BUI(double value)
Definition: rt_api.c:99
uint64_t sum1
Definition: rt_api.h:2322
rt_raster rt_raster_colormap(rt_raster raster, int nband, rt_colormap colormap)
Returns a new raster with up to four 8BUI bands (RGBA) from applying a colormap to the user-specified...
Definition: rt_api.c:14937
double skewY
Definition: rt_api.h:2223
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_api.c:8158
void rt_util_from_ogr_envelope(OGREnvelope env, rt_envelope *ext)
Definition: rt_api.c:514
double MinY
Definition: rt_api.h:154
struct rt_band_t * rt_band
Definition: rt_api.h:134
int rt_util_gdal_configured(void)
Definition: rt_api.c:424
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_api.c:5686
rt_raster rt_raster_gdal_warp(rt_raster raster, const char *src_srs, const char *dst_srs, double *scale_x, double *scale_y, int *width, int *height, double *ul_xw, double *ul_yw, double *grid_xw, double *grid_yw, double *skew_x, double *skew_y, GDALResampleAlg resample_alg, double max_err)
Return a warped raster using GDAL Warp API.
Definition: rt_api.c:9710
double mean
Definition: rt_api.h:2282
int32_t srid
Definition: rt_api.h:2225
void rtdealloc(void *mem)
Definition: rt_api.c:882
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_api.c:5527
uint16_t nentry
Definition: rt_api.h:2410
double UpperLeftX
Definition: rt_api.h:157
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_api.c:5387
rt_errorstate rt_raster_fully_within_distance(rt_raster rast1, int nband1, rt_raster rast2, int nband2, double distance, int *dfwithin)
Return ES_ERROR if error occurred in function.
Definition: rt_api.c:12685
Datum covers(PG_FUNCTION_ARGS)
rt_raster rt_raster_compute_skewed_raster(rt_envelope extent, double *skew, double *scale, double tolerance)
Definition: rt_api.c:6764
rt_errorstate rt_raster_covers(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *covers)
Return ES_ERROR if error occurred in function.
Definition: rt_api.c:12526
struct rt_raster_t * rt_raster
Types definitions.
Definition: rt_api.h:133
struct quantile_llist_element * element
Definition: rt_api.h:2335
uint32_t count
Definition: rt_api.h:2277
tuple data
Definition: ovdump.py:103
double quantile
Definition: rt_api.h:2311
struct quantile_llist_element * prev
Definition: rt_api.h:2330
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_api.c:1710
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_api.c:2061
void * mem
Definition: rt_api.h:2235
uint16_t numBands
Definition: rt_api.h:2215
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_api.c:1168
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band's clamped NODATA value.
Definition: rt_api.c:3126
struct rt_reclassexpr_t::rt_reclassrange dst
struct rt_bandstats_t * rt_bandstats
Definition: rt_api.h:137
float rt_util_clamp_to_32F(double value)
Definition: rt_api.c:134
void *(* rt_allocator)(size_t size)
Global functions for memory/logging handlers.
Definition: rt_api.h:216
double MaxY
Definition: rt_api.h:155
rt_raster raster
Definition: rt_api.h:2249
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...
Definition: rt_api.c:846
uint32_t count
Definition: rt_api.h:2342
int rt_raster_copy_band(rt_raster torast, rt_raster fromrast, int fromindex, int toindex)
Copy one band from one raster to another.
Definition: rt_api.c:8582
double MaxX
Definition: rt_api.h:153
rt_pixtype pixtype
Definition: rt_api.h:2239
int ** src_pixel
Definition: rt_api.h:2381
rt_errorstate rt_raster_coveredby(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *coveredby)
Return ES_ERROR if error occurred in function.
Definition: rt_api.c:12557
int32_t rt_util_clamp_to_32BSI(double value)
Definition: rt_api.c:124
double quantile
Definition: rt_api.h:2303
tuple gt
Definition: window.py:79
Definition: rt_api.h:184
int rt_band_get_nearest_pixel(rt_band band, int x, int y, uint16_t distancex, uint16_t distancey, int exclude_nodata_value, rt_pixel *npixels)
Get nearest pixel(s) with value (not NODATA) to specified pixel.
Definition: rt_api.c:2702
uint8_t rt_util_clamp_to_1BB(double value)
Definition: rt_api.c:89
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_api.c:1900
tuple fmt
Definition: pixval.py:92
double sum
Definition: rt_api.h:2281
char * short_name
Definition: rt_api.h:2390
void * rtrealloc(void *mem, size_t size)
Definition: rt_api.c:875
rt_extenttype rt_util_extent_type(const char *name)
Definition: rt_api.c:302
Datum contains(PG_FUNCTION_ARGS)
uint8_t color[4]
Definition: rt_api.h:2399
rt_band rt_raster_replace_band(rt_raster raster, rt_band band, int index)
Replace band at provided index with new band.
Definition: rt_api.c:8702
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_api.c:5486
LWGEOM * geom
Definition: rt_api.h:2265
double max
Definition: rt_api.h:2295
tuple band
Definition: ovdump.py:57
tuple rast
Definition: rtpixdump.py:62
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
Definition: rt_api.c:8563
GDALDatasetH rt_raster_to_gdal_mem(rt_raster raster, const char *srs, uint32_t *bandNums, int *excludeNodataValues, int count, GDALDriverH *rtn_drv, int *destroy_rtn_drv)
Return GDAL dataset using GDAL MEM driver from raster.
Definition: rt_api.c:8989
uint32_t rows
Definition: rt_api.h:2370
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_api.c:5495
rt_errorstate rt_band_corrected_clamped_value(rt_band band, double val, double *newval, int *corrected)
Correct value when clamped value is equal to clamped NODATA value.
Definition: rt_api.c:3162
uint16_t height
Definition: rt_api.h:2242
rt_errorstate rt_raster_overlaps(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *overlaps)
Return ES_ERROR if error occurred in function.
Definition: rt_api.c:12402
rt_errorstate rt_raster_get_perimeter(rt_raster raster, int nband, LWGEOM **perimeter)
Get raster perimeter.
Definition: rt_api.c:14683
double value
Definition: rt_api.h:2263
int rt_util_dbl_trunc_warning(double initialvalue, int32_t checkvalint, uint32_t checkvaluint, float checkvalfloat, double checkvaldouble, rt_pixtype pixtype)
Definition: rt_api.c:934
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_api.c:5518
double ipY
Definition: rt_api.h:2221
void *(* rt_reallocator)(void *mem, size_t size)
Definition: rt_api.h:217
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:123
uint8_t rt_util_clamp_to_2BUI(double value)
Definition: rt_api.c:94
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition: rt_api.c:1206
rt_quantile rt_band_get_quantiles(rt_bandstats stats, double *quantiles, int quantiles_count, uint32_t *rtn_count)
Compute the default set of or requested quantiles for a set of data the quantile formula used is same...
Definition: rt_api.c:3823
int rt_raster_calc_gt_coeff(double i_mag, double j_mag, double theta_i, double theta_ij, double *xscale, double *xskew, double *yskew, double *yscale)
Calculates the coefficients of a geotransform given the physically significant parameters describing ...
Definition: rt_api.c:5619
void rt_raster_set_phys_params(rt_raster rast, double i_mag, double j_mag, double theta_i, double theta_ij)
Calculates the geotransform coefficients and applies them to the supplied raster. ...
Definition: rt_api.c:5602
rt_errorstate rt_raster_from_two_rasters(rt_raster rast1, rt_raster rast2, rt_extenttype extenttype, rt_raster *rtnraster, double *offset)
Definition: rt_api.c:12876
rt_errorstate rt_band_set_pixel_line(rt_band band, int x, int y, void *vals, uint32_t len)
Set values of multiple pixels.
Definition: rt_api.c:2181
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
Definition: rt_api.c:5668
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
Definition: rt_api.c:487
rt_errorstate rt_util_rgb_to_hsv(double rgb[3], double hsv[3])
Definition: rt_api.c:611
Datum overlaps(PG_FUNCTION_ARGS)
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_api.c:5661
struct rt_reclassexpr_t * rt_reclassexpr
Definition: rt_api.h:142
Definition: rt_api.h:173
struct rt_pixel_t * rt_pixel
Definition: rt_api.h:135
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition: rt_api.c:2042
double value
Definition: rt_api.h:2341
rt_band rt_band_new_inline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t *data)
Create an in-db rt_band with no data.
Definition: rt_api.c:1466
GDALResampleAlg rt_util_gdal_resample_alg(const char *algname)
Convert cstring name to GDAL Resample Algorithm.
Definition: rt_api.c:202
uint32_t size
Definition: rt_api.h:2210
rt_errorstate rt_util_hsv_to_rgb(double hsv[3], double rgb[3])
Definition: rt_api.c:665
rt_band rt_band_duplicate(rt_band band)
Create a new band duplicated from source band.
Definition: rt_api.c:1594
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition: rt_api.c:5473
uint16_t height
Definition: rt_api.h:2227
Datum touches(PG_FUNCTION_ARGS)
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_api.c:1097
void rt_install_default_allocators(void)
Apply the default memory management (malloc() and free()) and error handlers.
Definition: rt_api.c:830
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition: rt_api.c:6005
double value
Definition: rt_api.h:2304
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 ...
Definition: rt_api.c:1928
rt_errorstate rt_raster_cell_to_geopoint(rt_raster raster, double xr, double yr, double *xw, double *yw, double *gt)
Convert an xr, yr raster point to an xw, yw point on map.
Definition: rt_api.c:6054
rt_histogram rt_band_get_histogram(rt_bandstats stats, int bin_count, double *bin_widths, int bin_widths_count, int right, double min, double max, uint32_t *rtn_count)
Count the distribution of data.
Definition: rt_api.c:3567
void rtinfo(const char *fmt,...)
Definition: rt_api.c:907
uint16_t rt_util_clamp_to_16BUI(double value)
Definition: rt_api.c:119
rt_errorstate rt_raster_intersects(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *intersects)
Return ES_ERROR if error occurred in function.
Definition: rt_api.c:11953
struct quantile_llist_element * next
Definition: rt_api.h:2331
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
Definition: rt_api.c:5706
LWPOLY * geom
Definition: rt_api.h:2270
double min
Definition: rt_api.h:2279
struct rt_colormap_t * rt_colormap
Definition: rt_api.h:148
uint8_t * rt_raster_to_gdal(rt_raster raster, const char *srs, char *format, char **options, uint64_t *gdalsize)
Return formatted GDAL raster from raster.
Definition: rt_api.c:8794
struct rt_geomval_t * rt_geomval
Definition: rt_api.h:136
void rtwarn(const char *fmt,...)
Definition: rt_api.c:920
int rt_util_gdal_driver_registered(const char *drv)
Definition: rt_api.c:461
int rt_band_get_pixel_of_value(rt_band band, int exclude_nodata_value, double *searchset, int searchcount, rt_pixel *pixels)
Search band for pixel(s) with search values.
Definition: rt_api.c:2980
rt_raster rt_raster_from_hexwkb(const char *hexwkb, uint32_t hexwkbsize)
Construct an rt_raster from a text HEXWKB representation.
Definition: rt_api.c:7799
struct rt_reclassexpr_t::rt_reclassrange src
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_api.c:5442
double val
Definition: rt_api.h:2271
struct rt_gdaldriver_t * rt_gdaldriver
Definition: rt_api.h:141
struct quantile_llist_element * tail
Definition: rt_api.h:2315
rt_pixtype rt_util_gdal_datatype_to_pixtype(GDALDataType gdt)
Convert GDALDataType to rt_pixtype.
Definition: rt_api.c:264
uint32_t rt_util_clamp_to_32BUI(double value)
Definition: rt_api.c:129
void default_rt_info_handler(const char *fmt, va_list ap)
Definition: rt_api.c:788
double percent
Definition: rt_api.h:2292
rt_pixtype
Definition: rt_api.h:172
uint16_t version
Definition: rt_api.h:2211
uint32_t columns
Definition: rt_api.h:2372
enum rt_colormap_t::@15 method
rt_errorstate rt_raster_get_inverse_geotransform_matrix(rt_raster raster, double *gt, double *igt)
Get 6-element array of raster inverse geotransform matrix.
Definition: rt_api.c:5975
struct rt_iterator_arg_t * rt_iterator_arg
Definition: rt_api.h:145
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
Definition: rt_api.c:2023
uint16_t rasters
Definition: rt_api.h:2368
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_api.c:1936
void default_rt_error_handler(const char *fmt, va_list ap)
Definition: rt_api.c:762
Datum intersects(PG_FUNCTION_ARGS)
tuple nband
Definition: pixval.py:52
uint64_t tau
Definition: rt_api.h:2312
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.
Definition: rt_api.c:1527
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
Definition: rt_api.c:3073
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_api.c:867
void default_rt_deallocator(void *mem)
Definition: rt_api.c:756
uint16_t width
Definition: rt_api.h:2226
rt_raster rt_raster_gdal_rasterize(const unsigned char *wkb, uint32_t wkb_len, const char *srs, uint32_t num_bands, rt_pixtype *pixtype, double *init, double *value, double *nodata, uint8_t *hasnodata, int *width, int *height, double *scale_x, double *scale_y, double *ul_xw, double *ul_yw, double *grid_xw, double *grid_yw, double *skew_x, double *skew_y, char **options)
Return a raster of the provided geometry.
Definition: rt_api.c:10620
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_api.c:3058
void rt_raster_get_phys_params(rt_raster rast, double *i_mag, double *j_mag, double *theta_i, double *theta_ij)
Calculates and returns the physically significant descriptors embodied in the geotransform attached t...
Definition: rt_api.c:5536
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
Definition: rt_api.c:6026
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_api.c:2549
void(* rt_deallocator)(void *mem)
Definition: rt_api.h:218
int8_t ownsdata
Definition: rt_api.h:2247
int count
Definition: genraster.py:57
tuple ds
Definition: pixval.py:66
uint8_t * rt_raster_to_wkb(rt_raster raster, int outasin, uint32_t *wkbsize)
Return this raster in WKB form.
Definition: rt_api.c:7887
double skewX
Definition: rt_api.h:2222
rt_colormap_entry entry
Definition: rt_api.h:2411
double * values
Definition: rt_api.h:2285
double nodataval
Definition: rt_api.h:2246
rt_errorstate rt_raster_within_distance(rt_raster rast1, int nband1, rt_raster rast2, int nband2, double distance, int *dwithin)
Return ES_ERROR if error occurred in function.
Definition: rt_api.c:12590
uint32_t index_max
Definition: rt_api.h:2320
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition: rt_api.c:8891
int rt_pixtype_alignment(rt_pixtype pixtype)
Return alignment requirements for data in the given pixel type.
Definition: rt_api.c:1133
rt_errorstate rt_raster_contains_properly(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *contains)
Return ES_ERROR if error occurred in function.
Definition: rt_api.c:12495
rt_errorstate rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode)
Get auth name and code.
Definition: rt_api.c:381
void rt_util_to_ogr_envelope(rt_envelope ext, OGREnvelope *env)
Definition: rt_api.c:530
struct rt_histogram_t * rt_histogram
Definition: rt_api.h:138
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_api.c:5455
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition: rt_api.c:1909
rt_raster raster
Definition: rt_api.h:2360
uint8_t nodata
Definition: rt_api.h:2262
rt_errorstate
Enum definitions.
Definition: rt_api.h:166
uint16_t width
Definition: rt_api.h:2241
rt_band rt_band_reclass(rt_band srcband, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, rt_reclassexpr *exprset, int exprcount)
Returns new band with values reclassified.
Definition: rt_api.c:5009
tuple x
Definition: pixval.py:53
double min
Definition: rt_api.h:2294
Datum distance(PG_FUNCTION_ARGS)
double sample
Definition: rt_api.h:2276
uint16_t nband
Definition: rt_api.h:2361
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_api.c:5434
rt_bandstats rt_band_get_summary_stats(rt_band band, int exclude_nodata_value, double sample, int inc_vals, uint64_t *cK, double *cM, double *cQ)
Compute summary statistics for a band.
Definition: rt_api.c:3269
union rt_band_t::@14 data
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_api.c:1650
void * default_rt_reallocator(void *mem, size_t size)
Definition: rt_api.c:749
rt_extenttype
Definition: rt_api.h:187
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_api.c:895
void * default_rt_allocator(size_t size)
The default memory/logging handlers installed by lwgeom_install_default_allocators() ...
Definition: rt_api.c:742
rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums, int count)
Construct a new rt_raster from an existing rt_raster and an array of band numbers.
Definition: rt_api.c:8643
char * rt_raster_to_hexwkb(rt_raster raster, int outasin, uint32_t *hexwkbsize)
Return this raster in HEXWKB form (null-terminated hex)
Definition: rt_api.c:8062
void rt_raster_calc_phys_params(double xscale, double xskew, double yskew, double yscale, double *i_mag, double *j_mag, double *theta_i, double *theta_ij)
Calculates the physically significant descriptors embodied in an arbitrary geotransform.
Definition: rt_api.c:5555
rt_errorstate rt_band_get_pixel_line(rt_band band, int x, int y, uint16_t len, void **vals, uint16_t *nvals)
Get values of multiple pixels.
Definition: rt_api.c:2465
double percent
Definition: rt_api.h:2343
struct rt_quantile_t * rt_quantile
Definition: rt_api.h:139
int quantile_llist_destroy(struct quantile_llist **list, uint32_t list_count)
Definition: rt_api.c:4025
int32_t offline
Definition: rt_api.h:2240
double *** values
Definition: rt_api.h:2376
int rt_util_gdal_supported_sr(const char *srs)
Definition: rt_api.c:354
Definition: rt_api.h:2396
int32_t isnodata
Definition: rt_api.h:2244
uint8_t nbnodata
Definition: rt_api.h:2362
double MinX
Definition: rt_api.h:152
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
Definition: rt_api.c:13242
rt_errorstate rt_raster_touches(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *touches)
Return ES_ERROR if error occurred in function.
Definition: rt_api.c:12433
Struct definitions.
Definition: rt_api.h:2175
int8_t rt_util_clamp_to_8BSI(double value)
Definition: rt_api.c:104
rt_band * bands
Definition: rt_api.h:2228
char * create_options
Definition: rt_api.h:2392
struct quantile_llist_index * index
Definition: rt_api.h:2319
LWPOLY * rt_raster_pixel_as_polygon(rt_raster raster, int x, int y)
Get a raster pixel as a polygon.
Definition: rt_api.c:13182
rt_errorstate rt_raster_get_envelope(rt_raster raster, rt_envelope *env)
Get raster's envelope.
Definition: rt_api.c:6681
char * rt_util_gdal_convert_sr(const char *srs, int proj4)
Definition: rt_api.c:323
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition: rt_api.c:3080
uint8_t bandNum
Definition: rt_api.h:2233
rt_errorstate rt_raster_iterator(rt_iterator itrset, uint16_t itrcount, rt_extenttype extenttype, rt_raster customextent, rt_pixtype pixtype, uint8_t hasnodata, double nodataval, uint16_t distancex, uint16_t distancey, void *userarg, int(*callback)(rt_iterator_arg arg, void *userarg, double *value, int *nodata), rt_raster *rtnraster)
n-raster iterator.
Definition: rt_api.c:13927
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition: rt_api.c:8550
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition: rt_api.c:1918
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_api.c:5464
void * mem
Definition: rt_api.h:2252
char * long_name
Definition: rt_api.h:2391
rt_errorstate rt_raster_contains(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *contains)
Return ES_ERROR if error occurred in function.
Definition: rt_api.c:12464
double max
Definition: rt_api.h:2280
uint32_t has_value
Definition: rt_api.h:2305
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_api.c:8350
rt_errorstate rt_raster_geopoint_to_cell(rt_raster raster, double xw, double yw, double *xr, double *yr, double *igt)
Convert an xw, yw map point to a xr, yr raster point.
Definition: rt_api.c:6105
uint8_t algeq
Definition: rt_api.h:2310
int32_t hasnodata
Definition: rt_api.h:2243
uint32_t count
Definition: rt_api.h:2316
double ipX
Definition: rt_api.h:2220
int rt_util_same_geotransform_matrix(double *gt1, double *gt2)
Definition: rt_api.c:595
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
Definition: rt_api.c:8740
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
Definition: rt_api.c:2009
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
Definition: rt_api.c:1138
rt_geomval rt_raster_gdal_polygonize(rt_raster raster, int nband, int exclude_nodata_value, int *pnElements)
Returns a set of "geomval" value, one for each group of pixel sharing the same value for the provided...
Definition: rt_api.c:6175
struct quantile_llist_element * head
Definition: rt_api.h:2314
rt_errorstate rt_raster_get_convex_hull(rt_raster raster, LWGEOM **hull)
Get raster's convex hull.
Definition: rt_api.c:6556
double stddev
Definition: rt_api.h:2283
const char * rt_util_gdal_version(const char *request)
Definition: rt_api.c:291
double scaleX
Definition: rt_api.h:2218
LWPOLY * rt_util_envelope_to_lwpoly(rt_envelope ext)
Definition: rt_api.c:543
int *** nodata
Definition: rt_api.h:2378
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_api.c:5353
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
Definition: rt_api.c:12774
char * path
Definition: rt_api.h:2234
rt_errorstate rt_band_load_offline_data(rt_band band)
Load offline band's data.
Definition: rt_api.c:1739
int isnodata
Definition: rt_api.h:2397
GDALDataType rt_util_pixtype_to_gdal_datatype(rt_pixtype pt)
Convert rt_pixtype to GDALDataType.
Definition: rt_api.c:229
rt_geos_spatial_test
GEOS spatial relationship tests available.
Definition: rt_api.h:204
struct rt_colormap_entry_t * rt_colormap_entry
Definition: rt_api.h:147
double UpperLeftY
Definition: rt_api.h:158
rt_errorstate rt_pixtype_compare_clamped_values(rt_pixtype pixtype, double val, double refval, int *isequal)
Test to see if two values are equal when clamped.
Definition: rt_api.c:1258
rt_errorstate rt_band_get_ext_band_num(rt_band band, uint8_t *bandnum)
Return bands' external band number (only valid when rt_band_is_offline returns non-zero).
Definition: rt_api.c:1686
void default_rt_warning_handler(const char *fmt, va_list ap)
Definition: rt_api.c:775
int dst_pixel[2]
Definition: rt_api.h:2384
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_api.c:2002
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_api.c:5504
rt_raster rt_raster_from_wkb(const uint8_t *wkb, uint32_t wkbsize)
Construct an rt_raster from a binary WKB representation.
Definition: rt_api.c:7669
double value
Definition: rt_api.h:2398
void(* rt_message_handler)(const char *string, va_list ap)
Definition: rt_api.h:219
tuple y
Definition: pixval.py:54
rt_quantile rt_band_get_quantiles_stream(rt_band band, int exclude_nodata_value, double sample, uint64_t cov_count, struct quantile_llist **qlls, uint32_t *qlls_count, double *quantiles, int quantiles_count, uint32_t *rtn_count)
Compute the default set of or requested quantiles for a coverage.
Definition: rt_api.c:4156
uint64_t sum2
Definition: rt_api.h:2323
double scaleY
Definition: rt_api.h:2219
rt_valuecount rt_band_get_value_count(rt_band band, int exclude_nodata_value, double *search_values, uint32_t search_values_count, double roundto, uint32_t *rtn_total, uint32_t *rtn_count)
Count the number of times provided value(s) occur in the band.
Definition: rt_api.c:4750
This library is the generic geometry handling section of PostGIS.
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_api.c:5426
struct rt_iterator_t * rt_iterator
Definition: rt_api.h:144
uint32_t count
Definition: rt_api.h:2291
const char * rt_band_get_ext_path(rt_band band)
Return band's external path (only valid when rt_band_is_offline returns non-zero).
Definition: rt_api.c:1673
int rt_raster_generate_new_band(rt_raster raster, rt_pixtype pixtype, double initialvalue, uint32_t hasnodata, double nodatavalue, int index)
Generate a new inline band and add it to a raster.
Definition: rt_api.c:5784
int16_t rt_util_clamp_to_16BSI(double value)
Definition: rt_api.c:114