Geo / OSM¶
The geo package brings real building layouts into the generators: it
queries building outlines from OpenStreetMap through the Overpass API
(data © OpenStreetMap contributors, ODbL), projects them from WGS84 into
a local east-north frame in metres, and hands them to the generators as
BuildingFootprint objects (through OsmBuildingPlacement in
TnNetworkGenerator, or LvNetworkLayout.from_osm). Design and
reasoning: ADR-0011.
The active functions need the optional geo extra
(pip install "groundfield[geo]": requests, pyproj, shapely);
without it they raise an ImportError with the install command. The
data class BuildingFootprint has no optional dependency.
Mathematical and physical context¶
The geo layer is topological: it decides which buildings exist, where they are and how their foundation earths are oriented. Three effects depend on that geometry rather than on the number of houses: the spreading resistance of a foundation earth grows with its buried length (the perimeter of the outline), the inductive coupling of a foundation to a PEN cable along the street depends on its orientation, and the mutual resistance between the earths depends on the real spacing of the houses, which a regular grid does not reproduce.
Projection. Azimuthal equidistant projection (+proj=aeqd) centred
on a user-supplied origin: one tangent plane, distortion below
\(10^{-5}\) within about 5 km of the origin, no UTM zone bookkeeping. The
origin is never inferred from the data, so two queries of the same area
at different dates give identical coordinates.
Foundation outline. A foundation earth (DIN 18014) is a closed
conductor in the strip foundation. The generators reduce an outline
either to its oriented minimum bounding rectangle (OMBR, the default:
smallest rectangle containing the polygon, rotating calipers) or follow
the polygon itself (foundation_outline="polygon" of the layout
builder). An outline whose OMBR is narrower than 1 m (a mapped wall or
fence) is widened to MIN_FOUNDATION_SIDE_M with a warning in both
cases; a polygon foundation then follows the widened OMBR.
Requests. Overpass queries are bounded (radius, timeout, response
size), validated before they are cached, and retried with back-off; a
malformed answer raises OverpassError and is not cached. Every
building=* value is a footprint by default; exclude_building_tags
(for example NON_SERVICE_BUILDING_TAGS: garages, sheds, carports, …)
drops buildings without a service connection.
Example (offline)¶
import math
import groundfield as gf
# a 12 m x 9 m house turned by 30 degrees, in local metres (east, north)
angle = math.radians(30.0)
corners = [(0.0, 0.0), (12.0, 0.0), (12.0, 9.0), (0.0, 9.0)]
outline = [
(math.cos(angle) * x - math.sin(angle) * y, math.sin(angle) * x + math.cos(angle) * y)
for x, y in corners
]
house = gf.BuildingFootprint(polygon_xy_m=outline, osm_id=1)
centre, size, orientation_deg = house.oriented_bounding_rectangle() # needs the geo extra
assert abs(house.area_m2() - 108.0) < 1e-9
assert abs(size[0] - 12.0) < 1e-9 and abs(size[1] - 9.0) < 1e-9
assert abs(orientation_deg - 30.0) < 1e-9
The tutorial on TN networks (T06) builds a complete network from a stored Overpass answer, without network access; the how-to guide on OSM offline use shows how to cache and replay queries.
API reference¶
geo ¶
Georeferenced data ingest for groundfield.
This subpackage bridges the external GIS world (OpenStreetMap via the
Overpass API, in the future also image-based footprint recognition)
and the groundfield.generators stack. The end product is a
list of BuildingFootprint instances in a local ENU frame,
which a OsmBuildingPlacement then feeds into a
TnNetworkGenerator so that synthetic worlds inherit real
street layouts and real building outlines for the foundation
electrodes.
Optional dependencies
groundfield.geo.osm and groundfield.geo.projection
import requests, pyproj, and shapely. These
ship in the geo Poetry / pip extra and are not part of the
core groundfield install. Calling any of the public APIs
without the extra raises a clear ImportError with the
install hint::
pip install groundfield[geo]
poetry install --extras geo
The Pydantic data class BuildingFootprint does not
depend on any of the optional libraries; it can be imported and
serialised on a core install. Only the active operations
(querying Overpass, projecting WGS84 to ENU, computing oriented
bounding rectangles) need the extra.
Design rationale
See docs/adr/0011-osm-building-footprints.md for the full
decision record (subpackage layout, projection choice, caching
strategy, integration with the generator stack, deferred
Phase B for non-rectangular foundations).
DEFAULT_ENDPOINT
module-attribute
¶
Default Overpass endpoint. Override with endpoint=….
DEFAULT_MAX_RESPONSE_BYTES
module-attribute
¶
Default cap on the size of an Overpass response (16 MiB).
The cap bounds the memory of decoding the body as well: parsed JSON takes
about 6 times its size for building payloads and up to 25 times for a
hostile body of empty objects (measured with tracemalloc), i.e. at
most about 0.4 GiB. The largest payload of the AP1 catalogue (196 LV
networks) is 3 MiB; pass a larger max_response_bytes for wide areas.
Until the first 2026.11 consolidation the default was 64 MiB (up to
1.6 GiB parsed, audit L7).
MAX_PAYLOAD_DEPTH
module-attribute
¶
Deepest container nesting accepted in an Overpass payload.
An Overpass result nests at most seven levels (payload → elements →
element → members → member → geometry → vertex). A body nested
far deeper is not an Overpass result: up to about 10 000 levels it decodes
and would reach the recursive pure-Python encoder of json.dump() in
the cache write (RecursionError beyond about 1 000 levels, audit
A2G-05); beyond that the decoder of Python 3.12 / 3.13 raises
RecursionError; Python 3.14, whose recursion guard follows the C
stack, may decode 100 000 levels (3.14.10 on the CI runner did, 3.14.6
did not). Every case becomes OverpassError right after
decoding.
MAX_RADIUS_M
module-attribute
¶
Largest accepted search radius in m (one LV / MV network area).
MAX_RETRY_DELAY_S
module-attribute
¶
Longest wait in s between two retries (also caps Retry-After).
MIN_OUTLINE_WIDTH_M
module-attribute
¶
Mean width in m below which an outline encloses no area.
The mean width \(w = 2A/P\) of a ring (twice its area over its
perimeter, mean_width()) is the width of a long thin rectangle and
0 for identical or collinear vertices. An outline narrower than 1 mm on
average is a digitising artefact, not a building:
groundfield.geo.osm.parse_overpass_payload() skips it
(BuildingFootprint.is_degenerate()). A mapped wall of 5 mm is kept
(\(w \approx 5\) mm); generators widen its foundation (audit L5).
NON_SERVICE_BUILDING_TAGS
module-attribute
¶
NON_SERVICE_BUILDING_TAGS: frozenset[str] = frozenset({'carport', 'container', 'garage', 'garages', 'greenhouse', 'hut', 'no', 'roof', 'ruins', 'shed', 'shelter', 'tent'})
building=* values that usually have neither an LV service
connection nor a foundation earth electrode (garages, sheds, roofs,
ruins, building=no, ...). Pass it as exclude_building_tags to
drop such footprints; it is not applied by default.
Point2D
module-attribute
¶
Type alias for a 2-D point in the local ENU frame, (x_m, y_m).
Ring
module-attribute
¶
Type alias for a closed ring; the first and last vertex are equal
(or ensure_orientation() will close it).
BuildingFootprint ¶
Bases: BaseModel
A single building's footprint, projected to the local ENU frame.
Attributes:
| Name | Type | Description |
|---|---|---|
polygon_xy_m |
Ring
|
Vertices of the exterior ring in metres, CCW. May be passed open or closed; on validation the ring is normalised to CCW and stored open (no duplicate final vertex). |
holes_xy_m |
list[Ring]
|
Interior rings (holes) in metres, CW. Each hole is normalised on validation. Empty list means no holes (the typical residential case). |
levels |
Optional[float]
|
|
building_use |
Optional[str]
|
Value of the |
osm_id |
Optional[int]
|
Original OSM way / relation id. Useful for tracing back to the source feature for debugging. |
osm_tags |
dict[str, str]
|
Untouched OSM key/value tag dictionary. Lets consumers
extract additional information (e.g. |
Notes
The instance is immutable (frozen=True) so that a
generators.placement.OsmBuildingPlacement can rely on
the polygon not changing while the generator iterates over
sites.
area_m2 ¶
Signed-area-based polygon area in m² (holes subtracted).
Returns:
| Type | Description |
|---|---|
float
|
|
Source code in src/groundfield/geo/footprint.py
axis_aligned_bounding_rectangle ¶
Axis-aligned bounding rectangle of the exterior ring.
Returns:
| Type | Description |
|---|---|
tuple
|
|
Notes
Pure-Python implementation; no shapely dependency.
Used as a fall-back when the optional geo extra is not
installed; for a fully rotated foundation electrode use
oriented_bounding_rectangle() instead.
Source code in src/groundfield/geo/footprint.py
centroid_xy_m ¶
Geometric centroid of the exterior ring in metres.
Notes
Holes are ignored — for the residential / commercial building shapes we care about, the moment shift caused by a hole is at most a few centimetres and irrelevant to the soil-spreading calculation. Implements
analogously for \(C_y\).
Source code in src/groundfield/geo/footprint.py
is_degenerate ¶
True when the exterior ring encloses no area.
That is, its mean width is below MIN_OUTLINE_WIDTH_M
(identical or collinear vertices, up to projection round-off).
Source code in src/groundfield/geo/footprint.py
mean_width_m ¶
Mean width \(2A/P\) of the exterior ring in m (mean_width()).
oriented_bounding_rectangle ¶
Oriented minimum bounding rectangle (OMBR) of the exterior ring.
Returns:
| Type | Description |
|---|---|
tuple
|
|
Notes
Uses Shapely's Polygon.minimum_rotated_rectangle,
which implements the rotating-calipers algorithm. Requires
the optional geo extra; raises ImportError
with the install hint otherwise.
Physical interpretation
The OMBR is the canonical projection of an arbitrary building outline onto a Streifenfundament (DIN 18014): the foundation ring follows the OMBR's perimeter, so its side lengths fix the conductor length that contributes to the galvanic spreading admittance, and the orientation fixes the angle relative to the PEN trunk for the inductive-coupling calculation. For a typical residential L-shape the OMBR captures the dominant edge alignment within a few degrees; full polygonal Strip chains are deferred to Phase B (ADR-0011).
Source code in src/groundfield/geo/footprint.py
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 407 408 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 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | |
OsmBuildingPlacement ¶
Bases: BaseModel
Placement driven by a list of pre-projected building footprints.
The class implements the same generate(n, rng) -> list[(x, y)]
interface as generators.placement.ManhattanGridPlacement
and generators.placement.ExplicitPlacement, so any
consumer that accepts a PlacementSpec will accept this
placement too (once it has been added to the discriminated union;
see Task 3 in ADR-0011's implementation plan).
Attributes:
| Name | Type | Description |
|---|---|---|
footprints |
list[BuildingFootprint]
|
Pre-projected building polygons in the local ENU frame. Order is preserved; the k-th footprint corresponds to the k-th building site. |
min_area_m2 |
float
|
Skip footprints whose area is strictly below this threshold
on |
selection |
Literal['first_n', 'all']
|
How to choose footprints when the generator requests fewer than are available:
|
Notes
The class is intentionally a plain Pydantic BaseModel with
a kind discriminator field; it does not inherit from a
common PlacementSpec ABC because the existing union uses
structural typing via the kind literal. Adding this class
to generators.placement.PlacementSpec is a one-line union
update tracked as a follow-up task.
n_footprints
property
¶
Number of footprints surviving the min_area_m2 filter.
Identical to len(placement) and provided as an explicit
attribute so consumers can pre-flight an i against
footprint_at() without invoking len() on the model
instance.
__len__ ¶
footprint_at ¶
Return the footprint associated with site i.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
int
|
Site index, matching the order returned by
|
required |
strict
|
bool
|
If If |
False
|
Returns:
| Type | Description |
|---|---|
BuildingFootprint or None
|
The footprint at index |
Raises:
| Type | Description |
|---|---|
IndexError
|
If |
Source code in src/groundfield/geo/placement.py
generate ¶
Return n site positions as polygon centroids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of sites the generator wants to populate. |
required |
rng
|
'np.random.Generator'
|
Unused. Accepted for interface parity with the other
|
required |
Returns:
| Type | Description |
|---|---|
list[tuple[float, float]]
|
Polygon centroids in metres. Length is |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Notes
The reported site is the polygon's area centroid, not
the centre of its oriented minimum bounding rectangle
(OMBR); the two coincide only for outlines with a centre of
symmetry (an L-shaped house separates them by several
metres). Consumers that build OMBR-aligned geometry — i.e.
footprint-driven FoundationElectrodeSpec in
TnNetworkGenerator
— must therefore compensate the centroid-to-OMBR-centre
difference themselves via offset_xy_m. The service-drop
/ PEN routing consumers legitimately use the centroid,
which is why generate keeps returning it.
Source code in src/groundfield/geo/placement.py
OverpassError ¶
Bases: RuntimeError
Raised on a non-success Overpass response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error message. |
required |
status_code
|
int
|
HTTP status code of the response, if any. |
None
|
body
|
str
|
Excerpt of the response body (the callers pass its first 1 kB). |
""
|
Attributes:
| Name | Type | Description |
|---|---|---|
status_code |
HTTP status code if available, else |
|
body |
First 1 kB of the response body for diagnostic purposes. |
Source code in src/groundfield/geo/osm.py
Projector ¶
WGS84 (longitude, latitude) <-> local ENU (x_m, y_m) projection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat0_deg
|
float
|
Latitude and longitude of the projection origin in decimal
degrees, WGS84. The origin is the point that maps to
|
required |
lon0_deg
|
float
|
Latitude and longitude of the projection origin in decimal
degrees, WGS84. The origin is the point that maps to
|
required |
ellps
|
str
|
Ellipsoid name accepted by |
'WGS84'
|
Notes
The projection is azimuthal equidistant
(+proj=aeqd) centred on (lat0, lon0) with the WGS84
ellipsoid. For distances \(r \lesssim 5 \, \mathrm{km}\)
around the origin the residual distortion is below
\(10^{-5}\) (a few centimetres on a kilometre baseline),
which is two orders of magnitude below typical OSM polygon
quantisation. Conformality is not preserved exactly — for
our use case (placing electrodes and measuring distances
between them) equal distance to the origin is the relevant
invariant, not angle preservation.
The projection is not thread-safe: each Projector
holds two pyproj.Transformer instances internally;
instantiate one per worker if you parallelise.
Source code in src/groundfield/geo/projection.py
origin ¶
ring_to_xy_m ¶
Vectorised forward projection of a list of (lat, lon).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_lon
|
list[tuple[float, float]]
|
List of WGS84 |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[float, float]]
|
Same length, each tuple in local ENU metres. |
Source code in src/groundfield/geo/projection.py
to_lat_lon ¶
Inverse of to_xy_m(): local ENU -> WGS84.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_m
|
float
|
Local ENU coordinates in metres. |
required |
y_m
|
float
|
Local ENU coordinates in metres. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
|
Source code in src/groundfield/geo/projection.py
to_xy_m ¶
Project a single point WGS84 -> local ENU.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_deg
|
float
|
WGS84 coordinates of the point in decimal degrees. |
required |
lon_deg
|
float
|
WGS84 coordinates of the point in decimal degrees. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
|
Source code in src/groundfield/geo/projection.py
build_query ¶
build_query(lat0_deg: float, lon0_deg: float, radius_m: float, *, timeout_s: int = DEFAULT_TIMEOUT_S) -> str
Construct the Overpass-QL query string for a buildings-in-radius lookup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat0_deg
|
float
|
Centre of the lookup in WGS84 decimal degrees. |
required |
lon0_deg
|
float
|
Centre of the lookup in WGS84 decimal degrees. |
required |
radius_m
|
float
|
Search radius in metres. Must be positive. |
required |
timeout_s
|
int
|
Query timeout passed to Overpass via |
DEFAULT_TIMEOUT_S
|
Returns:
| Type | Description |
|---|---|
str
|
A deterministic Overpass-QL query. The string is byte-identical across runs given the same inputs, so its SHA-256 hash is a stable cache key. |
Raises:
| Type | Description |
|---|---|
ValueError
|
For non-finite or out-of-range coordinates (latitude in
|
TypeError
|
If |
Source code in src/groundfield/geo/osm.py
default_cache_dir ¶
Return the default on-disk Overpass cache directory.
Honours XDG_CACHE_HOME when set; otherwise falls back to
~/.cache/groundfield/osm on Linux/macOS and the equivalent
on Windows via pathlib.Path.home.
The directory is not created here; the caller (e.g.
query_buildings()) creates it on first write.
Returns:
| Type | Description |
|---|---|
Path
|
|
Source code in src/groundfield/geo/osm.py
ensure_orientation ¶
Return ring reordered so its signed area has the requested sign.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ring
|
Ring
|
Input ring (open or closed). |
required |
ccw
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
list[Point2D]
|
A new list of vertices in the requested orientation. The ring is returned open (no duplicate final vertex) so that the caller can close it explicitly if needed. |
Source code in src/groundfield/geo/footprint.py
mean_width ¶
Mean width \(w = 2A/P\) of a ring in m.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ring
|
Ring
|
Vertex list in m (open or closed). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Twice the absolute area \(A\) over the perimeter \(P\): \(d_y\) for a thin \(d_x \times d_y\) rectangle (\(d_y \ll d_x\)), \(d/2\) for a square of side \(d\), and 0 for identical or collinear vertices (also for an empty ring). |
Source code in src/groundfield/geo/footprint.py
parse_overpass_payload ¶
parse_overpass_payload(payload: dict[str, Any], projector: Projector, *, min_area_m2: float = 0.0, exclude_building_tags: Optional[Collection[str]] = None) -> list[BuildingFootprint]
Convert an Overpass JSON payload into projected
BuildingFootprint instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
dict[str, Any]
|
Overpass JSON as returned by |
required |
projector
|
Projector
|
Projection from WGS84 to the local ENU frame. The same projector should be reused across all consumers of one payload to keep the metric coordinates consistent. |
required |
min_area_m2
|
float
|
Skip features whose footprint area is strictly below this
threshold. |
0.0
|
exclude_building_tags
|
Optional[Collection[str]]
|
|
None
|
Returns:
| Type | Description |
|---|---|
list[BuildingFootprint]
|
Order matches the Overpass element order, which Overpass keeps deterministic for the same query. |
Raises:
| Type | Description |
|---|---|
OverpassError
|
If the payload does not have the structure of an Overpass result
or a vertex is not a finite WGS84 coordinate (see the module
docstring). Elements whose geometry contains |
Notes
Multipolygon relations (type=multipolygon) are handled by
walking the relation's members and treating each outer
way as an independent footprint with the inner ways of the
same relation attached as holes. Relations without an
outer member are skipped.
Source code in src/groundfield/geo/osm.py
891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 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 | |
query_and_project ¶
query_and_project(lat0_deg: float, lon0_deg: float, radius_m: float, *, projector: Optional[Projector] = None, cache_dir: Optional[Path] = None, endpoint: str = DEFAULT_ENDPOINT, timeout_s: int = DEFAULT_TIMEOUT_S, min_area_m2: float = 0.0, force_refresh: bool = False, max_retries: int = 1, exclude_building_tags: Optional[Collection[str]] = None, max_response_bytes: int = DEFAULT_MAX_RESPONSE_BYTES, _post: Any = None) -> tuple[list[BuildingFootprint], Projector]
Run query_buildings() and parse_overpass_payload()
end-to-end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat0_deg
|
float
|
Buildings-in-radius parameters. |
required |
lon0_deg
|
float
|
Buildings-in-radius parameters. |
required |
radius_m
|
float
|
Buildings-in-radius parameters. |
required |
projector
|
Optional[Projector]
|
If |
None
|
cache_dir
|
Optional[Path]
|
Forwarded to |
None
|
endpoint
|
Optional[Path]
|
Forwarded to |
None
|
timeout_s
|
Optional[Path]
|
Forwarded to |
None
|
force_refresh
|
Optional[Path]
|
Forwarded to |
None
|
min_area_m2
|
float
|
Skip features below this footprint area. Defaults to
|
0.0
|
max_retries
|
int
|
Number of retry attempts on |
1
|
exclude_building_tags
|
Optional[Collection[str]]
|
Forwarded to |
None
|
max_response_bytes
|
int
|
Forwarded to |
DEFAULT_MAX_RESPONSE_BYTES
|
_post
|
Any
|
Test hook, forwarded to |
None
|
Returns:
| Type | Description |
|---|---|
tuple[list[BuildingFootprint], Projector]
|
Projected footprints and the projector used. The projector is returned so the caller can re-use it for further coordinate transforms (e.g. plotting a substation marker at a known lat/lon). |
Source code in src/groundfield/geo/osm.py
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 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 | |
query_buildings ¶
query_buildings(lat0_deg: float, lon0_deg: float, radius_m: float, *, cache_dir: Optional[Path] = None, endpoint: str = DEFAULT_ENDPOINT, timeout_s: int = DEFAULT_TIMEOUT_S, force_refresh: bool = False, max_retries: int = 1, max_response_bytes: int = DEFAULT_MAX_RESPONSE_BYTES, _post: Any = None) -> dict[str, Any]
Fetch (or load from cache) the raw Overpass response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat0_deg
|
float
|
Centre of the buildings-in-radius lookup, WGS84 degrees. |
required |
lon0_deg
|
float
|
Centre of the buildings-in-radius lookup, WGS84 degrees. |
required |
radius_m
|
float
|
Search radius in metres, at most |
required |
cache_dir
|
Optional[Path]
|
Directory in which the response is cached. Defaults to
|
None
|
endpoint
|
str
|
Overpass endpoint URL ( |
DEFAULT_ENDPOINT
|
timeout_s
|
int
|
Per-query timeout in s passed to Overpass, an integer in
|
DEFAULT_TIMEOUT_S
|
force_refresh
|
bool
|
If |
False
|
max_retries
|
int
|
Number of retry attempts on |
1
|
max_response_bytes
|
int
|
Cap on the response size in bytes (default
|
DEFAULT_MAX_RESPONSE_BYTES
|
_post
|
Any
|
Internal hook for tests: a callable with the signature
|
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The decoded Overpass JSON payload. The shape is
|
Raises:
| Type | Description |
|---|---|
OverpassError
|
On HTTP errors, oversized or malformed responses and payloads
whose |
(ValueError, TypeError)
|
For invalid arguments (see |
Notes
The cache filename is <sha256(query)>.json for the default
endpoint and <sha256(endpoint + newline + query)>.json for any
other endpoint. Files are written atomically; a cache file that
cannot be read back is re-fetched (with a UserWarning).
Source code in src/groundfield/geo/osm.py
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 | |
signed_area ¶
Signed area of a polygon ring via the shoelace formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ring
|
Ring
|
Vertex list. The ring may be open (last vertex != first); the shoelace formula closes it implicitly. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Signed area in m². Positive for counter-clockwise rings, negative for clockwise rings, zero for degenerate rings. |
Notes
Implements
with indices taken modulo n. The orientation convention used here (CCW positive) matches the right-hand rule with a z-axis pointing out of the ground in the local ENU frame.