PostGIS  2.5.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.h"
125 
126 #include "gdal_alg.h"
127 #include "gdal_frmts.h"
128 #include "gdal.h"
129 #include "gdalwarper.h"
130 #include "cpl_vsi.h"
131 #include "cpl_conv.h"
132 #include "ogr_api.h"
133 #include "ogr_srs_api.h"
134 
135 #include "../../postgis_config.h"
136 #include "../raster_config.h"
137 
138 #ifndef __GNUC__
139 # define __attribute__ (x)
140 #endif
141 
145 typedef struct rt_raster_t* rt_raster;
146 typedef struct rt_band_t* rt_band;
147 typedef struct rt_pixel_t* rt_pixel;
148 typedef struct rt_mask_t* rt_mask;
149 typedef struct rt_geomval_t* rt_geomval;
150 typedef struct rt_bandstats_t* rt_bandstats;
151 typedef struct rt_histogram_t* rt_histogram;
152 typedef struct rt_quantile_t* rt_quantile;
156 
157 typedef struct rt_iterator_t* rt_iterator;
159 
161 typedef struct rt_colormap_t* rt_colormap;
162 
163 /* envelope information */
164 typedef struct {
165  double MinX;
166  double MaxX;
167  double MinY;
168  double MaxY;
169 
170  double UpperLeftX;
171  double UpperLeftY;
172 } rt_envelope;
173 
178 /* function return error states */
179 typedef enum {
180  ES_NONE = 0, /* no error */
181  ES_ERROR = 1 /* generic error */
182 } rt_errorstate;
183 
184 /* Pixel types */
185 typedef enum {
186  PT_1BB=0, /* 1-bit boolean */
187  PT_2BUI=1, /* 2-bit unsigned integer */
188  PT_4BUI=2, /* 4-bit unsigned integer */
189  PT_8BSI=3, /* 8-bit signed integer */
190  PT_8BUI=4, /* 8-bit unsigned integer */
191  PT_16BSI=5, /* 16-bit signed integer */
192  PT_16BUI=6, /* 16-bit unsigned integer */
193  PT_32BSI=7, /* 32-bit signed integer */
194  PT_32BUI=8, /* 32-bit unsigned integer */
195  PT_32BF=10, /* 32-bit float */
196  PT_64BF=11, /* 64-bit float */
198 } rt_pixtype;
199 
200 typedef enum {
207 } rt_extenttype;
208 
217 typedef enum {
225 
229 typedef void* (*rt_allocator)(size_t size);
230 typedef void* (*rt_reallocator)(void *mem, size_t size);
231 typedef void (*rt_deallocator)(void *mem);
232 typedef void (*rt_message_handler)(const char* string, va_list ap)
233  __attribute__ (( format(printf,1,0) ));
234 
235 /*******************************************************************
236  * Functions that may be used by the raster core function's caller
237  * (for example: rt_pg functions, test functions, future loader/exporter)
238  *******************************************************************/
242 extern void rt_install_default_allocators(void);
243 
244 
249 extern void* rtalloc(size_t size);
250 extern void* rtrealloc(void* mem, size_t size);
251 extern void rtdealloc(void* mem);
252 
253 /******************************************************************/
254 
255 
259 void rterror(const char *fmt, ...);
260 void rtinfo(const char *fmt, ...);
261 void rtwarn(const char *fmt, ...);
262 
263 
267 void * default_rt_allocator(size_t size);
268 void * default_rt_reallocator(void * mem, size_t size);
269 void default_rt_deallocator(void * mem);
270 void default_rt_error_handler(const char * fmt, va_list ap);
271 void default_rt_warning_handler(const char * fmt, va_list ap);
272 void default_rt_info_handler(const char * fmt, va_list ap);
273 
274 
275 /* Debugging macros */
276 #if POSTGIS_DEBUG_LEVEL > 0
277 
278 /* Display a simple message at NOTICE level */
279 #define RASTER_DEBUG(level, msg) \
280  do { \
281  if (POSTGIS_DEBUG_LEVEL >= level) \
282  rtinfo("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__); \
283  } while (0);
284 
285 /* Display a formatted message at NOTICE level (like printf, with variadic arguments) */
286 #define RASTER_DEBUGF(level, msg, ...) \
287  do { \
288  if (POSTGIS_DEBUG_LEVEL >= level) \
289  rtinfo("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__, __VA_ARGS__); \
290  } while (0);
291 
292 #else
293 
294 /* Empty prototype that can be optimised away by the compiler for non-debug builds */
295 #define RASTER_DEBUG(level, msg) \
296  ((void) 0)
297 
298 /* Empty prototype that can be optimised away by the compiler for non-debug builds */
299 #define RASTER_DEBUGF(level, msg, ...) \
300  ((void) 0)
301 
302 #endif
303 
304 /*- memory context -------------------------------------------------------*/
305 
306 void rt_set_handlers(rt_allocator allocator, rt_reallocator reallocator,
307  rt_deallocator deallocator, rt_message_handler error_handler,
308  rt_message_handler info_handler, rt_message_handler warning_handler);
309 
310 
311 
312 /*- rt_pixtype --------------------------------------------------------*/
313 
321 int rt_pixtype_size(rt_pixtype pixtype);
322 
332 int rt_pixtype_alignment(rt_pixtype pixtype);
333 
334 /* Return human-readable name of pixel type */
335 const char* rt_pixtype_name(rt_pixtype pixtype);
336 
337 /* Return pixel type index from human-readable name */
338 rt_pixtype rt_pixtype_index_from_name(const char* pixname);
339 
347 double rt_pixtype_get_min_value(rt_pixtype pixtype);
348 
360  rt_pixtype pixtype,
361  double val, double refval,
362  int *isequal
363 );
364 
365 /*- rt_pixel ----------------------------------------------------------*/
366 
367 /*
368  * Convert an array of rt_pixel objects to two 2D arrays of value and NODATA.
369  * The dimensions of the returned 2D array are [Y][X], going by row Y and
370  * then column X.
371  *
372  * @param npixel : array of rt_pixel objects
373  * @param count : number of elements in npixel
374  * @param mask : mask to be respected when returning array
375  * @param x : the column of the center pixel (0-based)
376  * @param y : the line of the center pixel (0-based)
377  * @param distancex : the number of pixels around the specified pixel
378  * along the X axis
379  * @param distancey : the number of pixels around the specified pixel
380  * along the Y axis
381  * @param value : pointer to pointer for 2D value array
382  * @param nodata : pointer to pointer for 2D NODATA array
383  * @param dimx : size of value and nodata along the X axis
384  * @param dimy : size of value and nodata along the Y axis
385  *
386  * @return ES_NONE on success, ES_ERROR on error
387  */
389  rt_pixel npixel,uint32_t count,
390  rt_mask mask,
391  int x, int y,
392  uint16_t distancex, uint16_t distancey,
393  double ***value,
394  int ***nodata,
395  int *dimx, int *dimy
396 );
397 
398 /*- rt_band ----------------------------------------------------------*/
399 
420 rt_band rt_band_new_inline(
421  uint16_t width, uint16_t height,
422  rt_pixtype pixtype,
423  uint32_t hasnodata, double nodataval,
424  uint8_t* data
425 );
426 
446 rt_band rt_band_new_offline(
447  uint16_t width, uint16_t height,
448  rt_pixtype pixtype,
449  uint32_t hasnodata, double nodataval,
450  uint8_t bandNum, const char* path
451 );
452 
471 rt_band
473  uint16_t width,
474  uint16_t height,
475  int hasnodata,
476  double nodataval,
477  uint8_t bandNum,
478  const char* path,
479  int force
480 );
481 
492 rt_band rt_band_duplicate(rt_band band);
493 
503 int rt_band_is_offline(rt_band band);
504 
513 const char* rt_band_get_ext_path(rt_band band);
514 
525 
534 
542 uint16_t rt_band_get_width(rt_band band);
543 
551 uint16_t rt_band_get_height(rt_band band);
552 
562 int rt_band_get_ownsdata_flag(rt_band band);
563 
564 /* set ownsdata flag */
565 void rt_band_set_ownsdata_flag(rt_band band, int flag);
566 
574 void* rt_band_get_data(rt_band band);
575 
586 
592 void rt_band_destroy(rt_band band);
593 
601 int rt_band_get_hasnodata_flag(rt_band band);
602 
608 void rt_band_set_hasnodata_flag(rt_band band, int flag);
609 
618 rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag);
619 
627 int rt_band_get_isnodata_flag(rt_band band);
628 
639 rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted);
640 
649 rt_errorstate rt_band_get_nodata(rt_band band, double *nodata);
650 
671  rt_band band,
672  int x, int y,
673  void *vals, uint32_t len
674 );
675 
688  rt_band band,
689  int x, int y,
690  double val,
691  int *converted
692 );
693 
715  rt_band band,
716  int x, int y,
717  uint16_t len,
718  void **vals, uint16_t *nvals
719 );
720 
734  rt_band band,
735  int x, int y,
736  double *value,
737  int *nodata
738 );
739 
758  rt_band band,
759  int x, int y,
760  uint16_t distancex, uint16_t distancey,
761  int exclude_nodata_value,
762  rt_pixel *npixels
763 );
764 
777  rt_band band, int exclude_nodata_value,
778  double *searchset, int searchcount,
779  rt_pixel *pixels
780 );
781 
789 double rt_band_get_min_value(rt_band band);
790 
798 int rt_band_check_is_nodata(rt_band band);
799 
810 int rt_band_clamped_value_is_nodata(rt_band band, double val);
811 
826  rt_band band,
827  double val,
828  double *newval, int *corrected
829 );
830 
844 rt_bandstats rt_band_get_summary_stats(
845  rt_band band,
846  int exclude_nodata_value, double sample, int inc_vals,
847  uint64_t *cK, double *cM, double *cQ
848 );
849 
868 rt_histogram rt_band_get_histogram(
869  rt_bandstats stats,
870  uint32_t bin_count, double *bin_widths, uint32_t bin_widths_count,
871  int right, double min, double max,
872  uint32_t *rtn_count
873 );
874 
886 rt_quantile rt_band_get_quantiles(rt_bandstats stats,
887  double *quantiles, int quantiles_count, uint32_t *rtn_count);
888 
889 struct quantile_llist;
891  struct quantile_llist **list,
892  uint32_t list_count
893 );
894 
922 rt_quantile rt_band_get_quantiles_stream(
923  rt_band band,
924  int exclude_nodata_value, double sample,
925  uint64_t cov_count,
926  struct quantile_llist **qlls, uint32_t *qlls_count,
927  double *quantiles, uint32_t quantiles_count,
928  uint32_t *rtn_count
929 );
930 
945 rt_valuecount rt_band_get_value_count(
946  rt_band band, int exclude_nodata_value,
947  double *search_values, uint32_t search_values_count, double roundto,
948  uint32_t *rtn_total, uint32_t *rtn_count
949 );
950 
963 rt_band rt_band_reclass(
964  rt_band srcband, rt_pixtype pixtype,
965  uint32_t hasnodata, double nodataval,
966  rt_reclassexpr *exprset, int exprcount
967 );
968 
969 /*- rt_raster --------------------------------------------------------*/
970 
982 rt_raster rt_raster_new(uint32_t width, uint32_t height);
983 
994 rt_raster rt_raster_from_wkb(const uint8_t* wkb, uint32_t wkbsize);
995 
1006 rt_raster rt_raster_from_hexwkb(const char* hexwkb, uint32_t hexwkbsize);
1007 
1017 uint8_t *rt_raster_to_wkb(rt_raster raster, int outasin, uint32_t *wkbsize);
1018 
1029 char *rt_raster_to_hexwkb(rt_raster raster, int outasin, uint32_t *hexwkbsize);
1030 
1041 void rt_raster_destroy(rt_raster raster);
1042 
1043 /* Get number of bands */
1044 uint16_t rt_raster_get_num_bands(rt_raster raster);
1045 
1054 rt_band rt_raster_get_band(rt_raster raster, int bandNum);
1055 
1056 /* Get number of rows */
1057 uint16_t rt_raster_get_width(rt_raster raster);
1058 
1059 /* Get number of columns */
1060 uint16_t rt_raster_get_height(rt_raster raster);
1061 
1072 int rt_raster_add_band(rt_raster raster, rt_band band, int index);
1073 
1087  rt_raster raster,
1088  rt_pixtype pixtype,
1089  double initialvalue,
1090  uint32_t hasnodata, double nodatavalue,
1091  int index
1092 );
1093 
1103 void rt_raster_set_scale(rt_raster raster,
1104  double scaleX, double scaleY);
1105 
1113 double rt_raster_get_x_scale(rt_raster raster);
1114 
1122 double rt_raster_get_y_scale(rt_raster raster);
1123 
1133 void rt_raster_set_offsets(rt_raster raster,
1134  double x, double y);
1135 
1144 double rt_raster_get_x_offset(rt_raster raster);
1145 
1154 double rt_raster_get_y_offset(rt_raster raster);
1155 
1163 void rt_raster_set_skews(rt_raster raster,
1164  double skewX, double skewY);
1165 
1172 double rt_raster_get_x_skew(rt_raster raster);
1173 
1180 double rt_raster_get_y_skew(rt_raster raster);
1181 
1194 void rt_raster_get_phys_params(rt_raster rast,
1195  double *i_mag, double *j_mag, double *theta_i, double *theta_ij) ;
1196 
1212 void rt_raster_set_phys_params(rt_raster rast,
1213  double i_mag, double j_mag, double theta_i, double theta_ij) ;
1214 
1215 
1231 void rt_raster_calc_phys_params(double xscale,
1232  double xskew, double yskew, double yscale,
1233  double *i_mag, double *j_mag, double *theta_i, double *theta_ij) ;
1234 
1235 
1252 int rt_raster_calc_gt_coeff(double i_mag,
1253  double j_mag, double theta_i, double theta_ij,
1254  double *xscale, double *xskew, double *yskew, double *yscale) ;
1255 
1262 void rt_raster_set_srid(rt_raster raster, int32_t srid);
1263 
1270 int32_t rt_raster_get_srid(rt_raster raster);
1271 
1282  rt_raster raster,
1283  double *gt, double *igt
1284 );
1285 
1293  double *gt);
1294 
1303  double *gt);
1304 
1318  rt_raster raster,
1319  double xr, double yr,
1320  double* xw, double* yw,
1321  double *gt
1322 );
1323 
1337  rt_raster raster,
1338  double xw, double yw,
1339  double *xr, double *yr,
1340  double *igt
1341 );
1342 
1356 
1368 
1378 
1393  rt_raster raster, int nband,
1394  LWGEOM **perimeter
1395 );
1396 
1397 /*
1398  * Compute skewed extent that covers unskewed extent.
1399  *
1400  * @param envelope : unskewed extent of type rt_envelope
1401  * @param skew : pointer to 2-element array (x, y) of skew
1402  * @param scale : pointer to 2-element array (x, y) of scale
1403  * @param tolerance : value between 0 and 1 where the smaller the tolerance
1404  * results in an extent approaching the "minimum" skewed extent.
1405  * If value <= 0, tolerance = 0.1. If value > 1, tolerance = 1.
1406  *
1407  * @return skewed raster who's extent covers unskewed extent, NULL on error
1408  */
1409 rt_raster
1411  rt_envelope extent,
1412  double *skew,
1413  double *scale,
1414  double tolerance
1415 );
1416 
1431 LWPOLY* rt_raster_pixel_as_polygon(rt_raster raster, int x, int y);
1432 
1446 rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface);
1447 
1465 rt_geomval
1467  rt_raster raster, int nband,
1468  int exclude_nodata_value,
1469  int * pnElements
1470 );
1471 
1478 void* rt_raster_serialize(rt_raster raster);
1479 
1488 rt_raster rt_raster_deserialize(void* serialized, int header_only);
1489 
1497 int rt_raster_is_empty(rt_raster raster);
1498 
1507 int rt_raster_has_band(rt_raster raster, int nband);
1508 
1524  rt_raster torast, rt_raster fromrast,
1525  int fromindex, int toindex
1526 );
1527 
1539 rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums,
1540  int count);
1541 
1551 rt_band rt_raster_replace_band(rt_raster raster, rt_band band,
1552  int index);
1553 
1562 rt_raster rt_raster_clone(rt_raster raster, uint8_t deep);
1563 
1576 uint8_t *rt_raster_to_gdal(rt_raster raster, const char *srs,
1577  char *format, char **options, uint64_t *gdalsize);
1578 
1588 rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc);
1589 
1606 GDALDatasetH rt_raster_to_gdal_mem(
1607  rt_raster raster,
1608  const char *srs,
1609  uint32_t *bandNums,
1610  int *excludeNodataValues,
1611  int count,
1612  GDALDriverH *rtn_drv, int *destroy_rtn_drv
1613 );
1614 
1622 rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds);
1623 
1654 rt_raster rt_raster_gdal_warp(
1655  rt_raster raster,
1656  const char *src_srs, const char *dst_srs,
1657  double *scale_x, double *scale_y,
1658  int *width, int *height,
1659  double *ul_xw, double *ul_yw,
1660  double *grid_xw, double *grid_yw,
1661  double *skew_x, double *skew_y,
1662  GDALResampleAlg resample_alg, double max_err);
1663 
1690 rt_raster rt_raster_gdal_rasterize(const unsigned char *wkb,
1691  uint32_t wkb_len, const char *srs,
1692  uint32_t num_bands, rt_pixtype *pixtype,
1693  double *init, double *value,
1694  double *nodata, uint8_t *hasnodata,
1695  int *width, int *height,
1696  double *scale_x, double *scale_y,
1697  double *ul_xw, double *ul_yw,
1698  double *grid_xw, double *grid_yw,
1699  double *skew_x, double *skew_y,
1700  char **options
1701 );
1702 
1720  rt_raster rast1, int nband1,
1721  rt_raster rast2, int nband2,
1722  int *intersects
1723 );
1724 
1742  rt_raster rast1, int nband1,
1743  rt_raster rast2, int nband2,
1744  int *overlaps
1745 );
1746 
1764  rt_raster rast1, int nband1,
1765  rt_raster rast2, int nband2,
1766  int *contains
1767 );
1768 
1786  rt_raster rast1, int nband1,
1787  rt_raster rast2, int nband2,
1788  int *contains
1789 );
1790 
1808  rt_raster rast1, int nband1,
1809  rt_raster rast2, int nband2,
1810  int *touches
1811 );
1812 
1830  rt_raster rast1, int nband1,
1831  rt_raster rast2, int nband2,
1832  int *covers
1833 );
1834 
1852  rt_raster rast1, int nband1,
1853  rt_raster rast2, int nband2,
1854  int *coveredby
1855 );
1856 
1876  rt_raster rast1, int nband1,
1877  rt_raster rast2, int nband2,
1878  double distance,
1879  int *dwithin
1880 );
1881 
1901  rt_raster rast1, int nband1,
1902  rt_raster rast2, int nband2,
1903  double distance,
1904  int *dfwithin
1905 );
1906 
1907 /*
1908  * Return ES_ERROR if error occurred in function.
1909  * Paramter aligned returns non-zero if two rasters are aligned
1910  *
1911  * @param rast1 : the first raster for alignment test
1912  * @param rast2 : the second raster for alignment test
1913  * @param *aligned : non-zero value if the two rasters are aligned
1914  * @param *reason : reason why rasters are not aligned
1915  *
1916  * @return ES_NONE if success, ES_ERROR if error
1917  */
1919  rt_raster rast1,
1920  rt_raster rast2,
1921  int *aligned, char **reason
1922 );
1923 
1924 /*
1925  * Return raster of computed extent specified extenttype applied
1926  * on two input rasters. The raster returned should be freed by
1927  * the caller
1928  *
1929  * @param rast1 : the first raster
1930  * @param rast2 : the second raster
1931  * @param extenttype : type of extent for the output raster
1932  * @param *rtnraster : raster of computed extent
1933  * @param *offset : 4-element array indicating the X,Y offsets
1934  * for each raster. 0,1 for rast1 X,Y. 2,3 for rast2 X,Y.
1935  *
1936  * @return ES_NONE if success, ES_ERROR if error
1937  */
1940  rt_raster rast1, rt_raster rast2,
1941  rt_extenttype extenttype,
1942  rt_raster *rtnraster, double *offset
1943 );
1944 
1983  rt_iterator itrset, uint16_t itrcount,
1984  rt_extenttype extenttype, rt_raster customextent,
1985  rt_pixtype pixtype,
1986  uint8_t hasnodata, double nodataval,
1987  uint16_t distancex, uint16_t distancey,
1988  rt_mask mask,
1989  void *userarg,
1990  int (*callback)(
1991  rt_iterator_arg arg,
1992  void *userarg,
1993  double *value,
1994  int *nodata
1995  ),
1996  rt_raster *rtnraster
1997 );
1998 
2010 rt_raster rt_raster_colormap(
2011  rt_raster raster, int nband,
2012  rt_colormap colormap
2013 );
2014 
2015 /*- utilities -------------------------------------------------------*/
2016 
2017 /*
2018  * rt_core memory functions
2019  */
2020 extern void *rtalloc(size_t size);
2021 extern void *rtrealloc(void *mem, size_t size);
2022 extern void rtdealloc(void *mem);
2023 
2024 /*
2025  * GDAL driver flags
2026  */
2027 
2028 #define GDAL_ENABLE_ALL "ENABLE_ALL"
2029 #define GDAL_DISABLE_ALL "DISABLE_ALL"
2030 #define GDAL_VSICURL "VSICURL"
2031 
2032 /*
2033  * Set of functions to clamp double to int of different size
2034  */
2035 
2036 #if !defined(POSTGIS_RASTER_WARN_ON_TRUNCATION)
2037 #define POSTGIS_RASTER_WARN_ON_TRUNCATION 0
2038 #endif
2039 
2040 #define POSTGIS_RT_1BBMAX 1
2041 #define POSTGIS_RT_2BUIMAX 3
2042 #define POSTGIS_RT_4BUIMAX 15
2043 
2044 uint8_t
2045 rt_util_clamp_to_1BB(double value);
2046 
2047 uint8_t
2049 
2050 uint8_t
2052 
2053 int8_t
2055 
2056 uint8_t
2058 
2059 int16_t
2061 
2062 uint16_t
2064 
2065 int32_t
2067 
2068 uint32_t
2070 
2071 float
2072 rt_util_clamp_to_32F(double value);
2073 
2074 int
2076  double initialvalue,
2077  int32_t checkvalint, uint32_t checkvaluint,
2078  float checkvalfloat, double checkvaldouble,
2079  rt_pixtype pixtype
2080 );
2081 
2089 GDALResampleAlg
2090 rt_util_gdal_resample_alg(const char *algname);
2091 
2099 GDALDataType
2101 
2109 rt_pixtype
2110 rt_util_gdal_datatype_to_pixtype(GDALDataType gdt);
2111 
2112 /*
2113  get GDAL runtime version information
2114 */
2115 const char*
2116 rt_util_gdal_version(const char *request);
2117 
2118 /*
2119  computed extent type from c string
2120 */
2122 rt_util_extent_type(const char *name);
2123 
2124 /*
2125  convert the spatial reference string from a GDAL recognized format to either WKT or Proj4
2126 */
2127 char*
2128 rt_util_gdal_convert_sr(const char *srs, int proj4);
2129 
2130 /*
2131  is the spatial reference string supported by GDAL
2132 */
2133 int
2134 rt_util_gdal_supported_sr(const char *srs);
2135 
2147 rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode);
2148 
2149 /*
2150  is GDAL configured correctly?
2151 */
2152 int
2154 
2155 /*
2156  register all GDAL drivers
2157 */
2158 int
2159 rt_util_gdal_register_all(int force_register_all);
2160 
2161 /*
2162  is the driver registered?
2163 */
2164 int
2165 rt_util_gdal_driver_registered(const char *drv);
2166 
2167 /*
2168  wrapper for GDALOpen and GDALOpenShared
2169 */
2170 GDALDatasetH
2171 rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared);
2172 
2173 void
2175  OGREnvelope env,
2176  rt_envelope *ext
2177 );
2178 
2179 void
2181  rt_envelope ext,
2182  OGREnvelope *env
2183 );
2184 
2185 LWPOLY *
2187  rt_envelope ext
2188 );
2189 
2190 int
2192  double *gt1,
2193  double *gt2
2194 );
2195 
2196 /* coordinates in RGB and HSV are floating point values between 0 and 1 */
2199  double rgb[3],
2200  double hsv[3]
2201 );
2202 
2203 /* coordinates in RGB and HSV are floating point values between 0 and 1 */
2206  double hsv[3],
2207  double rgb[3]
2208 );
2209 
2210 /*
2211  helper macros for consistent floating point equality checks
2212 */
2213 #define FLT_NEQ(x, y) (fabs(x - y) > FLT_EPSILON)
2214 #define FLT_EQ(x, y) (!FLT_NEQ(x, y))
2215 #define DBL_NEQ(x, y) (fabs(x - y) > DBL_EPSILON)
2216 #define DBL_EQ(x, y) (!DBL_NEQ(x, y))
2217 
2218 /*
2219  helper macro for symmetrical rounding
2220 */
2221 #define ROUND(x, y) (((x > 0.0) ? floor((x * pow(10, y) + 0.5)) : ceil((x * pow(10, y) - 0.5))) / pow(10, y))
2222 
2231  /*---[ 8 byte boundary ]---{ */
2232  uint32_t size; /* required by postgresql: 4 bytes */
2233  uint16_t version; /* format version (this is version 0): 2 bytes */
2234  uint16_t numBands; /* Number of bands: 2 bytes */
2235 
2236  /* }---[ 8 byte boundary ]---{ */
2237  double scaleX; /* pixel width: 8 bytes */
2238 
2239  /* }---[ 8 byte boundary ]---{ */
2240  double scaleY; /* pixel height: 8 bytes */
2241 
2242  /* }---[ 8 byte boundary ]---{ */
2243  double ipX; /* insertion point X: 8 bytes */
2244 
2245  /* }---[ 8 byte boundary ]---{ */
2246  double ipY; /* insertion point Y: 8 bytes */
2247 
2248  /* }---[ 8 byte boundary ]---{ */
2249  double skewX; /* skew about the X axis: 8 bytes */
2250 
2251  /* }---[ 8 byte boundary ]---{ */
2252  double skewY; /* skew about the Y axis: 8 bytes */
2253 
2254  /* }---[ 8 byte boundary ]--- */
2255  int32_t srid; /* Spatial reference id: 4 bytes */
2256  uint16_t width; /* pixel columns: 2 bytes */
2257  uint16_t height; /* pixel rows: 2 bytes */
2258 };
2259 
2260 /* NOTE: the initial part of this structure matches the layout
2261  * of data in the serialized form version 0, starting
2262  * from the numBands element
2263  */
2264 struct rt_raster_t {
2266  uint16_t version;
2267 
2268  /* Number of bands, all share the same dimension
2269  * and georeference */
2270  uint16_t numBands;
2271 
2272  /* Georeference (in projection units) */
2273  double scaleX; /* pixel width */
2274  double scaleY; /* pixel height */
2275  double ipX; /* geo x ordinate of the corner of upper-left pixel */
2276  double ipY; /* geo y ordinate of the corner of bottom-right pixel */
2277  double skewX; /* skew about the X axis*/
2278  double skewY; /* skew about the Y axis */
2279 
2280  int32_t srid; /* spatial reference id */
2281  uint16_t width; /* pixel columns - max 65535 */
2282  uint16_t height; /* pixel rows - max 65535 */
2283  rt_band *bands; /* actual bands */
2284 
2285 };
2286 
2288  uint8_t bandNum; /* 0-based */
2289  char* path; /* internally owned */
2290  void *mem; /* loaded external band data, internally owned */
2291 };
2292 
2293 struct rt_band_t {
2295  int32_t offline;
2296  uint16_t width;
2297  uint16_t height;
2298  int32_t hasnodata; /* a flag indicating if this band contains nodata values */
2299  int32_t isnodata; /* a flag indicating if this band is filled only with
2300  nodata values. flag CANNOT be TRUE if hasnodata is FALSE */
2301  double nodataval; /* int will be converted ... */
2302  int8_t ownsdata; /* 0, externally owned. 1, internally owned. only applies to data.mem */
2303 
2304  rt_raster raster; /* reference to parent raster */
2305 
2306  union {
2307  void* mem; /* actual data, externally owned */
2308  struct rt_extband_t offline;
2309  } data;
2310 
2311 };
2312 
2313 struct rt_pixel_t {
2314  int x; /* column */
2315  int y; /* line */
2316 
2318  double value;
2319 
2321 };
2322 
2323 struct rt_mask_t {
2324  uint16_t dimx;
2325  uint16_t dimy;
2326  double **values;
2327  int **nodata;
2328  int weighted; /* 0 if not weighted values 1 if weighted values */
2329 };
2330 
2331 /* polygon as LWPOLY with associated value */
2334  double val;
2335 };
2336 
2337 /* summary stats of specified band */
2339  double sample;
2341 
2342  double min;
2343  double max;
2344  double sum;
2345  double mean;
2346  double stddev;
2347 
2348  double *values;
2349  int sorted; /* flag indicating that values is sorted ascending by value */
2350 };
2351 
2352 /* histogram bin(s) of specified band */
2355  double percent;
2356 
2357  double min;
2358  double max;
2359 
2360  int inc_min;
2361  int inc_max;
2362 };
2363 
2364 /* quantile(s) of the specified band */
2366  double quantile;
2367  double value;
2369 };
2370 
2371 /* listed-list structures for rt_band_get_quantiles_stream */
2373  uint8_t algeq; /* AL-GEQ (1) or AL-GT (0) */
2374  double quantile;
2375  uint64_t tau; /* position in sequence */
2376 
2377  struct quantile_llist_element *head; /* H index 0 */
2378  struct quantile_llist_element *tail; /* H index last */
2379  uint32_t count; /* # of elements in H */
2380 
2381  /* faster access to elements at specific intervals */
2383  uint32_t index_max; /* max # of elements in index */
2384 
2385  uint64_t sum1; /* N1H */
2386  uint64_t sum2; /* N2H */
2387 };
2388 
2390  double value;
2392 
2395 };
2396 
2400 };
2401 
2402 /* number of times a value occurs */
2404  double value;
2406  double percent;
2407 };
2408 
2409 /* reclassification expression */
2412  double min;
2413  double max;
2414  int inc_min; /* include min */
2415  int inc_max; /* include max */
2416  int exc_min; /* exceed min */
2417  int exc_max; /* exceed max */
2418  } src, dst;
2419 };
2420 
2421 /* raster iterator */
2423  rt_raster raster;
2424  uint16_t nband; /* 0-based */
2425  uint8_t nbnodata; /* no band = treat as NODATA */
2426 };
2427 
2428 /* callback argument from raster iterator */
2430  /* # of rasters, Z-axis */
2431  uint16_t rasters;
2432  /* # of rows, Y-axis */
2434  /* # of columns, X-axis */
2436 
2437  /* axis order: Z,X,Y */
2438  /* individual pixel values */
2439  double ***values;
2440  /* 0,1 value of nodata flag */
2441  int ***nodata;
2442 
2443  /* X,Y of pixel from each input raster */
2444  int **src_pixel;
2445 
2446  /* X,Y of pixel from output raster */
2447  int dst_pixel[2];
2448 };
2449 
2450 /* gdal driver information */
2452  int idx;
2453  char *short_name;
2454  char *long_name;
2458 };
2459 
2460 /* raster colormap entry */
2463  double value;
2464  uint8_t color[4]; /* RGBA */
2465 };
2466 
2468  enum {
2472  } method;
2473 
2474  int ncolor;
2475  uint16_t nentry;
2476  rt_colormap_entry entry;
2477 };
2478 
2479 #endif /* LIBRTCORE_H_INCLUDED */
Datum coveredby(PG_FUNCTION_ARGS)
void *(* rt_allocator)(size_t size)
Global functions for memory/logging handlers.
Definition: librtcore.h:229
int32_t rt_util_clamp_to_32BSI(double value)
Definition: rt_util.c:69
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:314
uint64_t sum1
Definition: librtcore.h:2385
double skewY
Definition: librtcore.h:2278
double MinY
Definition: librtcore.h:167
int32_t srid
Definition: librtcore.h:2280
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:1786
uint16_t nentry
Definition: librtcore.h:2475
double UpperLeftX
Definition: librtcore.h:170
int quantile_llist_destroy(struct quantile_llist **list, uint32_t list_count)
uint32_t rt_util_clamp_to_32BUI(double value)
Definition: rt_util.c:74
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
Definition: rt_serialize.c:521
int rt_util_gdal_register_all(int force_register_all)
Definition: rt_util.c:334
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition: rt_raster.c:213
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition: rt_raster.c:190
void *(* rt_reallocator)(void *mem, size_t size)
Definition: librtcore.h:230
Datum covers(PG_FUNCTION_ARGS)
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
struct quantile_llist_element * element
Definition: librtcore.h:2398
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
uint32_t count
Definition: librtcore.h:2340
double quantile
Definition: librtcore.h:2374
void default_rt_info_handler(const char *fmt, va_list ap)
Definition: rt_context.c:93
struct quantile_llist_element * prev
Definition: librtcore.h:2393
void * mem
Definition: librtcore.h:2290
raster
Be careful!! Zeros function&#39;s input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
void(* rt_message_handler)(const char *string, va_list ap) __attribute__((format(printf
Definition: librtcore.h:232
uint16_t numBands
Definition: librtcore.h:2270
struct rt_pixel_t * rt_pixel
Definition: librtcore.h:147
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:1439
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:940
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster&#39;s geotransform using 6-element array.
Definition: rt_raster.c:727
struct rt_raster_t * rt_raster
Types definitions.
Definition: librtcore.h:145
double MaxY
Definition: librtcore.h:168
rt_raster raster
Definition: librtcore.h:2304
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition: rt_raster.c:706
uint32_t count
Definition: librtcore.h:2405
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.
double MaxX
Definition: librtcore.h:166
rt_pixtype pixtype
Definition: librtcore.h:2294
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition: rt_raster.c:168
struct rt_gdaldriver_t * rt_gdaldriver
Definition: librtcore.h:154
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:151
band
Definition: ovdump.py:57
double quantile
Definition: librtcore.h:2366
def fmt
Definition: pixval.py:92
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:3465
char * short_name
Definition: librtcore.h:2453
rt_extenttype
Definition: librtcore.h:200
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:1830
Datum contains(PG_FUNCTION_ARGS)
LWGEOM * geom
Definition: librtcore.h:2320
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
Definition: rt_band.c:325
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
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:2513
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
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:195
void * default_rt_reallocator(void *mem, size_t size)
Definition: rt_context.c:54
data
Definition: ovdump.py:103
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
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:231
void * rtrealloc(void *mem, size_t size)
Definition: rt_context.c:179
uint16_t height
Definition: librtcore.h:2297
double value
Definition: librtcore.h:2318
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.
LWPOLY * rt_util_envelope_to_lwpoly(rt_envelope ext)
Definition: rt_util.c:435
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:1604
rt_errorstate
Enum definitions.
Definition: librtcore.h:179
int rt_util_same_geotransform_matrix(double *gt1, double *gt2)
Definition: rt_util.c:487
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.
#define __attribute__
Definition: librtcore.h:139
double ipY
Definition: librtcore.h:2276
gt
Definition: window.py:77
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:685
int ** nodata
Definition: librtcore.h:2327
rt_pixtype
Definition: librtcore.h:185
Datum overlaps(PG_FUNCTION_ARGS)
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:336
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.
struct rt_reclassexpr_t * rt_reclassexpr
Definition: librtcore.h:155
struct rt_quantile_t * rt_quantile
Definition: librtcore.h:152
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
uint32_t size
Definition: librtcore.h:2265
int weighted
Definition: librtcore.h:2328
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition: rt_raster.c:1338
uint16_t height
Definition: librtcore.h:2282
Datum touches(PG_FUNCTION_ARGS)
uint16_t dimy
Definition: librtcore.h:2325
double value
Definition: librtcore.h:2367
rt_geos_spatial_test
GEOS spatial relationship tests available.
Definition: librtcore.h:217
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1682
rt_errorstate rt_raster_get_convex_hull(rt_raster raster, LWGEOM **hull)
Get raster&#39;s convex hull.
Definition: rt_geometry.c:803
ds
Definition: pixval.py:66
void default_rt_warning_handler(const char *fmt, va_list ap)
Definition: rt_context.c:80
const char * rt_band_get_ext_path(rt_band band)
Return band&#39;s external path (only valid when rt_band_is_offline returns non-zero).
Definition: rt_band.c:359
struct quantile_llist_element * next
Definition: librtcore.h:2394
unsigned int uint32_t
Definition: uthash.h:78
LWPOLY * geom
Definition: librtcore.h:2333
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:755
int rt_pixtype_alignment(rt_pixtype pixtype)
Return alignment requirements for data in the given pixel type.
Definition: rt_pixel.c:75
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
Definition: rt_geometry.c:355
uint16_t rt_util_clamp_to_16BUI(double value)
Definition: rt_util.c:64
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_band.c:619
nband
Definition: pixval.py:52
double ** values
Definition: librtcore.h:2326
double val
Definition: librtcore.h:2334
struct quantile_llist_element * tail
Definition: librtcore.h:2378
GDALDataType rt_util_pixtype_to_gdal_datatype(rt_pixtype pt)
Convert rt_pixtype to GDALDataType.
Definition: rt_util.c:118
double percent
Definition: librtcore.h:2355
uint16_t version
Definition: librtcore.h:2266
void rt_util_to_ogr_envelope(rt_envelope ext, OGREnvelope *env)
Definition: rt_util.c:422
int rt_util_gdal_driver_registered(const char *drv)
Definition: rt_util.c:353
uint32_t columns
Definition: librtcore.h:2435
void rtwarn(const char *fmt,...)
Definition: rt_context.c:224
uint16_t rasters
Definition: librtcore.h:2431
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:611
Datum intersects(PG_FUNCTION_ARGS)
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_intersects(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *intersects)
Return ES_ERROR if error occurred in function.
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1173
rt_extenttype rt_util_extent_type(const char *name)
Definition: rt_util.c:191
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
uint64_t tau
Definition: librtcore.h:2375
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:485
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
Definition: rt_pixel.c:80
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:669
rt_errorstate rt_util_rgb_to_hsv(double rgb[3], double hsv[3])
Definition: rt_util.c:503
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:1089
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
Definition: rt_raster.c:1544
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
uint16_t width
Definition: librtcore.h:2281
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:297
int rt_util_gdal_supported_sr(const char *srs)
Definition: rt_util.c:243
rt_errorstate rt_band_load_offline_data(rt_band band)
Load offline band&#39;s data.
Definition: rt_band.c:425
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
int8_t rt_util_clamp_to_8BSI(double value)
Definition: rt_util.c:49
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:625
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band&#39;s clamped NODATA value.
Definition: rt_band.c:1750
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition: rt_raster.c:381
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:1374
rt_pixtype rt_util_gdal_datatype_to_pixtype(GDALDataType gdt)
Convert GDALDataType to rt_pixtype.
Definition: rt_util.c:153
void rtinfo(const char *fmt,...)
Definition: rt_context.c:211
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition: rt_band.c:1704
int8_t ownsdata
Definition: librtcore.h:2302
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:626
struct rt_colormap_entry_t * rt_colormap_entry
Definition: librtcore.h:160
int count
Definition: genraster.py:56
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition: rt_raster.c:150
LWPOLY * rt_raster_pixel_as_polygon(rt_raster raster, int x, int y)
Get a raster pixel as a polygon.
Definition: rt_geometry.c:610
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition: rt_band.c:592
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:1351
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition: rt_band.c:601
double skewX
Definition: librtcore.h:2277
rt_colormap_entry entry
Definition: librtcore.h:2476
double * values
Definition: librtcore.h:2348
rt_errorstate rt_raster_get_envelope_geom(rt_raster raster, LWGEOM **env)
Get raster&#39;s envelope as a geometry.
Definition: rt_geometry.c:670
struct rt_band_t * rt_band
Definition: librtcore.h:146
double nodataval
Definition: librtcore.h:2301
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:396
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition: rt_pixel.c:148
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster&#39;s SRID.
Definition: rt_raster.c:363
uint32_t index_max
Definition: librtcore.h:2383
int32_t rt_raster_get_srid(rt_raster raster)
Get raster&#39;s SRID.
Definition: rt_raster.c:356
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition: rt_raster.c:82
rt_raster raster
Definition: librtcore.h:2423
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:1502
uint8_t can_write
Definition: librtcore.h:2457
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:806
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.
uint8_t nodata
Definition: librtcore.h:2317
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition: rt_raster.c:159
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
uint16_t width
Definition: librtcore.h:2296
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_raster.c:181
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:59
struct rt_histogram_t * rt_histogram
Definition: librtcore.h:151
Datum distance(PG_FUNCTION_ARGS)
rt_errorstate rt_band_get_ext_band_num(rt_band band, uint8_t *bandnum)
Return bands&#39; external band number (only valid when rt_band_is_offline returns non-zero).
Definition: rt_band.c:372
uint16_t nband
Definition: librtcore.h:2424
uint8_t rt_util_clamp_to_4BUI(double value)
Definition: rt_util.c:44
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
Definition: rt_band.c:633
uint8_t rt_util_clamp_to_8BUI(double value)
Definition: rt_util.c:54
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_pixel.c:39
uint8_t rt_util_clamp_to_1BB(double value)
Definition: rt_util.c:34
struct rt_geomval_t * rt_geomval
Definition: librtcore.h:149
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:250
struct rt_mask_t * rt_mask
Definition: librtcore.h:148
struct rt_valuecount_t * rt_valuecount
Definition: librtcore.h:153
void default_rt_error_handler(const char *fmt, va_list ap)
Definition: rt_context.c:67
void(* rt_deallocator)(void *mem)
Definition: librtcore.h:231
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:286
struct rt_bandstats_t * rt_bandstats
Definition: librtcore.h:150
uint16_t rt_raster_get_width(rt_raster raster)
Definition: rt_raster.c:121
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_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
int32_t offline
Definition: librtcore.h:2295
double *** values
Definition: librtcore.h:2439
void default_rt_deallocator(void *mem)
Definition: rt_context.c:61
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
Definition: rt_band.c:647
void rtdealloc(void *mem)
Definition: rt_context.c:186
Definition: librtcore.h:2461
int32_t isnodata
Definition: librtcore.h:2299
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:1602
uint8_t nbnodata
Definition: librtcore.h:2425
double MinX
Definition: librtcore.h:165
rt_band rt_band_duplicate(rt_band band)
Create a new band duplicated from source band.
Definition: rt_band.c:283
Struct definitions.
Definition: librtcore.h:2230
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition: rt_raster.c:1720
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:1697
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_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:676
char * rt_util_gdal_convert_sr(const char *srs, int proj4)
Definition: rt_util.c:212
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition: rt_pixel.c:110
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.
void * default_rt_allocator(size_t size)
The default memory/logging handlers installed by lwgeom_install_default_allocators() ...
Definition: rt_context.c:47
rt_band * bands
Definition: librtcore.h:2283
char * create_options
Definition: librtcore.h:2455
struct quantile_llist_index * index
Definition: librtcore.h:2382
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_band.c:583
uint8_t bandNum
Definition: librtcore.h:2288
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:805
void * mem
Definition: librtcore.h:2307
rt_raster rt_raster_compute_skewed_raster(rt_envelope extent, double *skew, double *scale, double tolerance)
Definition: rt_raster.c:960
char * long_name
Definition: librtcore.h:2454
uint32_t has_value
Definition: librtcore.h:2368
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
Definition: rt_raster.c:405
uint8_t algeq
Definition: librtcore.h:2373
int32_t hasnodata
Definition: librtcore.h:2298
rt_errorstate rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode)
Get auth name and code.
Definition: rt_util.c:270
uint32_t count
Definition: librtcore.h:2379
void rt_util_from_ogr_envelope(OGREnvelope env, rt_envelope *ext)
Definition: rt_util.c:406
double ipX
Definition: librtcore.h:2275
struct rt_iterator_arg_t * rt_iterator_arg
Definition: librtcore.h:158
uint8_t rt_util_clamp_to_2BUI(double value)
Definition: rt_util.c:39
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition: rt_band.c:666
struct rt_colormap_t * rt_colormap
Definition: librtcore.h:161
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.
float rt_util_clamp_to_32F(double value)
Definition: rt_util.c:79
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel&#39;s value.
Definition: rt_band.c:926
int rt_util_gdal_configured(void)
Definition: rt_util.c:313
int value
Definition: genraster.py:61
const char * rt_util_gdal_version(const char *request)
Definition: rt_util.c:180
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
Definition: rt_raster.c:2186
struct quantile_llist_element * head
Definition: librtcore.h:2377
rt_errorstate rt_raster_get_perimeter(rt_raster raster, int nband, LWGEOM **perimeter)
Get raster perimeter.
Definition: rt_geometry.c:182
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
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.
uint16_t rt_raster_get_height(rt_raster raster)
Definition: rt_raster.c:129
double scaleX
Definition: librtcore.h:2273
struct rt_iterator_t * rt_iterator
Definition: librtcore.h:157
GDALResampleAlg rt_util_gdal_resample_alg(const char *algname)
Convert cstring name to GDAL Resample Algorithm.
Definition: rt_util.c:91
char * path
Definition: librtcore.h:2289
int isnodata
Definition: librtcore.h:2462
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:1326
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...
unsigned char uint8_t
Definition: uthash.h:79
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.
double UpperLeftY
Definition: librtcore.h:171
uint8_t can_read
Definition: librtcore.h:2456
uint16_t dimx
Definition: librtcore.h:2324
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
Definition: rt_serialize.c:717
rt_errorstate rt_raster_get_envelope(rt_raster raster, rt_envelope *env)
Get raster&#39;s envelope.
Definition: rt_raster.c:873
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
Definition: rt_util.c:379
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition: rt_raster.c:222
rt_errorstate rt_util_hsv_to_rgb(double hsv[3], double rgb[3])
Definition: rt_util.c:557
double value
Definition: librtcore.h:2463
uint64_t sum2
Definition: librtcore.h:2386
void(*) voi rt_install_default_allocators)(void)
Apply the default memory management (malloc() and free()) and error handlers.
double scaleY
Definition: librtcore.h:2274
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:200
This library is the generic geometry handling section of PostGIS.
uint32_t count
Definition: librtcore.h:2354
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:120
int16_t rt_util_clamp_to_16BSI(double value)
Definition: rt_util.c:59
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.
enum rt_colormap_t::@9 method
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.