Utils¶
Module for internal utility functions to share between modules
| CLASS | DESCRIPTION |
|---|---|
PolylineEditor |
Allow simple polyline editing using indexes and slices |
Vector |
Simple Vector implementation that takes a start and end point (uses Spherical notation for theta and phi). |
| FUNCTION | DESCRIPTION |
|---|---|
box_on_point |
Build a rectangular box on a point |
center_circle |
Create a circle using a center point and a radius |
convert_schema |
Convert a Schema from one format to another |
export_project_lyrx |
Pull all layers from a project file and output them in a directory as lyrx files |
export_project_maps |
Pull all layers from a project file and output them in a directory as mapx files |
get_subtype_count |
Get the subtype counts for a Table or FeatureClass |
get_subtype_counts |
Get a mapping of subtype counts for all featureclasses that have subtypes in the provided Dataset |
iter_parts |
Get a part iterator for a Polyline |
iter_points |
Get a point iterator for a Polyline |
nat |
Natural sort key for use in string sorting |
patch_schema_rules |
Patch an exported Schema doc by re-linking attribute rules to table names |
print |
Print a message to the ArcGIS Pro message queue and stdout |
shortest_path |
Find the shortest path or paths given a source point, target point and network of Polylines |
split_at_points |
Split lines at provided points |
split_lines_at_points |
Split a Polyline or Sequence/Iterable of polylines at provided points |
two_point_circle |
Create a circle using a center point and an end point |
vector_at |
Get the vector of the line at the given point (p-delta -> p+delta) |
vectors_at |
Get the vector of the line at the given point (p-delta -> p+delta) |
PolylineEditor
¶
PolylineEditor(polyline: Polyline)
Allow simple polyline editing using indexes and slices
multipart polylines will be indexed on global point index,
[[p1: 3pts], [p2: 2pts]] -> [0, 1, 2, 3, 4]
^^p1^^^|^p2^^
-
Modules
Utils
PolylineEditor
| METHOD | DESCRIPTION |
|---|---|
align |
Adjust points of the polyline to be coincident with the target line of they are within |
append |
Append a point to the last part of the Polyline |
append_part |
Add a part to the polyline |
copy |
Return a copy of the current editor with the active polyline state as the original polyline |
count |
Get the count of points in the line that match the input point |
dedupe |
Remove all duplicate points in a line keeping last instance (returns the number of points removed) |
discard |
Silently remove points without raising an error if it doesn't exist |
extend |
Extend the last part of the polyline with the points |
generalize |
Generalize the polyline |
index |
Get the global index of the first instance of the specified point, raise a ValueError if the point is not in the Polyline |
insert |
Insert a point at the specified index |
intersections |
Iterable of Point Intersections between this line and the other |
merge_lines |
Merge a sequence of Polylines into one Polyline (uses |
move |
Move the polyline along a Vector |
orenent_with |
Alter the direction of the polyline to match the direction of the input line (only works for lines that overlap) |
pop |
Remove a point from a polyline at the specified index (default: -1) |
pop_part |
pop a part from the polyline (default: -1) |
project_as |
Project the polyline in the given reference |
remove |
Remove the fist occurrence of the point from the polyline |
reset |
Revert all changes to |
reverse |
Reverse the polyline parts and the points of each part of the polyline |
split_at_angle |
Split the polyline at points where the instantaneous angle (radians) is greater than the specified angle (radians) |
| ATTRIBUTE | DESCRIPTION |
|---|---|
centroid |
Centroid of the feature if it is within the feature (same as measure@50%)
TYPE:
|
first_point |
PointGeometry of the Polyline's firstPoint
TYPE:
|
last_point |
PointGeometry of the Polyline's lastPoint
TYPE:
|
original |
The original Polyline given to the PolylineEditor
TYPE:
|
part_editors |
Get PolylineEditors for each part in the line
TYPE:
|
parts |
A list of parts of the Polyline as Polylines (singlepart polylines will contain one part)
TYPE:
|
segments |
Get all 2-point segments that make up the line
TYPE:
|
true_centroid |
Center of gravity of the feature (not always in the line)
TYPE:
|
Source code in src/arcpie/utils.py
1072 1073 1074 | |
centroid
property
¶
centroid: PointGeometry
Centroid of the feature if it is within the feature (same as measure@50%)
first_point
property
writable
¶
first_point: PointGeometry
PointGeometry of the Polyline's firstPoint
part_editors
property
writable
¶
part_editors: list[PolylineEditor]
Get PolylineEditors for each part in the line
parts
property
writable
¶
parts: list[Polyline]
A list of parts of the Polyline as Polylines (singlepart polylines will contain one part)
true_centroid
property
¶
true_centroid: PointGeometry
Center of gravity of the feature (not always in the line)
align
¶
align(
line: Polyline | PolylineEditor,
*,
tolerance: float = 0.01,
) -> None
Adjust points of the polyline to be coincident with the target line of they are within tolerance units
If multiple points are within the tolerance, the closest is picked
Source code in src/arcpie/utils.py
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 | |
append
¶
append(point: Point | PointGeometry) -> None
Append a point to the last part of the Polyline
Source code in src/arcpie/utils.py
1304 1305 1306 1307 1308 1309 1310 1311 1312 | |
append_part
¶
append_part(part: Polyline | PolylineEditor) -> None
Add a part to the polyline
Source code in src/arcpie/utils.py
1397 1398 1399 1400 1401 1402 1403 1404 1405 | |
copy
¶
copy() -> PolylineEditor
Return a copy of the current editor with the active polyline state as the original polyline
Source code in src/arcpie/utils.py
1341 1342 1343 | |
count
¶
count(point: Point | PointGeometry) -> int
Get the count of points in the line that match the input point
Source code in src/arcpie/utils.py
1336 1337 1338 1339 | |
dedupe
¶
Remove all duplicate points in a line keeping last instance (returns the number of points removed)
Note
If a duplciate is found in a seperate part, it is not considered a duplicate and will be kept
setting keep to 'last' will remove duplicates from the end of the line first
Source code in src/arcpie/utils.py
1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 | |
discard
¶
discard(point: Point | PointGeometry) -> None
Silently remove points without raising an error if it doesn't exist
Source code in src/arcpie/utils.py
1349 1350 1351 1352 1353 1354 | |
extend
¶
extend(points: Iterable[Point | PointGeometry]) -> None
Extend the last part of the polyline with the points
Source code in src/arcpie/utils.py
1314 1315 1316 1317 1318 1319 1320 1321 1322 | |
generalize
¶
generalize(distance: float) -> None
Generalize the polyline
Source code in src/arcpie/utils.py
1393 1394 1395 | |
index
¶
index(
point: Point | PointGeometry,
start: SupportsIndex = 0,
stop: SupportsIndex | None = None,
) -> int
Get the global index of the first instance of the specified point, raise a ValueError if the point is not in the Polyline
Source code in src/arcpie/utils.py
1297 1298 1299 1300 1301 1302 | |
insert
¶
insert(
index: SupportsIndex, point: Point | PointGeometry
) -> None
Insert a point at the specified index
Note
Inserts the point at the global point index, whichever part that may be in
If you want to insert a point at a specific part index, use .parts to access the
part and then insert the point there. This does not apply to single part features since
the local part index is equal to the global index.
Source code in src/arcpie/utils.py
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 | |
intersections
¶
intersections(
other: Polyline | PolylineEditor,
) -> Iterator[PointGeometry]
Iterable of Point Intersections between this line and the other
Note: Intersections are de-duplicated and returned as PointGeometry objects
Source code in src/arcpie/utils.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 | |
merge_lines
classmethod
¶
merge_lines(lines: Iterable[Polyline]) -> Polyline
Merge a sequence of Polylines into one Polyline (uses union so each line becomes a part)
Example
lines = [[a,b,c,d], [e,f,g,h]]
new = PolylineEditor.merge_lines(lines)
new == Polyline([p1[a,b,c,d], p2[e,f,g,h]])
Source code in src/arcpie/utils.py
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 | |
move
¶
move(vec: Vector) -> None
Move the polyline along a Vector
Source code in src/arcpie/utils.py
1416 1417 1418 1419 1420 1421 | |
orenent_with
¶
orenent_with(line: Polyline | PolylineEditor) -> None
Alter the direction of the polyline to match the direction of the input line (only works for lines that overlap)
Source code in src/arcpie/utils.py
1429 1430 1431 1432 1433 1434 1435 1436 | |
pop
¶
pop(index: SupportsIndex = -1) -> PointGeometry
Remove a point from a polyline at the specified index (default: -1)
Source code in src/arcpie/utils.py
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 | |
pop_part
¶
pop_part(index: SupportsIndex = -1) -> Polyline
pop a part from the polyline (default: -1)
Source code in src/arcpie/utils.py
1407 1408 1409 1410 1411 1412 1413 1414 | |
project_as
¶
project_as(ref: SpatialReference | int) -> None
Project the polyline in the given reference
Source code in src/arcpie/utils.py
1423 1424 1425 1426 1427 | |
remove
¶
remove(point: Point | PointGeometry) -> None
Remove the fist occurrence of the point from the polyline
Source code in src/arcpie/utils.py
1345 1346 1347 | |
reset
¶
reset() -> None
Revert all changes to polyline and restore the original geometry
Source code in src/arcpie/utils.py
1381 1382 1383 | |
reverse
¶
reverse() -> None
Reverse the polyline parts and the points of each part of the polyline
Example
[[a, b], [c, d]] -> [[d, c], [b, a]][a, b, c, d] -> [d, c, b, a]
Source code in src/arcpie/utils.py
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 | |
split_at_angle
¶
split_at_angle(
ang: float,
units: Literal["degrees", "radians"] = "radians",
*,
tolerance: float = 0.1,
) -> list[Polyline]
Split the polyline at points where the instantaneous angle (radians) is greater than the specified angle (radians)
| PARAMETER | DESCRIPTION |
|---|---|
|
The target angle at a point to be split at
TYPE:
|
|
Specify the units of the provided angle and tolerance
TYPE:
|
|
+/- of target angle to trigger a split (default:
TYPE:
|
Source code in src/arcpie/utils.py
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
Vector
dataclass
¶
Vector(
tail: Point | PointGeometry,
head: Point | PointGeometry,
ref: SpatialReference | None = None,
)
Simple Vector implementation that takes a start and end point (uses Spherical notation for theta and phi).
If PointGeometries are passed as the head and tail points, the head
will inherit the reference of the tail
| ATTRIBUTE | DESCRIPTION |
|---|---|
x |
The X component of the vector
TYPE:
|
y |
The Y component of the vector
TYPE:
|
z |
The Z component of the vector
TYPE:
|
theta |
The angle between the vector and the x-axis
TYPE:
|
dist |
The magnitute of the vector (distance b/w start and end)
TYPE:
|
mid |
The midpoint of the vector along its magnitude
TYPE:
|
ref |
Ano optional spatial reference for all Vector geometry to inherit
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
translate |
Translate a point along the Vector (Vector tail is set to point location) |
reverse |
Reverse the Vector |
add |
Vector addition (LHS is origin) |
subtract |
Vector subtraction (LHS is origin) |
dot |
Dot product of two vectors (LHS is origin) |
cross |
Cross product of two vectors (LHS is origin) |
scale |
Scale a vector using a scalar |
angle |
Get angle between two vectors |
__rshift__ |
Implements |
__neg__ |
Implements unary |
__add__ |
Implements |
__sub__ |
Implements |
__xor__ |
Implements |
__mul__ |
Implements |
__matmul__ |
Implements |
mid_geom
property
¶
mid_geom: PointGeometry
Get a point geometry object for the vector midpoint (inherits reference from head/tail)
tail_geom
property
¶
tail_geom: PointGeometry
Get a point geometry object for the vector tail (start)
add
¶
Vector addition originating at LHS (+)
Source code in src/arcpie/utils.py
909 910 911 | |
angle
¶
Get the angle in radians between two vectors
Note: When checking angle against a null vector, 0 is returned
Source code in src/arcpie/utils.py
964 965 966 967 968 969 970 971 972 973 974 975 | |
cross
¶
Cross product of two vectors originating at LHS (*)
Source code in src/arcpie/utils.py
923 924 925 926 927 928 929 930 931 932 933 934 935 | |
dot
¶
Dot product of two vectors originating at LHS (@)
Source code in src/arcpie/utils.py
956 957 958 959 | |
norm
¶
norm() -> Vector
Normal vector originating at tail
Source code in src/arcpie/utils.py
902 903 904 | |
reverse
¶
reverse() -> Vector
Reversed vector
Source code in src/arcpie/utils.py
895 896 897 | |
scale
¶
scale(scale: Scalar) -> Vector
Scalar multiplication of vector (*)
Note: Scaling by Zero will return a null vector located at the vector tail
Source code in src/arcpie/utils.py
937 938 939 940 941 942 943 944 | |
subtract
¶
Vector subtraction originating at LHS (-)
Source code in src/arcpie/utils.py
916 917 918 | |
translate
¶
Translate the provided point along the vector direction. >>
The Point will be moved from its original location along the vector angle the provided distance.
The location of the Vector object is not taken into account, only angle and magnitude
| PARAMETER | DESCRIPTION |
|---|---|
|
The point to translate along the given vector
TYPE:
|
|
The distance to translate the point (default:
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Any
|
A translated Point/PointGeometry |
Example
trans_point = vec >> point
Source code in src/arcpie/utils.py
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 | |
box_on_point
¶
box_on_point(
center: Point | PointGeometry,
width: float,
height: float,
angle: float = 0.0,
ref: SpatialReference | None = None,
start: Literal["tl", "tr", "bl", "br"] = "tl",
) -> Polygon
Build a rectangular box on a point
| PARAMETER | DESCRIPTION |
|---|---|
|
The center point of the box
TYPE:
|
|
The width of the box
TYPE:
|
|
The height of the box
TYPE:
|
|
An angle to roatate the box by in radians (default: 0.0)
TYPE:
|
|
An optional spatial reference to apply to the output polygon
TYPE:
|
|
The corner of the box that should be the start point (default: 'tl')
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Polygon
|
A rectangular polygon (with provided ref or ref inhereted from center) |
Source code in src/arcpie/utils.py
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
center_circle
¶
center_circle(
center: Point | PointGeometry,
radius: float,
ref: SpatialReference | None = None,
) -> Polyline
Create a circle using a center point and a radius
| PARAMETER | DESCRIPTION |
|---|---|
|
The center of the circle
TYPE:
|
|
(float): The dist
TYPE:
|
|
(SpatialReference|None): The SpatialReference to use with the returned geometry
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Polyline
|
A Circular Polyline |
Note
If a PointGeometry are provided, it will be projected as the provided ref If no ref is provided, the shape will inherit the reference of the center
Reference resolution is as follows:
ref -> center.spatialReference
If no center reference can be found and no ref is provided, the returned geometry will have no reference
Source code in src/arcpie/utils.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 | |
convert_schema
¶
convert_schema(
schema: Dataset[Any] | Path | str,
to: Literal[
"JSON", "XLSX", "HTML", "PDF", "XML", "DYNAMIC_HTML"
] = "JSON",
) -> BytesIO
Convert a Schema from one format to another
| PARAMETER | DESCRIPTION |
|---|---|
|
Path to the schemafile or Dataset to convert |
|
Target format (default: 'JSON')
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
bytes
|
Raw bytes object containing the schema file
TYPE::
|
Source code in src/arcpie/utils.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
export_project_lyrx
¶
export_project_lyrx(
project: Project,
out_dir: Path,
*,
indent: int = 4,
sort: bool = False,
skip_empty: bool = True,
) -> None
Pull all layers from a project file and output them in a directory as lyrx files
| PARAMETER | DESCRIPTION |
|---|---|
|
The
TYPE:
|
|
The target directory for the layer files |
|
Indentation level of the ouput files (default: 4)
TYPE:
|
|
Sort the output file by key name (default: False)
TYPE:
|
|
Skips writing empty lyrx files for layers with no lyrx data (default: True)
TYPE:
|
Usage
>>> export_project_lyrx(arcpie.Project('<path/to/aprx>'), '<path/to/output_dir>')
Note
Output structure will match the structure of the project:
Map -> Group -> Layer
Where each level is a directory. Group Layers will have a directory entry with individual
files for each layer they contain, as well as a single layerfile that contains all their
child layers.
Source code in src/arcpie/utils.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
export_project_maps
¶
export_project_maps(
project: Project,
out_dir: Path | str,
*,
indent: int = 4,
sort: bool = False,
) -> None
Pull all layers from a project file and output them in a directory as mapx files
| PARAMETER | DESCRIPTION |
|---|---|
|
The
TYPE:
|
|
The target directory for the mapx files |
|
Indentation level of the ouput files (default: 4)
TYPE:
|
|
Sort the output file by key name (default: False)
TYPE:
|
Usage
>>> export_project_maps(arcpie.Project('<path/to/aprx>'), '<path/to/output_dir>')
Source code in src/arcpie/utils.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
get_subtype_count
¶
get_subtype_count(
fc: Table | FeatureClass, drop_empty: bool = False
) -> dict[str, int]
Get the subtype counts for a Table or FeatureClass
| PARAMETER | DESCRIPTION |
|---|---|
|
The Table/FeatureClass you want subtype counts for
TYPE:
|
|
Drop any counts that have no features from the output dictionary (default: False)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, int]
|
A mapping of subtype name to subtype count |
Source code in src/arcpie/utils.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
get_subtype_counts
¶
Get a mapping of subtype counts for all featureclasses that have subtypes in the provided Dataset
| PARAMETER | DESCRIPTION |
|---|---|
|
The Dataset instance to get subtype counts for
TYPE:
|
|
Drop any counts that have no features from the output dictionary (default: False)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, dict[str, int]]
|
A mapping of FeatureClass -> SubtypeName -> SubtypeCount |
Usage
>>> get_subtype_counts(Dataset('<path/to/gdb>', drop_empty=True))
{
'FC1':
{
'Default': 10
'Subtype 1': 6
...
},
...
}
Source code in src/arcpie/utils.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
iter_parts
¶
iter_parts(
line: Polyline, start: bool = True, end: bool = True
) -> Iterator[Iterator[PointGeometry]]
Get a part iterator for a Polyline
| PARAMETER | DESCRIPTION |
|---|---|
|
The Polyline to iterate parts for
TYPE:
|
|
Include the line startpoint (default:
TYPE:
|
|
Include the line endpoint (default:
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
Iterator[PointGeometry]
|
Iterators of part PointGeometries for all parts in the line |
Source code in src/arcpie/utils.py
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | |
iter_points
¶
Get a point iterator for a Polyline
| PARAMETER | DESCRIPTION |
|---|---|
|
The Polyline to iterate points for
TYPE:
|
|
Include the line startpoint (default:
TYPE:
|
|
Include the line endpoint (default:
TYPE:
|
Yields: PointGeometries for all points in the line
Source code in src/arcpie/utils.py
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 | |
nat
¶
Natural sort key for use in string sorting
| PARAMETER | DESCRIPTION |
|---|---|
|
A value that you want the natural sort key for
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[tuple[int, ...], tuple[str, ...]
|
A tuple containing all numeric and |
tuple[str, ...]
|
string components in order of appearance. Best used as a sort key |
Usage
>>> pages = ['P-1.3', 'P-2.11', ...]
>>> pages.sort(key=nat)
>>> print(pages)
['P-1.1', 'P-1.2', ...]
Source code in src/arcpie/utils.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
patch_schema_rules
¶
patch_schema_rules(
schema: SchemaWorkspace | Path | str,
*,
remove_rules: bool = False,
) -> SchemaWorkspace
Patch an exported Schema doc by re-linking attribute rules to table names
| PARAMETER | DESCRIPTION |
|---|---|
|
The input schema to patch |
|
Remove attribute rules from the schema (default: False)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SchemaWorkspace
|
A patched schema dictionary
TYPE:
|
Source code in src/arcpie/utils.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 | |
print
¶
print(
*values: object,
sep: str = " ",
end: str = "\n",
file: Any = None,
flush: bool = False,
severity: Literal["INFO", "WARNING", "ERROR"]
| None = None,
) -> None
Print a message to the ArcGIS Pro message queue and stdout set severity to 'WARNING' or 'ERROR' to print to the ArcGIS Pro message queue with the appropriate severity
Source code in src/arcpie/utils.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
shortest_path
¶
shortest_path(
source: PointLike,
target: PointLike,
network: LineCollection,
*,
all_paths: bool = False,
method: Literal[
"dijkstra", "bellman-ford"
] = "dijkstra",
weighted: bool = True,
precision: int = 6,
) -> Polyline | list[Polyline] | None
Find the shortest path or paths given a source point, target point and network of Polylines
| PARAMETER | DESCRIPTION |
|---|---|
|
The start point for the path
TYPE:
|
|
The end point for the path
TYPE:
|
|
The polylines to traverse
TYPE:
|
|
If True, yield all shortest paths from (default: False)
TYPE:
|
|
The graph traversal algorithm to use (default: 'dijkstra')
TYPE:
|
|
Use line lengths to weight the paths (default: True)
TYPE:
|
|
Number of decimal places to round coordinates to (default: 6)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Polyline | None
|
The unioned polyline of the path or None if no path is found |
| YIELDS | DESCRIPTION |
|---|---|
Polyline
|
Yields all shortest paths if |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
When input arguments are not of the correct types ( |
Example
path = shortest_path(p1, p2, line_features)
paths = shortest_path(p1, p2, line_features, all_paths=True)
if path is None:
print('No Path')
else:
print(path.length)
# Check that path(s) were found
if paths is None:
print('No Path')
else:
for p in paths:
print(p.length)
Source code in src/arcpie/utils.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
split_at_points
¶
split_at_points(
lines: FeatureClass[Polyline, Any],
points: FeatureClass[PointGeometry, Any],
*,
buffer: float = 0.0,
min_len: float = 0.0,
) -> Iterator[tuple[int, Polyline]]
Split lines at provided points
| PARAMETER | DESCRIPTION |
|---|---|
|
Line features to split
TYPE:
|
|
Points to split on
TYPE:
|
|
Split buffer in feature units (default: 0.0 [exact])
TYPE:
|
|
Minumum length for a new line in feature units (default: 0.0)
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
tuple[int, Polyline]]
|
Tuples of parent OID and child shape |
Warning
When splitting features in differing projections, the point features will be projected into the spatial reference of the line features.
Example
>>> # Simple process for splitting lines in place
...
>>> # Initialize a set to capture the removed ids
>>> removed: set[int] = set()
>>> with lines.editor:
... # Insert new lines
... with lines.insert_cursor('SHAPE@') as cur:
... for parent, new_line in split_at_points(lines, points):
... cur.insertRow([new_line])
... removed.add(parent) # Add parent ID to removed
... # Remove old lines (if you're inserting to the same featureclass)
... with lines.update_cursor('OID@') as cur:
... for _ in filter(lambda r: r[0] in removed, cur):
... cur.deleteRow()
Source code in src/arcpie/utils.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
split_lines_at_points
¶
split_lines_at_points(
lines: Polyline
| Sequence[Polyline]
| Iterator[Polyline],
points: Sequence[PointGeometry]
| Iterator[PointGeometry],
) -> Iterator[Polyline]
Split a Polyline or Sequence/Iterable of polylines at provided points
| PARAMETER | DESCRIPTION |
|---|---|
|
The line or lines to split |
|
The points to split at |
| YIELDS | DESCRIPTION |
|---|---|
Polyline
|
Segments of the polyline split at the input points |
Source code in src/arcpie/utils.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
two_point_circle
¶
two_point_circle(
center: Point | PointGeometry,
end: Point | PointGeometry,
ref: SpatialReference | None = None,
) -> Polyline
Create a circle using a center point and an end point
| PARAMETER | DESCRIPTION |
|---|---|
|
The center of the circle
TYPE:
|
|
(Point|PointGeometry): The end point of the arc (distance from center is Circle radius)
TYPE:
|
|
(SpatialReference|None): The SpatialReference to use with the returned geometry
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Polyline
|
A Circular Polyline |
Note
If PointGeometries are provided, they will be projected as the provided ref If no ref is provided, the shape will inherit the reference of the center
Reference resolution is as follows:
ref -> center.spatialReference -> end.spatialReference
If both points are Point objects with no spatial reference, and no ref is provided, The returned Polyline will have no spatial reference
Source code in src/arcpie/utils.py
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 | |
vector_at
¶
vector_at(
line: Polyline,
point: PointGeometry | Point,
*,
delta: float = 0.01,
snap: bool = False,
) -> Vector
Get the vector of the line at the given point (p-delta -> p+delta)
| PARAMETER | DESCRIPTION |
|---|---|
|
The line to get a Vector for
TYPE:
|
|
The PointGeometry specifying the vector location (projects to line reference)
TYPE:
|
|
The distance (meters) to traverse the line in both directions (default:
TYPE:
|
|
If the input point is disjoint from the line, snap it to the line (default: 'False')
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Vector
|
A Vector of length delta*2 that describes the slope of the line at the provided point |
Source code in src/arcpie/utils.py
724 725 726 727 728 729 730 731 732 733 734 735 736 737 | |
vectors_at
¶
vectors_at(
line: Polyline,
point: PointGeometry | Point,
*,
delta: float = 0.01,
snap: bool = False,
) -> tuple[Vector, Vector]
Get the vector of the line at the given point (p-delta -> p+delta)
| PARAMETER | DESCRIPTION |
|---|---|
|
The line to get a Vector for
TYPE:
|
|
The PointGeometry specifying the vector location (projects to line reference)
TYPE:
|
|
The distance (meters) to traverse the line (default:
TYPE:
|
|
If the input point is disjoint from the line, snap it to the line (default: 'False')
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Vector, Vector]
|
A tuple of Vectors representing the bearing to start and end at distance delta from point |
Note
If the in point is a start/end point on the line, one of the Vectors will be a null vector!
Source code in src/arcpie/utils.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 | |