Get raster perimeter.
The perimeter is a 4 vertices (5 to be closed) single ring polygon bearing the raster's rotation and using projection coordinates.
186 {
188 int numband = 0;
189 uint16_t *_nband = NULL;
190 int i = 0;
191 int j = 0;
192 uint16_t _trim[4] = {0};
193 uint16_t
trim[4] = {0};
194 int isset[4] = {0};
195 double gt[6] = {0.0};
197
202
203 assert(perimeter != NULL);
204
205 *perimeter = NULL;
206
207
210
211
215
217
218
219 if (nband >= 0) {
220 if (nband >= numband) {
221 rterror(
"rt_raster_get_boundary: Band %d not found for raster", nband);
223 }
224
225 numband = 1;
226 }
227 else
229
230 RASTER_DEBUGF(3,
"rt_raster_get_perimeter: nband, numband = %d, %d", nband, numband);
231
232 _nband =
rtalloc(
sizeof(uint16_t) * numband);
233 if (_nband == NULL) {
234 rterror(
"rt_raster_get_boundary: Could not allocate memory for band indices");
236 }
237
238 if (nband < 0) {
239 for (i = 0; i < numband; i++)
240 _nband[i] = i;
241 }
242 else
244
245 for (i = 0; i < numband; i++) {
247 if (band == NULL) {
248 rterror(
"rt_raster_get_boundary: Could not get band at index %d", _nband[i]);
251 }
252
253
255 continue;
256
258 rterror(
"rt_raster_get_boundary: Could not get band perimeter");
261 }
262
263 for (j = 0; j < 4; j++) {
264 if (!isset[j] ||
trim[j] < _trim[j]) {
266 isset[j] = 1;
267 }
268 }
269 }
270
271
273
274
275 if (!isset[0]) {
276
278 }
279
282
283
285 if (!rings) {
286 rterror(
"rt_raster_get_perimeter: Could not allocate memory for polygon ring");
288 }
290 if (!rings[0]) {
291 rterror(
"rt_raster_get_perimeter: Could not construct point array");
293 }
294 pts = rings[0];
295
296
298 raster,
299 _trim[3], _trim[0],
301 gt
302 );
305
306
308 raster,
309 raster->width - _trim[1], _trim[0],
311 gt
312 );
314
315
317 raster,
320 gt
321 );
323
324
326 raster,
327 _trim[3],
raster->height - _trim[2],
329 gt
330 );
332
335
337}
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
#define SRID_UNKNOWN
Unknown SRID value.
void ptarray_set_point4d(POINTARRAY *pa, uint32_t n, const POINT4D *p4d)
LWGEOM * lwpoly_as_lwgeom(const LWPOLY *obj)
POINTARRAY * ptarray_construct(char hasz, char hasm, uint32_t npoints)
Construct an empty pointarray, allocating storage and setting the npoints, but not filling in any inf...
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.
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.
int32_t rt_raster_get_srid(rt_raster raster)
Get raster's SRID.
#define RASTER_DEBUGF(level, msg,...)
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
uint16_t rt_raster_get_num_bands(rt_raster raster)
void rtdealloc(void *mem)
void rt_raster_get_geotransform_matrix(rt_raster raster, double *gt)
Get 6-element array of raster geotransform matrix.
int rt_raster_is_empty(rt_raster raster)
Return TRUE if the raster is empty.
rt_band rt_raster_get_band(rt_raster raster, int bandNum)
Return Nth band, or NULL if unavailable.
raster
Be careful!! Zeros function's input parameter can be a (height x width) array, not (width x height): ...
static char * trim(const char *input)
static rt_errorstate _rti_raster_get_band_perimeter(rt_band band, uint16_t *trim)