| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | import fs from "fs" | 
					
						
							|  |  |  | import { GeoOperations } from "../Logic/GeoOperations" | 
					
						
							|  |  |  | import ScriptUtils from "./ScriptUtils" | 
					
						
							| 
									
										
										
										
											2021-12-09 18:01:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Given one of more files, calculates a somewhat convex hull for them | 
					
						
							|  |  |  |  * @param file | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function makeConvex(file) { | 
					
						
							|  |  |  |     ScriptUtils.erasableLog("Handling", file) | 
					
						
							|  |  |  |     const geoJson = JSON.parse(fs.readFileSync(file, "UTF8")) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  |     const convex = GeoOperations.convexHull(geoJson, { concavity: 2 }) | 
					
						
							| 
									
										
										
										
											2021-12-09 18:01:11 +01:00
										 |  |  |     if (convex.properties === undefined) { | 
					
						
							|  |  |  |         convex.properties = {} | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     fs.writeFileSync(file + ".convex.geojson", JSON.stringify(convex)) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let args = [...process.argv] | 
					
						
							|  |  |  | args.splice(0, 2) | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | args.forEach((file) => { | 
					
						
							| 
									
										
										
										
											2021-12-09 18:01:11 +01:00
										 |  |  |     try { | 
					
						
							|  |  |  |         makeConvex(file) | 
					
						
							|  |  |  |     } catch (e) { | 
					
						
							|  |  |  |         console.error("Could not handle file ", file, " due to ", e) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-09-08 21:40:48 +02:00
										 |  |  | }) |