18 static struct _region {
19 double center_easting;
20 double center_northing;
28 static struct _state {
36 static struct robject *draw_line_vertices(
void);
40 static struct robject *robj_alloc(
int,
int);
42 static double dist_in_px(
double);
43 static void en_to_xy(
double,
double,
int *,
int *);
44 static void draw_arrow(
int,
int,
int,
int,
double,
int,
int,
61 double center_easting,
62 double center_northing,
int map_width,
63 int map_height,
double map_res)
71 region.center_easting = center_easting;
72 region.center_northing = center_northing;
73 region.map_width = map_width;
74 region.map_height = map_height;
75 region.map_res = map_res;
76 region.map_west = center_easting - (map_width / 2.) * map_res;
77 region.map_north = center_northing + (map_height / 2.) * map_res;
81 state.nitems_alloc = 1000;
91 for (i = 0; i < nfeat; i++) {
93 draw_area(Map,
fid, list_obj);
100 G_debug(1,
"Vedit_render_map(): region: w=%f, e=%f, s=%f, n=%f nlines=%d",
101 box->
W, box->
E, box->
S, box->
N, nfeat);
104 for (i = 0; i <
list->n_values; i++) {
106 robj = draw_line(Map,
fid, draw_flag);
109 list_append(list_obj, robj);
114 robj = draw_line_vertices();
117 list_append(list_obj, robj);
121 draw_line_nodes(Map,
fid, draw_flag, list_obj);
125 draw_line_dir(list_obj,
fid);
133 G_debug(1,
"Vedit_render_map(): -> nitems = %d", list_obj->
nitems);
143 struct robject *draw_line(
struct Map_info *Map,
int line,
int draw_flag)
168 if (left == 0 && right == 0) {
172 else if (left > 0 && right > 0) {
194 else if (cret == 0) {
204 G_debug(3,
" draw_line(): type=%d rtype=%d npoints=%d draw=%d",
state.type,
205 obj->
type,
state.Points->n_points, draw);
215 robj_points(obj,
state.Points);
223 void en_to_xy(
double east,
double north,
int *
x,
int *
y)
227 w = region.center_easting - (region.map_width / 2) * region.map_res;
228 n = region.center_northing + (region.map_height / 2) * region.map_res;
231 *
x = (east - w) / region.map_res;
233 *
y = (n - north) / region.map_res;
241 void draw_line_nodes(
struct Map_info *Map,
int line,
int draw_flag,
255 for (i = 0; i <
sizeof(nodes) /
sizeof(
int); i++) {
273 robj = robj_alloc(
type, 1);
274 en_to_xy(east, north, &
x, &y);
279 list_append(
list, robj);
288 if (
list->nitems >=
state.nitems_alloc) {
289 state.nitems_alloc += 1000;
314 struct robject *draw_line_vertices(
void)
323 for (i = 1; i <
state.Points->n_points - 1; i++) {
324 en_to_xy(
state.Points->x[i],
state.Points->y[i], &
x, &y);
340 double dist, angle, pos;
349 G_debug(5,
" draw_line_dir() line=%d", line);
351 if (dist_in_px(dist) >= limit) {
353 pos = (narrows + 1) * 8 * limit * region.map_res;
360 en_to_xy(e, n, &x0, &y0);
363 pos - 3 * size * region.map_res, &e, &n,
368 en_to_xy(e, n, &x1, &y1);
370 draw_arrow(x0, y0, x1, y1, angle, size, line,
list);
384 en_to_xy(e, n, &x0, &y0);
387 dist - 3 * size * region.map_res, &e, &n,
390 en_to_xy(e, n, &x1, &y1);
392 draw_arrow(x0, y0, x1, y1, angle, size, line,
list);
404 double dist_in_px(
double dist)
408 en_to_xy(region.map_west + dist, region.map_north, &
x, &y);
416 void draw_arrow(
int x0,
int y0,
int x1,
int y1,
double angle,
int size,
425 angle_symb = angle -
M_PI / 2.;
426 robj->
point[0].
x = (int)x1 + size * cos(angle_symb);
427 robj->
point[0].
y = (int)y1 - size * sin(angle_symb);
432 angle_symb =
M_PI / 2. + angle;
433 robj->
point[2].
x = (int)x1 + size * cos(angle_symb);
434 robj->
point[2].
y = (int)y1 - size * sin(angle_symb);
436 list_append(
list, robj);
444 int i, centroid, isle;
466 robj_points(robj,
state.Points);
467 list_append(
list, robj);
471 for (i = 0; i < num_isles; i++) {
479 robj_points(robj, ipoints);
480 list_append(
list, robj);
494 for (i = 0; i < points->
n_points; i++) {
495 en_to_xy(points->
x[i], points->
y[i], &
x, &y);
void G_free(void *)
Free allocated memory.
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.
int Vect_get_line_nodes(struct Map_info *, int, int *, int *)
Get line nodes.
int Vect_get_node_coor(struct Map_info *, int, double *, double *, double *)
Get node coordinates.
double Vect_line_length(const struct line_pnts *)
Calculate line length, 3D-length in case of 3D vector line.
int Vect_area_alive(struct Map_info *, int)
Check if area is alive or dead (topological level required)
int Vect_point_on_line(const struct line_pnts *, double, double *, double *, double *, double *, double *)
Find point on line in the specified distance.
int Vect_get_line_type(struct Map_info *, int)
Get line type.
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.
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_centroid_area(struct Map_info *, int)
Get area id the centroid is within.
int Vect_isle_alive(struct Map_info *, int)
Check if isle is alive or dead (topological level required)
int Vect_get_area_isle(struct Map_info *, int, int)
Returns isle id for area.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int Vect_get_area_num_isles(struct Map_info *, int)
Returns number of isles for given area.
int Vect_line_alive(struct Map_info *, int)
Check if feature is alive or dead (topological level required)
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_node_n_lines(struct Map_info *, int)
Get number of lines for node.
int Vect_get_area_centroid(struct Map_info *, int)
Returns centroid id for given area.
int Vect_get_line_areas(struct Map_info *, int, int *, int *)
Get area id on the left and right side of the boundary.
#define GV_POINT
Feature types used in memory on run time (may change)
List of bounding boxes with id.
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
double * x
Array of X coordinates.
int n_points
Number of points.
struct robject_list * Vedit_render_map(struct Map_info *Map, struct bound_box *box, int draw_flag, double center_easting, double center_northing, int map_width, int map_height, double map_res)
Render vector features into list.