23 #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);
57 double maxdist,
int with_z)
63 double cur_dist, dist;
65 G_debug(3,
"Vect_find_node() for %f %f %f maxdist = %f", ux, uy, uz,
84 G_debug(3,
" %d nodes in box", nnodes);
92 for (i = 0; i < nnodes; i++) {
95 if (dist < cur_dist) {
100 G_debug(3,
" nearest node %d in distance %f", NList->
value[node],
104 if (cur_dist <= maxdist)
105 return (NList->
value[node]);
127 int type,
double maxdist,
int with_z,
int exclude)
130 struct ilist *exclude_list;
160 int type,
double maxdist,
int with_z,
161 const struct ilist *exclude,
struct ilist *found)
169 static int first_time = 1;
173 G_debug(3,
"Vect_find_line_list() for %f %f %f type = %d maxdist = %f", ux,
174 uy, uz, type, maxdist);
185 box.
N = uy + maxdist;
186 box.
S = uy - maxdist;
187 box.
E = ux + maxdist;
188 box.
W = ux - maxdist;
190 box.
T = uz + maxdist;
191 box.
B = uz - maxdist;
204 for (i = 0; i < List->
n_values; i++) {
207 G_debug(3,
" line = %d exclude", line);
222 G_debug(3,
" line = %d distance = %f", line, new_dist);
224 if (found && new_dist <= maxdist) {
228 if ((++gotone == 1) || (new_dist <= cur_dist)) {
229 if (new_dist == cur_dist) {
240 G_debug(3,
"min distance found = %f", cur_dist);
241 if (cur_dist > maxdist)
260 int i, j, ret, area, isle;
263 static BOX_SIZE *size_list;
264 static int alloc_size_list = 0;
268 G_debug(3,
"Vect_find_area() x = %f y = %f",
x, y);
272 alloc_size_list = 10;
273 size_list =
G_malloc(alloc_size_list *
sizeof(BOX_SIZE));
295 if (alloc_size_list < List->n_values) {
297 size_list =
G_realloc(size_list, alloc_size_list *
sizeof(BOX_SIZE));
300 for (i = 0; i < List->
n_values; i++) {
301 size_list[i].i = List->
id[i];
303 size_list[i].box = List->
box[i];
304 size_list[i].size = (box.
N - box.
S) * (box.
E - box.
W);
309 if (size_list[1].size < size_list[0].size) {
310 size_list[0].i = List->
id[1];
311 size_list[1].i = List->
id[0];
312 size_list[0].box = List->
box[1];
313 size_list[1].box = List->
box[0];
317 qsort(size_list, List->
n_values,
sizeof(BOX_SIZE), sort_by_size);
319 for (i = 0; i < List->
n_values; i++) {
320 area = size_list[i].i;
324 G_debug(3,
" area = %d Vect_point_in_area_outer_ring() = %d", area,
329 Area = Plus->
Area[area];
330 for (j = 0; j < Area->
n_isles; j++) {
331 isle = Area->
isles[j];
335 G_debug(3,
" area = %d Vect_point_in_island() = %d", area,
364 int i, ret, island, current, current_size, size;
365 static int first = 1;
372 G_debug(3,
"Vect_find_island() x = %f y = %f",
x,
y);
392 for (i = 0; i < List->
n_values; i++) {
393 island = List->
id[i];
398 if (current_size == -1) {
409 if (size < current_size) {
double G_area_of_polygon(const double *, const double *, int)
Area in square meters of polygon.
int G_debug(int, const char *,...) __attribute__((format(printf
int G_begin_polygon_area_calculations(void)
Begin polygon area calculations.
int Vect_get_node_coor(struct Map_info *, int, double *, double *, double *)
Get node coordinates.
int Vect_select_isles_by_box(struct Map_info *, const struct bound_box *, struct boxlist *)
Select isles with bounding boxes by box.
int Vect_point_in_island(double, double, struct Map_info *, int, struct bound_box *)
Determines if a point (X,Y) is inside an island.
struct boxlist * Vect_new_boxlist(int)
Creates and initializes a struct boxlist.
void Vect_destroy_boxlist(struct boxlist *)
Frees all memory associated with a struct boxlist, including the struct itself.
int Vect_get_isle_points(struct Map_info *, int, struct line_pnts *)
Returns polygon array of points for given isle.
void Vect_destroy_list(struct ilist *)
Frees all memory associated with a struct ilist, including the struct itself.
int Vect_list_append(struct ilist *, int)
Append new item to the end of list if not yet present.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int Vect_line_distance(const struct line_pnts *, double, double, double, int, double *, double *, double *, double *, double *, double *)
Calculate distance of point to line.
struct ilist * Vect_new_list(void)
Creates and initializes a struct ilist.
double Vect_points_distance(double, double, double, double, double, double, int)
Calculate distance of 2 points.
int Vect_point_in_area_outer_ring(double, double, struct Map_info *, int, struct bound_box *)
Determines if a point (X,Y) is inside an area outer ring. Islands are not considered.
int Vect_select_areas_by_box(struct Map_info *, const struct bound_box *, struct boxlist *)
Select areas with bounding boxes by box.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
int Vect_select_lines_by_box(struct Map_info *, const struct bound_box *, int, struct boxlist *)
Select lines with bounding boxes by box.
int Vect_get_isle_box(struct Map_info *, int, struct bound_box *)
Get bounding box of isle.
int Vect_val_in_list(const struct ilist *, int)
Find a given item in the list.
int Vect_reset_list(struct ilist *)
Reset ilist structure.
int Vect_select_nodes_by_box(struct Map_info *, const struct bound_box *, struct ilist *)
Select nodes by box.
#define PORT_DOUBLE_MAX
Limits for portable types.
struct Plus_head plus
Plus info (topology, version, ...)
plus_t n_isles
Number of islands inside.
plus_t * isles
1st generation interior islands
Basic topology-related info.
struct P_area ** Area
Array of areas.
List of bounding boxes with id.
struct bound_box * box
Array of bounding boxes.
int n_values
Number of items in the list.
int * value
Array of values.
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
int n_points
Number of points.
int Vect_find_area(struct Map_info *Map, double x, double y)
Find the nearest area.
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.
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_find_node(struct Map_info *Map, double ux, double uy, double uz, double maxdist, int with_z)
Find the nearest node.
int Vect_find_island(struct Map_info *Map, double x, double y)
Find the nearest island.