PostGIS  3.4.0dev-r@@SVN_REVISION@@
librtcore.h
Go to the documentation of this file.
1 /*
2  *
3  * WKTRaster - Raster Types for PostGIS
4  * http://trac.osgeo.org/postgis/wiki/WKTRaster
5  *
6  * Copyright (C) 2011-2013 Regents of the University of California
7  * <bkpark@ucdavis.edu>
8  * Copyright (C) 2010-2011 Jorge Arevalo <jorge.arevalo@deimos-space.com>
9  * Copyright (C) 2010-2011 David Zwarg <dzwarg@azavea.com>
10  * Copyright (C) 2009-2011 Pierre Racine <pierre.racine@sbf.ulaval.ca>
11  * Copyright (C) 2009-2011 Mateusz Loskot <mateusz@loskot.net>
12  * Copyright (C) 2008-2009 Sandro Santilli <strk@kbt.io>
13  * Copyright (C) 2013 Nathaneil Hunter Clay <clay.nathaniel@gmail.com
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 
48 /******************************************************************************
49 * Some rules for *.(c|h) files in rt_core
50 *
51 * All functions in rt_core that receive a band index parameter
52 * must be 0-based
53 *
54 * Variables and functions internal for a public function should be prefixed
55 * with _rti_, e.g. _rti_iterator_arg.
56 ******************************************************************************/
57 
58 #ifndef LIBRTCORE_H_INCLUDED
59 #define LIBRTCORE_H_INCLUDED
60 
61 /* define the systems */
62 #if defined(__linux__) /* (predefined) */
63 #if !defined(LINUX)
64 #define LINUX
65 #endif
66 #if !defined(UNIX)
67 #define UNIX /* make sure this is defined */
68 #endif
69 #endif
70 
71 
72 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) /* seems to work like Linux... */
73 #if !defined(LINUX)
74 #define LINUX
75 #endif
76 #if !defined(UNIX)
77 #define UNIX /* make sure this is defined */
78 #endif
79 #endif
80 
81 #if defined(__GNU__) /* GNU/Hurd is also like Linux */
82 #if !defined(LINUX)
83 #define LINUX
84 #endif
85 #if !defined(UNIX)
86 #define UNIX /* make sure this is defined */
87 #endif
88 #endif
89 
90 #if defined(__MSDOS__)
91 #if !defined(MSDOS)
92 #define MSDOS /* make sure this is defined */
93 #endif
94 #endif
95 
96 #if defined(__WIN32__) || defined(__NT__) || defined(_WIN32)
97 #if !defined(WIN32)
98 #define WIN32
99 #endif
100 #if defined(__BORLANDC__) && defined(MSDOS) /* Borland always defines MSDOS */
101 #undef MSDOS
102 #endif
103 #endif
104 
105 #if defined(__APPLE__)
106 #if !defined(UNIX)
107 #define UNIX
108 #endif
109 #endif
110 
111 #if defined(sun) || defined(__sun)
112 #if !defined(UNIX)
113 #define UNIX
114 #endif
115 #endif
116 
117 #include <stdio.h> /* for printf, sprintf */
118 #include <stdlib.h> /* For size_t, srand and rand */
119 #include <stdint.h> /* For C99 int types */
120 #include <string.h> /* for memcpy, strlen, etc */
121 #include <float.h> /* for FLT_EPSILON, DBL_EPSILON and float type limits */
122 #include <limits.h> /* for integer type limits */
123 
124 #include "liblwgeom_internal.h"
125 
126 #include "gdal.h"
127 #include "gdalgrid.h" /* for ParseAlgorithmAndOptions */
128 #include "gdal_frmts.h"
129 #include "gdalwarper.h"
130 #include "cpl_vsi.h"
131 #include "cpl_conv.h"
132 #include "cpl_string.h"
133 #include "cpl_minixml.h"
134 #include "ogr_api.h"
135 #include "ogr_srs_api.h"
136 
137 #include "postgis_config.h"
138 #include "raster_config.h"
139 
140 #ifndef __GNUC__
141 # define __attribute__ (x)
142 #endif
143 
147 typedef struct rt_raster_t* rt_raster;
148 typedef struct rt_band_t* rt_band;
149 typedef struct rt_pixel_t* rt_pixel;
150 typedef struct rt_mask_t* rt_mask;
151 typedef struct rt_geomval_t* rt_geomval;
152 typedef struct rt_bandstats_t* rt_bandstats;
153 typedef struct rt_histogram_t* rt_histogram;
154 typedef struct rt_quantile_t* rt_quantile;
158 
159 typedef struct rt_iterator_t* rt_iterator;
161 
163 typedef struct rt_colormap_t* rt_colormap;
164 
165 /* envelope information */
166 typedef struct {
167  double MinX;
168  double MaxX;
169  double MinY;
170  double MaxY;
171 
172  double UpperLeftX;
173  double UpperLeftY;
174 } rt_envelope;
175 
180 /* function return error states */
181 typedef enum {
182  ES_NONE = 0, /* no error */
183  ES_ERROR = 1 /* generic error */
185 
186 /* Pixel types */
187 typedef enum {
188  PT_1BB=0, /* 1-bit boolean */
189  PT_2BUI=1, /* 2-bit unsigned integer */
190  PT_4BUI=2, /* 4-bit unsigned integer */
191  PT_8BSI=3, /* 8-bit signed integer */
192  PT_8BUI=4, /* 8-bit unsigned integer */
193  PT_16BSI=5, /* 16-bit signed integer */
194  PT_16BUI=6, /* 16-bit unsigned integer */
195  PT_32BSI=7, /* 32-bit signed integer */
196  PT_32BUI=8, /* 32-bit unsigned integer */
197  PT_32BF=10, /* 32-bit float */
198  PT_64BF=11, /* 64-bit float */
199  PT_END=13
201 
202 typedef enum {
208  ET_CUSTOM
210 
219 typedef enum {
227 
231 typedef char* (*rt_options)(const char* varname);
232 typedef void* (*rt_allocator)(size_t size);
233 typedef void* (*rt_reallocator)(void *mem, size_t size);
234 typedef void (*rt_deallocator)(void *mem);
235 typedef void (*rt_message_handler)(const char* string, va_list ap)
236  __attribute__ (( format(printf,1,0) ));
237 
238 /*******************************************************************
239  * Functions that may be used by the raster core function's caller
240  * (for example: rt_pg functions, test functions, future loader/exporter)
241  *******************************************************************/
245 extern void rt_install_default_allocators(void);
246 
251 extern void* rtalloc(size_t size);
252 extern void* rtrealloc(void* mem, size_t size);
253 extern void rtdealloc(void* mem);
254 
255 /******************************************************************/
256 
257 
261 void rterror(const char *fmt, ...);
262 void rtinfo(const char *fmt, ...);
263 void rtwarn(const char *fmt, ...);
264 
268 char* rtoptions(const char* varname);
269 char* rtstrdup(const char *str);
270 
274 void * default_rt_allocator(size_t size);
275 void * default_rt_reallocator(void * mem, size_t size);
276 void default_rt_deallocator(void * mem);
277 void default_rt_error_handler(const char * fmt, va_list ap);
278 void default_rt_warning_handler(const char * fmt, va_list ap);
279 void default_rt_info_handler(const char * fmt, va_list ap);
280 char * default_rt_options(const char* varname);
281 
282 /* Debugging macros */
283 #if POSTGIS_DEBUG_LEVEL > 0
284 
285 /* Display a simple message at NOTICE level */
286 #define RASTER_DEBUG(level, msg) \
287  do { \
288  if (POSTGIS_DEBUG_LEVEL >= level) \
289  rtinfo("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__); \
290  } while (0);
291 
292 /* Display a formatted message at NOTICE level (like printf, with variadic arguments) */
293 #define RASTER_DEBUGF(level, msg, ...) \
294  do { \
295  if (POSTGIS_DEBUG_LEVEL >= level) \
296  rtinfo("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__, __VA_ARGS__); \
297  } while (0);
298 
299 #else
300 
301 /* Empty prototype that can be optimised away by the compiler for non-debug builds */
302 #define RASTER_DEBUG(level, msg) \
303  ((void) 0)
304 
305 /* Empty prototype that can be optimised away by the compiler for non-debug builds */
306 #define RASTER_DEBUGF(level, msg, ...) \
307  ((void) 0)
308 
309 #endif
310 
311 /*- memory context -------------------------------------------------------*/
312 
313 void rt_set_handlers(rt_allocator allocator, rt_reallocator reallocator,
314  rt_deallocator deallocator, rt_message_handler error_handler,
315  rt_message_handler info_handler, rt_message_handler warning_handler);
316 
317 void rt_set_handlers_options(rt_allocator allocator, rt_reallocator reallocator,
318  rt_deallocator deallocator, rt_message_handler error_handler,
319  rt_message_handler info_handler, rt_message_handler warning_handler,
320  rt_options options_handler);
321 
322 
323 
324 /*- rt_pixtype --------------------------------------------------------*/
325 
333 int rt_pixtype_size(rt_pixtype pixtype);
334 
344 int rt_pixtype_alignment(rt_pixtype pixtype);
345 
346 /* Return human-readable name of pixel type */
347 const char* rt_pixtype_name(rt_pixtype pixtype);
348 
349 /* Return pixel type index from human-readable name */
350 rt_pixtype rt_pixtype_index_from_name(const char* pixname);
351 
359 double rt_pixtype_get_min_value(rt_pixtype pixtype);
360 
372  rt_pixtype pixtype,
373  double val, double refval,
374  int *isequal
375 );
376 
377 /*- rt_pixel ----------------------------------------------------------*/
378 
379 /*
380  * Convert an array of rt_pixel objects to two 2D arrays of value and NODATA.
381  * The dimensions of the returned 2D array are [Y][X], going by row Y and
382  * then column X.
383  *
384  * @param npixel : array of rt_pixel objects
385  * @param count : number of elements in npixel
386  * @param mask : mask to be respected when returning array
387  * @param x : the column of the center pixel (0-based)
388  * @param y : the line of the center pixel (0-based)
389  * @param distancex : the number of pixels around the specified pixel
390  * along the X axis
391  * @param distancey : the number of pixels around the specified pixel
392  * along the Y axis
393  * @param value : pointer to pointer for 2D value array
394  * @param nodata : pointer to pointer for 2D NODATA array
395  * @param dimx : size of value and nodata along the X axis
396  * @param dimy : size of value and nodata along the Y axis
397  *
398  * @return ES_NONE on success, ES_ERROR on error
399  */
401  rt_pixel npixel,uint32_t count,
402  rt_mask mask,
403  int x, int y,
404  uint16_t distancex, uint16_t distancey,
405  double ***value,
406  int ***nodata,
407  int *dimx, int *dimy
408 );
409 
410 /*- rt_band ----------------------------------------------------------*/
411 
433  uint16_t width, uint16_t height,
434  rt_pixtype pixtype,
435  uint32_t hasnodata, double nodataval,
436  uint8_t* data
437 );
438 
459  uint16_t width, uint16_t height,
460  rt_pixtype pixtype,
461  uint32_t hasnodata, double nodataval,
462  uint8_t bandNum, const char* path
463 );
464 
483 rt_band
485  uint16_t width,
486  uint16_t height,
487  int hasnodata,
488  double nodataval,
489  uint8_t bandNum,
490  const char* path,
491  int force
492 );
493 
505 
516 
525 const char* rt_band_get_ext_path(rt_band band);
526 
536 
546 
557 
566 
574 uint16_t rt_band_get_width(rt_band band);
575 
584 
595 
596 /* set ownsdata flag */
597 void rt_band_set_ownsdata_flag(rt_band band, int flag);
598 
607 
618 
625 
634 
640 void rt_band_set_hasnodata_flag(rt_band band, int flag);
641 
651 
660 
671 rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted);
672 
682 
703  rt_band band,
704  int x, int y,
705  void *vals, uint32_t len
706 );
707 
720  rt_band band,
721  int x, int y,
722  double val,
723  int *converted
724 );
725 
747  rt_band band,
748  int x, int y,
749  uint16_t len,
750  void **vals, uint16_t *nvals
751 );
752 
766  rt_band band,
767  int x, int y,
768  double *value,
769  int *nodata
770 );
771 
790  rt_band band,
791  int x, int y,
792  uint16_t distancex, uint16_t distancey,
793  int exclude_nodata_value,
794  rt_pixel *npixels
795 );
796 
809  rt_band band, int exclude_nodata_value,
810  double *searchset, int searchcount,
811  rt_pixel *pixels
812 );
813 
822 
831 
843 
858  rt_band band,
859  double val,
860  double *newval, int *corrected
861 );
862 
877  rt_band band,
878  int exclude_nodata_value, double sample, int inc_vals,
879  uint64_t *cK, double *cM, double *cQ
880 );
881 
901  rt_bandstats stats,
902  uint32_t bin_count, double *bin_widths, uint32_t bin_widths_count,
903  int right, double min, double max,
904  uint32_t *rtn_count
905 );
906 
919  double *quantiles, int quantiles_count, uint32_t *rtn_count);
920 
921 struct quantile_llist;
923  struct quantile_llist **list,
924  uint32_t list_count
925 );
926 
955  rt_band band,
956  int exclude_nodata_value, double sample,
957  uint64_t cov_count,
958  struct quantile_llist **qlls, uint32_t *qlls_count,
959  double *quantiles, uint32_t quantiles_count,
960  uint32_t *rtn_count
961 );
962 
978  rt_band band, int exclude_nodata_value,
979  double *search_values, uint32_t search_values_count, double roundto,
980  uint32_t *rtn_total, uint32_t *rtn_count
981 );
982 
996  rt_band srcband, rt_pixtype pixtype,
997  uint32_t hasnodata, double nodataval,
998  rt_reclassexpr *exprset, int exprcount
999 );
1000 
1001 /*- rt_raster --------------------------------------------------------*/
1002 
1014 rt_raster rt_raster_new(uint32_t width, uint32_t height);
1015 
1026 rt_raster rt_raster_from_wkb(const uint8_t* wkb, uint32_t wkbsize);
1027 
1038 rt_raster rt_raster_from_hexwkb(const char* hexwkb, uint32_t hexwkbsize);
1039 
1049 uint8_t *rt_raster_to_wkb(rt_raster raster, int outasin, uint32_t *wkbsize);
1050 
1061 char *rt_raster_to_hexwkb(rt_raster raster, int outasin, uint32_t *hexwkbsize);
1062 
1074 
1075 /* Get number of bands */
1077 
1087 
1088 /* Get number of rows */
1090 
1091 /* Get number of columns */
1093 
1105 
1119  rt_raster raster,
1120  rt_pixtype pixtype,
1121  double initialvalue,
1122  uint32_t hasnodata, double nodatavalue,
1123  int index
1124 );
1125 
1136  double scaleX, double scaleY);
1137 
1146 
1155 
1166  double x, double y);
1167 
1177 
1187 
1196  double skewX, double skewY);
1197 
1205 
1213 
1227  double *i_mag, double *j_mag, double *theta_i, double *theta_ij) ;
1228 
1245  double i_mag, double j_mag, double theta_i, double theta_ij) ;
1246 
1247 
1263 void rt_raster_calc_phys_params(double xscale,
1264  double xskew, double yskew, double yscale,
1265  double *i_mag, double *j_mag, double *theta_i, double *theta_ij) ;
1266 
1267 
1284 int rt_raster_calc_gt_coeff(double i_mag,
1285  double j_mag, double theta_i, double theta_ij,
1286  double *xscale, double *xskew, double *yskew, double *yscale) ;
1287 
1294 void rt_raster_set_srid(rt_raster raster, int32_t srid);
1295 
1303 
1314  rt_raster raster,
1315  double *gt, double *igt
1316 );
1317 
1325  double *gt);
1326 
1335  double *gt);
1336 
1350  rt_raster raster,
1351  double xr, double yr,
1352  double* xw, double* yw,
1353  double *gt
1354 );
1355 
1369  rt_raster raster,
1370  double xw, double yw,
1371  double *xr, double *yr,
1372  double *igt
1373 );
1374 
1375 
1389  rt_raster raster,
1390  double xw, double yw,
1391  double *xr, double *yr,
1392  double *igt
1393 );
1394 
1395 
1409 
1421 
1431 
1445  rt_band band,
1446  double xr, double yr,
1447  double *r_value, int *r_nodata
1448 );
1449 
1450 typedef enum {
1452  RT_BILINEAR
1454 
1469  rt_band band,
1470  double xr, double yr,
1471  rt_resample_type resample,
1472  double *r_value, int *r_nodata
1473 );
1474 
1490  rt_raster raster,
1491  uint32_t bandnum,
1492  char dim, /* 'Z' or 'M' */
1493  rt_resample_type resample,
1494  const LWGEOM *lwgeom_in,
1495  LWGEOM **lwgeom_out
1496 );
1497 
1512  rt_raster raster, int nband,
1513  LWGEOM **perimeter
1514 );
1515 
1516 /*
1517  * Compute skewed extent that covers unskewed extent.
1518  *
1519  * @param envelope : unskewed extent of type rt_envelope
1520  * @param skew : pointer to 2-element array (x, y) of skew
1521  * @param scale : pointer to 2-element array (x, y) of scale
1522  * @param tolerance : value between 0 and 1 where the smaller the tolerance
1523  * results in an extent approaching the "minimum" skewed extent.
1524  * If value <= 0, tolerance = 0.1. If value > 1, tolerance = 1.
1525  *
1526  * @return skewed raster who's extent covers unskewed extent, NULL on error
1527  */
1528 rt_raster
1530  rt_envelope extent,
1531  double *skew,
1532  double *scale,
1533  double tolerance
1534 );
1535 
1551 
1562 
1577 
1595 rt_geomval
1597  rt_raster raster, int nband,
1598  int exclude_nodata_value,
1599  int * pnElements
1600 );
1601 
1609 
1618 rt_raster rt_raster_deserialize(void* serialized, int header_only);
1619 
1628 
1638 
1654  rt_raster torast, rt_raster fromrast,
1655  int fromindex, int toindex
1656 );
1657 
1669 rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums,
1670  int count);
1671 
1682  int index);
1683 
1692 rt_raster rt_raster_clone(rt_raster raster, uint8_t deep);
1693 
1706 uint8_t *rt_raster_to_gdal(rt_raster raster, const char *srs,
1707  char *format, char **options, uint64_t *gdalsize);
1708 
1718 rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc);
1719 
1736 GDALDatasetH rt_raster_to_gdal_mem(
1737  rt_raster raster,
1738  const char *srs,
1739  uint32_t *bandNums,
1740  int *excludeNodataValues,
1741  int count,
1742  GDALDriverH *rtn_drv, int *destroy_rtn_drv
1743 );
1744 
1745 /*
1746 * Generate contour vectors from a raster input
1747 */
1750  double elevation;
1751  int id;
1752 };
1753 
1764  /* input parameters */
1765  rt_raster src_raster,
1766  int src_band,
1767  int src_srid,
1768  const char* src_srs,
1769  double contour_interval,
1770  double contour_base,
1771  int fixed_level_count,
1772  double *fixed_levels,
1773  int polygonize,
1774  /* output parameters */
1775  size_t *ncontours,
1776  struct rt_contour_t **contours
1777  );
1778 
1787 
1819  rt_raster raster,
1820  const char *src_srs, const char *dst_srs,
1821  double *scale_x, double *scale_y,
1822  int *width, int *height,
1823  double *ul_xw, double *ul_yw,
1824  double *grid_xw, double *grid_yw,
1825  double *skew_x, double *skew_y,
1826  GDALResampleAlg resample_alg, double max_err);
1827 
1854 rt_raster rt_raster_gdal_rasterize(const unsigned char *wkb,
1855  uint32_t wkb_len, const char *srs,
1856  uint32_t num_bands, rt_pixtype *pixtype,
1857  double *init, double *value,
1858  double *nodata, uint8_t *hasnodata,
1859  int *width, int *height,
1860  double *scale_x, double *scale_y,
1861  double *ul_xw, double *ul_yw,
1862  double *grid_xw, double *grid_yw,
1863  double *skew_x, double *skew_y,
1864  char **options
1865 );
1866 
1884  rt_raster rast1, int nband1,
1885  rt_raster rast2, int nband2,
1886  int *intersects
1887 );
1888 
1906  rt_raster rast1, int nband1,
1907  rt_raster rast2, int nband2,
1908  int *overlaps
1909 );
1910 
1928  rt_raster rast1, int nband1,
1929  rt_raster rast2, int nband2,
1930  int *contains
1931 );
1932 
1950  rt_raster rast1, int nband1,
1951  rt_raster rast2, int nband2,
1952  int *contains
1953 );
1954 
1972  rt_raster rast1, int nband1,
1973  rt_raster rast2, int nband2,
1974  int *touches
1975 );
1976 
1994  rt_raster rast1, int nband1,
1995  rt_raster rast2, int nband2,
1996  int *covers
1997 );
1998 
2016  rt_raster rast1, int nband1,
2017  rt_raster rast2, int nband2,
2018  int *coveredby
2019 );
2020 
2040  rt_raster rast1, int nband1,
2041  rt_raster rast2, int nband2,
2042  double distance,
2043  int *dwithin
2044 );
2045 
2065  rt_raster rast1, int nband1,
2066  rt_raster rast2, int nband2,
2067  double distance,
2068  int *dfwithin
2069 );
2070 
2071 /*
2072  * Return ES_ERROR if error occurred in function.
2073  * Paramter aligned returns non-zero if two rasters are aligned
2074  *
2075  * @param rast1 : the first raster for alignment test
2076  * @param rast2 : the second raster for alignment test
2077  * @param *aligned : non-zero value if the two rasters are aligned
2078  * @param *reason : reason why rasters are not aligned
2079  *
2080  * @return ES_NONE if success, ES_ERROR if error
2081  */
2083  rt_raster rast1,
2084  rt_raster rast2,
2085  int *aligned, char **reason
2086 );
2087 
2088 /*
2089  * Return raster of computed extent specified extenttype applied
2090  * on two input rasters. The raster returned should be freed by
2091  * the caller
2092  *
2093  * @param rast1 : the first raster
2094  * @param rast2 : the second raster
2095  * @param extenttype : type of extent for the output raster
2096  * @param *rtnraster : raster of computed extent
2097  * @param *offset : 4-element array indicating the X,Y offsets
2098  * for each raster. 0,1 for rast1 X,Y. 2,3 for rast2 X,Y.
2099  *
2100  * @return ES_NONE if success, ES_ERROR if error
2101  */
2104  rt_raster rast1, rt_raster rast2,
2105  rt_extenttype extenttype,
2106  rt_raster *rtnraster, double *offset
2107 );
2108 
2147  rt_iterator itrset, uint16_t itrcount,
2148  rt_extenttype extenttype, rt_raster customextent,
2149  rt_pixtype pixtype,
2150  uint8_t hasnodata, double nodataval,
2151  uint16_t distancex, uint16_t distancey,
2152  rt_mask mask,
2153  void *userarg,
2154  int (*callback)(
2155  rt_iterator_arg arg,
2156  void *userarg,
2157  double *value,
2158  int *nodata
2159  ),
2160  rt_raster *rtnraster
2161 );
2162 
2175  rt_raster raster, int nband,
2176  rt_colormap colormap
2177 );
2178 
2179 /*- utilities -------------------------------------------------------*/
2180 
2181 /*
2182  * rt_core memory functions
2183  */
2184 extern void *rtalloc(size_t size);
2185 extern void *rtrealloc(void *mem, size_t size);
2186 extern void rtdealloc(void *mem);
2187 
2188 /*
2189  * GDAL driver flags
2190  */
2191 
2192 #define GDAL_ENABLE_ALL "ENABLE_ALL"
2193 #define GDAL_DISABLE_ALL "DISABLE_ALL"
2194 #define GDAL_VSICURL "VSICURL"
2195 
2196 /*
2197  * Set of functions to clamp double to int of different size
2198  */
2199 
2200 #if !defined(POSTGIS_RASTER_WARN_ON_TRUNCATION)
2201 #define POSTGIS_RASTER_WARN_ON_TRUNCATION 0
2202 #endif
2203 
2204 #define POSTGIS_RT_1BBMAX 1
2205 #define POSTGIS_RT_2BUIMAX 3
2206 #define POSTGIS_RT_4BUIMAX 15
2207 
2208 uint8_t
2209 rt_util_clamp_to_1BB(double value);
2210 
2211 uint8_t
2213 
2214 uint8_t
2216 
2217 int8_t
2219 
2220 uint8_t
2222 
2223 int16_t
2225 
2226 uint16_t
2228 
2229 int32_t
2231 
2232 uint32_t
2234 
2235 float
2236 rt_util_clamp_to_32F(double value);
2237 
2238 int
2240  double initialvalue,
2241  int32_t checkvalint, uint32_t checkvaluint,
2242  float checkvalfloat, double checkvaldouble,
2243  rt_pixtype pixtype
2244 );
2245 
2253 GDALResampleAlg
2254 rt_util_gdal_resample_alg(const char *algname);
2255 
2263 GDALDataType
2265 
2273 rt_pixtype
2274 rt_util_gdal_datatype_to_pixtype(GDALDataType gdt);
2275 
2276 /*
2277  get GDAL runtime version information
2278 */
2279 const char*
2280 rt_util_gdal_version(const char *request);
2281 
2282 /*
2283  computed extent type from c string
2284 */
2286 rt_util_extent_type(const char *name);
2287 
2288 /*
2289  convert the spatial reference string from a GDAL recognized format to either WKT or Proj4
2290 */
2291 char*
2292 rt_util_gdal_convert_sr(const char *srs, int proj4);
2293 
2294 /*
2295  is the spatial reference string supported by GDAL
2296 */
2297 int
2298 rt_util_gdal_supported_sr(const char *srs);
2299 
2311 rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode);
2312 
2313 /*
2314  is GDAL configured correctly?
2315 */
2316 int
2318 
2319 /*
2320  register all GDAL drivers
2321 */
2322 int
2323 rt_util_gdal_register_all(int force_register_all);
2324 
2325 /*
2326  is the driver registered?
2327 */
2328 int
2329 rt_util_gdal_driver_registered(const char *drv);
2330 
2331 /*
2332  wrapper for GDALOpen and GDALOpenShared
2333 */
2334 GDALDatasetH
2335 rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared);
2336 
2337 
2338 /*
2339  Callback for GDAL functions to hook into interrupt system
2340 */
2341 int
2342 rt_util_gdal_progress_func(double dfComplete, const char *pszMessage, void *pProgressArg);
2343 
2344 
2345 void
2347  OGREnvelope env,
2348  rt_envelope *ext
2349 );
2350 
2351 void
2353  rt_envelope ext,
2354  OGREnvelope *env
2355 );
2356 
2357 LWPOLY *
2359  rt_envelope ext
2360 );
2361 
2362 int
2364  double *gt1,
2365  double *gt2
2366 );
2367 
2368 /* coordinates in RGB and HSV are floating point values between 0 and 1 */
2371  double rgb[3],
2372  double hsv[3]
2373 );
2374 
2375 /* coordinates in RGB and HSV are floating point values between 0 and 1 */
2378  double hsv[3],
2379  double rgb[3]
2380 );
2381 
2382 /*
2383  helper macros for consistent floating point equality checks.
2384  NaN equals NaN for NODATA support.
2385 */
2386 #define FLT_NEQ(x, y) ((x != y) && !(isnan(x) && isnan(y)) && (fabs(x - y) > FLT_EPSILON))
2387 #define FLT_EQ(x, y) ((x == y) || (isnan(x) && isnan(y)) || (fabs(x - y) <= FLT_EPSILON))
2388 #define DBL_NEQ(x, y) ((x != y) && !(isnan(x) && isnan(y)) && (fabs(x - y) > DBL_EPSILON))
2389 #define DBL_EQ(x, y) ((x == y) || (isnan(x) && isnan(y)) || (fabs(x - y) <= DBL_EPSILON))
2390 
2391 /*
2392  helper macro for symmetrical rounding
2393 */
2394 #define ROUND(x, y) (((x > 0.0) ? floor((x * pow(10, y) + 0.5)) : ceil((x * pow(10, y) - 0.5))) / pow(10, y))
2395 
2404  /*---[ 8 byte boundary ]---{ */
2405  uint32_t size; /* required by postgresql: 4 bytes */
2406  uint16_t version; /* format version (this is version 0): 2 bytes */
2407  uint16_t numBands; /* Number of bands: 2 bytes */
2408 
2409  /* }---[ 8 byte boundary ]---{ */
2410  double scaleX; /* pixel width: 8 bytes */
2411 
2412  /* }---[ 8 byte boundary ]---{ */
2413  double scaleY; /* pixel height: 8 bytes */
2414 
2415  /* }---[ 8 byte boundary ]---{ */
2416  double ipX; /* insertion point X: 8 bytes */
2417 
2418  /* }---[ 8 byte boundary ]---{ */
2419  double ipY; /* insertion point Y: 8 bytes */
2420 
2421  /* }---[ 8 byte boundary ]---{ */
2422  double skewX; /* skew about the X axis: 8 bytes */
2423 
2424  /* }---[ 8 byte boundary ]---{ */
2425  double skewY; /* skew about the Y axis: 8 bytes */
2426 
2427  /* }---[ 8 byte boundary ]--- */
2428  int32_t srid; /* Spatial reference id: 4 bytes */
2429  uint16_t width; /* pixel columns: 2 bytes */
2430  uint16_t height; /* pixel rows: 2 bytes */
2431 };
2432 
2433 /* NOTE: the initial part of this structure matches the layout
2434  * of data in the serialized form version 0, starting
2435  * from the numBands element
2436  */
2437 struct rt_raster_t {
2438  uint32_t size;
2439  uint16_t version;
2440 
2441  /* Number of bands, all share the same dimension
2442  * and georeference */
2443  uint16_t numBands;
2444 
2445  /* Georeference (in projection units) */
2446  double scaleX; /* pixel width */
2447  double scaleY; /* pixel height */
2448  double ipX; /* geo x ordinate of the corner of upper-left pixel */
2449  double ipY; /* geo y ordinate of the corner of bottom-right pixel */
2450  double skewX; /* skew about the X axis*/
2451  double skewY; /* skew about the Y axis */
2452 
2453  int32_t srid; /* spatial reference id */
2454  uint16_t width; /* pixel columns - max 65535 */
2455  uint16_t height; /* pixel rows - max 65535 */
2456  rt_band *bands; /* actual bands */
2457 
2458 };
2459 
2461  uint8_t bandNum; /* 0-based */
2462  char* path; /* internally owned */
2463  void *mem; /* loaded external band data, internally owned */
2464 };
2465 
2466 struct rt_band_t {
2468  int32_t offline;
2469  uint16_t width;
2470  uint16_t height;
2471  int32_t hasnodata; /* a flag indicating if this band contains nodata values */
2472  int32_t isnodata; /* a flag indicating if this band is filled only with
2473  nodata values. flag CANNOT be TRUE if hasnodata is FALSE */
2474  double nodataval; /* int will be converted ... */
2475  int8_t ownsdata; /* 0, externally owned. 1, internally owned. only applies to data.mem */
2476 
2477  rt_raster raster; /* reference to parent raster */
2478 
2479  union {
2480  void* mem; /* actual data, externally owned */
2481  struct rt_extband_t offline;
2482  } data;
2483 
2484 };
2485 
2486 struct rt_pixel_t {
2487  int x; /* column */
2488  int y; /* line */
2489 
2490  uint8_t nodata;
2491  double value;
2492 
2494 };
2495 
2496 struct rt_mask_t {
2497  uint16_t dimx;
2498  uint16_t dimy;
2499  double **values;
2500  int **nodata;
2501  int weighted; /* 0 if not weighted values 1 if weighted values */
2502 };
2503 
2504 /* polygon as LWPOLY with associated value */
2507  double val;
2508 };
2509 
2510 /* summary stats of specified band */
2512  double sample;
2513  uint32_t count;
2514 
2515  double min;
2516  double max;
2517  double sum;
2518  double mean;
2519  double stddev;
2520 
2521  double *values;
2522  int sorted; /* flag indicating that values is sorted ascending by value */
2523 };
2524 
2525 /* histogram bin(s) of specified band */
2527  uint32_t count;
2528  double percent;
2529 
2530  double min;
2531  double max;
2532 
2533  int inc_min;
2534  int inc_max;
2535 };
2536 
2537 /* quantile(s) of the specified band */
2539  double quantile;
2540  double value;
2541  uint32_t has_value;
2542 };
2543 
2544 /* listed-list structures for rt_band_get_quantiles_stream */
2546  uint8_t algeq; /* AL-GEQ (1) or AL-GT (0) */
2547  double quantile;
2548  uint64_t tau; /* position in sequence */
2549 
2550  struct quantile_llist_element *head; /* H index 0 */
2551  struct quantile_llist_element *tail; /* H index last */
2552  uint32_t count; /* # of elements in H */
2553 
2554  /* faster access to elements at specific intervals */
2556  uint32_t index_max; /* max # of elements in index */
2557 
2558  uint64_t sum1; /* N1H */
2559  uint64_t sum2; /* N2H */
2560 };
2561 
2563  double value;
2564  uint32_t count;
2565 
2568 };
2569 
2572  uint32_t index;
2573 };
2574 
2575 /* number of times a value occurs */
2577  double value;
2578  uint32_t count;
2579  double percent;
2580 };
2581 
2582 /* reclassification expression */
2585  double min;
2586  double max;
2587  int inc_min; /* include min */
2588  int inc_max; /* include max */
2589  int exc_min; /* exceed min */
2590  int exc_max; /* exceed max */
2591  } src, dst;
2592 };
2593 
2594 /* raster iterator */
2597  uint16_t nband; /* 0-based */
2598  uint8_t nbnodata; /* no band = treat as NODATA */
2599 };
2600 
2601 /* callback argument from raster iterator */
2603  /* # of rasters, Z-axis */
2604  uint16_t rasters;
2605  /* # of rows, Y-axis */
2606  uint32_t rows;
2607  /* # of columns, X-axis */
2608  uint32_t columns;
2609 
2610  /* axis order: Z,X,Y */
2611  /* individual pixel values */
2612  double ***values;
2613  /* 0,1 value of nodata flag */
2614  int ***nodata;
2615 
2616  /* X,Y of pixel from each input raster */
2617  int **src_pixel;
2618 
2619  /* X,Y of pixel from output raster */
2620  int dst_pixel[2];
2621 };
2622 
2623 /* gdal driver information */
2625  int idx;
2626  char *short_name;
2627  char *long_name;
2629  uint8_t can_read;
2630  uint8_t can_write;
2631 };
2632 
2633 /* raster colormap entry */
2636  double value;
2637  uint8_t color[4]; /* RGBA */
2638 };
2639 
2641  enum {
2644  CM_NEAREST
2646 
2647  int ncolor;
2648  uint16_t nentry;
2650 };
2651 
2652 #endif /* LIBRTCORE_H_INCLUDED */
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.
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_band.c:63
void * default_rt_allocator(size_t size)
The default memory/logging handlers installed by lwgeom_install_default_allocators()
Definition: rt_context.c:47
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_band.c:667
void(* rt_message_handler)(const char *string, va_list ap) __attribute__((format(printf
Definition: librtcore.h:235
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_mapalgebra.c:50
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_band.c:1809
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:219
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:191
rt_pixtype rt_util_gdal_datatype_to_pixtype(GDALDataType gdt)
Convert GDALDataType to rt_pixtype.
Definition: rt_util.c:159
rt_band rt_band_duplicate(rt_band band)
Create a new band duplicated from source band.
Definition: rt_band.c:287
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition: rt_band.c:640
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.
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
Definition: rt_band.c:681
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
Definition: rt_band.c:695
void default_rt_error_handler(const char *fmt, va_list ap)
Definition: rt_context.c:67
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_raster.c:759
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition: rt_raster.c:360
rt_errorstate rt_util_rgb_to_hsv(double rgb[3], double hsv[3])
Definition: rt_util.c:554
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_util.c:342
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_raster.c:185
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_raster.c:217
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_raster.c:318
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_raster.c:489
int rt_util_gdal_configured(void)
Definition: rt_util.c:321
rt_raster rt_raster_from_wkb(const uint8_t *wkb, uint32_t wkbsize)
Construct an rt_raster from a binary WKB representation.
Definition: rt_wkb.c:276
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_band.c:363
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
Definition: rt_raster.c:731
int8_t rt_util_clamp_to_8BSI(double value)
Definition: rt_util.c:50
struct rt_quantile_t * rt_quantile
Definition: librtcore.h:154
uint8_t rt_util_clamp_to_1BB(double value)
Definition: rt_util.c:35
void rtinfo(const char *fmt,...)
Definition: rt_context.c:231
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...
rt_errorstate rt_band_load_offline_data(rt_band band)
Load offline band's data.
Definition: rt_band.c:429
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.
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition: rt_raster.c:1838
int32_t rt_util_clamp_to_32BSI(double value)
Definition: rt_util.c:70
struct rt_reclassexpr_t * rt_reclassexpr
Definition: librtcore.h:157
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:141
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
Definition: rt_raster.c:409
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_raster.c:680
char * rt_util_gdal_convert_sr(const char *srs, int proj4)
Definition: rt_util.c:218
void(* rt_deallocator)(void *mem)
Definition: librtcore.h:234
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_raster.c:1720
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:674
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
Definition: rt_pixel.c:80
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_raster.c:808
char * rt_raster_to_hexwkb(rt_raster raster, int outasin, uint32_t *hexwkbsize)
Return this raster in HEXWKB form (null-terminated hex)
Definition: rt_wkb.c:679
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1376
struct rt_mask_t * rt_mask
Definition: librtcore.h:150
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:86
LWPOLY * rt_raster_pixel_as_polygon(rt_raster raster, int x, int y)
Get a raster pixel as a polygon.
Definition: rt_geometry.c:607
rt_pixtype
Definition: librtcore.h:187
@ PT_32BUI
Definition: librtcore.h:196
@ PT_2BUI
Definition: librtcore.h:189
@ PT_32BSI
Definition: librtcore.h:195
@ PT_END
Definition: librtcore.h:199
@ PT_4BUI
Definition: librtcore.h:190
@ PT_32BF
Definition: librtcore.h:197
@ PT_1BB
Definition: librtcore.h:188
@ PT_16BUI
Definition: librtcore.h:194
@ PT_8BSI
Definition: librtcore.h:191
@ PT_16BSI
Definition: librtcore.h:193
@ PT_64BF
Definition: librtcore.h:198
@ PT_8BUI
Definition: librtcore.h:192
LWPOINT * rt_raster_pixel_as_centroid_point(rt_raster rast, int x, int y)
Get a raster pixel centroid point.
Definition: rt_geometry.c:668
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition: rt_raster.c:172
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition: rt_band.c:714
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
Definition: rt_geometry.c:355
rt_errorstate rt_raster_geopoint_to_rasterpoint(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_raster.c:852
const char * rt_util_gdal_version(const char *request)
Definition: rt_util.c:186
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:52
rt_extenttype rt_util_extent_type(const char *name)
Definition: rt_util.c:197
int rt_util_dbl_trunc_warning(double initialvalue, int32_t checkvalint, uint32_t checkvaluint, float checkvalfloat, double checkvaldouble, rt_pixtype pixtype)
Definition: rt_util.c:676
GDALDataType rt_util_pixtype_to_gdal_datatype(rt_pixtype pt)
Convert rt_pixtype to GDALDataType.
Definition: rt_util.c:124
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.
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.
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition: rt_pixel.c:150
int rt_raster_has_band(rt_raster raster, int nband)
Return TRUE if the raster has a band of this number.
Definition: rt_raster.c:1375
rt_raster rt_raster_compute_skewed_raster(rt_envelope extent, double *skew, double *scale, double tolerance)
Definition: rt_raster.c:991
struct rt_pixel_t * rt_pixel
Definition: librtcore.h:149
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_serialize.c:521
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.
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
Definition: rt_raster.c:2291
int rt_util_gdal_progress_func(double dfComplete, const char *pszMessage, void *pProgressArg)
Definition: rt_gdal.c:58
rt_resample_type
Definition: librtcore.h:1450
@ RT_BILINEAR
Definition: librtcore.h:1452
@ RT_NEAREST
Definition: librtcore.h:1451
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, uint32_t quantiles_count, uint32_t *rtn_count)
Compute the default set of or requested quantiles for a coverage.
struct rt_colormap_entry_t * rt_colormap_entry
Definition: librtcore.h:162
char * rtoptions(const char *varname)
Wrappers used for options.
Definition: rt_context.c:256
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_geometry.c:975
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_raster.c:154
rt_band rt_raster_replace_band(rt_raster raster, rt_band band, int index)
Replace band at provided index with new band.
Definition: rt_raster.c:1526
uint8_t rt_util_clamp_to_2BUI(double value)
Definition: rt_util.c:40
void default_rt_deallocator(void *mem)
Definition: rt_context.c:61
int rt_pixtype_alignment(rt_pixtype pixtype)
Return alignment requirements for data in the given pixel type.
Definition: rt_pixel.c:75
void rtwarn(const char *fmt,...)
Definition: rt_context.c:244
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_pixel.c:202
uint8_t rt_util_clamp_to_8BUI(double value)
Definition: rt_util.c:55
double rt_band_get_min_value(rt_band band)
Returns the minimal possible value for the band according to the pixel type.
Definition: rt_band.c:1902
uint64_t rt_band_get_file_size(rt_band band)
Return file size in bytes.
Definition: rt_band.c:586
struct rt_bandstats_t * rt_bandstats
Definition: librtcore.h:152
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
Definition: rt_util.c:389
int quantile_llist_destroy(struct quantile_llist **list, uint32_t list_count)
uint8_t * rt_raster_to_wkb(rt_raster raster, int outasin, uint32_t *wkbsize)
Return this raster in WKB form.
Definition: rt_wkb.c:494
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition: rt_band.c:1909
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:733
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_band.c:974
void *(* rt_allocator)(size_t size)
Definition: librtcore.h:232
rt_errorstate
Enum definitions.
Definition: librtcore.h:181
@ ES_NONE
Definition: librtcore.h:182
@ ES_ERROR
Definition: librtcore.h:183
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_band.c:853
rt_raster rt_raster_from_hexwkb(const char *hexwkb, uint32_t hexwkbsize)
Construct an rt_raster from a text HEXWKB representation.
Definition: rt_wkb.c:406
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_raster.c:2618
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:340
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.
int rt_util_gdal_supported_sr(const char *srs)
Definition: rt_util.c:249
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_raster.c:235
int16_t rt_util_clamp_to_16BSI(double value)
Definition: rt_util.c:60
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_band.c:1991
void * rtrealloc(void *mem, size_t size)
Definition: rt_context.c:199
GDALResampleAlg rt_util_gdal_resample_alg(const char *algname)
Convert cstring name to GDAL Resample Algorithm.
Definition: rt_util.c:94
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:376
struct rt_valuecount_t * rt_valuecount
Definition: librtcore.h:155
struct rt_gdaldriver_t * rt_gdaldriver
Definition: librtcore.h:156
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
Definition: rt_raster.c:1568
rt_errorstate rt_raster_get_convex_hull(rt_raster raster, LWGEOM **hull)
Get raster's convex hull.
Definition: rt_geometry.c:838
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:133
char *(* rt_options)(const char *varname)
Global functions for memory/logging handlers.
Definition: librtcore.h:231
int rt_util_gdal_driver_registered(const char *drv)
Definition: rt_util.c:361
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_band.c:124
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_band.c:376
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, rt_mask mask, void *userarg, int(*callback)(rt_iterator_arg arg, void *userarg, double *value, int *nodata), rt_raster *rtnraster)
n-raster iterator.
uint64_t rt_band_get_file_timestamp(rt_band band)
Return file timestamp.
Definition: rt_band.c:608
struct rt_iterator_arg_t * rt_iterator_arg
Definition: librtcore.h:160
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
Definition: rt_raster.c:367
void *(* rt_reallocator)(void *mem, size_t size)
Definition: librtcore.h:233
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_raster.c:301
rt_extenttype
Definition: librtcore.h:202
@ ET_CUSTOM
Definition: librtcore.h:208
@ ET_LAST
Definition: librtcore.h:207
@ ET_INTERSECTION
Definition: librtcore.h:203
@ ET_UNION
Definition: librtcore.h:204
@ ET_SECOND
Definition: librtcore.h:206
@ ET_FIRST
Definition: librtcore.h:205
rt_errorstate rt_band_get_pixel_resample(rt_band band, double xr, double yr, rt_resample_type resample, double *r_value, int *r_nodata)
Retrieve a point value from the raster using a world coordinate and selected resampling method.
Definition: rt_band.c:1221
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_raster.c:1463
struct rt_geomval_t * rt_geomval
Definition: librtcore.h:151
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1887
uint8_t rt_util_clamp_to_4BUI(double value)
Definition: rt_util.c:45
rt_errorstate rt_util_hsv_to_rgb(double hsv[3], double rgb[3])
Definition: rt_util.c:608
void rt_util_to_ogr_envelope(rt_envelope ext, OGREnvelope *env)
Definition: rt_util.c:473
char * default_rt_options(const char *varname)
Definition: rt_context.c:105
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_band.c:631
rt_errorstate rt_pixel_set_to_array(rt_pixel npixel, uint32_t count, rt_mask mask, int x, int y, uint16_t distancex, uint16_t distancey, double ***value, int ***nodata, int *dimx, int *dimy)
Definition: rt_pixel.c:288
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110
rt_band rt_band_new_offline_from_path(uint16_t width, uint16_t height, int hasnodata, double nodataval, uint8_t bandNum, const char *path, int force)
Create an out-db rt_band from path.
Definition: rt_band.c:199
rt_histogram rt_band_get_histogram(rt_bandstats stats, uint32_t bin_count, double *bin_widths, uint32_t bin_widths_count, int right, double min, double max, uint32_t *rtn_count)
Count the distribution of data.
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:125
uint32_t 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_band.c:1529
void rtdealloc(void *mem)
Definition: rt_context.c:206
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:400
rt_errorstate rt_band_get_pixel_bilinear(rt_band band, double xr, double yr, double *r_value, int *r_nodata)
Retrieve a point value from the raster using a world coordinate and bilinear interpolation.
Definition: rt_band.c:1260
rt_errorstate rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode)
Get auth name and code.
Definition: rt_util.c:276
uint16_t rt_util_clamp_to_16BUI(double value)
Definition: rt_util.c:65
rt_errorstate rt_raster_get_envelope_geom(rt_raster raster, LWGEOM **env)
Get raster's envelope as a geometry.
Definition: rt_geometry.c:705
struct rt_colormap_t * rt_colormap
Definition: librtcore.h:163
struct rt_iterator_t * rt_iterator
Definition: librtcore.h:159
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band's clamped NODATA value.
Definition: rt_band.c:1955
uint32_t rt_util_clamp_to_32BUI(double value)
Definition: rt_util.c:75
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_warp.c:178
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_band.c:659
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_raster.c:1935
void rt_set_handlers_options(rt_allocator allocator, rt_reallocator reallocator, rt_deallocator deallocator, rt_message_handler error_handler, rt_message_handler info_handler, rt_message_handler warning_handler, rt_options options_handler)
Definition: rt_context.c:169
void default_rt_warning_handler(const char *fmt, va_list ap)
Definition: rt_context.c:80
rt_errorstate rt_raster_get_perimeter(rt_raster raster, int nband, LWGEOM **perimeter)
Get raster perimeter.
Definition: rt_geometry.c:182
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
Definition: rt_band.c:329
LWPOLY * rt_util_envelope_to_lwpoly(rt_envelope ext)
Definition: rt_util.c:486
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.
char * rtstrdup(const char *str)
Definition: rt_context.c:263
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.
rt_errorstate rt_raster_from_two_rasters(rt_raster rast1, rt_raster rast2, rt_extenttype extenttype, rt_raster *rtnraster, double *offset)
Definition: rt_raster.c:3464
void(*) voi rt_install_default_allocators)(void)
Apply the default memory management (malloc() and free()) and error handlers.
rt_geos_spatial_test
GEOS spatial relationship tests available.
Definition: librtcore.h:219
@ GSR_TOUCHES
Definition: librtcore.h:221
@ GSR_COVERS
Definition: librtcore.h:224
@ GSR_COVEREDBY
Definition: librtcore.h:225
@ GSR_CONTAINSPROPERLY
Definition: librtcore.h:223
@ GSR_OVERLAPS
Definition: librtcore.h:220
@ GSR_CONTAINS
Definition: librtcore.h:222
struct rt_raster_t * rt_raster
Types definitions.
Definition: librtcore.h:147
int rt_util_same_geotransform_matrix(double *gt1, double *gt2)
Definition: rt_util.c:538
#define __attribute__
Definition: librtcore.h:141
int rt_raster_gdal_contour(rt_raster src_raster, int src_band, int src_srid, const char *src_srs, double contour_interval, double contour_base, int fixed_level_count, double *fixed_levels, int polygonize, size_t *ncontours, struct rt_contour_t **contours)
Return palloc'ed list of contours.
Definition: rt_gdal.c:114
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_raster.c:1398
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_raster.c:163
float rt_util_clamp_to_32F(double value)
Definition: rt_util.c:80
void default_rt_info_handler(const char *fmt, va_list ap)
Definition: rt_context.c:93
rt_errorstate rt_raster_get_envelope(rt_raster raster, rt_envelope *env)
Get raster's envelope.
Definition: rt_raster.c:904
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
void * default_rt_reallocator(void *mem, size_t size)
Definition: rt_context.c:54
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.
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_raster.c:194
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition: rt_raster.c:710
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...
rt_errorstate rt_raster_copy_to_geometry(rt_raster raster, uint32_t bandnum, char dim, rt_resample_type resample, const LWGEOM *lwgeom_in, LWGEOM **lwgeom_out)
Copy values from a raster to the points on a geometry using the requested interpolation type.
Definition: rt_raster.c:1614
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:203
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.
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_context.c:159
void rt_util_from_ogr_envelope(OGREnvelope env, rt_envelope *ext)
Definition: rt_util.c:457
struct rt_histogram_t * rt_histogram
Definition: librtcore.h:153
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition: rt_band.c:649
struct rt_band_t * rt_band
Definition: librtcore.h:148
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:725
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_pixel.c:39
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_raster.c:254
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_band.c:1137
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_raster.c:226
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition: rt_raster.c:1362
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:385
#define str(s)
static double distance(double x1, double y1, double x2, double y2)
Definition: lwtree.c:1032
int value
Definition: genraster.py:62
int count
Definition: genraster.py:57
band
Definition: ovdump.py:58
data
Definition: ovdump.py:104
ds
Definition: pixval.py:67
src_band
Definition: pixval.py:76
nband
Definition: pixval.py:53
def fmt
Definition: pixval.py:93
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
gt
Definition: window.py:78
Datum contains(PG_FUNCTION_ARGS)
Datum coveredby(PG_FUNCTION_ARGS)
Datum covers(PG_FUNCTION_ARGS)
Datum touches(PG_FUNCTION_ARGS)
Datum overlaps(PG_FUNCTION_ARGS)
struct quantile_llist_element * prev
Definition: librtcore.h:2566
struct quantile_llist_element * next
Definition: librtcore.h:2567
struct quantile_llist_element * element
Definition: librtcore.h:2571
uint32_t count
Definition: librtcore.h:2552
uint64_t sum1
Definition: librtcore.h:2558
uint64_t tau
Definition: librtcore.h:2548
uint64_t sum2
Definition: librtcore.h:2559
uint32_t index_max
Definition: librtcore.h:2556
struct quantile_llist_element * head
Definition: librtcore.h:2550
double quantile
Definition: librtcore.h:2547
uint8_t algeq
Definition: librtcore.h:2546
struct quantile_llist_element * tail
Definition: librtcore.h:2551
struct quantile_llist_index * index
Definition: librtcore.h:2555
rt_pixtype pixtype
Definition: librtcore.h:2467
int32_t hasnodata
Definition: librtcore.h:2471
int32_t offline
Definition: librtcore.h:2468
uint16_t height
Definition: librtcore.h:2470
rt_raster raster
Definition: librtcore.h:2477
double nodataval
Definition: librtcore.h:2474
uint16_t width
Definition: librtcore.h:2469
void * mem
Definition: librtcore.h:2480
int32_t isnodata
Definition: librtcore.h:2472
union rt_band_t::@11 data
int8_t ownsdata
Definition: librtcore.h:2475
uint32_t count
Definition: librtcore.h:2513
double * values
Definition: librtcore.h:2521
uint8_t color[4]
Definition: librtcore.h:2637
double value
Definition: librtcore.h:2636
int isnodata
Definition: librtcore.h:2635
Definition: librtcore.h:2634
rt_colormap_entry entry
Definition: librtcore.h:2649
enum rt_colormap_t::@12 method
uint16_t nentry
Definition: librtcore.h:2648
GSERIALIZED * geom
Definition: librtcore.h:1749
double elevation
Definition: librtcore.h:1750
double MinX
Definition: librtcore.h:167
double UpperLeftY
Definition: librtcore.h:173
double UpperLeftX
Definition: librtcore.h:172
double MaxX
Definition: librtcore.h:168
double MinY
Definition: librtcore.h:169
double MaxY
Definition: librtcore.h:170
uint8_t bandNum
Definition: librtcore.h:2461
void * mem
Definition: librtcore.h:2463
char * path
Definition: librtcore.h:2462
uint8_t can_write
Definition: librtcore.h:2630
char * long_name
Definition: librtcore.h:2627
char * create_options
Definition: librtcore.h:2628
char * short_name
Definition: librtcore.h:2626
uint8_t can_read
Definition: librtcore.h:2629
double val
Definition: librtcore.h:2507
LWPOLY * geom
Definition: librtcore.h:2506
uint32_t count
Definition: librtcore.h:2527
double percent
Definition: librtcore.h:2528
double *** values
Definition: librtcore.h:2612
uint32_t columns
Definition: librtcore.h:2608
uint16_t rasters
Definition: librtcore.h:2604
rt_raster raster
Definition: librtcore.h:2596
uint16_t nband
Definition: librtcore.h:2597
uint8_t nbnodata
Definition: librtcore.h:2598
double ** values
Definition: librtcore.h:2499
uint16_t dimy
Definition: librtcore.h:2498
uint16_t dimx
Definition: librtcore.h:2497
int ** nodata
Definition: librtcore.h:2500
int weighted
Definition: librtcore.h:2501
LWGEOM * geom
Definition: librtcore.h:2493
double value
Definition: librtcore.h:2491
uint8_t nodata
Definition: librtcore.h:2490
double value
Definition: librtcore.h:2540
double quantile
Definition: librtcore.h:2539
uint32_t has_value
Definition: librtcore.h:2541
Struct definitions.
Definition: librtcore.h:2403
double scaleX
Definition: librtcore.h:2446
rt_band * bands
Definition: librtcore.h:2456
uint16_t width
Definition: librtcore.h:2454
uint16_t version
Definition: librtcore.h:2439
double skewY
Definition: librtcore.h:2451
uint16_t numBands
Definition: librtcore.h:2443
int32_t srid
Definition: librtcore.h:2453
double ipX
Definition: librtcore.h:2448
uint16_t height
Definition: librtcore.h:2455
uint32_t size
Definition: librtcore.h:2438
double scaleY
Definition: librtcore.h:2447
double ipY
Definition: librtcore.h:2449
double skewX
Definition: librtcore.h:2450
struct rt_reclassexpr_t::rt_reclassrange src
struct rt_reclassexpr_t::rt_reclassrange dst
uint32_t count
Definition: librtcore.h:2578