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, ref: SpatialReference | None = None
)
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 |
|---|---|
add_point |
Insert a point in the polyline determining the ideal index based on measure |
add_points |
Insert points into the line based on measure |
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 |
offset |
Offset the line in the provided direction |
orienent_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) |
split_at_point |
Split the Polyline at a point returning two Polylines |
split_at_points |
Split the line at the provided points |
| 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
1145 1146 1147 1148 1149 | |
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)
add_point
¶
Insert a point in the polyline determining the ideal index based on measure
| PARAMETER | DESCRIPTION |
|---|---|
|
The point to insert
TYPE:
|
|
Snap the point to the line before adding it (default: False)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int | None
|
The index of the newly added point or |
Source code in src/arcpie/utils.py
1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 | |
add_points
¶
Insert points into the line based on measure
| PARAMETER | DESCRIPTION |
|---|---|
|
The points to insert
TYPE:
|
|
Snap the points to the line before adding them (default: False)
TYPE:
|
Source code in src/arcpie/utils.py
1654 1655 1656 1657 1658 1659 1660 1661 | |
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
1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 | |
append
¶
append(point: Point | PointGeometry) -> None
Append a point to the last part of the Polyline
Source code in src/arcpie/utils.py
1375 1376 1377 1378 1379 1380 1381 | |
append_part
¶
append_part(part: Polyline | PolylineEditor) -> None
Add a part to the polyline
Source code in src/arcpie/utils.py
1466 1467 1468 1469 1470 1471 1472 1473 1474 | |
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
1408 1409 1410 | |
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
1403 1404 1405 1406 | |
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
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 | |
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
1416 1417 1418 1419 1420 1421 | |
extend
¶
extend(points: Iterable[Point | PointGeometry]) -> None
Extend the last part of the polyline with the points
Source code in src/arcpie/utils.py
1383 1384 1385 1386 1387 1388 1389 | |
generalize
¶
generalize(distance: float) -> None
Generalize the polyline
Source code in src/arcpie/utils.py
1462 1463 1464 | |
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
1368 1369 1370 1371 1372 1373 | |
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
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 | |
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
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 | |
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
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 | |
move
¶
move(vec: Vector) -> None
Move the polyline along a Vector
Source code in src/arcpie/utils.py
1485 1486 1487 | |
offset
¶
offset(
dist: float,
side: Literal['left', 'right', 'both'] = 'both',
) -> Polyline | tuple[Polyline, Polyline]
Offset the line in the provided direction
| PARAMETER | DESCRIPTION |
|---|---|
|
The distance to offet by (feature units)
TYPE:
|
|
The side of the line to offset to
TYPE:
|
Source code in src/arcpie/utils.py
1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 | |
orienent_with
¶
orienent_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
1535 1536 1537 1538 1539 1540 1541 1542 | |
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
1341 1342 1343 1344 1345 1346 1347 1348 1349 | |
pop_part
¶
pop_part(index: SupportsIndex = -1) -> Polyline
pop a part from the polyline (default: -1)
Source code in src/arcpie/utils.py
1476 1477 1478 1479 1480 1481 1482 1483 | |
project_as
¶
project_as(ref: SpatialReference | int) -> None
Project the polyline in the given reference
Source code in src/arcpie/utils.py
1529 1530 1531 1532 1533 | |
remove
¶
remove(point: Point | PointGeometry) -> None
Remove the fist occurrence of the point from the polyline
Source code in src/arcpie/utils.py
1412 1413 1414 | |
reset
¶
reset() -> None
Revert all changes to polyline and restore the original geometry
Source code in src/arcpie/utils.py
1450 1451 1452 | |
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
1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 | |
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
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 | |
split_at_point
¶
split_at_point(
point: Point | PointGeometry, snap: bool = False
) -> tuple[Polyline, Polyline] | Polyline | None
Split the Polyline at a point returning two Polylines
| PARAMETER | DESCRIPTION |
|---|---|
|
The Point to split the line at
TYPE:
|
|
Snap the point to the line before splitting (default:
TYPE:
|
Note
If the point is at the line extremeties, the polyline will be returned
Source code in src/arcpie/utils.py
1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | |
split_at_points
¶
Split the line at the provided points
| PARAMETER | DESCRIPTION |
|---|---|
|
The Points to split the line at
TYPE:
|
|
Snap the points to the line before splitting (default:
TYPE:
|
Source code in src/arcpie/utils.py
1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 | |
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 |
- Modules Utils
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
950 951 952 | |
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
1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 | |
cross
¶
Cross product of two vectors originating at LHS (*)
Source code in src/arcpie/utils.py
964 965 966 967 968 969 970 971 972 973 974 975 976 | |
dot
¶
Dot product of two vectors originating at LHS (@)
Source code in src/arcpie/utils.py
997 998 999 1000 | |
norm
¶
norm() -> Vector
Normal vector originating at tail
Source code in src/arcpie/utils.py
939 940 941 | |
reverse
¶
reverse() -> Vector
Reversed vector
Source code in src/arcpie/utils.py
932 933 934 | |
rotate
¶
Rotate the vector counter-clockwise around the tail (2D)
Args:
angle: The angle in radians to rotate the vector by
Source code in src/arcpie/utils.py
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 | |
rotate_degrees
¶
Alternate method for rotate that accepts an angle in degrees
Source code in src/arcpie/utils.py
1120 1121 1122 | |
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
978 979 980 981 982 983 984 985 | |
subtract
¶
Vector subtraction originating at LHS (-)
Source code in src/arcpie/utils.py
957 958 959 | |
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
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 | |
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
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 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 | |
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
671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | |
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
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
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
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
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
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
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
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
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
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
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
780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 | |
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
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 | |
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 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
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 100 101 102 103 | |
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
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 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
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
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
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
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 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
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
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 394 395 396 397 398 399 400 401 402 403 404 405 406 | |
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
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
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
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 | |
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
745 746 747 748 749 750 751 752 753 754 755 756 757 758 | |
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
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | |