100 const double *
y,
const double *
z,
int n)
107 for (i = 0; i < n; i++) {
181 if (index < 0 || index > Points->
n_points - 1)
183 _(
"Index out of range in"));
189 for (n = Points->
n_points; n > index; n--) {
190 Points->
x[n] = Points->
x[n - 1];
191 Points->
y[n] = Points->
y[n - 1];
192 Points->
z[n] = Points->
z[n - 1];
195 Points->
x[index] =
x;
196 Points->
y[index] =
y;
197 Points->
z[index] =
z;
214 if (index < 0 || index > Points->
n_points - 1)
216 _(
"Index out of range in"));
222 for (n = index; n < Points->
n_points - 1; n++) {
223 Points->
x[n] = Points->
x[n + 1];
224 Points->
y[n] = Points->
y[n + 1];
225 Points->
z[n] = Points->
z[n + 1];
245 double *
y,
double *
z)
247 if (index < 0 || index > Points->
n_points - 1)
248 G_fatal_error(
"Vect_line_get_point(): %s",
_(
"Index out of range in"));
251 *
x = Points->
x[index];
253 *
y = Points->
y[index];
255 *
z = Points->
z[index];
285 for (i = 1; i < Points->
n_points; i++) {
286 if (Points->
x[i] != Points->
x[j - 1] ||
287 Points->
y[i] != Points->
y[j - 1] ||
288 Points->
z[i] != Points->
z[j - 1]) {
289 Points->
x[j] = Points->
x[i];
290 Points->
y[j] = Points->
y[i];
291 Points->
z[j] = Points->
z[i];
336 const struct line_pnts *APoints,
int direction)
349 for (i = 0; i < an; i++) {
350 Points->
x[on + i] = APoints->
x[i];
351 Points->
y[on + i] = APoints->
y[i];
352 Points->
z[on + i] = APoints->
z[i];
356 for (i = 0; i < an; i++) {
357 Points->
x[on + i] = APoints->
x[an - i - 1];
358 Points->
y[on + i] = APoints->
y[an - i - 1];
359 Points->
z[on + i] = APoints->
z[an - i - 1];
385 for (i = 0; i < *n; i++) {
414 double *
x,
double *
y,
double *
z,
double *angle,
418 double dist = 0, length;
419 double xp = 0, yp = 0, zp = 0, dx = 0, dy = 0, dz = 0, dxy = 0, dxyz, k,
422 G_debug(3,
"Vect_point_on_line(): distance = %f", distance);
423 if ((distance < 0) || (Points->
n_points < 2))
428 G_debug(3,
" length = %f", length);
429 if (distance < 0 || distance > length) {
430 G_debug(3,
" -> outside line");
440 dx = Points->
x[1] - Points->
x[0];
441 dy = Points->
y[1] - Points->
y[0];
442 dz = Points->
z[1] - Points->
z[0];
446 else if (distance == length) {
448 xp = Points->
x[np - 1];
449 yp = Points->
y[np - 1];
450 zp = Points->
z[np - 1];
451 dx = Points->
x[np - 1] - Points->
x[np - 2];
452 dy = Points->
y[np - 1] - Points->
y[np - 2];
453 dz = Points->
z[np - 1] - Points->
z[np - 2];
458 for (j = 0; j < Points->
n_points - 1; j++) {
461 dx = Points->
x[j + 1] - Points->
x[j];
462 dy = Points->
y[j + 1] - Points->
y[j];
463 dz = Points->
z[j + 1] - Points->
z[j];
465 dxyz = hypot(dxy, dz);
468 if (dist >= distance) {
469 rest = distance - dist +
473 xp = Points->
x[j] + k * dx;
474 yp = Points->
y[j] + k * dy;
475 zp = Points->
z[j] + k * dz;
491 *angle = atan2(dy, dx);
495 *slope = atan2(dz, dxy);
522 double x1, y1, z1, x2, y2, z2;
524 G_debug(3,
"Vect_line_segment(): start = %f, end = %f, n_points = %d",
546 G_debug(3,
" -> seg1 = %d seg2 = %d", seg1, seg2);
548 if (seg1 == 0 || seg2 == 0) {
549 G_warning(
_(
"Segment outside line, no segment created"));
555 for (i = seg1; i < seg2; i++) {
578 double dx, dy, dz, len = 0;
583 for (j = 0; j < Points->
n_points - 1; j++) {
584 dx = Points->
x[j + 1] - Points->
x[j];
585 dy = Points->
y[j + 1] - Points->
y[j];
586 dz = Points->
z[j + 1] - Points->
z[j];
587 len += hypot(hypot(dx, dy), dz);
605 double dx, dy, dz, dxy, len = 0;
612 for (j = 0; j < Points->
n_points - 1; j++) {
615 Points->
x[j + 1], Points->
y[j + 1]);
617 dx = Points->
x[j + 1] - Points->
x[j];
618 dy = Points->
y[j + 1] - Points->
y[j];
622 dz = Points->
z[j + 1] - Points->
z[j];
623 len += hypot(dxy, dz);
649 double uz,
int with_z,
double *px,
double *py,
650 double *pz,
double *dist,
double *spdist,
double *lpdist)
655 double tpx, tpy, tpz, tdist, tspdist, tlpdist = 0;
664 ux, uy, uz, points->
x[0], points->
y[0], points->
z[0], points->
x[0],
669 tdist = sqrt(distance);
677 ux, uy, uz, points->
x[0], points->
y[0], points->
z[0], points->
x[1],
681 for (i = 1; i <
n_points - 1; i++) {
683 ux, uy, uz, points->
x[i], points->
y[i], points->
z[i],
684 points->
x[i + 1], points->
y[i + 1], points->
z[i + 1], with_z,
686 if (new_dist < distance) {
694 ux, uy, uz, points->
x[segment - 1], points->
y[segment - 1],
695 points->
z[segment - 1], points->
x[segment], points->
y[segment],
696 points->
z[segment], with_z, &tpx, &tpy, &tpz, &tspdist,
NULL);
701 for (i = 0; i < segment - 1; i++) {
702 dx = points->
x[i + 1] - points->
x[i];
703 dy = points->
y[i + 1] - points->
y[i];
705 dz = points->
z[i + 1] - points->
z[i];
709 tlpdist += hypot(hypot(dx, dy), dz);
713 tdist = sqrt(distance);
752 double uy,
double uz,
int with_z,
double *px,
753 double *py,
double *pz,
double *dist,
754 double *spdist,
double *lpdist)
759 double tpx, tpy, tpz, ttpx, ttpy, ttpz;
760 double tdist, tspdist, tlpdist = 0, tlpdistseg;
770 distance =
G_distance(ux, uy, points->
x[0], points->
y[0]);
772 distance = hypot(distance, uz - points->
z[0]);
784 ux, uy, uz, points->
x[0], points->
y[0], points->
z[0], points->
x[1],
785 points->
y[1], points->
z[1], with_z, &tpx, &tpy, &tpz,
NULL,
NULL);
789 distance = hypot(distance, uz - tpz);
793 for (i = 1; i <
n_points - 1; i++) {
795 ux, uy, uz, points->
x[i], points->
y[i], points->
z[i],
796 points->
x[i + 1], points->
y[i + 1], points->
z[i + 1], with_z,
801 new_dist = hypot(new_dist, uz - ttpz);
803 if (new_dist < distance) {
813 tspdist =
G_distance(points->
x[segment - 1], points->
y[segment - 1],
816 dz = points->
z[segment - 1] - tpz;
817 tspdist += hypot(tspdist, dz);
823 for (i = 0; i < segment - 1; i++) {
825 points->
x[i + 1], points->
y[i + 1]);
828 dz = points->
z[i + 1] - points->
z[i];
829 tlpdistseg += hypot(tlpdistseg, dz);
832 tlpdist += tlpdistseg;
867 double x2,
double y2,
double z2,
877 return hypot(hypot(dx, dy), dz);
879 return hypot(dx, dy);
905 for (i = 0; i < np; i++) {
910 Points->
x[i] = Points->
x[j];
911 Points->
y[i] = Points->
y[j];
912 Points->
z[i] = Points->
z[j];
940 G_debug(3,
"Vect_get_line_cat: display line %d, ltype %d, cat %d", line,
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
double G_geodesic_distance(double, double, double, double)
Calculates geodesic distance.
double G_distance(double, double, double, double)
Returns distance in meters.
int G_debug(int, const char *,...) __attribute__((format(printf
int int G_begin_distance_calculations(void)
Begin distance calculations.
int Vect_cat_get(const struct line_cats *, int, int *)
Get first found category of given field.
int Vect_read_line(struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
#define GV_FORWARD
Line direction indicator forward/backward.
double dig_distance2_point_to_line(double, double, double, double, double, double, double, double, double, int, double *, double *, double *, double *, int *)
int dig_alloc_points(struct line_pnts *, int)
allocate room for 'num' X and Y arrays in struct line_pnts
int dig_prune(struct line_pnts *, double)
int dig_line_box(const struct line_pnts *, struct bound_box *)
float Box[8][3]
Vertices for box.
int Vect_line_prune_thresh(struct line_pnts *Points, double threshold)
Remove points in threshold.
int Vect_line_insert_point(struct line_pnts *Points, int index, double x, double y, double z)
Insert new point at index position and move all old points at that position and above up.
int Vect_line_geodesic_distance(const struct line_pnts *points, double ux, double uy, double uz, int with_z, double *px, double *py, double *pz, double *dist, double *spdist, double *lpdist)
Calculate geodesic distance of point to line in meters.
int Vect_line_segment(const struct line_pnts *InPoints, double start, double end, struct line_pnts *OutPoints)
Create line segment.
double Vect_line_geodesic_length(const struct line_pnts *Points)
Calculate line length.
int Vect_line_distance(const struct line_pnts *points, double ux, double uy, double uz, int with_z, double *px, double *py, double *pz, double *dist, double *spdist, double *lpdist)
Calculate distance of point to line.
int Vect_copy_xyz_to_pnts(struct line_pnts *Points, const double *x, const double *y, const double *z, int n)
Copy points from array to line_pnts structure.
void Vect_reset_line(struct line_pnts *Points)
Reset line.
int Vect_line_delete_point(struct line_pnts *Points, int index)
Delete point at given index and move all points above down.
int Vect_line_get_point(const struct line_pnts *Points, int index, double *x, double *y, double *z)
Get line point of given index.
int Vect_get_num_line_points(const struct line_pnts *Points)
Get number of line points.
int Vect_append_point(struct line_pnts *Points, double x, double y, double z)
Appends one point to the end of a line.
int Vect_point_on_line(const struct line_pnts *Points, double distance, double *x, double *y, double *z, double *angle, double *slope)
Find point on line in the specified distance.
void Vect_destroy_line_struct(struct line_pnts *p)
Frees all memory associated with a line_pnts structure, including the structure itself.
void Vect_line_box(const struct line_pnts *Points, struct bound_box *Box)
Get bounding box of line.
void Vect_line_reverse(struct line_pnts *Points)
Reverse the order of vertices.
int Vect_append_points(struct line_pnts *Points, const struct line_pnts *APoints, int direction)
Appends points to the end of a line.
struct line_pnts * Vect__new_line_struct(void)
Creates and initializes a struct line_pnts (internal use only)
double Vect_points_distance(double x1, double y1, double z1, double x2, double y2, double z2, int with_z)
Calculate distance of 2 points.
struct line_pnts * Vect_new_line_struct(void)
Creates and initializes a line_pnts structure.
double Vect_line_length(const struct line_pnts *Points)
Calculate line length, 3D-length in case of 3D vector line.
int Vect_copy_pnts_to_xyz(const struct line_pnts *Points, double *x, double *y, double *z, int *n)
Copy points from line structure to array.
int Vect_line_prune(struct line_pnts *Points)
Remove duplicate points, i.e. zero length segments.
int Vect_get_line_cat(struct Map_info *Map, int line, int field)
Fetches FIRST category number for given vector line and field.
int * field
Array of layers (fields)
int * cat
Array of categories.
Feature geometry info - coordinates.
double * y
Array of Y coordinates.
int alloc_points
Allocated space for points.
double * x
Array of X coordinates.
int n_points
Number of points.
double * z
Array of Z coordinates.