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.
185 {
187 int numband = 0;
188 uint16_t *_nband = NULL;
189 int i = 0;
190 int j = 0;
191 uint16_t _trim[4] = {0};
192 uint16_t
trim[4] = {0};
193 int isset[4] = {0};
194 double gt[6] = {0.0};
196
201
202 assert(perimeter != NULL);
203
204 *perimeter = NULL;
205
206
209
210
214
216
217
218 if (nband >= 0) {
219 if (nband >= numband) {
220 rterror(
"rt_raster_get_boundary: Band %d not found for raster", nband);
222 }
223
224 numband = 1;
225 }
226 else
228
229 RASTER_DEBUGF(3,
"rt_raster_get_perimeter: nband, numband = %d, %d", nband, numband);
230
231 _nband =
rtalloc(
sizeof(uint16_t) * numband);
232 if (_nband == NULL) {
233 rterror(
"rt_raster_get_boundary: Could not allocate memory for band indices");
235 }
236
237 if (nband < 0) {
238 for (i = 0; i < numband; i++)
239 _nband[i] = i;
240 }
241 else
243
244 for (i = 0; i < numband; i++) {
246 if (band == NULL) {
247 rterror(
"rt_raster_get_boundary: Could not get band at index %d", _nband[i]);
250 }
251
252
254 continue;
255
257 rterror(
"rt_raster_get_boundary: Could not get band perimeter");
260 }
261
262 for (j = 0; j < 4; j++) {
263 if (!isset[j] ||
trim[j] < _trim[j]) {
265 isset[j] = 1;
266 }
267 }
268 }
269
270
272
273
274 if (!isset[0]) {
275
277 }
278
281
282
284 if (!rings) {
285 rterror(
"rt_raster_get_perimeter: Could not allocate memory for polygon ring");
287 }
289 if (!rings[0]) {
290 rterror(
"rt_raster_get_perimeter: Could not construct point array");
292 }
293 pts = rings[0];
294
295
297 raster,
298 _trim[3], _trim[0],
300 gt
301 );
304
305
307 raster,
308 raster->width - _trim[1], _trim[0],
310 gt
311 );
313
314
316 raster,
319 gt
320 );
322
323
325 raster,
326 _trim[3],
raster->height - _trim[2],
328 gt
329 );
331
334
336}
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)