100 const double *
z,
int n)
107 for (i = 0; i < n; i++) {
182 if (index < 0 || index > Points->
n_points - 1)
184 _(
"Index out of range in"));
190 for (n = Points->
n_points; n > index; n--) {
191 Points->
x[n] = Points->
x[n - 1];
192 Points->
y[n] = Points->
y[n - 1];
193 Points->
z[n] = Points->
z[n - 1];
196 Points->
x[index] =
x;
197 Points->
y[index] =
y;
198 Points->
z[index] =
z;
215 if (index < 0 || index > Points->
n_points - 1)
217 _(
"Index out of range in"));
223 for (n = index; n < Points->
n_points - 1; n++) {
224 Points->
x[n] = Points->
x[n + 1];
225 Points->
y[n] = Points->
y[n + 1];
226 Points->
z[n] = Points->
z[n + 1];
246 double *
x,
double *
y,
double *
z)
248 if (index < 0 || index > Points->
n_points - 1)
250 _(
"Index out of range in"));
253 *x = Points->
x[index];
255 *y = Points->
y[index];
257 *z = Points->
z[index];
287 for (i = 1; i < Points->
n_points; i++) {
288 if (Points->
x[i] != Points->
x[j - 1] ||
289 Points->
y[i] != Points->
y[j - 1]
290 || Points->
z[i] != Points->
z[j - 1]) {
291 Points->
x[j] = Points->
x[i];
292 Points->
y[j] = Points->
y[i];
293 Points->
z[j] = Points->
z[i];
351 for (i = 0; i < an; i++) {
352 Points->
x[on + i] = APoints->
x[i];
353 Points->
y[on + i] = APoints->
y[i];
354 Points->
z[on + i] = APoints->
z[i];
358 for (i = 0; i < an; i++) {
359 Points->
x[on + i] = APoints->
x[an - i - 1];
360 Points->
y[on + i] = APoints->
y[an - i - 1];
361 Points->
z[on + i] = APoints->
z[an - i - 1];
388 for (i = 0; i < *n; i++) {
416 double *
x,
double *
y,
double *
z,
double *angle,
420 double dist = 0, length;
421 double xp = 0, yp = 0, zp = 0, dx = 0, dy = 0, dz = 0, dxy =
424 G_debug(3,
"Vect_point_on_line(): distance = %f", distance);
425 if ((distance < 0) || (Points->
n_points < 2))
430 G_debug(3,
" length = %f", length);
431 if (distance < 0 || distance > length) {
432 G_debug(3,
" -> outside line");
442 dx = Points->
x[1] - Points->
x[0];
443 dy = Points->
y[1] - Points->
y[0];
444 dz = Points->
z[1] - Points->
z[0];
448 else if (distance == length) {
450 xp = Points->
x[np - 1];
451 yp = Points->
y[np - 1];
452 zp = Points->
z[np - 1];
453 dx = Points->
x[np - 1] - Points->
x[np - 2];
454 dy = Points->
y[np - 1] - Points->
y[np - 2];
455 dz = Points->
z[np - 1] - Points->
z[np - 2];
460 for (j = 0; j < Points->
n_points - 1; j++) {
463 dx = Points->
x[j + 1] - Points->
x[j];
464 dy = Points->
y[j + 1] - Points->
y[j];
465 dz = Points->
z[j + 1] - Points->
z[j];
467 dxyz = hypot(dxy, dz);
470 if (dist >= distance) {
471 rest = distance - dist + dxyz;
474 xp = Points->
x[j] + k * dx;
475 yp = Points->
y[j] + k * dy;
476 zp = Points->
z[j] + k * dz;
492 *angle = atan2(dy, dx);
496 *slope = atan2(dz, dxy);
523 double x1, y1, z1, x2, y2, z2;
525 G_debug(3,
"Vect_line_segment(): start = %f, end = %f, n_points = %d",
547 G_debug(3,
" -> seg1 = %d seg2 = %d", seg1, seg2);
549 if (seg1 == 0 || seg2 == 0) {
550 G_warning(
_(
"Segment outside line, no segment created"));
556 for (i = seg1; i < seg2; i++) {
579 double dx, dy, dz, len = 0;
584 for (j = 0; j < Points->
n_points - 1; j++) {
585 dx = Points->
x[j + 1] - Points->
x[j];
586 dy = Points->
y[j + 1] - Points->
y[j];
587 dz = Points->
z[j + 1] - Points->
z[j];
588 len += hypot(hypot(dx, dy), dz);
607 double dx, dy, dz, dxy, len = 0;
614 for (j = 0; j < Points->
n_points - 1; j++) {
618 Points->
x[j + 1], Points->
y[j + 1]);
620 dx = Points->
x[j + 1] - Points->
x[j];
621 dy = Points->
y[j + 1] - Points->
y[j];
625 dz = Points->
z[j + 1] - Points->
z[j];
626 len += hypot(dxy, dz);
652 double ux,
double uy,
double uz,
654 double *px,
double *py,
double *pz,
655 double *dist,
double *spdist,
double *lpdist)
660 double tpx, tpy, tpz, tdist, tspdist, tlpdist = 0;
670 points->
y[0], points->
z[0],
671 points->
x[0], points->
y[0],
677 tdist = sqrt(distance);
687 points->
y[0], points->
z[0],
688 points->
x[1], points->
y[1],
693 for (i = 1; i < n_points - 1; i++) {
695 points->
x[i], points->
y[i],
699 points->
z[i + 1], with_z,
702 if (new_dist < distance) {
710 points->
x[segment - 1],
711 points->
y[segment - 1],
712 points->
z[segment - 1],
715 points->
z[segment], with_z,
716 &tpx, &tpy, &tpz, &tspdist,
722 for (i = 0; i < segment - 1; i++) {
723 dx = points->
x[i + 1] - points->
x[i];
724 dy = points->
y[i + 1] - points->
y[i];
726 dz = points->
z[i + 1] - points->
z[i];
730 tlpdist += hypot(hypot(dx, dy), dz);
734 tdist = sqrt(distance);
773 double ux,
double uy,
double uz,
775 double *px,
double *py,
double *pz,
776 double *dist,
double *spdist,
782 double tpx, tpy, tpz, ttpx, ttpy, ttpz;
783 double tdist, tspdist, tlpdist = 0, tlpdistseg;
793 distance =
G_distance(ux, uy, points->
x[0], points->
y[0]);
795 distance = hypot(distance, uz - points->
z[0]);
808 points->
y[0], points->
z[0],
809 points->
x[1], points->
y[1],
810 points->
z[1], with_z,
816 distance = hypot(distance, uz - tpz);
820 for (i = 1; i < n_points - 1; i++) {
822 points->
x[i], points->
y[i],
826 points->
z[i + 1], with_z,
832 new_dist = hypot(new_dist, uz - ttpz);
834 if (new_dist < distance) {
844 tspdist =
G_distance(points->
x[segment - 1], points->
y[segment - 1],
847 dz = points->
z[segment - 1] - tpz;
848 tspdist += hypot(tspdist, dz);
854 for (i = 0; i < segment - 1; i++) {
856 points->
x[i + 1], points->
y[i + 1]);
859 dz = points->
z[i + 1] - points->
z[i];
860 tlpdistseg += hypot(tlpdistseg, dz);
863 tlpdist += tlpdistseg;
899 double x2,
double y2,
double z2,
910 return hypot(hypot(dx, dy), dz);
912 return hypot(dx, dy);
939 for (i = 0; i < np; i++) {
944 Points->
x[i] = Points->
x[j];
945 Points->
y[i] = Points->
y[j];
946 Points->
z[i] = Points->
z[j];
974 G_debug(3,
"Vect_get_line_cat: display line %d, ltype %d, cat %d", line,
#define GV_FORWARD
Line direction indicator forward/backward.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int alloc_points
Allocated space for points.
void Vect_line_box(const struct line_pnts *Points, struct bound_box *Box)
Get bounding box of line.
int Vect_get_num_line_points(const struct line_pnts *Points)
Get number of line points.
float Box[8][3]
Vertices for box.
struct line_pnts * Vect_new_line_struct()
Creates and initializes a line_pnts structure.
int dig_line_box(const struct line_pnts *, struct bound_box *)
int n_points
Number of points.
void G_free(void *)
Free allocated memory.
int Vect_line_prune_thresh(struct line_pnts *Points, double threshold)
Remove points in threshold.
void Vect_destroy_line_struct(struct line_pnts *p)
Frees all memory associated with a line_pnts structure, including the structure itself.
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.
int Vect_line_segment(const struct line_pnts *InPoints, double start, double end, struct line_pnts *OutPoints)
Create line segment.
double Vect_line_length(const struct line_pnts *Points)
Calculate line length, 3D-length in case of 3D vector line.
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_append_points(struct line_pnts *Points, const struct line_pnts *APoints, int direction)
Appends points to the end of a line.
double * x
Array of X coordinates.
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.
Feature geometry info - coordinates.
void Vect_line_reverse(struct line_pnts *Points)
Reverse the order of vertices.
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...
double G_geodesic_distance(double, double, double, double)
Calculates geodesic distance.
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 * cat
Array of categories.
double dig_distance2_point_to_line(double, double, double, double, double, double, double, double, double, int, double *, double *, double *, double *, int *)
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 dig_alloc_points(struct line_pnts *, int)
allocate room for 'num' X and Y arrays in struct line_pnts
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.
struct line_pnts * Vect__new_line_struct(void)
Creates and initializes a struct line_pnts (internal use only)
double * y
Array of Y coordinates.
int int G_begin_distance_calculations(void)
Begin distance calculations.
int Vect_line_prune(struct line_pnts *Points)
Remove duplicate points, i.e. zero length segments.
struct line_cats * Vect_new_cats_struct(void)
Creates and initializes line_cats structure.
void G_warning(const char *,...) __attribute__((format(printf
int Vect_get_line_cat(const struct Map_info *Map, int line, int field)
Fetches FIRST category number for given vector line and field.
double * z
Array of Z coordinates.
double Vect_points_distance(double x1, double y1, double z1, double x2, double y2, double z2, int with_z)
Calculate distance of 2 points.
double G_distance(double, double, double, double)
Returns distance in meters.
int Vect_line_delete_point(struct line_pnts *Points, int index)
Delete point at given index and move all points above down.
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_reset_line(struct line_pnts *Points)
Reset line.
double Vect_line_geodesic_length(const struct line_pnts *Points)
Calculate line length.
int Vect_read_line(const struct Map_info *, struct line_pnts *, struct line_cats *, int)
Read vector feature (topological level required)
int dig_prune(struct line_pnts *, double)
int G_debug(int, const char *,...) __attribute__((format(printf
int Vect_cat_get(const struct line_cats *, int, int *)
Get first found category of given field.