# HG changeset patch # User Markus Kottlaender # Date 1540388287 -7200 # Node ID 4299f9c1f191a35c2923838cdf46d2e0bc1347fc # Parent fd7059f7cbdc88576e8b250a78c28b22ebfc4f32# Parent 4c0c4dd393dee28866f00c8cb0196fe714ce2877 merge diff -r fd7059f7cbdc -r 4299f9c1f191 client/src/application/Main.vue --- a/client/src/application/Main.vue Wed Oct 24 15:35:50 2018 +0200 +++ b/client/src/application/Main.vue Wed Oct 24 15:38:07 2018 +0200 @@ -1,8 +1,28 @@ @@ -65,7 +85,7 @@ "selectedWaterLevel", "availableSurveys" ]), - ...mapState("morphstore", ["selectedMorph"]), + ...mapState("fairwayprofile", ["selectedMorph"]), additionalSurveys() { if (!this.availableSurveys) return []; return this.availableSurveys.surveys.filter(x => { diff -r fd7059f7cbdc -r 4299f9c1f191 client/src/application/lib/geo.js --- a/client/src/application/lib/geo.js Wed Oct 24 15:35:50 2018 +0200 +++ b/client/src/application/lib/geo.js Wed Oct 24 15:38:07 2018 +0200 @@ -22,6 +22,12 @@ import { GeoJSON } from "ol/format.js"; import Feature from "ol/Feature"; +import distance from "@turf/distance"; +import { + lineString as turfLineString, + polygon as turfPolygon +} from "@turf/helpers"; +import lineIntersect from "@turf/line-intersect"; const EARTHRADIUS = 6378137.0; @@ -163,13 +169,40 @@ }; }; -const generateFeatureRequest = (profileLine, survey) => { +const generateFeatureRequest = (profileLine, bottleneck_id, date_info) => { const feature = new Feature({ geometry: profileLine, - bottleneck: survey.bottleneck_id, - date: survey.date_info + bottleneck: bottleneck_id, + date: date_info }); return new GeoJSON({ geometryName: "geometry" }).writeFeature(feature); }; -export { generateFeatureRequest, prepareProfile }; +const calculateFairwayCoordinates = (profileLine, fairwayGeometry, depth) => { + // both geometries have to be in EPSG:4326 + // uses turfjs distance() function + let fairwayCoordinates = []; + var line = turfLineString(profileLine.getCoordinates()); + var polygon = turfPolygon(fairwayGeometry.getCoordinates()); + var intersects = lineIntersect(line, polygon); + var l = intersects.features.length; + if (l % 2 != 0) { + console.log("Ignoring fairway because profile only intersects once."); + } else { + for (let i = 0; i < l; i += 2) { + let pStartPoint = profileLine.getCoordinates()[0]; + let fStartPoint = intersects.features[i].geometry.coordinates; + let fEndPoint = intersects.features[i + 1].geometry.coordinates; + let opts = { units: "kilometers" }; + + fairwayCoordinates.push([ + distance(pStartPoint, fStartPoint, opts) * 1000, + distance(pStartPoint, fEndPoint, opts) * 1000, + depth + ]); + } + } + return fairwayCoordinates; +}; + +export { generateFeatureRequest, prepareProfile, calculateFairwayCoordinates }; diff -r fd7059f7cbdc -r 4299f9c1f191 client/src/fairway/Fairwayprofile.vue --- a/client/src/fairway/Fairwayprofile.vue Wed Oct 24 15:35:50 2018 +0200 +++ b/client/src/fairway/Fairwayprofile.vue Wed Oct 24 15:38:07 2018 +0200 @@ -1,22 +1,28 @@