Files
laadpalenviewer/webapp/lib/pointInGemeente.ts
T
robbertjanssen85andClaude Fable 5 cbd4531574 Rework freight classification and fix analysis/webapp derivations
Freight classification v2: two-tier freightKind ('dedicated' via truck
operator, truck-named location (forklifts excluded), MCS, logistics depot
>=150 kW DC, or curated hub; 'hpc' for power-only >=350 kW DC) with
freightReason carried through to the map and detail panel. Connector power
is now derived from V x A when max_electric_power is missing or implausible
(caps out NDW garbage like 7.36 MW on a 22 kW AC post), eliminating all
zero-kW points. Adds Milence Waddinxveen to curated hubs and a
nearest-gemeente fallback so coastal/industrial sites get detail bundles.
Tariff matching now honors one-sided time windows.

Analysis: peak load finally uses the 150 kW freight constant (was priced at
11 kW), crop stats split by layer so freight no longer skews supply/price
metrics, occupancy is EVSE-weighted, charging_now samples one common hour,
and a new Logistiek metric group exports chargers_freight/freight_dedicated/
freight_power_kw. Relabels peer-model outputs as modelled supply.

Webapp: freight markers colored by kind with status ring, dedicated-only
filter, filter counts respect the power filter, status tallies scoped to
passenger, national-view detail panel can jump into the point's gemeente,
connector kW display mirrors the pipeline derivation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 01:08:54 +02:00

41 lines
1.3 KiB
TypeScript

// Locate the gemeente (by slug) whose polygon contains a point, using the
// analysis choropleth as the polygon source. Ray casting; holes respected.
import type { ChoroplethData } from "@/types/analysis";
function inRing(ring: number[][], lng: number, lat: number): boolean {
let inside = false;
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
const [xi, yi] = ring[i];
const [xj, yj] = ring[j];
if (yi > lat !== yj > lat && lng < ((xj - xi) * (lat - yi)) / (yj - yi) + xi) inside = !inside;
}
return inside;
}
function inPolygon(coords: number[][][], lng: number, lat: number): boolean {
if (!coords.length || !inRing(coords[0], lng, lat)) return false;
for (let k = 1; k < coords.length; k++) {
if (inRing(coords[k], lng, lat)) return false; // inside a hole
}
return true;
}
export function findGemeenteSlug(
choropleth: ChoroplethData | null,
lng: number,
lat: number,
): string | null {
if (!choropleth) return null;
for (const f of choropleth.features) {
const g = f.geometry;
const hit =
g.type === "Polygon"
? inPolygon(g.coordinates as number[][][], lng, lat)
: g.type === "MultiPolygon"
? (g.coordinates as number[][][][]).some((p) => inPolygon(p, lng, lat))
: false;
if (hit) return f.properties.slug ?? null;
}
return null;
}