PostGIS  2.3.7dev-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 /* if we are in Unix define stricmp to be strcasecmp and strnicmp to */
118 /* be strncasecmp. I'm not sure if all Unices have these, but Linux */
119 /* does. */
120 #if defined(UNIX)
121 #if !defined(HAVE_STRICMP)
122 #define stricmp strcasecmp
123 #endif
124 #if !defined(HAVE_STRNICMP)
125 #define strnicmp strncasecmp
126 #endif
127 #endif
128 
129 #include <stdio.h> /* for printf, sprintf */
130 #include <stdlib.h> /* For size_t, srand and rand */
131 #include <stdint.h> /* For C99 int types */
132 #include <string.h> /* for memcpy, strlen, etc */
133 #include <float.h> /* for FLT_EPSILON, DBL_EPSILON and float type limits */
134 #include <limits.h> /* for integer type limits */
135 
136 #include "liblwgeom.h"
137 
138 #include "gdal_alg.h"
139 #include "gdal_frmts.h"
140 #include "gdal.h"
141 #include "gdalwarper.h"
142 #include "cpl_vsi.h"
143 #include "cpl_conv.h"
144 #include "ogr_api.h"
145 #include "ogr_srs_api.h"
146 
147 #include "../../postgis_config.h"
148 #include "../raster_config.h"
149 
150 #ifndef __GNUC__
151 # define __attribute__ (x)
152 #endif
153 
157 typedef struct rt_raster_t* rt_raster;
158 typedef struct rt_band_t* rt_band;
159 typedef struct rt_pixel_t* rt_pixel;
160 typedef struct rt_mask_t* rt_mask;
161 typedef struct rt_geomval_t* rt_geomval;
162 typedef struct rt_bandstats_t* rt_bandstats;
163 typedef struct rt_histogram_t* rt_histogram;
164 typedef struct rt_quantile_t* rt_quantile;
168 
169 typedef struct rt_iterator_t* rt_iterator;
171 
173 typedef struct rt_colormap_t* rt_colormap;
174 
175 /* envelope information */
176 typedef struct {
177  double MinX;
178  double MaxX;
179  double MinY;
180  double MaxY;
181 
182  double UpperLeftX;
183  double UpperLeftY;
184 } rt_envelope;
185 
190 /* function return error states */
191 typedef enum {
192  ES_NONE = 0, /* no error */
193  ES_ERROR = 1 /* generic error */
194 } rt_errorstate;
195 
196 /* Pixel types */
197 typedef enum {
198  PT_1BB=0, /* 1-bit boolean */
199  PT_2BUI=1, /* 2-bit unsigned integer */
200  PT_4BUI=2, /* 4-bit unsigned integer */
201  PT_8BSI=3, /* 8-bit signed integer */
202  PT_8BUI=4, /* 8-bit unsigned integer */
203  PT_16BSI=5, /* 16-bit signed integer */
204  PT_16BUI=6, /* 16-bit unsigned integer */
205  PT_32BSI=7, /* 32-bit signed integer */
206  PT_32BUI=8, /* 32-bit unsigned integer */
207  PT_32BF=10, /* 32-bit float */
208  PT_64BF=11, /* 64-bit float */
210 } rt_pixtype;
211 
212 typedef enum {
219 } rt_extenttype;
220 
229 typedef enum {
237 
241 typedef void* (*rt_allocator)(size_t size);
242 typedef void* (*rt_reallocator)(void *mem, size_t size);
243 typedef void (*rt_deallocator)(void *mem);
244 typedef void (*rt_message_handler)(const char* string, va_list ap)
245  __attribute__ (( format(printf,1,0) ));
246 
247 /*******************************************************************
248  * Functions that may be used by the raster core function's caller
249  * (for example: rt_pg functions, test functions, future loader/exporter)
250  *******************************************************************/
254 extern void rt_install_default_allocators(void);
255 
256 
261 extern void* rtalloc(size_t size);
262 extern void* rtrealloc(void* mem, size_t size);
263 extern void rtdealloc(void* mem);
264 
265 /******************************************************************/
266 
267 
271 void rterror(const char *fmt, ...);
272 void rtinfo(const char *fmt, ...);
273 void rtwarn(const char *fmt, ...);
274 
275 
279 void * default_rt_allocator(size_t size);
280 void * default_rt_reallocator(void * mem, size_t size);
281 void default_rt_deallocator(void * mem);
282 void default_rt_error_handler(const char * fmt, va_list ap);
283 void default_rt_warning_handler(const char * fmt, va_list ap);
284 void default_rt_info_handler(const char * fmt, va_list ap);
285 
286 
287 /* Debugging macros */
288 #if POSTGIS_DEBUG_LEVEL > 0
289 
290 /* Display a simple message at NOTICE level */
291 #define RASTER_DEBUG(level, msg) \
292  do { \
293  if (POSTGIS_DEBUG_LEVEL >= level) \
294  rtinfo("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__); \
295  } while (0);
296 
297 /* Display a formatted message at NOTICE level (like printf, with variadic arguments) */
298 #define RASTER_DEBUGF(level, msg, ...) \
299  do { \
300  if (POSTGIS_DEBUG_LEVEL >= level) \
301  rtinfo("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__, __VA_ARGS__); \
302  } while (0);
303 
304 #else
305 
306 /* Empty prototype that can be optimised away by the compiler for non-debug builds */
307 #define RASTER_DEBUG(level, msg) \
308  ((void) 0)
309 
310 /* Empty prototype that can be optimised away by the compiler for non-debug builds */
311 #define RASTER_DEBUGF(level, msg, ...) \
312  ((void) 0)
313 
314 #endif
315 
316 /*- memory context -------------------------------------------------------*/
317 
318 void rt_set_handlers(rt_allocator allocator, rt_reallocator reallocator,
319  rt_deallocator deallocator, rt_message_handler error_handler,
320  rt_message_handler info_handler, rt_message_handler warning_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,int 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 
432 rt_band rt_band_new_inline(
433  uint16_t width, uint16_t height,
434  rt_pixtype pixtype,
435  uint32_t hasnodata, double nodataval,
436  uint8_t* data
437 );
438 
458 rt_band rt_band_new_offline(
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 
475 rt_band rt_band_duplicate(rt_band band);
476 
486 int rt_band_is_offline(rt_band band);
487 
496 const char* rt_band_get_ext_path(rt_band band);
497 
507 rt_errorstate rt_band_get_ext_band_num(rt_band band, uint8_t *bandnum);
508 
517 
525 uint16_t rt_band_get_width(rt_band band);
526 
534 uint16_t rt_band_get_height(rt_band band);
535 
545 int rt_band_get_ownsdata_flag(rt_band band);
546 
547 /* set ownsdata flag */
548 void rt_band_set_ownsdata_flag(rt_band band, int flag);
549 
557 void* rt_band_get_data(rt_band band);
558 
569 
575 void rt_band_destroy(rt_band band);
576 
584 int rt_band_get_hasnodata_flag(rt_band band);
585 
591 void rt_band_set_hasnodata_flag(rt_band band, int flag);
592 
601 rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag);
602 
610 int rt_band_get_isnodata_flag(rt_band band);
611 
622 rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted);
623 
632 rt_errorstate rt_band_get_nodata(rt_band band, double *nodata);
633 
654  rt_band band,
655  int x, int y,
656  void *vals, uint32_t len
657 );
658 
671  rt_band band,
672  int x, int y,
673  double val,
674  int *converted
675 );
676 
698  rt_band band,
699  int x, int y,
700  uint16_t len,
701  void **vals, uint16_t *nvals
702 );
703 
717  rt_band band,
718  int x, int y,
719  double *value,
720  int *nodata
721 );
722 
741  rt_band band,
742  int x, int y,
743  uint16_t distancex, uint16_t distancey,
744  int exclude_nodata_value,
745  rt_pixel *npixels
746 );
747 
760  rt_band band, int exclude_nodata_value,
761  double *searchset, int searchcount,
762  rt_pixel *pixels
763 );
764 
772 double rt_band_get_min_value(rt_band band);
773 
781 int rt_band_check_is_nodata(rt_band band);
782 
793 int rt_band_clamped_value_is_nodata(rt_band band, double val);
794 
809  rt_band band,
810  double val,
811  double *newval, int *corrected
812 );
813 
827 rt_bandstats rt_band_get_summary_stats(
828  rt_band band,
829  int exclude_nodata_value, double sample, int inc_vals,
830  uint64_t *cK, double *cM, double *cQ
831 );
832 
851 rt_histogram rt_band_get_histogram(
852  rt_bandstats stats,
853  int bin_count, double *bin_widths, int bin_widths_count,
854  int right, double min, double max,
855  uint32_t *rtn_count
856 );
857 
869 rt_quantile rt_band_get_quantiles(rt_bandstats stats,
870  double *quantiles, int quantiles_count, uint32_t *rtn_count);
871 
872 struct quantile_llist;
874  struct quantile_llist **list,
875  uint32_t list_count
876 );
877 
905 rt_quantile rt_band_get_quantiles_stream(
906  rt_band band,
907  int exclude_nodata_value, double sample,
908  uint64_t cov_count,
909  struct quantile_llist **qlls, uint32_t *qlls_count,
910  double *quantiles, int quantiles_count,
911  uint32_t *rtn_count
912 );
913 
928 rt_valuecount rt_band_get_value_count(
929  rt_band band, int exclude_nodata_value,
930  double *search_values, uint32_t search_values_count, double roundto,
931  uint32_t *rtn_total, uint32_t *rtn_count
932 );
933 
946 rt_band rt_band_reclass(
947  rt_band srcband, rt_pixtype pixtype,
948  uint32_t hasnodata, double nodataval,
949  rt_reclassexpr *exprset, int exprcount
950 );
951 
952 /*- rt_raster --------------------------------------------------------*/
953 
965 rt_raster rt_raster_new(uint32_t width, uint32_t height);
966 
977 rt_raster rt_raster_from_wkb(const uint8_t* wkb, uint32_t wkbsize);
978 
989 rt_raster rt_raster_from_hexwkb(const char* hexwkb, uint32_t hexwkbsize);
990 
1000 uint8_t *rt_raster_to_wkb(rt_raster raster, int outasin, uint32_t *wkbsize);
1001 
1012 char *rt_raster_to_hexwkb(rt_raster raster, int outasin, uint32_t *hexwkbsize);
1013 
1024 void rt_raster_destroy(rt_raster raster);
1025 
1026 /* Get number of bands */
1027 int rt_raster_get_num_bands(rt_raster raster);
1028 
1037 rt_band rt_raster_get_band(rt_raster raster, int bandNum);
1038 
1039 /* Get number of rows */
1040 uint16_t rt_raster_get_width(rt_raster raster);
1041 
1042 /* Get number of columns */
1043 uint16_t rt_raster_get_height(rt_raster raster);
1044 
1055 int rt_raster_add_band(rt_raster raster, rt_band band, int index);
1056 
1070  rt_raster raster,
1071  rt_pixtype pixtype,
1072  double initialvalue,
1073  uint32_t hasnodata, double nodatavalue,
1074  int index
1075 );
1076 
1086 void rt_raster_set_scale(rt_raster raster,
1087  double scaleX, double scaleY);
1088 
1096 double rt_raster_get_x_scale(rt_raster raster);
1097 
1105 double rt_raster_get_y_scale(rt_raster raster);
1106 
1116 void rt_raster_set_offsets(rt_raster raster,
1117  double x, double y);
1118 
1127 double rt_raster_get_x_offset(rt_raster raster);
1128 
1137 double rt_raster_get_y_offset(rt_raster raster);
1138 
1146 void rt_raster_set_skews(rt_raster raster,
1147  double skewX, double skewY);
1148 
1155 double rt_raster_get_x_skew(rt_raster raster);
1156 
1163 double rt_raster_get_y_skew(rt_raster raster);
1164 
1177 void rt_raster_get_phys_params(rt_raster rast,
1178  double *i_mag, double *j_mag, double *theta_i, double *theta_ij) ;
1179 
1195 void rt_raster_set_phys_params(rt_raster rast,
1196  double i_mag, double j_mag, double theta_i, double theta_ij) ;
1197 
1198 
1214 void rt_raster_calc_phys_params(double xscale,
1215  double xskew, double yskew, double yscale,
1216  double *i_mag, double *j_mag, double *theta_i, double *theta_ij) ;
1217 
1218 
1235 int rt_raster_calc_gt_coeff(double i_mag,
1236  double j_mag, double theta_i, double theta_ij,
1237  double *xscale, double *xskew, double *yskew, double *yscale) ;
1238 
1245 void rt_raster_set_srid(rt_raster raster, int32_t srid);
1246 
1253 int32_t rt_raster_get_srid(rt_raster raster);
1254 
1265  rt_raster raster,
1266  double *gt, double *igt
1267 );
1268 
1276  double *gt);
1277 
1286  double *gt);
1287 
1301  rt_raster raster,
1302  double xr, double yr,
1303  double* xw, double* yw,
1304  double *gt
1305 );
1306 
1320  rt_raster raster,
1321  double xw, double yw,
1322  double *xr, double *yr,
1323  double *igt
1324 );
1325 
1339 
1351 
1361 
1376  rt_raster raster, int nband,
1377  LWGEOM **perimeter
1378 );
1379 
1380 /*
1381  * Compute skewed extent that covers unskewed extent.
1382  *
1383  * @param envelope : unskewed extent of type rt_envelope
1384  * @param skew : pointer to 2-element array (x, y) of skew
1385  * @param scale : pointer to 2-element array (x, y) of scale
1386  * @param tolerance : value between 0 and 1 where the smaller the tolerance
1387  * results in an extent approaching the "minimum" skewed extent.
1388  * If value <= 0, tolerance = 0.1. If value > 1, tolerance = 1.
1389  *
1390  * @return skewed raster who's extent covers unskewed extent, NULL on error
1391  */
1392 rt_raster
1394  rt_envelope extent,
1395  double *skew,
1396  double *scale,
1397  double tolerance
1398 );
1399 
1414 LWPOLY* rt_raster_pixel_as_polygon(rt_raster raster, int x, int y);
1415 
1429 rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface);
1430 
1448 rt_geomval
1450  rt_raster raster, int nband,
1451  int exclude_nodata_value,
1452  int * pnElements
1453 );
1454 
1461 void* rt_raster_serialize(rt_raster raster);
1462 
1471 rt_raster rt_raster_deserialize(void* serialized, int header_only);
1472 
1480 int rt_raster_is_empty(rt_raster raster);
1481 
1490 int rt_raster_has_band(rt_raster raster, int nband);
1491 
1507  rt_raster torast, rt_raster fromrast,
1508  int fromindex, int toindex
1509 );
1510 
1522 rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums,
1523  int count);
1524 
1534 rt_band rt_raster_replace_band(rt_raster raster, rt_band band,
1535  int index);
1536 
1545 rt_raster rt_raster_clone(rt_raster raster, uint8_t deep);
1546 
1559 uint8_t *rt_raster_to_gdal(rt_raster raster, const char *srs,
1560  char *format, char **options, uint64_t *gdalsize);
1561 
1571 rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc);
1572 
1589 GDALDatasetH rt_raster_to_gdal_mem(
1590  rt_raster raster,
1591  const char *srs,
1592  uint32_t *bandNums,
1593  int *excludeNodataValues,
1594  int count,
1595  GDALDriverH *rtn_drv, int *destroy_rtn_drv
1596 );
1597 
1605 rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds);
1606 
1637 rt_raster rt_raster_gdal_warp(
1638  rt_raster raster,
1639  const char *src_srs, const char *dst_srs,
1640  double *scale_x, double *scale_y,
1641  int *width, int *height,
1642  double *ul_xw, double *ul_yw,
1643  double *grid_xw, double *grid_yw,
1644  double *skew_x, double *skew_y,
1645  GDALResampleAlg resample_alg, double max_err);
1646 
1673 rt_raster rt_raster_gdal_rasterize(const unsigned char *wkb,
1674  uint32_t wkb_len, const char *srs,
1675  uint32_t num_bands, rt_pixtype *pixtype,
1676  double *init, double *value,
1677  double *nodata, uint8_t *hasnodata,
1678  int *width, int *height,
1679  double *scale_x, double *scale_y,
1680  double *ul_xw, double *ul_yw,
1681  double *grid_xw, double *grid_yw,
1682  double *skew_x, double *skew_y,
1683  char **options
1684 );
1685 
1703  rt_raster rast1, int nband1,
1704  rt_raster rast2, int nband2,
1705  int *intersects
1706 );
1707 
1725  rt_raster rast1, int nband1,
1726  rt_raster rast2, int nband2,
1727  int *overlaps
1728 );
1729 
1747  rt_raster rast1, int nband1,
1748  rt_raster rast2, int nband2,
1749  int *contains
1750 );
1751 
1769  rt_raster rast1, int nband1,
1770  rt_raster rast2, int nband2,
1771  int *contains
1772 );
1773 
1791  rt_raster rast1, int nband1,
1792  rt_raster rast2, int nband2,
1793  int *touches
1794 );
1795 
1813  rt_raster rast1, int nband1,
1814  rt_raster rast2, int nband2,
1815  int *covers
1816 );
1817 
1835  rt_raster rast1, int nband1,
1836  rt_raster rast2, int nband2,
1837  int *coveredby
1838 );
1839 
1859  rt_raster rast1, int nband1,
1860  rt_raster rast2, int nband2,
1861  double distance,
1862  int *dwithin
1863 );
1864 
1884  rt_raster rast1, int nband1,
1885  rt_raster rast2, int nband2,
1886  double distance,
1887  int *dfwithin
1888 );
1889 
1890 /*
1891  * Return ES_ERROR if error occurred in function.
1892  * Paramter aligned returns non-zero if two rasters are aligned
1893  *
1894  * @param rast1 : the first raster for alignment test
1895  * @param rast2 : the second raster for alignment test
1896  * @param *aligned : non-zero value if the two rasters are aligned
1897  * @param *reason : reason why rasters are not aligned
1898  *
1899  * @return ES_NONE if success, ES_ERROR if error
1900  */
1902  rt_raster rast1,
1903  rt_raster rast2,
1904  int *aligned, char **reason
1905 );
1906 
1907 /*
1908  * Return raster of computed extent specified extenttype applied
1909  * on two input rasters. The raster returned should be freed by
1910  * the caller
1911  *
1912  * @param rast1 : the first raster
1913  * @param rast2 : the second raster
1914  * @param extenttype : type of extent for the output raster
1915  * @param *rtnraster : raster of computed extent
1916  * @param *offset : 4-element array indicating the X,Y offsets
1917  * for each raster. 0,1 for rast1 X,Y. 2,3 for rast2 X,Y.
1918  *
1919  * @return ES_NONE if success, ES_ERROR if error
1920  */
1923  rt_raster rast1, rt_raster rast2,
1924  rt_extenttype extenttype,
1925  rt_raster *rtnraster, double *offset
1926 );
1927 
1966  rt_iterator itrset, uint16_t itrcount,
1967  rt_extenttype extenttype, rt_raster customextent,
1968  rt_pixtype pixtype,
1969  uint8_t hasnodata, double nodataval,
1970  uint16_t distancex, uint16_t distancey,
1971  rt_mask mask,
1972  void *userarg,
1973  int (*callback)(
1974  rt_iterator_arg arg,
1975  void *userarg,
1976  double *value,
1977  int *nodata
1978  ),
1979  rt_raster *rtnraster
1980 );
1981 
1993 rt_raster rt_raster_colormap(
1994  rt_raster raster, int nband,
1995  rt_colormap colormap
1996 );
1997 
1998 /*- utilities -------------------------------------------------------*/
1999 
2000 /*
2001  * rt_core memory functions
2002  */
2003 extern void *rtalloc(size_t size);
2004 extern void *rtrealloc(void *mem, size_t size);
2005 extern void rtdealloc(void *mem);
2006 
2007 /*
2008  * GDAL driver flags
2009  */
2010 
2011 #define GDAL_ENABLE_ALL "ENABLE_ALL"
2012 #define GDAL_DISABLE_ALL "DISABLE_ALL"
2013 #define GDAL_VSICURL "VSICURL"
2014 
2015 /*
2016  * Set of functions to clamp double to int of different size
2017  */
2018 
2019 #if !defined(POSTGIS_RASTER_WARN_ON_TRUNCATION)
2020 #define POSTGIS_RASTER_WARN_ON_TRUNCATION 0
2021 #endif
2022 
2023 #define POSTGIS_RT_1BBMAX 1
2024 #define POSTGIS_RT_2BUIMAX 3
2025 #define POSTGIS_RT_4BUIMAX 15
2026 
2027 uint8_t
2028 rt_util_clamp_to_1BB(double value);
2029 
2030 uint8_t
2032 
2033 uint8_t
2035 
2036 int8_t
2038 
2039 uint8_t
2041 
2042 int16_t
2044 
2045 uint16_t
2047 
2048 int32_t
2050 
2051 uint32_t
2053 
2054 float
2055 rt_util_clamp_to_32F(double value);
2056 
2057 int
2059  double initialvalue,
2060  int32_t checkvalint, uint32_t checkvaluint,
2061  float checkvalfloat, double checkvaldouble,
2062  rt_pixtype pixtype
2063 );
2064 
2072 GDALResampleAlg
2073 rt_util_gdal_resample_alg(const char *algname);
2074 
2082 GDALDataType
2084 
2092 rt_pixtype
2093 rt_util_gdal_datatype_to_pixtype(GDALDataType gdt);
2094 
2095 /*
2096  get GDAL runtime version information
2097 */
2098 const char*
2099 rt_util_gdal_version(const char *request);
2100 
2101 /*
2102  computed extent type from c string
2103 */
2105 rt_util_extent_type(const char *name);
2106 
2107 /*
2108  convert the spatial reference string from a GDAL recognized format to either WKT or Proj4
2109 */
2110 char*
2111 rt_util_gdal_convert_sr(const char *srs, int proj4);
2112 
2113 /*
2114  is the spatial reference string supported by GDAL
2115 */
2116 int
2117 rt_util_gdal_supported_sr(const char *srs);
2118 
2130 rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode);
2131 
2132 /*
2133  is GDAL configured correctly?
2134 */
2135 int
2137 
2138 /*
2139  register all GDAL drivers
2140 */
2141 int
2142 rt_util_gdal_register_all(int force_register_all);
2143 
2144 /*
2145  is the driver registered?
2146 */
2147 int
2148 rt_util_gdal_driver_registered(const char *drv);
2149 
2150 /*
2151  wrapper for GDALOpen and GDALOpenShared
2152 */
2153 GDALDatasetH
2154 rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared);
2155 
2156 void
2158  OGREnvelope env,
2159  rt_envelope *ext
2160 );
2161 
2162 void
2164  rt_envelope ext,
2165  OGREnvelope *env
2166 );
2167 
2168 LWPOLY *
2170  rt_envelope ext
2171 );
2172 
2173 int
2175  double *gt1,
2176  double *gt2
2177 );
2178 
2179 /* coordinates in RGB and HSV are floating point values between 0 and 1 */
2182  double rgb[3],
2183  double hsv[3]
2184 );
2185 
2186 /* coordinates in RGB and HSV are floating point values between 0 and 1 */
2189  double hsv[3],
2190  double rgb[3]
2191 );
2192 
2193 /*
2194  helper macros for consistent floating point equality checks
2195 */
2196 #define FLT_NEQ(x, y) (fabs(x - y) > FLT_EPSILON)
2197 #define FLT_EQ(x, y) (!FLT_NEQ(x, y))
2198 #define DBL_NEQ(x, y) (fabs(x - y) > DBL_EPSILON)
2199 #define DBL_EQ(x, y) (!DBL_NEQ(x, y))
2200 
2201 /*
2202  helper macro for symmetrical rounding
2203 */
2204 #define ROUND(x, y) (((x > 0.0) ? floor((x * pow(10, y) + 0.5)) : ceil((x * pow(10, y) - 0.5))) / pow(10, y))
2205 
2214  /*---[ 8 byte boundary ]---{ */
2215  uint32_t size; /* required by postgresql: 4 bytes */
2216  uint16_t version; /* format version (this is version 0): 2 bytes */
2217  uint16_t numBands; /* Number of bands: 2 bytes */
2218 
2219  /* }---[ 8 byte boundary ]---{ */
2220  double scaleX; /* pixel width: 8 bytes */
2221 
2222  /* }---[ 8 byte boundary ]---{ */
2223  double scaleY; /* pixel height: 8 bytes */
2224 
2225  /* }---[ 8 byte boundary ]---{ */
2226  double ipX; /* insertion point X: 8 bytes */
2227 
2228  /* }---[ 8 byte boundary ]---{ */
2229  double ipY; /* insertion point Y: 8 bytes */
2230 
2231  /* }---[ 8 byte boundary ]---{ */
2232  double skewX; /* skew about the X axis: 8 bytes */
2233 
2234  /* }---[ 8 byte boundary ]---{ */
2235  double skewY; /* skew about the Y axis: 8 bytes */
2236 
2237  /* }---[ 8 byte boundary ]--- */
2238  int32_t srid; /* Spatial reference id: 4 bytes */
2239  uint16_t width; /* pixel columns: 2 bytes */
2240  uint16_t height; /* pixel rows: 2 bytes */
2241 };
2242 
2243 /* NOTE: the initial part of this structure matches the layout
2244  * of data in the serialized form version 0, starting
2245  * from the numBands element
2246  */
2247 struct rt_raster_t {
2248  uint32_t size;
2249  uint16_t version;
2250 
2251  /* Number of bands, all share the same dimension
2252  * and georeference */
2253  uint16_t numBands;
2254 
2255  /* Georeference (in projection units) */
2256  double scaleX; /* pixel width */
2257  double scaleY; /* pixel height */
2258  double ipX; /* geo x ordinate of the corner of upper-left pixel */
2259  double ipY; /* geo y ordinate of the corner of bottom-right pixel */
2260  double skewX; /* skew about the X axis*/
2261  double skewY; /* skew about the Y axis */
2262 
2263  int32_t srid; /* spatial reference id */
2264  uint16_t width; /* pixel columns - max 65535 */
2265  uint16_t height; /* pixel rows - max 65535 */
2266  rt_band *bands; /* actual bands */
2267 
2268 };
2269 
2271  uint8_t bandNum; /* 0-based */
2272  char* path; /* internally owned */
2273  void *mem; /* loaded external band data, internally owned */
2274 };
2275 
2276 struct rt_band_t {
2278  int32_t offline;
2279  uint16_t width;
2280  uint16_t height;
2281  int32_t hasnodata; /* a flag indicating if this band contains nodata values */
2282  int32_t isnodata; /* a flag indicating if this band is filled only with
2283  nodata values. flag CANNOT be TRUE if hasnodata is FALSE */
2284  double nodataval; /* int will be converted ... */
2285  int8_t ownsdata; /* 0, externally owned. 1, internally owned. only applies to data.mem */
2286 
2287  rt_raster raster; /* reference to parent raster */
2288 
2289  union {
2290  void* mem; /* actual data, externally owned */
2291  struct rt_extband_t offline;
2292  } data;
2293 
2294 };
2295 
2296 struct rt_pixel_t {
2297  int x; /* column */
2298  int y; /* line */
2299 
2300  uint8_t nodata;
2301  double value;
2302 
2304 };
2305 
2306 struct rt_mask_t {
2307  uint16_t dimx;
2308  uint16_t dimy;
2309  double **values;
2310  int **nodata;
2311  int weighted; /* 0 if not weighted values 1 if weighted values */
2312 };
2313 
2314 /* polygon as LWPOLY with associated value */
2317  double val;
2318 };
2319 
2320 /* summary stats of specified band */
2322  double sample;
2323  uint32_t count;
2324 
2325  double min;
2326  double max;
2327  double sum;
2328  double mean;
2329  double stddev;
2330 
2331  double *values;
2332  int sorted; /* flag indicating that values is sorted ascending by value */
2333 };
2334 
2335 /* histogram bin(s) of specified band */
2337  uint32_t count;
2338  double percent;
2339 
2340  double min;
2341  double max;
2342 
2343  int inc_min;
2344  int inc_max;
2345 };
2346 
2347 /* quantile(s) of the specified band */
2349  double quantile;
2350  double value;
2351  uint32_t has_value;
2352 };
2353 
2354 /* listed-list structures for rt_band_get_quantiles_stream */
2356  uint8_t algeq; /* AL-GEQ (1) or AL-GT (0) */
2357  double quantile;
2358  uint64_t tau; /* position in sequence */
2359 
2360  struct quantile_llist_element *head; /* H index 0 */
2361  struct quantile_llist_element *tail; /* H index last */
2362  uint32_t count; /* # of elements in H */
2363 
2364  /* faster access to elements at specific intervals */
2366  uint32_t index_max; /* max # of elements in index */
2367 
2368  uint64_t sum1; /* N1H */
2369  uint64_t sum2; /* N2H */
2370 };
2371 
2373  double value;
2374  uint32_t count;
2375 
2378 };
2379 
2382  uint32_t index;
2383 };
2384 
2385 /* number of times a value occurs */
2387  double value;
2388  uint32_t count;
2389  double percent;
2390 };
2391 
2392 /* reclassification expression */
2395  double min;
2396  double max;
2397  int inc_min; /* include min */
2398  int inc_max; /* include max */
2399  int exc_min; /* exceed min */
2400  int exc_max; /* exceed max */
2401  } src, dst;
2402 };
2403 
2404 /* raster iterator */
2406  rt_raster raster;
2407  uint16_t nband; /* 0-based */
2408  uint8_t nbnodata; /* no band = treat as NODATA */
2409 };
2410 
2411 /* callback argument from raster iterator */
2413  /* # of rasters, Z-axis */
2414  uint16_t rasters;
2415  /* # of rows, Y-axis */
2416  uint32_t rows;
2417  /* # of columns, X-axis */
2418  uint32_t columns;
2419 
2420  /* axis order: Z,X,Y */
2421  /* individual pixel values */
2422  double ***values;
2423  /* 0,1 value of nodata flag */
2424  int ***nodata;
2425 
2426  /* X,Y of pixel from each input raster */
2427  int **src_pixel;
2428 
2429  /* X,Y of pixel from output raster */
2430  int dst_pixel[2];
2431 };
2432 
2433 /* gdal driver information */
2435  int idx;
2436  char *short_name;
2437  char *long_name;
2439 };
2440 
2441 /* raster colormap entry */
2444  double value;
2445  uint8_t color[4]; /* RGBA */
2446 };
2447 
2449  enum {
2453  } method;
2454 
2455  int ncolor;
2456  uint16_t nentry;
2457  rt_colormap_entry entry;
2458 };
2459 
2460 #endif /* LIBRTCORE_H_INCLUDED */
Datum coveredby(PG_FUNCTION_ARGS)
void *(* rt_allocator)(size_t size)
Global functions for memory/logging handlers.
Definition: librtcore.h:241
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:2368
double skewY
Definition: librtcore.h:2261
double MinY
Definition: librtcore.h:179
int32_t srid
Definition: librtcore.h:2263
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:1701
uint16_t nentry
Definition: librtcore.h:2456
double UpperLeftX
Definition: librtcore.h:182
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
int rt_raster_get_num_bands(rt_raster raster)
Definition: rt_raster.c:372
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:242
Datum covers(PG_FUNCTION_ARGS)
struct quantile_llist_element * element
Definition: librtcore.h:2381
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
uint32_t count
Definition: librtcore.h:2323
tuple data
Definition: ovdump.py:103
double quantile
Definition: librtcore.h:2357
void default_rt_info_handler(const char *fmt, va_list ap)
Definition: rt_context.c:93
struct quantile_llist_element * prev
Definition: librtcore.h:2376
void * mem
Definition: librtcore.h:2273
void(* rt_message_handler)(const char *string, va_list ap) __attribute__((format(printf
Definition: librtcore.h:244
uint16_t numBands
Definition: librtcore.h:2253
struct rt_pixel_t * rt_pixel
Definition: librtcore.h:159
rt_errorstate rt_pixel_set_to_array(rt_pixel npixel, int 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
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
struct rt_reclassexpr_t::rt_reclassrange dst
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's geotransform using 6-element array.
Definition: rt_raster.c:727
struct rt_raster_t * rt_raster
Types definitions.
Definition: librtcore.h:157
double MaxY
Definition: librtcore.h:180
rt_raster raster
Definition: librtcore.h:2287
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:2388
double MaxX
Definition: librtcore.h:178
rt_pixtype pixtype
Definition: librtcore.h:2277
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:166
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
double quantile
Definition: librtcore.h:2349
tuple gt
Definition: window.py:77
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:3444
tuple fmt
Definition: pixval.py:92
char * short_name
Definition: librtcore.h:2436
rt_extenttype
Definition: librtcore.h:212
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:1809
Datum contains(PG_FUNCTION_ARGS)
uint8_t color[4]
Definition: librtcore.h:2445
LWGEOM * geom
Definition: librtcore.h:2303
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
Definition: rt_band.c:228
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
tuple band
Definition: ovdump.py:57
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:2492
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
tuple rast
Definition: rtpixdump.py:61
void * default_rt_reallocator(void *mem, size_t size)
Definition: rt_context.c:54
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:2280
double value
Definition: librtcore.h:2301
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:1519
rt_errorstate
Enum definitions.
Definition: librtcore.h:191
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:151
double ipY
Definition: librtcore.h:2259
tuple raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
Definition: rtrowdump.py:121
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:600
int ** nodata
Definition: librtcore.h:2310
rt_pixtype
Definition: librtcore.h:197
Datum overlaps(PG_FUNCTION_ARGS)
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:242
struct rt_reclassexpr_t * rt_reclassexpr
Definition: librtcore.h:167
struct rt_quantile_t * rt_quantile
Definition: librtcore.h:164
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:2248
int weighted
Definition: librtcore.h:2311
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:2265
Datum touches(PG_FUNCTION_ARGS)
uint16_t dimy
Definition: librtcore.h:2308
rt_quantile rt_band_get_quantiles_stream(rt_band band, int exclude_nodata_value, double sample, uint64_t cov_count, struct quantile_llist **qlls, uint32_t *qlls_count, double *quantiles, int quantiles_count, uint32_t *rtn_count)
Compute the default set of or requested quantiles for a coverage.
double value
Definition: librtcore.h:2350
rt_geos_spatial_test
GEOS spatial relationship tests available.
Definition: librtcore.h:229
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1597
rt_errorstate rt_raster_get_convex_hull(rt_raster raster, LWGEOM **hull)
Get raster's convex hull.
Definition: rt_geometry.c:803
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's external path (only valid when rt_band_is_offline returns non-zero).
Definition: rt_band.c:265
struct quantile_llist_element * next
Definition: librtcore.h:2377
LWPOLY * geom
Definition: librtcore.h:2316
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:534
struct rt_reclassexpr_t::rt_reclassrange src
double ** values
Definition: librtcore.h:2309
double val
Definition: librtcore.h:2317
struct quantile_llist_element * tail
Definition: librtcore.h:2361
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:2338
uint16_t version
Definition: librtcore.h:2249
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:2418
void rtwarn(const char *fmt,...)
Definition: rt_context.c:224
uint16_t rasters
Definition: librtcore.h:2414
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:526
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:1088
tuple nband
Definition: pixval.py:52
enum rt_colormap_t::@7 method
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:2358
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:1004
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:2264
union rt_band_t::@6 data
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's data.
Definition: rt_band.c:331
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's clamped NODATA value.
Definition: rt_band.c:1665
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:1619
int8_t ownsdata
Definition: librtcore.h:2285
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:541
struct rt_colormap_entry_t * rt_colormap_entry
Definition: librtcore.h:172
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
tuple ds
Definition: pixval.py:66
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:507
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:516
double skewX
Definition: librtcore.h:2260
rt_colormap_entry entry
Definition: librtcore.h:2457
double * values
Definition: librtcore.h:2331
rt_errorstate rt_raster_get_envelope_geom(rt_raster raster, LWGEOM **env)
Get raster's envelope as a geometry.
Definition: rt_geometry.c:670
struct rt_band_t * rt_band
Definition: librtcore.h:158
double nodataval
Definition: librtcore.h:2284
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:302
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's SRID.
Definition: rt_raster.c:363
uint32_t index_max
Definition: librtcore.h:2366
int32_t rt_raster_get_srid(rt_raster raster)
Get raster'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:2406
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
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:2300
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:2279
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition: rt_raster.c:181
tuple x
Definition: pixval.py:53
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:58
struct rt_histogram_t * rt_histogram
Definition: librtcore.h:163
Datum distance(PG_FUNCTION_ARGS)
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:278
uint16_t nband
Definition: librtcore.h:2407
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:548
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:161
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:160
struct rt_valuecount_t * rt_valuecount
Definition: librtcore.h:165
void default_rt_error_handler(const char *fmt, va_list ap)
Definition: rt_context.c:67
void(* rt_deallocator)(void *mem)
Definition: librtcore.h:243
struct rt_bandstats_t * rt_bandstats
Definition: librtcore.h:162
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:2278
double *** values
Definition: librtcore.h:2422
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:562
void rtdealloc(void *mem)
Definition: rt_context.c:186
Definition: librtcore.h:2442
int32_t isnodata
Definition: librtcore.h:2282
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:2408
double MinX
Definition: librtcore.h:177
rt_band rt_band_duplicate(rt_band band)
Create a new band duplicated from source band.
Definition: rt_band.c:186
Struct definitions.
Definition: librtcore.h:2213
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition: rt_raster.c:1705
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:1612
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:2266
char * create_options
Definition: librtcore.h:2438
struct quantile_llist_index * index
Definition: librtcore.h:2365
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_band.c:498
uint8_t bandNum
Definition: librtcore.h:2271
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:720
void * mem
Definition: librtcore.h:2290
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:2437
rt_histogram rt_band_get_histogram(rt_bandstats stats, int bin_count, double *bin_widths, int bin_widths_count, int right, double min, double max, uint32_t *rtn_count)
Count the distribution of data.
uint32_t has_value
Definition: librtcore.h:2351
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:2356
int32_t hasnodata
Definition: librtcore.h:2281
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:2362
void rt_util_from_ogr_envelope(OGREnvelope env, rt_envelope *ext)
Definition: rt_util.c:406
double ipX
Definition: librtcore.h:2258
struct rt_iterator_arg_t * rt_iterator_arg
Definition: librtcore.h:170
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:581
struct rt_colormap_t * rt_colormap
Definition: librtcore.h:173
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's value.
Definition: rt_band.c:841
int rt_util_gdal_configured(void)
Definition: rt_util.c:313
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:2165
struct quantile_llist_element * head
Definition: librtcore.h:2360
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:2256
struct rt_iterator_t * rt_iterator
Definition: librtcore.h:169
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:2272
int isnodata
Definition: librtcore.h:2443
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_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:183
uint16_t dimx
Definition: librtcore.h:2307
int rt_band_get_nearest_pixel(rt_band band, int x, int y, uint16_t distancex, uint16_t distancey, int exclude_nodata_value, rt_pixel *npixels)
Get nearest pixel(s) with value (not NODATA) to specified pixel.
Definition: rt_band.c:1241
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'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:2444
tuple y
Definition: pixval.py:54
uint64_t sum2
Definition: librtcore.h:2369
void(*) voi rt_install_default_allocators)(void)
Apply the default memory management (malloc() and free()) and error handlers.
double scaleY
Definition: librtcore.h:2257
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:2337
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:119
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.
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.