| 1234567891011121314151617181920212223242526 |
- import * as turf from '@turf/turf'
- export function candidateFootprint({ lon, lat, width, depth, heading }) {
- const cosLat = Math.cos((lat * Math.PI) / 180)
- const dx = (Math.cos(heading) * width) / 111320
- const dy = (Math.sin(heading) * width) / (111320 * cosLat)
- const ex = (-Math.sin(heading) * depth) / (111320 * cosLat)
- const ey = (Math.cos(heading) * depth) / 111320
- return turf.polygon([[
- [lon - dx / 2 - ex / 2, lat - dy / 2 - ey / 2],
- [lon + dx / 2 - ex / 2, lat + dy / 2 - ey / 2],
- [lon + dx / 2 + ex / 2, lat + dy / 2 + ey / 2],
- [lon - dx / 2 + ex / 2, lat - dy / 2 + ey / 2],
- [lon - dx / 2 - ex / 2, lat - dy / 2 - ey / 2],
- ]])
- }
- export function isSafeOldTownPlacement(footprint, { mask, roads, water, existing, modeled, accepted }) {
- if (!turf.booleanWithin(footprint, mask)) return false
- if (roads.some(road => turf.booleanIntersects(footprint, road))) return false
- if (water.some(polygon => turf.booleanIntersects(footprint, polygon))) return false
- if (existing.some(building => turf.booleanIntersects(footprint, building))) return false
- if (modeled.some(building => turf.booleanIntersects(footprint, building))) return false
- if (accepted.some(building => turf.booleanIntersects(footprint, building))) return false
- return true
- }
|