Mercurial > gemma
comparison client/src/lib/geo.js @ 2264:627bfcbbf631
client: Draw fairway dimensions for all LoS and in more "cut cases".
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 14 Feb 2019 13:53:54 +0100 |
parents | ca33ad696594 |
children | 940ae7c20326 |
comparison
equal
deleted
inserted
replaced
2263:7efa29d16e77 | 2264:627bfcbbf631 |
---|---|
24 import distance from "@turf/distance"; | 24 import distance from "@turf/distance"; |
25 import { | 25 import { |
26 lineString as turfLineString, | 26 lineString as turfLineString, |
27 polygon as turfPolygon | 27 polygon as turfPolygon |
28 } from "@turf/helpers"; | 28 } from "@turf/helpers"; |
29 import lineSplit from "@turf/line-split"; | |
30 import lineSlice from "@turf/line-slice"; | |
29 import lineIntersect from "@turf/line-intersect"; | 31 import lineIntersect from "@turf/line-intersect"; |
32 import booleanWithin from "@turf/boolean-within"; | |
33 import booleanContains from "@turf/boolean-contains"; | |
30 | 34 |
31 const EARTHRADIUS = 6378137.0; | 35 const EARTHRADIUS = 6378137.0; |
32 | 36 |
33 /** | 37 /** |
34 * Converts to radiant | 38 * Converts to radiant |
182 // uses turfjs distance() function | 186 // uses turfjs distance() function |
183 let fairwayCoordinates = []; | 187 let fairwayCoordinates = []; |
184 var line = turfLineString(profileLine.getCoordinates()); | 188 var line = turfLineString(profileLine.getCoordinates()); |
185 var polygon = turfPolygon(fairwayGeometry.getCoordinates()); | 189 var polygon = turfPolygon(fairwayGeometry.getCoordinates()); |
186 var intersects = lineIntersect(line, polygon); | 190 var intersects = lineIntersect(line, polygon); |
187 var l = intersects.features.length; | 191 |
188 if (l % 2 != 0) { | 192 var startPoint, endPoint |
189 console.log("Ignoring fairway because profile only intersects once."); | 193 |
194 if (intersects.features.length == 2) { | |
195 let line1 = lineSlice(intersects.features[0].geometry, intersects.features[1].geometry, line); | |
196 startPoint = line1.geometry.coordinates[0]; | |
197 endPoint = line1.geometry.coordinates[1]; | |
198 } else if (booleanWithin(line, polygon)) { | |
199 startPoint = line.geometry.coordinates[0]; | |
200 endPoint = line.geometry.coordinates[1]; | |
190 } else { | 201 } else { |
191 for (let i = 0; i < l; i += 2) { | 202 let split = lineSplit(line, polygon); |
192 let pStartPoint = profileLine.getCoordinates()[0]; | 203 for (let feature of split.features) { |
193 let fStartPoint = intersects.features[i].geometry.coordinates; | 204 if (booleanWithin(feature, polygon)){ |
194 let fEndPoint = intersects.features[i + 1].geometry.coordinates; | 205 startPoint = feature.geometry.coordinates[0]; |
195 let opts = { units: "kilometers" }; | 206 endPoint = feature.geometry.coordinates[1]; |
196 | 207 } |
197 fairwayCoordinates.push([ | 208 if (booleanContains(polygon, feature)){ |
198 distance(pStartPoint, fStartPoint, opts) * 1000, | 209 startPoint = feature.geometry.coordinates[0]; |
199 distance(pStartPoint, fEndPoint, opts) * 1000, | 210 endPoint = feature.geometry.coordinates[1]; |
200 depth | 211 } |
201 ]); | |
202 } | 212 } |
203 } | 213 } |
214 | |
215 let opts = { units: "kilometers" }; | |
216 let pStartPoint = profileLine.getCoordinates()[0]; | |
217 fairwayCoordinates.push([ | |
218 distance(pStartPoint, startPoint, opts) * 1000, | |
219 distance(pStartPoint, endPoint, opts) * 1000, | |
220 depth | |
221 ]); | |
222 | |
204 return fairwayCoordinates; | 223 return fairwayCoordinates; |
205 }; | 224 }; |
206 | 225 |
207 export { generateFeatureRequest, prepareProfile, calculateFairwayCoordinates }; | 226 const featureToFairwayCoordinates = (feature, profileLine) => { |
227 // need to use EPSG:3857 which is the proj of vectorSource | |
228 var intersectingPolygon = feature | |
229 .getGeometry() | |
230 .clone() | |
231 .transform("EPSG:3857", "EPSG:4326"); | |
232 const fairwayCoordinates = calculateFairwayCoordinates( | |
233 profileLine, | |
234 intersectingPolygon, | |
235 feature.get("min_depth") ? feature.get("min_depth") / 100 : 2.5 | |
236 ); | |
237 return fairwayCoordinates; | |
238 }; | |
239 | |
240 export { | |
241 generateFeatureRequest, | |
242 prepareProfile, | |
243 calculateFairwayCoordinates, | |
244 featureToFairwayCoordinates | |
245 }; |