PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
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#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) /* seems to work like Linux... */
72#if !defined(LINUX)
73#define LINUX
74#endif
75#if !defined(UNIX)
76#define UNIX /* make sure this is defined */
77#endif
78#endif
79
80#if defined(__GNU__) /* GNU/Hurd is also like Linux */
81#if !defined(LINUX)
82#define LINUX
83#endif
84#if !defined(UNIX)
85#define UNIX /* make sure this is defined */
86#endif
87#endif
88
89#if defined(__MSDOS__)
90#if !defined(MSDOS)
91#define MSDOS /* make sure this is defined */
92#endif
93#endif
94
95#if defined(__WIN32__) || defined(__NT__) || defined(_WIN32)
96#if !defined(WIN32)
97#define WIN32
98#endif
99#if defined(__BORLANDC__) && defined(MSDOS) /* Borland always defines MSDOS */
100#undef MSDOS
101#endif
102#endif
103
104#if defined(__APPLE__)
105#if !defined(UNIX)
106#define UNIX
107#endif
108#endif
109
110#if defined(sun) || defined(__sun)
111#if !defined(UNIX)
112#define UNIX
113#endif
114#endif
115
116#include <stdio.h> /* for printf, sprintf */
117#include <stdlib.h> /* For size_t, srand and rand */
118#include <stdint.h> /* For C99 int types */
119#include <string.h> /* for memcpy, strlen, etc */
120#include <float.h> /* for FLT_EPSILON, DBL_EPSILON and float type limits */
121#include <limits.h> /* for integer type limits */
122
123#include "liblwgeom_internal.h"
124
125#include "gdal.h"
126#include "gdalgrid.h" /* for ParseAlgorithmAndOptions */
127#include "gdal_frmts.h"
128#include "gdalwarper.h"
129#include "cpl_vsi.h"
130#include "cpl_conv.h"
131#include "cpl_string.h"
132#include "cpl_minixml.h"
133#include "ogr_api.h"
134#include "ogr_srs_api.h"
135
136#include "postgis_config.h"
137#include "raster_config.h"
138
139#ifndef __GNUC__
140# define __attribute__ (x)
141#endif
142
146typedef struct rt_raster_t* rt_raster;
147typedef struct rt_band_t* rt_band;
148typedef struct rt_pixel_t* rt_pixel;
149typedef struct rt_mask_t* rt_mask;
150typedef struct rt_geomval_t* rt_geomval;
158
161
164
165/* envelope information */
166typedef struct {
167 double MinX;
168 double MaxX;
169 double MinY;
170 double MaxY;
171
175
180/* function return error states */
181typedef enum {
182 ES_NONE = 0, /* no error */
183 ES_ERROR = 1 /* generic error */
185
186/* Pixel types */
187typedef enum
188{
189 PT_1BB = 0, /* 1-bit boolean */
190 PT_2BUI = 1, /* 2-bit unsigned integer */
191 PT_4BUI = 2, /* 4-bit unsigned integer */
192 PT_8BSI = 3, /* 8-bit signed integer */
193 PT_8BUI = 4, /* 8-bit unsigned integer */
194 PT_16BSI = 5, /* 16-bit signed integer */
195 PT_16BUI = 6, /* 16-bit unsigned integer */
196 PT_32BSI = 7, /* 32-bit signed integer */
197 PT_32BUI = 8, /* 32-bit unsigned integer */
198 PT_16BF = 9, /* 16-bit float */
199 PT_32BF = 10, /* 32-bit float */
200 PT_64BF = 11, /* 64-bit float */
201 PT_END = 13
203
212
229
233typedef char* (*rt_options)(const char* varname);
234typedef void* (*rt_allocator)(size_t size);
235typedef void* (*rt_reallocator)(void *mem, size_t size);
236typedef void (*rt_deallocator)(void *mem);
237typedef void (*rt_message_handler)(const char* string, va_list ap)
238 __attribute__ (( format(printf,1,0) ));
239
240/*******************************************************************
241 * Functions that may be used by the raster core function's caller
242 * (for example: rt_pg functions, test functions, future loader/exporter)
243 *******************************************************************/
247extern void rt_install_default_allocators(void);
248
253extern void* rtalloc(size_t size);
254extern void* rtrealloc(void* mem, size_t size);
255extern void rtdealloc(void* mem);
256
257/******************************************************************/
258
259
263void rterror(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
264void rtinfo(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
265void rtwarn(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
266
270char* rtoptions(const char* varname);
271char* rtstrdup(const char *str);
272
276void * default_rt_allocator(size_t size);
277void * default_rt_reallocator(void * mem, size_t size);
278void default_rt_deallocator(void * mem);
279void default_rt_error_handler(const char * fmt, va_list ap) __attribute__ ((format (printf, 1, 0)));
280void default_rt_warning_handler(const char * fmt, va_list ap) __attribute__ ((format (printf, 1, 0)));
281void default_rt_info_handler(const char * fmt, va_list ap) __attribute__ ((format (printf, 1, 0)));
282char * default_rt_options(const char* varname);
283
284/* Debugging macros */
285#if POSTGIS_DEBUG_LEVEL > 0
286
287/* Display a simple message at NOTICE level */
288#define RASTER_DEBUG(level, msg) \
289 do { \
290 if (POSTGIS_DEBUG_LEVEL >= level) \
291 rtinfo("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__); \
292 } while (0);
293
294/* Display a formatted message at NOTICE level (like printf, with variadic arguments) */
295#define RASTER_DEBUGF(level, msg, ...) \
296 do { \
297 if (POSTGIS_DEBUG_LEVEL >= level) \
298 rtinfo("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__, __VA_ARGS__); \
299 } while (0);
300
301#else
302
303/* Empty prototype that can be optimised away by the compiler for non-debug builds */
304#define RASTER_DEBUG(level, msg) \
305 ((void) 0)
306
307/* Empty prototype that can be optimised away by the compiler for non-debug builds */
308#define RASTER_DEBUGF(level, msg, ...) \
309 ((void) 0)
310
311#endif
312
313/*- memory context -------------------------------------------------------*/
314
315void rt_set_handlers(rt_allocator allocator, rt_reallocator reallocator,
316 rt_deallocator deallocator, rt_message_handler error_handler,
317 rt_message_handler info_handler, rt_message_handler warning_handler);
318
319void rt_set_handlers_options(rt_allocator allocator, rt_reallocator reallocator,
320 rt_deallocator deallocator, rt_message_handler error_handler,
321 rt_message_handler info_handler, rt_message_handler warning_handler,
322 rt_options options_handler);
323
324
325
326/*- rt_pixtype --------------------------------------------------------*/
327
335int rt_pixtype_size(rt_pixtype pixtype);
336
347
348/* Return human-readable name of pixel type */
349const char* rt_pixtype_name(rt_pixtype pixtype);
350
351/* Return pixel type index from human-readable name */
352rt_pixtype rt_pixtype_index_from_name(const char* pixname);
353
362
374 rt_pixtype pixtype,
375 double val, double refval,
376 int *isequal
377);
378
379/*- rt_pixel ----------------------------------------------------------*/
380
381/*
382 * Convert an array of rt_pixel objects to two 2D arrays of value and NODATA.
383 * The dimensions of the returned 2D array are [Y][X], going by row Y and
384 * then column X.
385 *
386 * @param npixel : array of rt_pixel objects
387 * @param count : number of elements in npixel
388 * @param mask : mask to be respected when returning array
389 * @param x : the column of the center pixel (0-based)
390 * @param y : the line of the center pixel (0-based)
391 * @param distancex : the number of pixels around the specified pixel
392 * along the X axis
393 * @param distancey : the number of pixels around the specified pixel
394 * along the Y axis
395 * @param value : pointer to pointer for 2D value array
396 * @param nodata : pointer to pointer for 2D NODATA array
397 * @param dimx : size of value and nodata along the X axis
398 * @param dimy : size of value and nodata along the Y axis
399 *
400 * @return ES_NONE on success, ES_ERROR on error
401 */
403 rt_pixel npixel,uint32_t count,
404 rt_mask mask,
405 int x, int y,
406 uint16_t distancex, uint16_t distancey,
407 double ***value,
408 int ***nodata,
409 int *dimx, int *dimy
410);
411
412/*- rt_band ----------------------------------------------------------*/
413
435 uint16_t width, uint16_t height,
436 rt_pixtype pixtype,
437 uint32_t hasnodata, double nodataval,
438 uint8_t* data
439);
440
449 rt_band band,
450 double initval
451);
452
473 uint16_t width, uint16_t height,
474 rt_pixtype pixtype,
475 uint32_t hasnodata, double nodataval,
476 uint8_t bandNum, const char* path
477);
478
499 uint16_t width,
500 uint16_t height,
501 int hasnodata,
502 double nodataval,
503 uint8_t bandNum,
504 const char* path,
505 int force
506);
507
519
530
539const char* rt_band_get_ext_path(rt_band band);
540
549uint64_t rt_band_get_file_size(rt_band band);
550
560
570rt_errorstate rt_band_get_ext_band_num(rt_band band, uint8_t *bandnum);
571
580
588uint16_t rt_band_get_width(rt_band band);
589
597uint16_t rt_band_get_height(rt_band band);
598
609
610/* set ownsdata flag */
611void rt_band_set_ownsdata_flag(rt_band band, int flag);
612
620void* rt_band_get_data(rt_band band);
621
632
638void rt_band_destroy(rt_band band);
639
648
654void rt_band_set_hasnodata_flag(rt_band band, int flag);
655
665
674
685rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted);
686
695rt_errorstate rt_band_get_nodata(rt_band band, double *nodata);
696
717 rt_band band,
718 int x, int y,
719 void *vals, uint32_t len
720);
721
734 rt_band band,
735 int x, int y,
736 double val,
737 int *converted
738);
739
761 rt_band band,
762 int x, int y,
763 uint16_t len,
764 void **vals, uint16_t *nvals
765);
766
780 rt_band band,
781 int x, int y,
782 double *value,
783 int *nodata
784);
785
804 rt_band band,
805 int x, int y,
806 uint16_t distancex, uint16_t distancey,
807 int exclude_nodata_value,
808 rt_pixel *npixels
809);
810
823 rt_band band, int exclude_nodata_value,
824 double *searchset, int searchcount,
825 rt_pixel *pixels
826);
827
835double rt_band_get_min_value(rt_band band);
836
845
856int rt_band_clamped_value_is_nodata(rt_band band, double val);
857
872 rt_band band,
873 double val,
874 double *newval, int *corrected
875);
876
891 rt_band band,
892 int exclude_nodata_value, double sample, int inc_vals,
893 uint64_t *cK, double *cM, double *cQ
894);
895
915 rt_bandstats stats,
916 uint32_t bin_count, double *bin_widths, uint32_t bin_widths_count,
917 int right, double min, double max,
918 uint32_t *rtn_count
919);
920
933 double *quantiles, int quantiles_count, uint32_t *rtn_count);
934
935struct quantile_llist;
937 struct quantile_llist **list,
938 uint32_t list_count
939);
940
969 rt_band band,
970 int exclude_nodata_value, double sample,
971 uint64_t cov_count,
972 struct quantile_llist **qlls, uint32_t *qlls_count,
973 double *quantiles, uint32_t quantiles_count,
974 uint32_t *rtn_count
975);
976
992 rt_band band, int exclude_nodata_value,
993 double *search_values, uint32_t search_values_count, double roundto,
994 uint32_t *rtn_total, uint32_t *rtn_count
995);
996
1010 rt_band srcband, rt_pixtype pixtype,
1011 uint32_t hasnodata, double nodataval,
1012 rt_reclassexpr *exprset, int exprcount
1013);
1014
1025 rt_band srcband, rt_reclassmap map,
1026 uint32_t hasnodata, double nodataval
1027);
1028
1029/*- rt_raster --------------------------------------------------------*/
1030
1042rt_raster rt_raster_new(uint32_t width, uint32_t height);
1043
1054rt_raster rt_raster_from_wkb(const uint8_t* wkb, uint32_t wkbsize);
1055
1066rt_raster rt_raster_from_hexwkb(const char* hexwkb, uint32_t hexwkbsize);
1067
1077uint8_t *rt_raster_to_wkb(rt_raster raster, int outasin, uint32_t *wkbsize);
1078
1089char *rt_raster_to_hexwkb(rt_raster raster, int outasin, uint32_t *hexwkbsize);
1090
1101void rt_raster_destroy(rt_raster raster);
1102
1103/* Get number of bands */
1104uint16_t rt_raster_get_num_bands(rt_raster raster);
1105
1114rt_band rt_raster_get_band(rt_raster raster, int bandNum);
1115
1116/* Get number of rows */
1117uint16_t rt_raster_get_width(rt_raster raster);
1118
1119/* Get number of columns */
1120uint16_t rt_raster_get_height(rt_raster raster);
1121
1132int rt_raster_add_band(rt_raster raster, rt_band band, int index);
1133
1147 rt_raster raster,
1148 rt_pixtype pixtype,
1149 double initialvalue,
1150 uint32_t hasnodata, double nodatavalue,
1151 int index
1152);
1153
1163void rt_raster_set_scale(rt_raster raster,
1164 double scaleX, double scaleY);
1165
1173double rt_raster_get_x_scale(rt_raster raster);
1174
1182double rt_raster_get_y_scale(rt_raster raster);
1183
1194 double x, double y);
1195
1204double rt_raster_get_x_offset(rt_raster raster);
1205
1214double rt_raster_get_y_offset(rt_raster raster);
1215
1223void rt_raster_set_skews(rt_raster raster,
1224 double skewX, double skewY);
1225
1232double rt_raster_get_x_skew(rt_raster raster);
1233
1240double rt_raster_get_y_skew(rt_raster raster);
1241
1255 double *i_mag, double *j_mag, double *theta_i, double *theta_ij) ;
1256
1273 double i_mag, double j_mag, double theta_i, double theta_ij) ;
1274
1275
1291void rt_raster_calc_phys_params(double xscale,
1292 double xskew, double yskew, double yscale,
1293 double *i_mag, double *j_mag, double *theta_i, double *theta_ij) ;
1294
1295
1312int rt_raster_calc_gt_coeff(double i_mag,
1313 double j_mag, double theta_i, double theta_ij,
1314 double *xscale, double *xskew, double *yskew, double *yscale) ;
1315
1322void rt_raster_set_srid(rt_raster raster, int32_t srid);
1323
1330int32_t rt_raster_get_srid(rt_raster raster);
1331
1342 rt_raster raster,
1343 double *gt, double *igt
1344);
1345
1353 double *gt);
1354
1363 double *gt);
1364
1378 rt_raster raster,
1379 double xr, double yr,
1380 double* xw, double* yw,
1381 double *gt
1382);
1383
1397 rt_raster raster,
1398 double xw, double yw,
1399 double *xr, double *yr,
1400 double *igt
1401);
1402
1403
1417 rt_raster raster,
1418 double xw, double yw,
1419 double *xr, double *yr,
1420 double *igt
1421);
1422
1423
1437
1449
1459
1473 rt_band band,
1474 double xr, double yr,
1475 double *r_value, int *r_nodata
1476);
1477
1482
1497 rt_band band,
1498 double xr, double yr,
1499 rt_resample_type resample,
1500 double *r_value, int *r_nodata
1501);
1502
1518 rt_raster raster,
1519 uint32_t bandnum,
1520 char dim, /* 'Z' or 'M' */
1521 rt_resample_type resample,
1522 const LWGEOM *lwgeom_in,
1523 LWGEOM **lwgeom_out
1524);
1525
1540 rt_raster raster, int nband,
1541 LWGEOM **perimeter
1542);
1543
1544/*
1545 * Compute skewed extent that covers unskewed extent.
1546 *
1547 * @param envelope : unskewed extent of type rt_envelope
1548 * @param skew : pointer to 2-element array (x, y) of skew
1549 * @param scale : pointer to 2-element array (x, y) of scale
1550 * @param tolerance : value between 0 and 1 where the smaller the tolerance
1551 * results in an extent approaching the "minimum" skewed extent.
1552 * If value <= 0, tolerance = 0.1. If value > 1, tolerance = 1.
1553 *
1554 * @return skewed raster who's extent covers unskewed extent, NULL on error
1555 */
1558 rt_envelope extent,
1559 double *skew,
1560 double *scale,
1561 double tolerance
1562);
1563
1578LWPOLY* rt_raster_pixel_as_polygon(rt_raster raster, int x, int y);
1579
1590
1604rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface);
1605
1625 rt_raster raster, int nband,
1626 int exclude_nodata_value,
1627 int * pnElements
1628);
1629
1636void* rt_raster_serialize(rt_raster raster);
1637
1646rt_raster rt_raster_deserialize(void* serialized, int header_only);
1647
1655int rt_raster_is_empty(rt_raster raster);
1656
1665int rt_raster_has_band(rt_raster raster, int nband);
1666
1682 rt_raster torast, rt_raster fromrast,
1683 int fromindex, int toindex
1684);
1685
1697rt_raster rt_raster_from_band(rt_raster raster, uint32_t *bandNums,
1698 int count);
1699
1710 int index);
1711
1720rt_raster rt_raster_clone(rt_raster raster, uint8_t deep);
1721
1734uint8_t *rt_raster_to_gdal(rt_raster raster, const char *srs,
1735 char *format, char **options, uint64_t *gdalsize);
1736
1746rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc);
1747
1764GDALDatasetH rt_raster_to_gdal_mem(
1765 rt_raster raster,
1766 const char *srs,
1767 uint32_t *bandNums,
1768 int *excludeNodataValues,
1769 int count,
1770 GDALDriverH *rtn_drv, int *destroy_rtn_drv
1771);
1772
1773/*
1774* Generate contour vectors from a raster input
1775*/
1781
1792 /* input parameters */
1793 rt_raster src_raster,
1794 int src_band,
1795 int src_srid,
1796 const char* src_srs,
1797 double contour_interval,
1798 double contour_base,
1799 int fixed_level_count,
1800 double *fixed_levels,
1801 int polygonize,
1802 /* output parameters */
1803 size_t *ncontours,
1804 struct rt_contour_t **contours
1805 );
1806
1814rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds);
1815
1847 rt_raster raster,
1848 const char *src_srs, const char *dst_srs,
1849 double *scale_x, double *scale_y,
1850 int *width, int *height,
1851 double *ul_xw, double *ul_yw,
1852 double *grid_xw, double *grid_yw,
1853 double *skew_x, double *skew_y,
1854 GDALResampleAlg resample_alg, double max_err);
1855
1882rt_raster rt_raster_gdal_rasterize(const unsigned char *wkb,
1883 uint32_t wkb_len, const char *srs,
1884 uint32_t num_bands, rt_pixtype *pixtype,
1885 double *init, double *value,
1886 double *nodata, uint8_t *hasnodata,
1887 int *width, int *height,
1888 double *scale_x, double *scale_y,
1889 double *ul_xw, double *ul_yw,
1890 double *grid_xw, double *grid_yw,
1891 double *skew_x, double *skew_y,
1892 char **options
1893);
1894
1912 rt_raster rast1, int nband1,
1913 rt_raster rast2, int nband2,
1914 int *intersects
1915);
1916
1934 rt_raster rast1, int nband1,
1935 rt_raster rast2, int nband2,
1936 int *overlaps
1937);
1938
1956 rt_raster rast1, int nband1,
1957 rt_raster rast2, int nband2,
1958 int *contains
1959);
1960
1978 rt_raster rast1, int nband1,
1979 rt_raster rast2, int nband2,
1980 int *contains
1981);
1982
2000 rt_raster rast1, int nband1,
2001 rt_raster rast2, int nband2,
2002 int *touches
2003);
2004
2022 rt_raster rast1, int nband1,
2023 rt_raster rast2, int nband2,
2024 int *covers
2025);
2026
2044 rt_raster rast1, int nband1,
2045 rt_raster rast2, int nband2,
2046 int *coveredby
2047);
2048
2068 rt_raster rast1, int nband1,
2069 rt_raster rast2, int nband2,
2070 double distance,
2071 int *dwithin
2072);
2073
2093 rt_raster rast1, int nband1,
2094 rt_raster rast2, int nband2,
2095 double distance,
2096 int *dfwithin
2097);
2098
2099/*
2100 * Return ES_ERROR if error occurred in function.
2101 * Parameter aligned returns non-zero if two rasters are aligned
2102 *
2103 * @param rast1 : the first raster for alignment test
2104 * @param rast2 : the second raster for alignment test
2105 * @param *aligned : non-zero value if the two rasters are aligned
2106 * @param *reason : reason why rasters are not aligned
2107 *
2108 * @return ES_NONE if success, ES_ERROR if error
2109 */
2111 rt_raster rast1,
2112 rt_raster rast2,
2113 int *aligned, char **reason
2114);
2115
2116/*
2117 * Return raster of computed extent specified extenttype applied
2118 * on two input rasters. The raster returned should be freed by
2119 * the caller
2120 *
2121 * @param rast1 : the first raster
2122 * @param rast2 : the second raster
2123 * @param extenttype : type of extent for the output raster
2124 * @param *rtnraster : raster of computed extent
2125 * @param *offset : 4-element array indicating the X,Y offsets
2126 * for each raster. 0,1 for rast1 X,Y. 2,3 for rast2 X,Y.
2127 *
2128 * @return ES_NONE if success, ES_ERROR if error
2129 */
2132 rt_raster rast1, rt_raster rast2,
2133 rt_extenttype extenttype,
2134 rt_raster *rtnraster, double *offset
2135);
2136
2175 rt_iterator itrset, uint16_t itrcount,
2176 rt_extenttype extenttype, rt_raster customextent,
2177 rt_pixtype pixtype,
2178 uint8_t hasnodata, double nodataval,
2179 uint16_t distancex, uint16_t distancey,
2180 rt_mask mask,
2181 void *userarg,
2182 int (*callback)(
2183 rt_iterator_arg arg,
2184 void *userarg,
2185 double *value,
2186 int *nodata
2187 ),
2188 rt_raster *rtnraster
2189);
2190
2203 rt_raster raster, int nband,
2204 rt_colormap colormap
2205);
2206
2207#if POSTGIS_GEOS_VERSION >= 31400
2220rt_raster rt_raster_intersection_fractions(
2221 const rt_raster rast_in,
2222 const LWGEOM *geom
2223);
2224#endif
2225
2226/*- utilities -------------------------------------------------------*/
2227
2228/*
2229 * rt_core memory functions
2230 */
2231extern void *rtalloc(size_t size);
2232extern void *rtrealloc(void *mem, size_t size);
2233extern void rtdealloc(void *mem);
2234
2235/*
2236 * GDAL driver flags
2237 */
2238
2239#define GDAL_ENABLE_ALL "ENABLE_ALL"
2240#define GDAL_DISABLE_ALL "DISABLE_ALL"
2241#define GDAL_VSICURL "VSICURL"
2242
2243/*
2244 * Set of functions to clamp double to int of different size
2245 */
2246
2247#if !defined(POSTGIS_RASTER_WARN_ON_TRUNCATION)
2248#define POSTGIS_RASTER_WARN_ON_TRUNCATION 0
2249#endif
2250
2251#define POSTGIS_RT_1BBMAX 1
2252#define POSTGIS_RT_2BUIMAX 3
2253#define POSTGIS_RT_4BUIMAX 15
2254#define POSTGIS_RT_16F_MAX 65504.0F
2255
2256uint8_t
2257rt_util_clamp_to_1BB(double value);
2258
2259uint8_t
2260rt_util_clamp_to_2BUI(double value);
2261
2262uint8_t
2263rt_util_clamp_to_4BUI(double value);
2264
2265int8_t
2266rt_util_clamp_to_8BSI(double value);
2267
2268uint8_t
2269rt_util_clamp_to_8BUI(double value);
2270
2271int16_t
2272rt_util_clamp_to_16BSI(double value);
2273
2274uint16_t
2275rt_util_clamp_to_16BUI(double value);
2276
2277int32_t
2278rt_util_clamp_to_32BSI(double value);
2279
2280uint32_t
2281rt_util_clamp_to_32BUI(double value);
2282
2283float
2284rt_util_clamp_to_32F(double value);
2285
2286float rt_util_clamp_to_16F(double value);
2287
2288uint16_t rt_util_float_to_float16(float value);
2289
2290float rt_util_float16_to_float(uint16_t value);
2291
2292int
2294 double initialvalue,
2295 int32_t checkvalint, uint32_t checkvaluint,
2296 float checkvalfloat, double checkvaldouble,
2297 rt_pixtype pixtype
2298);
2299
2307GDALResampleAlg
2308rt_util_gdal_resample_alg(const char *algname);
2309
2317GDALDataType
2319
2328rt_util_gdal_datatype_to_pixtype(GDALDataType gdt);
2329
2330/*
2331 get GDAL runtime version information
2332*/
2333const char*
2334rt_util_gdal_version(const char *request);
2335
2336/*
2337 computed extent type from c string
2338*/
2340rt_util_extent_type(const char *name);
2341
2342/*
2343 convert the spatial reference string from a GDAL recognized format to either WKT or Proj4
2344*/
2345char*
2346rt_util_gdal_convert_sr(const char *srs, int proj4);
2347
2348/*
2349 is the spatial reference string supported by GDAL
2350*/
2351int
2352rt_util_gdal_supported_sr(const char *srs);
2353
2365rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode);
2366
2367/*
2368 is GDAL configured correctly?
2369*/
2370int
2372
2373/*
2374 register all GDAL drivers
2375*/
2376int
2377rt_util_gdal_register_all(int force_register_all);
2378
2379/*
2380 is the driver registered?
2381*/
2382int
2383rt_util_gdal_driver_registered(const char *drv);
2384
2385int
2386rt_util_gdal_progress_func(double dfComplete, const char *pszMessage, void *pProgressArg);
2387
2388/*
2389 wrapper for GDALOpen and GDALOpenShared
2390*/
2391GDALDatasetH
2392rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared);
2393
2394void
2396 OGREnvelope env,
2397 rt_envelope *ext
2398);
2399
2400void
2402 rt_envelope ext,
2403 OGREnvelope *env
2404);
2405
2406LWPOLY *
2408 rt_envelope ext
2409);
2410
2411int
2413 double *gt1,
2414 double *gt2
2415);
2416
2417/* coordinates in RGB and HSV are floating point values between 0 and 1 */
2420 double rgb[3],
2421 double hsv[3]
2422);
2423
2424/* coordinates in RGB and HSV are floating point values between 0 and 1 */
2427 double hsv[3],
2428 double rgb[3]
2429);
2430
2431/*
2432 helper macros for consistent floating point equality checks.
2433 NaN equals NaN for NODATA support.
2434*/
2435#define FLT_NEQ(x, y) ((x != y) && !(isnan(x) && isnan(y)) && (fabs(x - y) > FLT_EPSILON))
2436#define FLT_EQ(x, y) ((x == y) || (isnan(x) && isnan(y)) || (fabs(x - y) <= FLT_EPSILON))
2437#define DBL_NEQ(x, y) ((x != y) && !(isnan(x) && isnan(y)) && (fabs(x - y) > DBL_EPSILON))
2438#define DBL_EQ(x, y) ((x == y) || (isnan(x) && isnan(y)) || (fabs(x - y) <= DBL_EPSILON))
2439
2440/*
2441 helper macro for symmetrical rounding
2442*/
2443#define ROUND(x, y) (((x > 0.0) ? floor((x * pow(10, y) + 0.5)) : ceil((x * pow(10, y) - 0.5))) / pow(10, y))
2444
2453 /*---[ 8 byte boundary ]---{ */
2454 uint32_t size; /* required by postgresql: 4 bytes */
2455 uint16_t version; /* format version (this is version 0): 2 bytes */
2456 uint16_t numBands; /* Number of bands: 2 bytes */
2457
2458 /* }---[ 8 byte boundary ]---{ */
2459 double scaleX; /* pixel width: 8 bytes */
2460
2461 /* }---[ 8 byte boundary ]---{ */
2462 double scaleY; /* pixel height: 8 bytes */
2463
2464 /* }---[ 8 byte boundary ]---{ */
2465 double ipX; /* insertion point X: 8 bytes */
2466
2467 /* }---[ 8 byte boundary ]---{ */
2468 double ipY; /* insertion point Y: 8 bytes */
2469
2470 /* }---[ 8 byte boundary ]---{ */
2471 double skewX; /* skew about the X axis: 8 bytes */
2472
2473 /* }---[ 8 byte boundary ]---{ */
2474 double skewY; /* skew about the Y axis: 8 bytes */
2475
2476 /* }---[ 8 byte boundary ]--- */
2477 int32_t srid; /* Spatial reference id: 4 bytes */
2478 uint16_t width; /* pixel columns: 2 bytes */
2479 uint16_t height; /* pixel rows: 2 bytes */
2480};
2481
2482/* NOTE: the initial part of this structure matches the layout
2483 * of data in the serialized form version 0, starting
2484 * from the numBands element
2485 */
2487 uint32_t size;
2488 uint16_t version;
2489
2490 /* Number of bands, all share the same dimension
2491 * and georeference */
2492 uint16_t numBands;
2493
2494 /* Georeference (in projection units) */
2495 double scaleX; /* pixel width */
2496 double scaleY; /* pixel height */
2497 double ipX; /* geo x ordinate of the corner of upper-left pixel */
2498 double ipY; /* geo y ordinate of the corner of bottom-right pixel */
2499 double skewX; /* skew about the X axis*/
2500 double skewY; /* skew about the Y axis */
2501
2502 int32_t srid; /* spatial reference id */
2503 uint16_t width; /* pixel columns - max 65535 */
2504 uint16_t height; /* pixel rows - max 65535 */
2505 rt_band *bands; /* actual bands */
2506
2507};
2508
2510 uint8_t bandNum; /* 0-based */
2511 char* path; /* internally owned */
2512 void *mem; /* loaded external band data, internally owned */
2513};
2514
2517 int32_t offline;
2518 uint16_t width;
2519 uint16_t height;
2520 int32_t hasnodata; /* a flag indicating if this band contains nodata values */
2521 int32_t isnodata; /* a flag indicating if this band is filled only with
2522 nodata values. flag CANNOT be TRUE if hasnodata is FALSE */
2523 double nodataval; /* int will be converted ... */
2524 int8_t ownsdata; /* 0, externally owned. 1, internally owned. only applies to data.mem */
2525
2526 rt_raster raster; /* reference to parent raster */
2527
2528 union {
2529 void* mem; /* actual data, externally owned */
2532
2533};
2534
2536 int x; /* column */
2537 int y; /* line */
2538
2539 uint8_t nodata;
2540 double value;
2541
2543};
2544
2546 uint16_t dimx;
2547 uint16_t dimy;
2548 double **values;
2549 int **nodata;
2550 int weighted; /* 0 if not weighted values 1 if weighted values */
2551};
2552
2553/* polygon as LWPOLY with associated value */
2556 double val;
2557};
2558
2559/* summary stats of specified band */
2561 double sample;
2562 uint32_t count;
2563
2564 double min;
2565 double max;
2566 double sum;
2567 double mean;
2568 double stddev;
2569
2570 double *values;
2571 int sorted; /* flag indicating that values is sorted ascending by value */
2572};
2573
2574/* histogram bin(s) of specified band */
2576 uint32_t count;
2577 double percent;
2578
2579 double min;
2580 double max;
2581
2584};
2585
2586/* quantile(s) of the specified band */
2588 double quantile;
2589 double value;
2590 uint32_t has_value;
2591};
2592
2593/* listed-list structures for rt_band_get_quantiles_stream */
2595 uint8_t algeq; /* AL-GEQ (1) or AL-GT (0) */
2596 double quantile;
2597 uint64_t tau; /* position in sequence */
2598
2599 struct quantile_llist_element *head; /* H index 0 */
2600 struct quantile_llist_element *tail; /* H index last */
2601 uint32_t count; /* # of elements in H */
2602
2603 /* faster access to elements at specific intervals */
2605 uint32_t index_max; /* max # of elements in index */
2606
2607 uint64_t sum1; /* N1H */
2608 uint64_t sum2; /* N2H */
2609};
2610
2618
2623
2624/* number of times a value occurs */
2626 double value;
2627 uint32_t count;
2628 double percent;
2629};
2630
2631/* reclassification expression */
2634 double min;
2635 double max;
2636 int inc_min; /* include min */
2637 int inc_max; /* include max */
2638 int exc_min; /* exceed min */
2639 int exc_max; /* exceed max */
2641};
2642
2643/* src/dst mapping for rt_classmap */
2645 double src;
2646 double dst;
2647};
2648
2649/* exact reclassification expression */
2656
2657/* raster iterator */
2660 uint16_t nband; /* 0-based */
2661 uint8_t nbnodata; /* no band = treat as NODATA */
2662};
2663
2664/* callback argument from raster iterator */
2666 /* # of rasters, Z-axis */
2667 uint16_t rasters;
2668 /* # of rows, Y-axis */
2669 uint32_t rows;
2670 /* # of columns, X-axis */
2671 uint32_t columns;
2672
2673 /* axis order: Z,X,Y */
2674 /* individual pixel values */
2675 double ***values;
2676 /* 0,1 value of nodata flag */
2677 int ***nodata;
2678
2679 /* X,Y of pixel from each input raster */
2681
2682 /* X,Y of pixel from output raster */
2684};
2685
2686/* gdal driver information */
2695
2696/* raster colormap entry */
2699 double value;
2700 uint8_t color[4]; /* RGBA */
2701};
2702
2714
2715#endif /* LIBRTCORE_H_INCLUDED */
void rt_band_init_value(rt_band band, double initval)
Fill in the cells of a band with a starting value frequently used to init with nodata value.
Definition rt_band.c:113
rt_errorstate rt_raster_contains(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *contains)
Return ES_ERROR if error occurred in function.
rt_band rt_band_new_inline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t *data)
Create an in-db rt_band with no data.
Definition rt_band.c:64
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition rt_band.c:826
void(* rt_message_handler)(const char *string, va_list ap) __attribute__((format(printf
Definition librtcore.h:237
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.
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:1989
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition rt_context.c:191
rt_pixtype rt_util_gdal_datatype_to_pixtype(GDALDataType gdt)
Convert GDALDataType to rt_pixtype.
Definition rt_util.c:255
rt_band rt_band_duplicate(rt_band band)
Create a new band duplicated from source band.
Definition rt_band.c:446
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition rt_band.c:799
rt_errorstate rt_raster_fully_within_distance(rt_raster rast1, int nband1, rt_raster rast2, int nband2, double distance, int *dfwithin)
Return ES_ERROR if error occurred in function.
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
Definition rt_band.c:840
rt_errorstate rt_band_set_isnodata_flag(rt_band band, int flag)
Set isnodata flag value.
Definition rt_band.c:854
LWPOLY * rt_util_envelope_to_lwpoly(rt_envelope ext)
Definition rt_util.c:588
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:637
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
Definition rt_raster.c:360
void * default_rt_allocator(size_t size)
The default memory/logging handlers installed by lwgeom_install_default_allocators()
Definition rt_context.c:47
rt_errorstate rt_util_rgb_to_hsv(double rgb[3], double hsv[3])
Definition rt_util.c:656
int rt_util_gdal_register_all(int force_register_all)
Definition rt_util.c:444
double rt_raster_get_x_skew(rt_raster raster)
Get skew about the X axis.
Definition rt_raster.c:185
double rt_raster_get_x_offset(rt_raster raster)
Get raster x offset, in projection units.
Definition rt_raster.c:217
int rt_raster_calc_gt_coeff(double i_mag, double j_mag, double theta_i, double theta_ij, double *xscale, double *xskew, double *yskew, double *yscale)
Calculates the coefficients of a geotransform given the physically significant parameters describing ...
Definition rt_raster.c:318
int rt_raster_generate_new_band(rt_raster raster, rt_pixtype pixtype, double initialvalue, uint32_t hasnodata, double nodatavalue, int index)
Generate a new inline band and add it to a raster.
Definition rt_raster.c:489
int rt_util_gdal_configured(void)
Definition rt_util.c: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:283
LWPOLY * rt_raster_pixel_as_polygon(rt_raster raster, int x, int y)
Get a raster pixel as a polygon.
void rt_raster_set_geotransform_matrix(rt_raster raster, double *gt)
Set raster's geotransform using 6-element array.
Definition rt_raster.c:609
int8_t rt_util_clamp_to_8BSI(double value)
Definition rt_util.c:51
struct rt_quantile_t * rt_quantile
Definition librtcore.h:153
uint8_t rt_util_clamp_to_1BB(double value)
Definition rt_util.c:36
void void rtinfo(const char *fmt,...) __attribute__((format(printf
float rt_util_clamp_to_16F(double value)
Definition rt_util.c:88
rt_raster rt_raster_colormap(rt_raster raster, int nband, rt_colormap colormap)
Returns a new raster with up to four 8BUI bands (RGBA) from applying a colormap to the user-specified...
rt_errorstate rt_band_load_offline_data(rt_band band)
Load offline band's data.
Definition rt_band.c:588
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
rt_errorstate rt_raster_contains_properly(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *contains)
Return ES_ERROR if error occurred in function.
rt_gdaldriver rt_raster_gdal_drivers(uint32_t *drv_count, uint8_t cancc)
Returns a set of available GDAL drivers.
Definition rt_raster.c:1716
int32_t rt_util_clamp_to_32BSI(double value)
Definition rt_util.c:71
uint16_t rt_util_float_to_float16(float value)
Definition rt_util.c:101
struct rt_reclassexpr_t * rt_reclassexpr
Definition librtcore.h:156
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition rt_raster.c:141
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
Definition rt_raster.c:409
rt_errorstate rt_raster_get_inverse_geotransform_matrix(rt_raster raster, double *gt, double *igt)
Get 6-element array of raster inverse geotransform matrix.
Definition rt_raster.c:558
void(* rt_deallocator)(void *mem)
Definition librtcore.h:236
float rt_util_float16_to_float(uint16_t value)
Definition rt_util.c:134
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition rt_band.c:833
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
Definition rt_pixel.c:82
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:1598
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition rt_band.c:559
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:686
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition rt_band.c:1551
struct rt_mask_t * rt_mask
Definition librtcore.h:149
void rt_raster_destroy(rt_raster raster)
Release memory associated to a raster.
Definition rt_raster.c:86
rt_pixtype
Definition librtcore.h:188
@ PT_32BUI
Definition librtcore.h:197
@ PT_16BF
Definition librtcore.h:198
@ PT_2BUI
Definition librtcore.h:190
@ PT_32BSI
Definition librtcore.h:196
@ PT_END
Definition librtcore.h:201
@ PT_4BUI
Definition librtcore.h:191
@ PT_32BF
Definition librtcore.h:199
@ PT_1BB
Definition librtcore.h:189
@ PT_16BUI
Definition librtcore.h:195
@ PT_8BSI
Definition librtcore.h:192
@ PT_16BSI
Definition librtcore.h:194
@ PT_64BF
Definition librtcore.h:200
@ PT_8BUI
Definition librtcore.h:193
void rt_raster_set_skews(rt_raster raster, double skewX, double skewY)
Set skews about the X and Y axis.
Definition rt_raster.c:172
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition rt_band.c:873
rt_errorstate rt_raster_surface(rt_raster raster, int nband, LWMPOLY **surface)
Get a raster as a surface (multipolygon).
rt_errorstate rt_raster_geopoint_to_rasterpoint(rt_raster raster, double xw, double yw, double *xr, double *yr, double *igt)
Convert an xw,yw map point to a xr,yr raster point.
Definition rt_raster.c:730
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition rt_raster.c:52
char * rt_util_gdal_convert_sr(const char *srs, int proj4)
Definition rt_util.c:322
rt_extenttype rt_util_extent_type(const char *name)
Definition rt_util.c:301
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:778
GDALDataType rt_util_pixtype_to_gdal_datatype(rt_pixtype pt)
Convert rt_pixtype to GDALDataType.
Definition rt_util.c:213
rt_errorstate rt_raster_intersects(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *intersects)
Return ES_ERROR if error occurred in function.
rt_errorstate rt_raster_coveredby(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *coveredby)
Return ES_ERROR if error occurred in function.
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
Definition rt_pixel.c:156
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:1253
rt_raster rt_raster_compute_skewed_raster(rt_envelope extent, double *skew, double *scale, double tolerance)
Definition rt_raster.c:869
struct rt_pixel_t * rt_pixel
Definition librtcore.h:148
void void void char * default_rt_options(const char *varname)
Definition rt_context.c:105
rt_errorstate rt_raster_touches(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *touches)
Return ES_ERROR if error occurred in function.
rt_raster rt_raster_from_gdal_dataset(GDALDatasetH ds)
Return a raster from a GDAL dataset.
Definition rt_raster.c:2175
int rt_util_gdal_progress_func(double dfComplete, const char *pszMessage, void *pProgressArg)
Definition rt_gdal.c:66
rt_resample_type
Definition librtcore.h:1478
@ RT_BILINEAR
Definition librtcore.h:1480
@ RT_NEAREST
Definition librtcore.h:1479
rt_quantile rt_band_get_quantiles_stream(rt_band band, int exclude_nodata_value, double sample, uint64_t cov_count, struct quantile_llist **qlls, uint32_t *qlls_count, double *quantiles, uint32_t quantiles_count, uint32_t *rtn_count)
Compute the default set of or requested quantiles for a coverage.
struct rt_colormap_entry_t * rt_colormap_entry
Definition librtcore.h:162
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...
double rt_raster_get_x_scale(rt_raster raster)
Get scale X in projection units.
Definition rt_raster.c:154
rt_band rt_raster_replace_band(rt_raster raster, rt_band band, int index)
Replace band at provided index with new band.
Definition rt_raster.c:1404
uint8_t rt_util_clamp_to_2BUI(double value)
Definition rt_util.c:41
void default_rt_deallocator(void *mem)
Definition rt_context.c:61
const char * rt_pixtype_name(rt_pixtype pixtype)
Definition rt_pixel.c:114
int rt_pixtype_alignment(rt_pixtype pixtype)
Return alignment requirements for data in the given pixel type.
Definition rt_pixel.c:77
void * default_rt_reallocator(void *mem, size_t size)
Definition rt_context.c:54
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:211
const char * rt_util_gdal_version(const char *request)
Definition rt_util.c:290
uint8_t rt_util_clamp_to_8BUI(double value)
Definition rt_util.c:56
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:2082
uint64_t rt_band_get_file_size(rt_band band)
Return file size in bytes.
Definition rt_band.c:745
struct rt_bandstats_t * rt_bandstats
Definition librtcore.h:151
GDALDatasetH rt_util_gdal_open(const char *fn, GDALAccess fn_access, int shared)
Definition rt_util.c:491
int quantile_llist_destroy(struct quantile_llist **list, uint32_t list_count)
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition rt_band.c:2089
void void void char * rtoptions(const char *varname)
Wrappers used for options.
Definition rt_context.c:256
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition rt_band.c:892
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:693
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:1140
rt_errorstate
Enum definitions.
Definition librtcore.h:181
@ ES_NONE
Definition librtcore.h:182
@ ES_ERROR
Definition librtcore.h:183
rt_errorstate rt_band_set_pixel_line(rt_band band, int x, int y, void *vals, uint32_t len)
Set values of multiple pixels.
Definition rt_band.c:1019
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:414
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:2502
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition rt_band.c:499
rt_errorstate rt_raster_overlaps(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *overlaps)
Return ES_ERROR if error occurred in function.
int rt_util_gdal_supported_sr(const char *srs)
Definition rt_util.c:353
void rt_raster_get_phys_params(rt_raster rast, double *i_mag, double *j_mag, double *theta_i, double *theta_ij)
Calculates and returns the physically significant descriptors embodied in the geotransform attached t...
Definition rt_raster.c:235
int16_t rt_util_clamp_to_16BSI(double value)
Definition rt_util.c:61
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:2171
void * rtrealloc(void *mem, size_t size)
Definition rt_context.c:199
GDALResampleAlg rt_util_gdal_resample_alg(const char *algname)
Convert cstring name to GDAL Resample Algorithm.
Definition rt_util.c:183
uint16_t rt_raster_get_num_bands(rt_raster raster)
Definition rt_raster.c:376
struct rt_valuecount_t * rt_valuecount
Definition librtcore.h:154
struct rt_gdaldriver_t * rt_gdaldriver
Definition librtcore.h:155
rt_raster rt_raster_clone(rt_raster raster, uint8_t deep)
Clone an existing raster.
Definition rt_raster.c:1446
rt_errorstate rt_raster_get_convex_hull(rt_raster raster, LWGEOM **hull)
Get raster's convex hull.
uint16_t rt_raster_get_height(rt_raster raster)
Definition rt_raster.c:133
struct rt_reclassmap_t * rt_reclassmap
Definition librtcore.h:157
void *(* rt_reallocator)(void *mem, size_t size)
Definition librtcore.h:235
int rt_util_gdal_driver_registered(const char *drv)
Definition rt_util.c:463
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:283
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:535
rt_errorstate rt_raster_iterator(rt_iterator itrset, uint16_t itrcount, rt_extenttype extenttype, rt_raster customextent, rt_pixtype pixtype, uint8_t hasnodata, double nodataval, uint16_t distancex, uint16_t distancey, rt_mask mask, void *userarg, int(*callback)(rt_iterator_arg arg, void *userarg, double *value, int *nodata), rt_raster *rtnraster)
n-raster iterator.
uint64_t rt_band_get_file_timestamp(rt_band band)
Return file timestamp.
Definition rt_band.c:767
struct rt_iterator_arg_t * rt_iterator_arg
Definition librtcore.h:160
void rt_raster_set_srid(rt_raster raster, int32_t srid)
Set raster's SRID.
Definition rt_raster.c:367
rt_band rt_band_reclass_exact(rt_band srcband, rt_reclassmap map, uint32_t hasnodata, double nodataval)
Returns new band with values reclassified.
void rt_raster_set_phys_params(rt_raster rast, double i_mag, double j_mag, double theta_i, double theta_ij)
Calculates the geotransform coefficients and applies them to the supplied raster.
Definition rt_raster.c:301
rt_extenttype
Definition librtcore.h:204
@ ET_CUSTOM
Definition librtcore.h:210
@ ET_LAST
Definition librtcore.h:209
@ ET_INTERSECTION
Definition librtcore.h:205
@ ET_UNION
Definition librtcore.h:206
@ ET_SECOND
Definition librtcore.h:208
@ ET_FIRST
Definition librtcore.h:207
rt_errorstate rt_band_get_pixel_resample(rt_band band, double xr, double yr, rt_resample_type resample, double *r_value, int *r_nodata)
Retrieve a point value from the raster using a world coordinate and selected resampling method.
Definition rt_band.c:1396
uint8_t * rt_raster_to_wkb(rt_raster raster, int outasin, uint32_t *wkbsize)
Return this raster in WKB form.
Definition rt_wkb.c:502
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:1341
struct rt_geomval_t * rt_geomval
Definition librtcore.h:150
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition rt_band.c:2067
uint8_t rt_util_clamp_to_4BUI(double value)
Definition rt_util.c:46
rt_errorstate rt_util_hsv_to_rgb(double hsv[3], double rgb[3])
Definition rt_util.c:710
void rt_util_to_ogr_envelope(rt_envelope ext, OGREnvelope *env)
Definition rt_util.c:575
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition rt_band.c:790
char * rtstrdup(const char *str)
Definition rt_context.c:263
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:301
char *(* rt_options)(const char *varname)
Global functions for memory/logging handlers.
Definition librtcore.h:233
void *(* rt_allocator)(size_t size)
Definition librtcore.h:234
LWPOINT * rt_raster_pixel_as_centroid_point(rt_raster rast, int x, int y)
Get a raster pixel centroid point.
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:522
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:358
rt_histogram rt_band_get_histogram(rt_bandstats stats, uint32_t bin_count, double *bin_widths, uint32_t bin_widths_count, int right, double min, double max, uint32_t *rtn_count)
Count the distribution of data.
uint16_t rt_raster_get_width(rt_raster raster)
Definition rt_raster.c:125
uint32_t rt_band_get_nearest_pixel(rt_band band, int x, int y, uint16_t distancex, uint16_t distancey, int exclude_nodata_value, rt_pixel *npixels)
Get nearest pixel(s) with value (not NODATA) to specified pixel.
Definition rt_band.c:1709
void default_rt_error_handler(const char *fmt, va_list ap) __attribute__((format(printf
void rtdealloc(void *mem)
Definition rt_context.c:206
rt_errorstate rt_band_get_pixel_bilinear(rt_band band, double xr, double yr, double *r_value, int *r_nodata)
Retrieve a point value from the raster using a world coordinate and bilinear interpolation.
Definition rt_band.c:1435
rt_errorstate rt_util_gdal_sr_auth_info(GDALDatasetH hds, char **authname, char **authcode)
Get auth name and code.
Definition rt_util.c:380
uint16_t rt_util_clamp_to_16BUI(double value)
Definition rt_util.c:66
rt_errorstate rt_raster_get_envelope_geom(rt_raster raster, LWGEOM **env)
Get raster's envelope as a geometry.
struct rt_colormap_t * rt_colormap
Definition librtcore.h:163
struct rt_iterator_t * rt_iterator
Definition librtcore.h:159
int rt_band_clamped_value_is_nodata(rt_band band, double val)
Compare clamped value to band's clamped NODATA value.
Definition rt_band.c:2135
void * rt_raster_serialize(rt_raster raster)
Return this raster in serialized form.
uint32_t rt_util_clamp_to_32BUI(double value)
Definition rt_util.c:76
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:177
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:818
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:1813
void rt_set_handlers_options(rt_allocator allocator, rt_reallocator reallocator, rt_deallocator deallocator, rt_message_handler error_handler, rt_message_handler info_handler, rt_message_handler warning_handler, rt_options options_handler)
Definition rt_context.c:169
rt_errorstate rt_raster_get_perimeter(rt_raster raster, int nband, LWGEOM **perimeter)
Get raster perimeter.
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
Definition rt_band.c:488
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.
rt_valuecount rt_band_get_value_count(rt_band band, int exclude_nodata_value, double *search_values, uint32_t search_values_count, double roundto, uint32_t *rtn_total, uint32_t *rtn_count)
Count the number of times provided value(s) occur in the band.
rt_errorstate rt_raster_from_two_rasters(rt_raster rast1, rt_raster rast2, rt_extenttype extenttype, rt_raster *rtnraster, double *offset)
Definition rt_raster.c:3348
void(*) voi rt_install_default_allocators)(void)
Apply the default memory management (malloc() and free()) and error handlers.
rt_geos_spatial_test
GEOS spatial relationship tests available.
Definition librtcore.h:221
@ GSR_TOUCHES
Definition librtcore.h:223
@ GSR_COVERS
Definition librtcore.h:226
@ GSR_COVEREDBY
Definition librtcore.h:227
@ GSR_CONTAINSPROPERLY
Definition librtcore.h:225
@ GSR_OVERLAPS
Definition librtcore.h:222
@ GSR_CONTAINS
Definition librtcore.h:224
struct rt_raster_t * rt_raster
Types definitions.
Definition librtcore.h:146
int rt_util_same_geotransform_matrix(double *gt1, double *gt2)
Definition rt_util.c:640
#define __attribute__
Definition librtcore.h:140
int rt_raster_gdal_contour(rt_raster src_raster, int src_band, int src_srid, const char *src_srs, double contour_interval, double contour_base, int fixed_level_count, double *fixed_levels, int polygonize, size_t *ncontours, struct rt_contour_t **contours)
Return palloc'ed list of contours.
Definition rt_gdal.c:119
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:1276
double rt_raster_get_y_scale(rt_raster raster)
Get scale Y in projection units.
Definition rt_raster.c:163
float rt_util_clamp_to_32F(double value)
Definition rt_util.c:81
rt_errorstate rt_raster_get_envelope(rt_raster raster, rt_envelope *env)
Get raster's envelope.
Definition rt_raster.c:782
rt_errorstate rt_raster_same_alignment(rt_raster rast1, rt_raster rast2, int *aligned, char **reason)
rt_errorstate rt_raster_covers(rt_raster rast1, int nband1, rt_raster rast2, int nband2, int *covers)
Return ES_ERROR if error occurred in function.
double rt_raster_get_y_skew(rt_raster raster)
Get skew about the Y axis.
Definition rt_raster.c:194
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
Definition rt_raster.c:588
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...
void void void default_rt_info_handler(const char *fmt, va_list ap) __attribute__((format(printf
rt_errorstate rt_raster_copy_to_geometry(rt_raster raster, uint32_t bandnum, char dim, rt_resample_type resample, const LWGEOM *lwgeom_in, LWGEOM **lwgeom_out)
Copy values from a raster to the points on a geometry using the requested interpolation type.
Definition rt_raster.c:1492
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition rt_raster.c:203
rt_bandstats rt_band_get_summary_stats(rt_band band, int exclude_nodata_value, double sample, int inc_vals, uint64_t *cK, double *cM, double *cQ)
Compute summary statistics for a band.
void rt_set_handlers(rt_allocator allocator, rt_reallocator reallocator, rt_deallocator deallocator, rt_message_handler error_handler, rt_message_handler info_handler, rt_message_handler warning_handler)
This function is called when the PostgreSQL backend is taking care of the memory and we want to use p...
Definition rt_context.c:159
void rt_util_from_ogr_envelope(OGREnvelope env, rt_envelope *ext)
Definition rt_util.c:559
struct rt_histogram_t * rt_histogram
Definition librtcore.h:152
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition rt_band.c:808
struct rt_band_t * rt_band
Definition librtcore.h:147
rt_raster rt_raster_deserialize(void *serialized, int header_only)
Return a raster from a serialized form.
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition rt_pixel.c:40
void rt_raster_calc_phys_params(double xscale, double xskew, double yskew, double yscale, double *i_mag, double *j_mag, double *theta_i, double *theta_ij)
Calculates the physically significant descriptors embodied in an arbitrary geotransform.
Definition rt_raster.c:254
rt_errorstate rt_band_get_pixel_line(rt_band band, int x, int y, uint16_t len, void **vals, uint16_t *nvals)
Get values of multiple pixels.
Definition rt_band.c:1312
double rt_raster_get_y_offset(rt_raster raster)
Get raster y offset, in projection units.
Definition rt_raster.c:226
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
Definition rt_raster.c:1240
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
Definition rt_raster.c:385
void void default_rt_warning_handler(const char *fmt, va_list ap) __attribute__((format(printf
#define str(s)
Datum contains(PG_FUNCTION_ARGS)
Datum coveredby(PG_FUNCTION_ARGS)
Datum covers(PG_FUNCTION_ARGS)
Datum touches(PG_FUNCTION_ARGS)
Datum overlaps(PG_FUNCTION_ARGS)
static double distance(double x1, double y1, double x2, double y2)
Definition lwtree.c:1032
struct quantile_llist_element * prev
Definition librtcore.h:2615
struct quantile_llist_element * next
Definition librtcore.h:2616
struct quantile_llist_element * element
Definition librtcore.h:2620
uint32_t count
Definition librtcore.h:2601
uint64_t sum1
Definition librtcore.h:2607
uint64_t sum2
Definition librtcore.h:2608
uint32_t index_max
Definition librtcore.h:2605
struct quantile_llist_element * head
Definition librtcore.h:2599
struct quantile_llist_element * tail
Definition librtcore.h:2600
struct quantile_llist_index * index
Definition librtcore.h:2604
rt_pixtype pixtype
Definition librtcore.h:2516
int32_t hasnodata
Definition librtcore.h:2520
int32_t offline
Definition librtcore.h:2517
uint16_t height
Definition librtcore.h:2519
rt_raster raster
Definition librtcore.h:2526
double nodataval
Definition librtcore.h:2523
union rt_band_t::@12 data
uint16_t width
Definition librtcore.h:2518
void * mem
Definition librtcore.h:2529
int32_t isnodata
Definition librtcore.h:2521
int8_t ownsdata
Definition librtcore.h:2524
uint32_t count
Definition librtcore.h:2562
double * values
Definition librtcore.h:2570
uint8_t color[4]
Definition librtcore.h:2700
double value
Definition librtcore.h:2699
int isnodata
Definition librtcore.h:2698
Definition librtcore.h:2697
rt_colormap_entry entry
Definition librtcore.h:2712
uint16_t nentry
Definition librtcore.h:2711
enum rt_colormap_t::@13 method
GSERIALIZED * geom
Definition librtcore.h:1777
double elevation
Definition librtcore.h:1778
double MinX
Definition librtcore.h:167
double UpperLeftY
Definition librtcore.h:173
double UpperLeftX
Definition librtcore.h:172
double MaxX
Definition librtcore.h:168
double MinY
Definition librtcore.h:169
double MaxY
Definition librtcore.h:170
uint8_t bandNum
Definition librtcore.h:2510
uint8_t can_write
Definition librtcore.h:2693
char * create_options
Definition librtcore.h:2691
LWPOLY * geom
Definition librtcore.h:2555
uint32_t count
Definition librtcore.h:2576
double *** values
Definition librtcore.h:2675
rt_raster raster
Definition librtcore.h:2659
uint16_t nband
Definition librtcore.h:2660
uint8_t nbnodata
Definition librtcore.h:2661
double ** values
Definition librtcore.h:2548
uint16_t dimy
Definition librtcore.h:2547
uint16_t dimx
Definition librtcore.h:2546
int ** nodata
Definition librtcore.h:2549
LWGEOM * geom
Definition librtcore.h:2542
double value
Definition librtcore.h:2540
uint8_t nodata
Definition librtcore.h:2539
double quantile
Definition librtcore.h:2588
uint32_t has_value
Definition librtcore.h:2590
Struct definitions.
Definition librtcore.h:2452
double scaleX
Definition librtcore.h:2495
rt_band * bands
Definition librtcore.h:2505
uint16_t width
Definition librtcore.h:2503
uint16_t version
Definition librtcore.h:2488
double skewY
Definition librtcore.h:2500
uint16_t numBands
Definition librtcore.h:2492
int32_t srid
Definition librtcore.h:2502
uint16_t height
Definition librtcore.h:2504
uint32_t size
Definition librtcore.h:2487
double scaleY
Definition librtcore.h:2496
double skewX
Definition librtcore.h:2499
struct rt_reclassexpr_t::rt_reclassrange src
struct rt_reclassexpr_t::rt_reclassrange dst
rt_pixtype dsttype
Definition librtcore.h:2653
struct rt_classpair_t * pairs
Definition librtcore.h:2654
rt_pixtype srctype
Definition librtcore.h:2652