PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ _rti_raster_get_band_perimeter()

static rt_errorstate _rti_raster_get_band_perimeter ( rt_band  band,
uint16_t *  trim 
)
static

Definition at line 40 of file rt_geometry.c.

40 {
41 uint16_t width = 0;
42 uint16_t height = 0;
43 int x = 0;
44 int y = 0;
45 int offset = 0;
46 int done[4] = {0};
47 double value = 0;
48 int nodata = 0;
49
50 assert(band != NULL);
51 assert(band->raster != NULL);
52 assert(trim != NULL);
53
54 memset(trim, 0, sizeof(uint16_t) * 4);
55
56 width = rt_band_get_width(band);
57 height = rt_band_get_height(band);
58
59 /* top */
60 for (y = 0; y < height; y++) {
61 for (offset = 0; offset < 3; offset++) {
62 /* every third pixel */
63 for (x = offset; x < width; x += 3) {
64 if (rt_band_get_pixel(band, x, y, &value, &nodata) != ES_NONE) {
65 rterror("_rti_raster_get_band_perimeter: Could not get band pixel");
66 return ES_ERROR;
67 }
68
69 RASTER_DEBUGF(4, "top (x, y, value, nodata) = (%d, %d, %f, %d)", x, y, value, nodata);
70 if (!nodata) {
71 trim[0] = y;
72 done[0] = 1;
73 break;
74 }
75 }
76
77 if (done[0])
78 break;
79 }
80
81 if (done[0])
82 break;
83 }
84
85 /* right */
86 for (x = width - 1; x >= 0; x--) {
87 for (offset = 0; offset < 3; offset++) {
88 /* every third pixel */
89 for (y = offset; y < height; y += 3) {
90 if (rt_band_get_pixel(band, x, y, &value, &nodata) != ES_NONE) {
91 rterror("_rti_raster_get_band_perimeter: Could not get band pixel");
92 return ES_ERROR;
93 }
94
95 RASTER_DEBUGF(4, "right (x, y, value, nodata) = (%d, %d, %f, %d)", x, y, value, nodata);
96 if (!nodata) {
97 trim[1] = width - (x + 1);
98 done[1] = 1;
99 break;
100 }
101 }
102
103 if (done[1])
104 break;
105 }
106
107 if (done[1])
108 break;
109 }
110
111 /* bottom */
112 for (y = height - 1; y >= 0; y--) {
113 for (offset = 0; offset < 3; offset++) {
114 /* every third pixel */
115 for (x = offset; x < width; x += 3) {
116 if (rt_band_get_pixel(band, x, y, &value, &nodata) != ES_NONE) {
117 rterror("_rti_raster_get_band_perimeter: Could not get band pixel");
118 return ES_ERROR;
119 }
120
121 RASTER_DEBUGF(4, "bottom (x, y, value, nodata) = (%d, %d, %f, %d)", x, y, value, nodata);
122 if (!nodata) {
123 trim[2] = height - (y + 1);
124 done[2] = 1;
125 break;
126 }
127 }
128
129 if (done[2])
130 break;
131 }
132
133 if (done[2])
134 break;
135 }
136
137 /* left */
138 for (x = 0; x < width; x++) {
139 for (offset = 0; offset < 3; offset++) {
140 /* every third pixel */
141 for (y = offset; y < height; y += 3) {
142 if (rt_band_get_pixel(band, x, y, &value, &nodata) != ES_NONE) {
143 rterror("_rti_raster_get_band_perimeter: Could not get band pixel");
144 return ES_ERROR;
145 }
146
147 RASTER_DEBUGF(4, "left (x, , value, nodata) = (%d, %d, %f, %d)", x, y, value, nodata);
148 if (!nodata) {
149 trim[3] = x;
150 done[3] = 1;
151 break;
152 }
153 }
154
155 if (done[3])
156 break;
157 }
158
159 if (done[3])
160 break;
161 }
162
163 RASTER_DEBUGF(4, "trim = (%d, %d, %d, %d)",
164 trim[0], trim[1], trim[2], trim[3]);
165
166 return ES_NONE;
167}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition rt_band.c:799
#define RASTER_DEBUGF(level, msg,...)
Definition librtcore.h:308
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
@ ES_NONE
Definition librtcore.h:182
@ ES_ERROR
Definition librtcore.h:183
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition rt_band.c:808
int value
Definition genraster.py:62
static char * trim(const char *input)

References ES_ERROR, ES_NONE, RASTER_DEBUGF, rt_band_get_height(), rt_band_get_pixel(), rt_band_get_width(), rterror(), and trim().

Referenced by rt_raster_get_perimeter().

Here is the call graph for this function:
Here is the caller graph for this function: