22 #define HUGE_VAL 9999999999999.0 34 static int sort_by_size(
const void *a,
const void *
b)
36 BOX_SIZE *as = (BOX_SIZE *)a;
37 BOX_SIZE *bs = (BOX_SIZE *)b;
39 if (as->size < bs->size)
42 return (as->size > bs->size);
59 double ux,
double uy,
double uz,
double maxdist,
int with_z)
65 double cur_dist, dist;
67 G_debug(3,
"Vect_find_node() for %f %f %f maxdist = %f", ux, uy, uz,
86 G_debug(3,
" %d nodes in box", nnodes);
94 for (i = 0; i < nnodes; i++) {
97 if (dist < cur_dist) {
102 G_debug(3,
" nearest node %d in distance %f", NList->
value[node],
106 if (cur_dist <= maxdist)
107 return (NList->
value[node]);
130 double ux,
double uy,
double uz,
131 int type,
double maxdist,
int with_z,
int exclude)
134 struct ilist *exclude_list;
141 type, maxdist, with_z, exclude_list,
NULL);
165 double ux,
double uy,
double uz,
166 int type,
double maxdist,
int with_z,
167 const struct ilist *exclude,
struct ilist *found)
175 static int first_time = 1;
179 G_debug(3,
"Vect_find_line_list() for %f %f %f type = %d maxdist = %f",
180 ux, uy, uz, type, maxdist);
191 box.
N = uy + maxdist;
192 box.
S = uy - maxdist;
193 box.
E = ux + maxdist;
194 box.
W = ux - maxdist;
196 box.
T = uz + maxdist;
197 box.
B = uz - maxdist;
210 for (i = 0; i < List->
n_values; i++) {
213 G_debug(3,
" line = %d exclude", line);
228 G_debug(3,
" line = %d distance = %f", line, new_dist);
230 if (found && new_dist <= maxdist) {
234 if ((++gotone == 1) || (new_dist <= cur_dist)) {
235 if (new_dist == cur_dist) {
246 G_debug(3,
"min distance found = %f", cur_dist);
247 if (cur_dist > maxdist)
266 int i, j, ret, area, isle;
269 static BOX_SIZE *size_list;
270 static int alloc_size_list = 0;
274 G_debug(3,
"Vect_find_area() x = %f y = %f", x, y);
278 alloc_size_list = 10;
279 size_list =
G_malloc(alloc_size_list *
sizeof(BOX_SIZE));
301 if (alloc_size_list < List->n_values) {
303 size_list =
G_realloc(size_list, alloc_size_list *
sizeof(BOX_SIZE));
306 for (i = 0; i < List->
n_values; i++) {
307 size_list[i].i = List->
id[i];
309 size_list[i].box = List->
box[i];
310 size_list[i].size = (box.
N - box.
S) * (box.
E - box.
W);
315 if (size_list[1].size < size_list[0].size) {
316 size_list[0].i = List->
id[1];
317 size_list[1].i = List->
id[0];
318 size_list[0].box = List->
box[1];
319 size_list[1].box = List->
box[0];
323 qsort(size_list, List->
n_values,
sizeof(BOX_SIZE), sort_by_size);
325 for (i = 0; i < List->
n_values; i++) {
326 area = size_list[i].i;
330 G_debug(3,
" area = %d Vect_point_in_area_outer_ring() = %d", area, ret);
334 Area = Plus->
Area[area];
335 for (j = 0; j < Area->
n_isles; j++) {
336 isle = Area->
isles[j];
340 G_debug(3,
" area = %d Vect_point_in_island() = %d", area, ret);
368 int i, ret, island, current, current_size, size;
369 static int first = 1;
376 G_debug(3,
"Vect_find_island() x = %f y = %f", x, y);
396 for (i = 0; i < List->
n_values; i++) {
397 island = List->
id[i];
402 if (current_size == -1) {
414 if (size < current_size) {
void Vect_destroy_boxlist(struct boxlist *)
Frees all memory associated with a struct boxlist, including the struct itself.
int Vect_select_areas_by_box(struct Map_info *, const struct bound_box *, struct boxlist *)
Select areas with bounding boxes by box.
int Vect_point_in_island(double, double, const struct Map_info *, int, struct bound_box *)
Determines if a point (X,Y) is inside an island.
int Vect_reset_list(struct ilist *)
Reset ilist structure.
int Vect_select_isles_by_box(struct Map_info *, const struct bound_box *, struct boxlist *)
Select isles with bounding boxes by box.
int Vect_select_nodes_by_box(struct Map_info *, const struct bound_box *, struct ilist *)
Select nodes by box.
int Vect_point_in_area_outer_ring(double, double, const struct Map_info *, int, struct bound_box *)
Determines if a point (X,Y) is inside an area outer ring. Islands are not considered.
struct P_area ** Area
Array of areas.
int n_points
Number of points.
int Vect_val_in_list(const struct ilist *, int)
Find a given item in the list.
int Vect_line_distance(const struct line_pnts *, double, double, double, int, double *, double *, double *, double *, double *, double *)
Calculate distance of point to line.
plus_t * isles
1st generation interior islands
double Vect_points_distance(double, double, double, double, double, double, int)
Calculate distance of 2 points.
int n_values
Number of items in the list.
struct bound_box * box
Array of bounding boxes.
int G_begin_polygon_area_calculations(void)
Begin polygon area calculations.
int Vect_get_node_coor(const struct Map_info *, int, double *, double *, double *)
Get node coordinates.
int Vect_find_area(struct Map_info *Map, double x, double y)
Find the nearest area.
double * x
Array of X coordinates.
int Vect_select_lines_by_box(struct Map_info *, const struct bound_box *, int, struct boxlist *)
Select lines with bounding boxes by box.
Feature geometry info - coordinates.
Basic topology-related info.
void Vect_destroy_list(struct ilist *)
Frees all memory associated with a struct ilist, including the struct itself.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
int Vect_find_line_list(struct Map_info *map, double ux, double uy, double uz, int type, double maxdist, int with_z, const struct ilist *exclude, struct ilist *found)
Find the nearest line(s).
int Vect_get_isle_points(const struct Map_info *, int, struct line_pnts *)
Returns polygon array of points for given isle.
struct Plus_head plus
Plus info (topology, version, ...)
int Vect_get_isle_box(const struct Map_info *, int, struct bound_box *)
Get bounding box of isle.
plus_t n_isles
Number of islands inside.
#define PORT_DOUBLE_MAX
Limits for portable types.
double * y
Array of Y coordinates.
int Vect_find_node(struct Map_info *Map, double ux, double uy, double uz, double maxdist, int with_z)
Find the nearest node.
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
int Vect_find_island(struct Map_info *Map, double x, double y)
Find the nearest island.
int Vect_list_append(struct ilist *, int)
Append new item to the end of list if not yet present.
List of bounding boxes with id.
int * value
Array of values.
struct boxlist * Vect_new_boxlist(int)
Creates and initializes a struct boxlist.
int Vect_read_line(const struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int G_debug(int, const char *,...) __attribute__((format(printf
int Vect_find_line(struct Map_info *map, double ux, double uy, double uz, int type, double maxdist, int with_z, int exclude)
Find the nearest line.
double G_area_of_polygon(const double *, const double *, int)
Area in square meters of polygon.