34 #include "iclass_local_proto.h" 37 #define extrema(x,y,z) (((x<y)&&(z<y))||((x>y)&&(z>y))) 38 #define non_extrema(x,y,z) (((x<y)&&(y<z))||((x>y)&&(y>z))) 53 int category, IClass_perimeter_list * perimeters,
58 int nareas, nareas_cat, layer;
64 G_debug(3,
"iclass_vector2perimeters():layer = %s, category = %d",
65 layer_name, category);
74 for (i = 1; i <= nareas; i++) {
81 else if (cat == category) {
88 perimeters->nperimeters = nareas_cat;
89 perimeters->perimeters =
90 (IClass_perimeter *)
G_calloc(nareas_cat,
sizeof(IClass_perimeter));
93 for (i = 1; i <= nareas; i++) {
100 else if (cat == category) {
113 (points, &perimeters->perimeters[j - 1], band_region) <= 0) {
140 G_debug(5,
"free_perimeters()");
142 for (i = 0; i < perimeters->nperimeters; i++) {
143 G_free(perimeters->perimeters[i].points);
145 G_free(perimeters->perimeters);
161 IClass_point *tmp_points;
163 IClass_point *vertex_points;
165 int i, first, prev, skip, next;
167 int count, vertex_count;
171 G_debug(5,
"iclass_make_perimeter()");
174 tmp_points = (IClass_point *)
G_calloc(count,
sizeof(IClass_point));
176 for (i = 0; i <
count; i++) {
177 G_debug(5,
"iclass_make_perimeter(): points: x: %f y: %f",
178 points->
x[i], points->
y[i]);
191 tmp_points[i].y = (band_region->
north - points->
y[i]) / band_region->
ns_res;
192 tmp_points[i].x = (points->
x[i] - band_region->
west) / band_region->
ew_res;
199 for (i = 0; i <
count; prev = i++) {
201 if (tmp_points[i].
y != tmp_points[prev].
y) {
215 vertex_points = (IClass_point *)
G_calloc(count,
sizeof(IClass_point));
222 vertex_points[vertex_count].x = tmp_points[i].x;
223 vertex_points[vertex_count].y = tmp_points[i].y;
230 if ((next = i + 1) >=
count)
233 skip = ((tmp_points[prev].y == tmp_points[i].y) &&
234 (tmp_points[next].
y == tmp_points[i].
y));
243 prev = vertex_count - 1;
244 for (i = 0; i < vertex_count; prev = i++) {
245 np += abs(vertex_points[prev].
y - vertex_points[i].
y);
250 perimeter->points = (IClass_point *)
G_calloc(np,
sizeof(IClass_point));
251 if (!perimeter->points) {
259 perimeter->npoints = 0;
260 prev = vertex_count - 1;
261 for (i = 0; i < vertex_count; prev = i++) {
263 vertex_points[prev].
y, vertex_points[i].x,
277 prev = vertex_count - 1;
281 if (next >= vertex_count)
285 (vertex_points[prev].
y, vertex_points[i].y,
286 vertex_points[next].y))
289 (vertex_points[prev].y, vertex_points[i].y,
290 vertex_points[next].y))
294 if (++next >= vertex_count)
297 (vertex_points[prev].y, vertex_points[i].y,
298 vertex_points[next].y))
314 qsort(perimeter->points, (
size_t) perimeter->npoints,
345 m = (float)(x0 - x1) / (float)(y0 - y1);
375 G_debug(5,
"perimeter_add_point(): x: %d, y: %d", x, y);
377 n = perimeter->npoints++;
378 perimeter->points[n].x =
x;
379 perimeter->points[n].y =
y;
390 const IClass_point *a = aa;
392 const IClass_point *
b = bb;
int make_perimeter(struct line_pnts *points, IClass_perimeter *perimeter, struct Cell_head *band_region)
Creates one perimeter from vector area.
2D/3D raster map header (used also for region)
double west
Extent coordinates (west)
int edge_order(const void *aa, const void *bb)
Determines points order during sorting.
int n_points
Number of points.
void G_free(void *)
Free allocated memory.
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.
double * x
Array of X coordinates.
int Vect_get_field_number(const struct Map_info *, const char *)
Get field number of given field.
Feature geometry info - coordinates.
void free_perimeters(IClass_perimeter_list *perimeters)
Frees all perimeters in list of perimeters.
double north
Extent coordinates (north)
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
#define non_extrema(x, y, z)
void perimeter_add_point(IClass_perimeter *perimeter, int x, int y)
Adds point to perimeter.
plus_t Vect_get_num_areas(const struct Map_info *)
Get number of areas in vector map.
int Vect_area_alive(const struct Map_info *, int)
Check if area is alive or dead (topological level required)
int edge2perimeter(IClass_perimeter *perimeter, int x0, int y0, int x1, int y1)
Converts edge to cells.
double * y
Array of Y coordinates.
double ns_res
Resolution - north to south cell size for 2D data.
void G_warning(const char *,...) __attribute__((format(printf
double ew_res
Resolution - east to west cell size for 2D data.
void Vect_destroy_line_struct(struct line_pnts *)
Frees all memory associated with a line_pnts structure, including the structure itself.
int Vect_get_area_points(const struct Map_info *, int, struct line_pnts *)
Returns polygon array of points (outer ring) of given area.
int G_debug(int, const char *,...) __attribute__((format(printf
int Vect_get_area_cat(const struct Map_info *, int, int)
Find FIRST category of given field and area.