sitecontext 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sitecontext-0.1.0/.gitattributes +6 -0
- sitecontext-0.1.0/.gitignore +16 -0
- sitecontext-0.1.0/CHANGELOG.md +15 -0
- sitecontext-0.1.0/CONTRIBUTING.md +34 -0
- sitecontext-0.1.0/LICENSE +21 -0
- sitecontext-0.1.0/PKG-INFO +207 -0
- sitecontext-0.1.0/README.md +168 -0
- sitecontext-0.1.0/examples/make_gif.py +29 -0
- sitecontext-0.1.0/examples/render_blender.py +98 -0
- sitecontext-0.1.0/pyproject.toml +62 -0
- sitecontext-0.1.0/src/sitecontext/__init__.py +3 -0
- sitecontext-0.1.0/src/sitecontext/check.py +110 -0
- sitecontext-0.1.0/src/sitecontext/cli.py +183 -0
- sitecontext-0.1.0/src/sitecontext/config.py +119 -0
- sitecontext-0.1.0/src/sitecontext/context.py +394 -0
- sitecontext-0.1.0/src/sitecontext/earth.py +211 -0
- sitecontext-0.1.0/src/sitecontext/fetch.py +194 -0
- sitecontext-0.1.0/src/sitecontext/fit.py +208 -0
- sitecontext-0.1.0/src/sitecontext/geo.py +81 -0
- sitecontext-0.1.0/src/sitecontext/gltf.py +252 -0
- sitecontext-0.1.0/src/sitecontext/http.py +45 -0
- sitecontext-0.1.0/src/sitecontext/osm.py +43 -0
- sitecontext-0.1.0/src/sitecontext/parcels.py +141 -0
- sitecontext-0.1.0/src/sitecontext/terrain.py +67 -0
- sitecontext-0.1.0/tests/conftest.py +92 -0
- sitecontext-0.1.0/tests/test_cli.py +16 -0
- sitecontext-0.1.0/tests/test_context.py +84 -0
- sitecontext-0.1.0/tests/test_earth.py +96 -0
- sitecontext-0.1.0/tests/test_fetch.py +63 -0
- sitecontext-0.1.0/tests/test_fit.py +77 -0
- sitecontext-0.1.0/tests/test_geo.py +66 -0
- sitecontext-0.1.0/tests/test_gltf.py +105 -0
- sitecontext-0.1.0/tests/test_parcels.py +82 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First release.
|
|
6
|
+
|
|
7
|
+
- `init`, `fetch`: geocoding (Nominatim), OpenStreetMap (Overpass, with a fallback to the main API), county parcels
|
|
8
|
+
from any ArcGIS layer (LA County preset), USGS 3DEP terrain, GEOID18 / EGM96 geoid heights.
|
|
9
|
+
- `fit`: rigid fit of the model's property lines to the lot parcel (coarse search + robust ICP) with per-line
|
|
10
|
+
residuals; `register` for manual registration.
|
|
11
|
+
- `build`: terrain, roads, paths, buildings and destroyed-building pads to a named, attributed GLB in the model frame;
|
|
12
|
+
optional cutout with a ground skirt; snapping OSM roads onto the model street.
|
|
13
|
+
- `check`: top-down check plot.
|
|
14
|
+
- `earth`: Google Earth Pro KMZ of the model and context with the correct altitude, heading and imagery offset.
|
|
15
|
+
- Dependency-free GLB writer and reader.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for helping. Bug reports with the `site.json` that shows the problem are the most useful thing you can send.
|
|
4
|
+
Please leave out private addresses if the site is a client's; any public address near it usually reproduces the
|
|
5
|
+
issue.
|
|
6
|
+
|
|
7
|
+
## Development
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
git clone https://github.com/sumanthreddyc/sitecontext
|
|
11
|
+
cd sitecontext
|
|
12
|
+
python -m venv .venv && . .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
13
|
+
pip install -e ".[dev]"
|
|
14
|
+
pytest
|
|
15
|
+
ruff check . && ruff format --check .
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The tests are offline: they build synthetic sites (OSM XML, parcels, a DEM) in a temp folder. Please keep it that
|
|
19
|
+
way, and add a test with every fix.
|
|
20
|
+
|
|
21
|
+
## Adding a county parcel preset
|
|
22
|
+
|
|
23
|
+
1. Find the county's parcel layer (an ArcGIS REST `.../MapServer/<n>` or `.../FeatureServer/<n>`) and check that
|
|
24
|
+
its terms allow public use.
|
|
25
|
+
2. Check that a query by envelope with `outSR=4326` returns polygons, and note the parcel id field and the
|
|
26
|
+
situs-address fields.
|
|
27
|
+
3. Add it to `PRESETS` in `src/sitecontext/parcels.py`, with a `note` naming the source. In the PR, include one
|
|
28
|
+
public address you tested it on.
|
|
29
|
+
|
|
30
|
+
## Style
|
|
31
|
+
|
|
32
|
+
- Small, focused pull requests with a clear title (`fix: ...`, `feat: ...`, `docs: ...`).
|
|
33
|
+
- Respect the data services: identify the client, cache downloads, and never add parallel request fan-out to
|
|
34
|
+
Nominatim or Overpass.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sumanth Reddy Challaram
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sitecontext
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 3D site context for any building model from an address: OpenStreetMap roads and buildings, county parcels and USGS terrain, registered to the lot and exported to glTF and Google Earth.
|
|
5
|
+
Project-URL: Homepage, https://github.com/sumanthreddyc/sitecontext
|
|
6
|
+
Project-URL: Issues, https://github.com/sumanthreddyc/sitecontext/issues
|
|
7
|
+
Author: Sumanth Reddy Challaram
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: aec,bim,gis,gltf,google-earth,kml,openstreetmap,parcels,site-analysis,terrain
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: numpy>=1.24
|
|
21
|
+
Requires-Dist: shapely>=2.1
|
|
22
|
+
Provides-Extra: all
|
|
23
|
+
Requires-Dist: matplotlib>=3.7; extra == 'all'
|
|
24
|
+
Requires-Dist: pillow>=10; extra == 'all'
|
|
25
|
+
Requires-Dist: scipy>=1.10; extra == 'all'
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: matplotlib>=3.7; extra == 'dev'
|
|
28
|
+
Requires-Dist: pillow>=10; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
31
|
+
Requires-Dist: scipy>=1.10; extra == 'dev'
|
|
32
|
+
Provides-Extra: fit
|
|
33
|
+
Requires-Dist: scipy>=1.10; extra == 'fit'
|
|
34
|
+
Provides-Extra: plot
|
|
35
|
+
Requires-Dist: matplotlib>=3.7; extra == 'plot'
|
|
36
|
+
Provides-Extra: terrain
|
|
37
|
+
Requires-Dist: pillow>=10; extra == 'terrain'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# sitecontext
|
|
41
|
+
|
|
42
|
+
**3D site context for any building model, from an address and open public data.**
|
|
43
|
+
|
|
44
|
+
Give it an address. It downloads the roads and buildings around it from OpenStreetMap, the parcels from the county,
|
|
45
|
+
and the terrain from USGS, then builds a 3D context model as glTF. If you have a building model, it fits the model
|
|
46
|
+
onto its lot from the property lines, so the context lands in your model's own coordinates. It can also place the
|
|
47
|
+
model in Google Earth Pro at the right position, height and heading.
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
<sub>250 m around the Palisades Branch Library, Los Angeles. White: standing buildings. Orange: buildings destroyed in the
|
|
52
|
+
January 2025 Palisades fire, as tagged in OpenStreetMap. Built in about a second from open data, rendered with the
|
|
53
|
+
included Blender script.</sub>
|
|
54
|
+
|
|
55
|
+
## Why
|
|
56
|
+
|
|
57
|
+
Every architecture, engineering or construction project starts with "what is around the site?" The usual answer is
|
|
58
|
+
a paid data service, a day of hand modelling, or a screenshot from Google Maps. For most early design, coordination
|
|
59
|
+
and client work you need something simpler: the street, the neighbours, the slope and the lot, in the same
|
|
60
|
+
coordinates as your model. That is what this tool builds.
|
|
61
|
+
|
|
62
|
+
## What you get
|
|
63
|
+
|
|
64
|
+
| Output | What it is |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| `context.glb` | Terrain (USGS 3DEP), roads and paths at their real widths, draped on a smoothed profile, OSM buildings at their tagged heights, destroyed buildings as bare pads. Every mesh is named and carries its address, parcel, height and source. Opens in Blender, Rhino, three.js, Unreal, Unity, Windows 3D Viewer and anything else that imports glTF. |
|
|
67
|
+
| `check.png` | Top-down plot of the context, every parcel, your lot and your property lines, for checking the registration. |
|
|
68
|
+
| `site.kmz` | Your model (and optionally the context) placed in Google Earth Pro at the correct latitude, longitude, altitude and heading. |
|
|
69
|
+
| `context.json` | Counts, the datum, and the offset between OSM and the parcels. |
|
|
70
|
+
|
|
71
|
+
<p align="center"><img src="https://raw.githubusercontent.com/sumanthreddyc/sitecontext/main/docs/img/palisades-3d.jpg" width="49%"> <img src="https://raw.githubusercontent.com/sumanthreddyc/sitecontext/main/docs/img/palisades-check.jpg" width="40%"></p>
|
|
72
|
+
|
|
73
|
+
## Install
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install "sitecontext[all]"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Python 3.10+. The core needs only `numpy` and `shapely`. The extras add `scipy` (lot fitting), `pillow` (terrain) and
|
|
80
|
+
`matplotlib` (check plot).
|
|
81
|
+
|
|
82
|
+
## Quick start
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
sitecontext init palisades --address "861 Alma Real Dr, Pacific Palisades, CA 90272" --radius 250 --parcels la-county
|
|
86
|
+
sitecontext fetch palisades # OSM, parcels, terrain, geoid heights (~1 min, cached)
|
|
87
|
+
sitecontext build palisades # -> palisades/context.glb
|
|
88
|
+
sitecontext check palisades # -> palisades/check.png
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
That gives you the context in local east/north metres, with z = 0 at the ground at the address. To put it in your
|
|
92
|
+
model's coordinates, register the model.
|
|
93
|
+
|
|
94
|
+
## Registering your model
|
|
95
|
+
|
|
96
|
+
The context is most useful in your model's own coordinate system. There are two ways to tie the two together.
|
|
97
|
+
|
|
98
|
+
**Fit to the lot (recommended).** Read the property lines off your site plan, in model coordinates, and give the lot's
|
|
99
|
+
parcel number:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"parcels": {"source": "la-county", "lot_id": "<the lot's parcel number>"},
|
|
104
|
+
"model": {
|
|
105
|
+
"units": "ft",
|
|
106
|
+
"property_lines": [[[0, 0], [62.5, 0]], [[62.5, 0], [64.1, 141.2]], [[0, 0], [-1.8, 139.7]]],
|
|
107
|
+
"z0_elevation": 652.0
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
sitecontext fit mysite
|
|
114
|
+
# prints the bearing of model +Y, the anchor, and the median / max distance of each line from the parcel
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The fit is rigid (rotation and translation, no scale). A coarse search runs over every bearing, followed by a
|
|
118
|
+
robust ICP against the exact parcel boundary, so one misread line does not pull the result off. Read the residuals.
|
|
119
|
+
A line more than about 0.3 m off the parcel is usually a fence or setback line read as the property line, or the
|
|
120
|
+
wrong parcel. Fix the input rather than accepting the fit. Use lines you are sure of: the front and both sides are
|
|
121
|
+
enough. Don't trust the sheet's north arrow; it is often several degrees off, which is why the fit uses the parcel.
|
|
122
|
+
|
|
123
|
+
**By hand.** If you know the bearing of your model's +Y axis and where one point is:
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
sitecontext register mysite --bearing 23.4 --anchor 0,0 --at 34.04431,-118.52487
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
After registering, `build` writes the context in model coordinates (metres, z up, z = 0 at `model.z0_elevation`).
|
|
130
|
+
Import it at the origin and it sits around your building.
|
|
131
|
+
|
|
132
|
+
### Other options in `site.json`
|
|
133
|
+
|
|
134
|
+
| Key | Meaning |
|
|
135
|
+
| --- | --- |
|
|
136
|
+
| `model.cutout` | Polygons (model units) where the context is cut out: your modelled site, so terrain never pokes through it. A ground skirt is added down the cut edge. `build --cut-lot` cuts out the whole lot. |
|
|
137
|
+
| `model.street` | `{"osm_name": "Alma Real Drive", "centerline": [[x, y], ...]}`. Shifts OSM roads onto your model's street. OSM is traced from imagery and is often a few metres off the parcels. `earth` reuses this offset to line the model up with the aerial photo. |
|
|
138
|
+
| `context.default_building_height_m` | Height for OSM buildings without `height` or `building:levels` (default 6 m). |
|
|
139
|
+
| `terrain` | `"flat"` outside the US, or when you don't want terrain. |
|
|
140
|
+
| `parcels.url`, `id_field`, `address_fields` | Any county's ArcGIS parcel layer, instead of a preset. |
|
|
141
|
+
|
|
142
|
+
## Google Earth
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
sitecontext earth mysite --model my_house.glb --name "My house"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Export the model as a `.glb` in the same frame you registered (metres). Open the KMZ in Google Earth Pro and untick
|
|
149
|
+
**Layers > 3D Buildings**: Google's photo mesh shows what stands on the site today. A few details are handled for you:
|
|
150
|
+
|
|
151
|
+
- **Height.** USGS terrain is in NAVD88, while Google Earth's `absolute` altitude is EGM96 sea level. The difference
|
|
152
|
+
(about 0.4 m in Los Angeles) is looked up for the site from NOAA GEOID18 and EGM96.
|
|
153
|
+
- **Heading.** The KML model heading is set to the bearing of model +Y.
|
|
154
|
+
- **Transparency.** Earth Pro reads COLLADA transparency inverted, so opaque materials are written without it.
|
|
155
|
+
- **Mesh size.** Large meshes are split at 60k vertices.
|
|
156
|
+
|
|
157
|
+
Google Earth on the web does not show KML 3D models; use Earth Pro.
|
|
158
|
+
|
|
159
|
+
## Other counties
|
|
160
|
+
|
|
161
|
+
Parcels come from any ArcGIS REST layer; most US counties publish one. Find the county's parcel map service, then:
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
"parcels": {"url": "https://.../MapServer/0/query", "id_field": "APN", "address_fields": ["SITUS_ADDR"], "lot_id": "..."}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Pull requests adding verified presets are welcome (see [CONTRIBUTING](https://github.com/sumanthreddyc/sitecontext/blob/main/CONTRIBUTING.md)). Without parcels everything
|
|
168
|
+
except `fit` still works.
|
|
169
|
+
|
|
170
|
+
## Limitations
|
|
171
|
+
|
|
172
|
+
- Terrain comes from USGS 3DEP, so the **United States** only. Elsewhere use `"terrain": "flat"`; a global DEM source
|
|
173
|
+
is on the roadmap.
|
|
174
|
+
- Neighbouring buildings are flat-roofed footprint prisms. They are only as good as OpenStreetMap, and footprints
|
|
175
|
+
may predate recent rebuilds.
|
|
176
|
+
- Trees, walls and driveways are not modelled.
|
|
177
|
+
- Equirectangular local frame: accurate over the ~1 km a site context covers, not for city-scale areas.
|
|
178
|
+
|
|
179
|
+
## Data and attribution
|
|
180
|
+
|
|
181
|
+
Everything is downloaded from public services. Only the address or coordinates are sent, never project or owner
|
|
182
|
+
names. When you share outputs, credit the sources:
|
|
183
|
+
|
|
184
|
+
- Map data © [OpenStreetMap contributors](https://www.openstreetmap.org/copyright), available under the
|
|
185
|
+
[Open Database License](https://opendatacommons.org/licenses/odbl/). Outputs derived from OSM must keep this
|
|
186
|
+
attribution.
|
|
187
|
+
- Elevation: [USGS 3D Elevation Program](https://www.usgs.gov/3d-elevation-program) (public domain).
|
|
188
|
+
- Parcels: the county's terms apply (e.g. LA County Assessor open data).
|
|
189
|
+
- Geoid heights: [NOAA NGS GEOID18](https://geodesy.noaa.gov/GEOID/GEOID18/) and
|
|
190
|
+
[GeographicLib EGM96](https://geographiclib.sourceforge.io/).
|
|
191
|
+
- Geocoding: [Nominatim](https://nominatim.org/), within its usage policy (1 request per second, identified client).
|
|
192
|
+
|
|
193
|
+
## Roadmap
|
|
194
|
+
|
|
195
|
+
- Global terrain (Copernicus GLO-30)
|
|
196
|
+
- IFC input for `earth` and an IFC context export
|
|
197
|
+
- Roof shapes from OSM `roof:*` tags, and trees from OSM
|
|
198
|
+
- More verified county parcel presets
|
|
199
|
+
|
|
200
|
+
## Contributing
|
|
201
|
+
|
|
202
|
+
Issues and pull requests are welcome; see [CONTRIBUTING.md](https://github.com/sumanthreddyc/sitecontext/blob/main/CONTRIBUTING.md). If you use sitecontext on a real
|
|
203
|
+
project, I'd like to hear how it went.
|
|
204
|
+
|
|
205
|
+
## License
|
|
206
|
+
|
|
207
|
+
[MIT](https://github.com/sumanthreddyc/sitecontext/blob/main/LICENSE) © Sumanth Reddy Challaram
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# sitecontext
|
|
2
|
+
|
|
3
|
+
**3D site context for any building model, from an address and open public data.**
|
|
4
|
+
|
|
5
|
+
Give it an address. It downloads the roads and buildings around it from OpenStreetMap, the parcels from the county,
|
|
6
|
+
and the terrain from USGS, then builds a 3D context model as glTF. If you have a building model, it fits the model
|
|
7
|
+
onto its lot from the property lines, so the context lands in your model's own coordinates. It can also place the
|
|
8
|
+
model in Google Earth Pro at the right position, height and heading.
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
<sub>250 m around the Palisades Branch Library, Los Angeles. White: standing buildings. Orange: buildings destroyed in the
|
|
13
|
+
January 2025 Palisades fire, as tagged in OpenStreetMap. Built in about a second from open data, rendered with the
|
|
14
|
+
included Blender script.</sub>
|
|
15
|
+
|
|
16
|
+
## Why
|
|
17
|
+
|
|
18
|
+
Every architecture, engineering or construction project starts with "what is around the site?" The usual answer is
|
|
19
|
+
a paid data service, a day of hand modelling, or a screenshot from Google Maps. For most early design, coordination
|
|
20
|
+
and client work you need something simpler: the street, the neighbours, the slope and the lot, in the same
|
|
21
|
+
coordinates as your model. That is what this tool builds.
|
|
22
|
+
|
|
23
|
+
## What you get
|
|
24
|
+
|
|
25
|
+
| Output | What it is |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `context.glb` | Terrain (USGS 3DEP), roads and paths at their real widths, draped on a smoothed profile, OSM buildings at their tagged heights, destroyed buildings as bare pads. Every mesh is named and carries its address, parcel, height and source. Opens in Blender, Rhino, three.js, Unreal, Unity, Windows 3D Viewer and anything else that imports glTF. |
|
|
28
|
+
| `check.png` | Top-down plot of the context, every parcel, your lot and your property lines, for checking the registration. |
|
|
29
|
+
| `site.kmz` | Your model (and optionally the context) placed in Google Earth Pro at the correct latitude, longitude, altitude and heading. |
|
|
30
|
+
| `context.json` | Counts, the datum, and the offset between OSM and the parcels. |
|
|
31
|
+
|
|
32
|
+
<p align="center"><img src="https://raw.githubusercontent.com/sumanthreddyc/sitecontext/main/docs/img/palisades-3d.jpg" width="49%"> <img src="https://raw.githubusercontent.com/sumanthreddyc/sitecontext/main/docs/img/palisades-check.jpg" width="40%"></p>
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install "sitecontext[all]"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Python 3.10+. The core needs only `numpy` and `shapely`. The extras add `scipy` (lot fitting), `pillow` (terrain) and
|
|
41
|
+
`matplotlib` (check plot).
|
|
42
|
+
|
|
43
|
+
## Quick start
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
sitecontext init palisades --address "861 Alma Real Dr, Pacific Palisades, CA 90272" --radius 250 --parcels la-county
|
|
47
|
+
sitecontext fetch palisades # OSM, parcels, terrain, geoid heights (~1 min, cached)
|
|
48
|
+
sitecontext build palisades # -> palisades/context.glb
|
|
49
|
+
sitecontext check palisades # -> palisades/check.png
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
That gives you the context in local east/north metres, with z = 0 at the ground at the address. To put it in your
|
|
53
|
+
model's coordinates, register the model.
|
|
54
|
+
|
|
55
|
+
## Registering your model
|
|
56
|
+
|
|
57
|
+
The context is most useful in your model's own coordinate system. There are two ways to tie the two together.
|
|
58
|
+
|
|
59
|
+
**Fit to the lot (recommended).** Read the property lines off your site plan, in model coordinates, and give the lot's
|
|
60
|
+
parcel number:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"parcels": {"source": "la-county", "lot_id": "<the lot's parcel number>"},
|
|
65
|
+
"model": {
|
|
66
|
+
"units": "ft",
|
|
67
|
+
"property_lines": [[[0, 0], [62.5, 0]], [[62.5, 0], [64.1, 141.2]], [[0, 0], [-1.8, 139.7]]],
|
|
68
|
+
"z0_elevation": 652.0
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
sitecontext fit mysite
|
|
75
|
+
# prints the bearing of model +Y, the anchor, and the median / max distance of each line from the parcel
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The fit is rigid (rotation and translation, no scale). A coarse search runs over every bearing, followed by a
|
|
79
|
+
robust ICP against the exact parcel boundary, so one misread line does not pull the result off. Read the residuals.
|
|
80
|
+
A line more than about 0.3 m off the parcel is usually a fence or setback line read as the property line, or the
|
|
81
|
+
wrong parcel. Fix the input rather than accepting the fit. Use lines you are sure of: the front and both sides are
|
|
82
|
+
enough. Don't trust the sheet's north arrow; it is often several degrees off, which is why the fit uses the parcel.
|
|
83
|
+
|
|
84
|
+
**By hand.** If you know the bearing of your model's +Y axis and where one point is:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
sitecontext register mysite --bearing 23.4 --anchor 0,0 --at 34.04431,-118.52487
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
After registering, `build` writes the context in model coordinates (metres, z up, z = 0 at `model.z0_elevation`).
|
|
91
|
+
Import it at the origin and it sits around your building.
|
|
92
|
+
|
|
93
|
+
### Other options in `site.json`
|
|
94
|
+
|
|
95
|
+
| Key | Meaning |
|
|
96
|
+
| --- | --- |
|
|
97
|
+
| `model.cutout` | Polygons (model units) where the context is cut out: your modelled site, so terrain never pokes through it. A ground skirt is added down the cut edge. `build --cut-lot` cuts out the whole lot. |
|
|
98
|
+
| `model.street` | `{"osm_name": "Alma Real Drive", "centerline": [[x, y], ...]}`. Shifts OSM roads onto your model's street. OSM is traced from imagery and is often a few metres off the parcels. `earth` reuses this offset to line the model up with the aerial photo. |
|
|
99
|
+
| `context.default_building_height_m` | Height for OSM buildings without `height` or `building:levels` (default 6 m). |
|
|
100
|
+
| `terrain` | `"flat"` outside the US, or when you don't want terrain. |
|
|
101
|
+
| `parcels.url`, `id_field`, `address_fields` | Any county's ArcGIS parcel layer, instead of a preset. |
|
|
102
|
+
|
|
103
|
+
## Google Earth
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
sitecontext earth mysite --model my_house.glb --name "My house"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Export the model as a `.glb` in the same frame you registered (metres). Open the KMZ in Google Earth Pro and untick
|
|
110
|
+
**Layers > 3D Buildings**: Google's photo mesh shows what stands on the site today. A few details are handled for you:
|
|
111
|
+
|
|
112
|
+
- **Height.** USGS terrain is in NAVD88, while Google Earth's `absolute` altitude is EGM96 sea level. The difference
|
|
113
|
+
(about 0.4 m in Los Angeles) is looked up for the site from NOAA GEOID18 and EGM96.
|
|
114
|
+
- **Heading.** The KML model heading is set to the bearing of model +Y.
|
|
115
|
+
- **Transparency.** Earth Pro reads COLLADA transparency inverted, so opaque materials are written without it.
|
|
116
|
+
- **Mesh size.** Large meshes are split at 60k vertices.
|
|
117
|
+
|
|
118
|
+
Google Earth on the web does not show KML 3D models; use Earth Pro.
|
|
119
|
+
|
|
120
|
+
## Other counties
|
|
121
|
+
|
|
122
|
+
Parcels come from any ArcGIS REST layer; most US counties publish one. Find the county's parcel map service, then:
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
"parcels": {"url": "https://.../MapServer/0/query", "id_field": "APN", "address_fields": ["SITUS_ADDR"], "lot_id": "..."}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Pull requests adding verified presets are welcome (see [CONTRIBUTING](https://github.com/sumanthreddyc/sitecontext/blob/main/CONTRIBUTING.md)). Without parcels everything
|
|
129
|
+
except `fit` still works.
|
|
130
|
+
|
|
131
|
+
## Limitations
|
|
132
|
+
|
|
133
|
+
- Terrain comes from USGS 3DEP, so the **United States** only. Elsewhere use `"terrain": "flat"`; a global DEM source
|
|
134
|
+
is on the roadmap.
|
|
135
|
+
- Neighbouring buildings are flat-roofed footprint prisms. They are only as good as OpenStreetMap, and footprints
|
|
136
|
+
may predate recent rebuilds.
|
|
137
|
+
- Trees, walls and driveways are not modelled.
|
|
138
|
+
- Equirectangular local frame: accurate over the ~1 km a site context covers, not for city-scale areas.
|
|
139
|
+
|
|
140
|
+
## Data and attribution
|
|
141
|
+
|
|
142
|
+
Everything is downloaded from public services. Only the address or coordinates are sent, never project or owner
|
|
143
|
+
names. When you share outputs, credit the sources:
|
|
144
|
+
|
|
145
|
+
- Map data © [OpenStreetMap contributors](https://www.openstreetmap.org/copyright), available under the
|
|
146
|
+
[Open Database License](https://opendatacommons.org/licenses/odbl/). Outputs derived from OSM must keep this
|
|
147
|
+
attribution.
|
|
148
|
+
- Elevation: [USGS 3D Elevation Program](https://www.usgs.gov/3d-elevation-program) (public domain).
|
|
149
|
+
- Parcels: the county's terms apply (e.g. LA County Assessor open data).
|
|
150
|
+
- Geoid heights: [NOAA NGS GEOID18](https://geodesy.noaa.gov/GEOID/GEOID18/) and
|
|
151
|
+
[GeographicLib EGM96](https://geographiclib.sourceforge.io/).
|
|
152
|
+
- Geocoding: [Nominatim](https://nominatim.org/), within its usage policy (1 request per second, identified client).
|
|
153
|
+
|
|
154
|
+
## Roadmap
|
|
155
|
+
|
|
156
|
+
- Global terrain (Copernicus GLO-30)
|
|
157
|
+
- IFC input for `earth` and an IFC context export
|
|
158
|
+
- Roof shapes from OSM `roof:*` tags, and trees from OSM
|
|
159
|
+
- More verified county parcel presets
|
|
160
|
+
|
|
161
|
+
## Contributing
|
|
162
|
+
|
|
163
|
+
Issues and pull requests are welcome; see [CONTRIBUTING.md](https://github.com/sumanthreddyc/sitecontext/blob/main/CONTRIBUTING.md). If you use sitecontext on a real
|
|
164
|
+
project, I'd like to hear how it went.
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
[MIT](https://github.com/sumanthreddyc/sitecontext/blob/main/LICENSE) © Sumanth Reddy Challaram
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Turn orbit_####.png frames (from render_blender.py --orbit) into a looping GIF.
|
|
2
|
+
|
|
3
|
+
python examples/make_gif.py out_dir [--width 800] [--fps 15] [--colors 64]
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from PIL import Image
|
|
10
|
+
|
|
11
|
+
args = sys.argv[1:]
|
|
12
|
+
folder = Path(args[0])
|
|
13
|
+
width = int(args[args.index("--width") + 1]) if "--width" in args else 800
|
|
14
|
+
fps = float(args[args.index("--fps") + 1]) if "--fps" in args else 15.0
|
|
15
|
+
colors = int(args[args.index("--colors") + 1]) if "--colors" in args else 64
|
|
16
|
+
frames = sorted(folder.glob("orbit_*.png"))
|
|
17
|
+
if not frames:
|
|
18
|
+
raise SystemExit(f"no orbit_*.png in {folder}")
|
|
19
|
+
imgs = []
|
|
20
|
+
for p in frames:
|
|
21
|
+
im = Image.open(p).convert("RGB")
|
|
22
|
+
im = im.resize((width, round(im.height * width / im.width)), Image.LANCZOS)
|
|
23
|
+
imgs.append(im)
|
|
24
|
+
# one shared palette keeps the file small and stops colour flicker between frames
|
|
25
|
+
pal = imgs[0].quantize(colors=colors, method=Image.Quantize.MEDIANCUT)
|
|
26
|
+
q = [im.quantize(palette=pal, dither=Image.Dither.NONE) for im in imgs]
|
|
27
|
+
out = folder / "orbit.gif"
|
|
28
|
+
q[0].save(out, save_all=True, append_images=q[1:], duration=round(1000 / fps), loop=0, optimize=True)
|
|
29
|
+
print(f"wrote {out} ({out.stat().st_size / 1e6:.1f} MB, {len(q)} frames)")
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Render a context.glb (and optionally your model) with Blender - a still and an orbit for a GIF.
|
|
2
|
+
|
|
3
|
+
blender -b --factory-startup -P examples/render_blender.py -- context.glb out_dir [--model house.glb]
|
|
4
|
+
[--still] [--orbit FRAMES] [--size 1600x1000] [--elev 38] [--azimuth 210] [--distance 1.15]
|
|
5
|
+
|
|
6
|
+
Writes out_dir/still.png and/or out_dir/orbit_####.png (turn them into a GIF with
|
|
7
|
+
``python examples/make_gif.py out_dir``). EEVEE, sun + sky, the glTF materials as exported.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import math
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
import bpy
|
|
15
|
+
from mathutils import Vector
|
|
16
|
+
|
|
17
|
+
argv = sys.argv[sys.argv.index("--") + 1 :]
|
|
18
|
+
ctx, out = Path(argv[0]).resolve(), Path(argv[1]).resolve()
|
|
19
|
+
opt = {
|
|
20
|
+
a: argv[i + 1]
|
|
21
|
+
for i, a in enumerate(argv)
|
|
22
|
+
if a.startswith("--") and i + 1 < len(argv) and not argv[i + 1].startswith("--")
|
|
23
|
+
}
|
|
24
|
+
flags = set(a for a in argv if a.startswith("--"))
|
|
25
|
+
out.mkdir(parents=True, exist_ok=True)
|
|
26
|
+
W, H = (int(v) for v in opt.get("--size", "1600x1000").split("x"))
|
|
27
|
+
|
|
28
|
+
bpy.ops.wm.read_factory_settings(use_empty=True)
|
|
29
|
+
scene = bpy.context.scene
|
|
30
|
+
for p in [ctx] + ([Path(opt["--model"])] if "--model" in opt else []):
|
|
31
|
+
bpy.ops.import_scene.gltf(filepath=str(p))
|
|
32
|
+
|
|
33
|
+
# bounds of the context (ignore the terrain skirt below ground)
|
|
34
|
+
pts = [o.matrix_world @ Vector(c) for o in scene.objects if o.type == "MESH" for c in o.bound_box]
|
|
35
|
+
lo = Vector((min(p.x for p in pts), min(p.y for p in pts), min(p.z for p in pts)))
|
|
36
|
+
hi = Vector((max(p.x for p in pts), max(p.y for p in pts), max(p.z for p in pts)))
|
|
37
|
+
centre = (lo + hi) / 2
|
|
38
|
+
radius = max(hi.x - lo.x, hi.y - lo.y) / 2
|
|
39
|
+
|
|
40
|
+
# look: soft sun + sky, filmic, slight AO
|
|
41
|
+
world = bpy.data.worlds.new("sky")
|
|
42
|
+
scene.world = world
|
|
43
|
+
world.use_nodes = True
|
|
44
|
+
bg = world.node_tree.nodes["Background"]
|
|
45
|
+
bg.inputs[0].default_value = (0.55, 0.66, 0.82, 1.0)
|
|
46
|
+
bg.inputs[1].default_value = 0.6
|
|
47
|
+
sun = bpy.data.objects.new("sun", bpy.data.lights.new("sun", "SUN"))
|
|
48
|
+
sun.data.energy = 4.0
|
|
49
|
+
sun.data.angle = math.radians(3)
|
|
50
|
+
sun.rotation_euler = (math.radians(50), 0, math.radians(135))
|
|
51
|
+
scene.collection.objects.link(sun)
|
|
52
|
+
scene.render.engine = "BLENDER_EEVEE"
|
|
53
|
+
scene.render.resolution_x, scene.render.resolution_y = W, H
|
|
54
|
+
scene.render.film_transparent = False
|
|
55
|
+
scene.view_settings.view_transform = "Standard"
|
|
56
|
+
try:
|
|
57
|
+
scene.eevee.use_shadows = True
|
|
58
|
+
scene.eevee.taa_render_samples = 32
|
|
59
|
+
except AttributeError:
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
cam = bpy.data.objects.new("cam", bpy.data.cameras.new("cam"))
|
|
63
|
+
cam.data.lens = 35
|
|
64
|
+
cam.data.clip_end = 10 * radius
|
|
65
|
+
scene.collection.objects.link(cam)
|
|
66
|
+
scene.camera = cam
|
|
67
|
+
target = bpy.data.objects.new("target", None)
|
|
68
|
+
target.location = (centre.x, centre.y, lo.z + 0.15 * (hi.z - lo.z))
|
|
69
|
+
scene.collection.objects.link(target)
|
|
70
|
+
track = cam.constraints.new("TRACK_TO")
|
|
71
|
+
track.target = target
|
|
72
|
+
track.track_axis, track.up_axis = "TRACK_NEGATIVE_Z", "UP_Y"
|
|
73
|
+
|
|
74
|
+
elev = math.radians(float(opt.get("--elev", 38)))
|
|
75
|
+
dist = float(opt.get("--distance", 1.0)) * radius / math.tan(math.radians(25)) * 1.25
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def place(az_deg: float) -> None:
|
|
79
|
+
a = math.radians(az_deg)
|
|
80
|
+
cam.location = (
|
|
81
|
+
target.location.x + dist * math.cos(elev) * math.sin(a),
|
|
82
|
+
target.location.y - dist * math.cos(elev) * math.cos(a),
|
|
83
|
+
target.location.z + dist * math.sin(elev),
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
az0 = float(opt.get("--azimuth", 210))
|
|
88
|
+
if "--still" in flags or "--orbit" not in opt:
|
|
89
|
+
place(az0)
|
|
90
|
+
scene.render.filepath = str(out / "still.png")
|
|
91
|
+
bpy.ops.render.render(write_still=True)
|
|
92
|
+
if "--orbit" in opt:
|
|
93
|
+
n = int(opt["--orbit"])
|
|
94
|
+
for i in range(n):
|
|
95
|
+
place(az0 + 360.0 * i / n)
|
|
96
|
+
scene.render.filepath = str(out / f"orbit_{i:04d}.png")
|
|
97
|
+
bpy.ops.render.render(write_still=True)
|
|
98
|
+
print("done", out)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sitecontext"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "3D site context for any building model from an address: OpenStreetMap roads and buildings, county parcels and USGS terrain, registered to the lot and exported to glTF and Google Earth."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Sumanth Reddy Challaram" }]
|
|
14
|
+
keywords = ["aec", "bim", "gis", "openstreetmap", "gltf", "kml", "google-earth", "site-analysis", "parcels", "terrain"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Science/Research",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Topic :: Scientific/Engineering :: GIS",
|
|
23
|
+
"Topic :: Multimedia :: Graphics :: 3D Modeling",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"numpy>=1.24",
|
|
27
|
+
"shapely>=2.1",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.optional-dependencies]
|
|
31
|
+
fit = ["scipy>=1.10"]
|
|
32
|
+
terrain = ["pillow>=10"]
|
|
33
|
+
plot = ["matplotlib>=3.7"]
|
|
34
|
+
all = ["scipy>=1.10", "pillow>=10", "matplotlib>=3.7"]
|
|
35
|
+
dev = ["scipy>=1.10", "pillow>=10", "matplotlib>=3.7", "pytest>=8", "ruff>=0.6"]
|
|
36
|
+
|
|
37
|
+
[project.scripts]
|
|
38
|
+
sitecontext = "sitecontext.cli:main"
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/sumanthreddyc/sitecontext"
|
|
42
|
+
Issues = "https://github.com/sumanthreddyc/sitecontext/issues"
|
|
43
|
+
|
|
44
|
+
[tool.hatch.version]
|
|
45
|
+
path = "src/sitecontext/__init__.py"
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.targets.wheel]
|
|
48
|
+
packages = ["src/sitecontext"]
|
|
49
|
+
|
|
50
|
+
[tool.ruff]
|
|
51
|
+
line-length = 110
|
|
52
|
+
target-version = "py310"
|
|
53
|
+
|
|
54
|
+
[tool.ruff.lint]
|
|
55
|
+
select = ["E", "F", "W", "I", "B", "UP"]
|
|
56
|
+
ignore = ["E501", "B905"]
|
|
57
|
+
|
|
58
|
+
[tool.pytest.ini_options]
|
|
59
|
+
testpaths = ["tests"]
|
|
60
|
+
|
|
61
|
+
[tool.hatch.build.targets.sdist]
|
|
62
|
+
exclude = ["docs/img", ".github"]
|