Return a line segment between specified distances along a LineString. Negative distance values are taken as measured in the reverse direction from the end of the geometry. Out-of-range index values are handled by clamping them to the valid range of values. If the start distance equ
(geom, start_dist, end_dist, normalized=False)
| 540 | |
| 541 | |
| 542 | def substring(geom, start_dist, end_dist, normalized=False): |
| 543 | """Return a line segment between specified distances along a LineString. |
| 544 | |
| 545 | Negative distance values are taken as measured in the reverse |
| 546 | direction from the end of the geometry. Out-of-range index |
| 547 | values are handled by clamping them to the valid range of values. |
| 548 | |
| 549 | If the start distance equals the end distance, a Point is returned. |
| 550 | |
| 551 | If the start distance is actually beyond the end distance, then the |
| 552 | reversed substring is returned such that the start distance is |
| 553 | at the first coordinate. |
| 554 | |
| 555 | Parameters |
| 556 | ---------- |
| 557 | geom : LineString |
| 558 | The geometry to get a substring of. |
| 559 | start_dist : float |
| 560 | The distance along `geom` of the start of the substring. |
| 561 | end_dist : float |
| 562 | The distance along `geom` of the end of the substring. |
| 563 | normalized : bool, False |
| 564 | Whether the distance parameters are interpreted as a |
| 565 | fraction of the geometry's length. |
| 566 | |
| 567 | Returns |
| 568 | ------- |
| 569 | Union[Point, LineString] |
| 570 | The substring between `start_dist` and `end_dist` or a Point |
| 571 | if they are at the same location. |
| 572 | |
| 573 | Raises |
| 574 | ------ |
| 575 | TypeError |
| 576 | If `geom` is not a LineString. |
| 577 | |
| 578 | Examples |
| 579 | -------- |
| 580 | >>> from shapely.geometry import LineString |
| 581 | >>> from shapely.ops import substring |
| 582 | >>> ls = LineString((i, 0) for i in range(6)) |
| 583 | >>> ls.wkt |
| 584 | 'LINESTRING (0 0, 1 0, 2 0, 3 0, 4 0, 5 0)' |
| 585 | >>> substring(ls, start_dist=1, end_dist=3).wkt |
| 586 | 'LINESTRING (1 0, 2 0, 3 0)' |
| 587 | >>> substring(ls, start_dist=3, end_dist=1).wkt |
| 588 | 'LINESTRING (3 0, 2 0, 1 0)' |
| 589 | >>> substring(ls, start_dist=1, end_dist=-3).wkt |
| 590 | 'LINESTRING (1 0, 2 0)' |
| 591 | >>> substring(ls, start_dist=0.2, end_dist=-0.6, normalized=True).wkt |
| 592 | 'LINESTRING (1 0, 2 0)' |
| 593 | |
| 594 | Returning a `Point` when `start_dist` and `end_dist` are at the |
| 595 | same location. |
| 596 | |
| 597 | >>> substring(ls, 2.5, -2.5).wkt |
| 598 | 'POINT (2.5 0)' |
| 599 |
searching dependent graphs…