34 #include "iclass_local_proto.h"
36 #define extrema(x, y, z) (((x < y) && (z < y)) || ((x > y) && (z > y)))
37 #define non_extrema(x, y, z) (((x < y) && (y < z)) || ((x > y) && (y > z)))
52 int category, IClass_perimeter_list *perimeters,
57 int nareas, nareas_cat, layer;
63 G_debug(3,
"iclass_vector2perimeters():layer = %s, category = %d",
64 layer_name, category);
73 for (i = 1; i <= nareas; i++) {
80 else if (cat == category) {
87 perimeters->nperimeters = nareas_cat;
88 perimeters->perimeters =
89 (IClass_perimeter *)
G_calloc(nareas_cat,
sizeof(IClass_perimeter));
92 for (i = 1; i <= nareas; i++) {
99 else if (cat == category) {
138 G_debug(5,
"free_perimeters()");
140 for (i = 0; i < perimeters->nperimeters; i++) {
141 G_free(perimeters->perimeters[i].points);
143 G_free(perimeters->perimeters);
159 IClass_point *tmp_points;
161 IClass_point *vertex_points;
163 int i, first, prev, skip, next;
165 int count, vertex_count;
169 G_debug(5,
"iclass_make_perimeter()");
175 for (i = 0; i <
count; i++) {
176 G_debug(5,
"iclass_make_perimeter(): points: x: %f y: %f", points->
x[i],
191 (band_region->
north - points->
y[i]) / band_region->
ns_res;
193 (points->
x[i] - band_region->
west) / band_region->
ew_res;
200 for (i = 0; i <
count; prev = i++) {
202 if (tmp_points[i].
y != tmp_points[prev].
y) {
224 vertex_points[vertex_count].x = tmp_points[i].x;
225 vertex_points[vertex_count].y = tmp_points[i].y;
232 if ((next = i + 1) >=
count)
235 skip = ((tmp_points[prev].y == tmp_points[i].y) &&
236 (tmp_points[next].
y == tmp_points[i].
y));
237 }
while (i != first);
244 prev = vertex_count - 1;
245 for (i = 0; i < vertex_count; prev = i++) {
246 np += abs(vertex_points[prev].
y - vertex_points[i].
y);
251 perimeter->points = (IClass_point *)
G_calloc(np,
sizeof(IClass_point));
252 if (!perimeter->points) {
260 perimeter->npoints = 0;
261 prev = vertex_count - 1;
262 for (i = 0; i < vertex_count; prev = i++) {
264 vertex_points[i].
x, vertex_points[i].
y);
277 prev = vertex_count - 1;
281 if (next >= vertex_count)
284 if (
extrema(vertex_points[prev].
y, vertex_points[i].
y,
285 vertex_points[next].
y))
287 else if (
non_extrema(vertex_points[prev].
y, vertex_points[i].
y,
288 vertex_points[next].
y))
292 if (++next >= vertex_count)
294 if (
extrema(vertex_points[prev].
y, vertex_points[i].
y,
295 vertex_points[next].
y))
310 qsort(perimeter->points, (
size_t)perimeter->npoints,
sizeof(IClass_point),
339 m = (float)(x0 - x1) / (float)(y0 - y1);
369 G_debug(5,
"perimeter_add_point(): x: %d, y: %d",
x,
y);
371 n = perimeter->npoints++;
372 perimeter->points[n].x =
x;
373 perimeter->points[n].y =
y;
384 const IClass_point *a = aa;
386 const IClass_point *
b = bb;
void G_free(void *)
Free allocated memory.
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
plus_t Vect_get_num_areas(struct Map_info *)
Get number of areas in vector map.
int Vect_area_alive(struct Map_info *, int)
Check if area is alive or dead (topological level required)
int Vect_get_field_number(struct Map_info *, const char *)
Get field number of given field.
int Vect_get_area_points(struct Map_info *, int, struct line_pnts *)
Returns polygon array of points (outer ring) of given area.
int Vect_get_area_cat(struct Map_info *, int, int)
Find FIRST category of given field and area.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
void perimeter_add_point(IClass_perimeter *perimeter, int x, int y)
Adds point to perimeter.
int vector2perimeters(struct Map_info *Map, const char *layer_name, int category, IClass_perimeter_list *perimeters, struct Cell_head *band_region)
Creates perimeters from vector areas of given category.
int edge2perimeter(IClass_perimeter *perimeter, int x0, int y0, int x1, int y1)
Converts edge to cells.
void free_perimeters(IClass_perimeter_list *perimeters)
Frees all perimeters in list of perimeters.
int make_perimeter(struct line_pnts *points, IClass_perimeter *perimeter, struct Cell_head *band_region)
Creates one perimeter from vector area.
#define non_extrema(x, y, z)
int edge_order(const void *aa, const void *bb)
Determines points order during sorting.
2D/3D raster map header (used also for region)
double ew_res
Resolution - east to west cell size for 2D data.
double north
Extent coordinates (north)
double ns_res
Resolution - north to south cell size for 2D data.
double west
Extent coordinates (west)
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
int n_points
Number of points.