Skip to content

Commit f95f972

Browse files
committed
Working on auto neighbourhood splitting: handling coastline severances,
visualizing the outputs better, plumbing through the area
1 parent 6ede41d commit f95f972

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

backend/src/auto_boundaries.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use geo::{Coord, LineString, Polygon};
1+
use geo::{Area, Coord, LineString, Polygon};
22
use geojson::FeatureCollection;
33
use i_float::f64_point::F64Point;
44
use i_overlay::core::fill_rule::FillRule;
@@ -54,6 +54,8 @@ impl MapModel {
5454
for polygon in split_polygon(self.mercator.to_mercator(&self.boundary_wgs84), severances) {
5555
let mut f = self.mercator.to_wgs84_gj(&polygon);
5656
f.set_property("kind", "area");
57+
// Convert from m^2 to km^2. Use unsigned area to ignore polygon orientation.
58+
f.set_property("area_km2", polygon.unsigned_area() / 1_000_000.0);
5759
features.push(f);
5860
}
5961

backend/src/scrape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn scrape_osm(
6161
node_ids.into_iter().map(|n| node_mapping[&n]).collect(),
6262
));
6363
}
64-
} else if tags.is("natural", "water") {
64+
} else if tags.is_any("natural", vec!["water", "coastline"]) {
6565
// If the entire area is inside the study area, the LineString will be closed. If
6666
// it intersects the study area, then it might not be.
6767
node_ids.retain(|n| node_mapping.contains_key(n));

web/src/AutoBoundariesMode.svelte

+34-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
hoverStateFilter,
88
type LayerClickInfo,
99
} from "svelte-maplibre";
10-
import { Link, layerId } from "./common";
11-
import { isLine } from "svelte-utils/map";
10+
import { Link, Popup, layerId } from "./common";
11+
import { isLine, isPolygon } from "svelte-utils/map";
1212
import { SplitComponent } from "svelte-utils/top_bar_layout";
1313
import { app, mode, autosave } from "./stores";
1414
import { downloadGeneratedFile } from "svelte-utils";
1515
1616
let gj = JSON.parse($app!.renderAutoBoundaries());
17+
let minArea = 0;
1718
1819
function add(e: CustomEvent<LayerClickInfo>) {
1920
let name = window.prompt("What do you want to name the neighbourhood?");
@@ -71,26 +72,52 @@
7172

7273
<div slot="sidebar">
7374
<BackButton on:click={() => ($mode = { mode: "network" })} />
75+
7476
<p>
7577
Click an area to use it as a neighbourhood. These are generated by finding
76-
roads, railways, and water thatform severances. There are many bugs; this
77-
is experimental.
78+
roads, railways, and water that form severances. There are many bugs; this
79+
is experimental. The colors are arbitrary, just to distinguish better.
7880
</p>
81+
7982
<button class="secondary" on:click={download}>Export to GeoJSON</button>
83+
84+
<label>
85+
Minimum area (km²)
86+
<input type="number" bind:value={minArea} min="0" max="1" step="0.01" />
87+
</label>
8088
</div>
8189

8290
<div slot="map">
8391
<GeoJSON data={gj} generateId>
8492
<FillLayer
8593
{...layerId("auto-boundaries-areas")}
94+
filter={["all", isPolygon, [">=", ["get", "area_km2"], minArea]]}
8695
manageHoverState
8796
paint={{
88-
"fill-color": hoverStateFilter("cyan", "red"),
89-
"fill-opacity": 0.3,
97+
"fill-color": [
98+
"match",
99+
["%", ["id"], 5],
100+
0,
101+
"blue",
102+
1,
103+
"yellow",
104+
2,
105+
"green",
106+
3,
107+
"purple",
108+
4,
109+
"orange",
110+
"black",
111+
],
112+
"fill-opacity": hoverStateFilter(0.3, 0.7),
90113
}}
91114
on:click={add}
92115
hoverCursor="pointer"
93-
/>
116+
>
117+
<Popup openOn="hover" let:props>
118+
Area: {props.area_km2.toFixed(5)} km²
119+
</Popup>
120+
</FillLayer>
94121

95122
<LineLayer
96123
{...layerId("auto-boundaries-severances")}

web/src/common/zorder.ts

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const layerZorder = [
6161
// TODO Handle all basemaps now
6262
"Background",
6363

64+
// TODO These don't show up at low zoom, I think because Residential is hidden
6465
"neighbourhood-boundaries",
6566

6667
// MapTiler basemap

0 commit comments

Comments
 (0)