forked from MapComplete/MapComplete
		
	Merge develop
This commit is contained in:
		
						commit
						0162d52b68
					
				
					 127 changed files with 6609 additions and 15167 deletions
				
			
		|  | @ -276,14 +276,61 @@ export class GeoOperations { | |||
|         } | ||||
|         return undefined; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Generates the closest point on a way from a given point | ||||
|      * @param way The road on which you want to find a point | ||||
|      * @param point Point defined as [lon, lat] | ||||
|      */ | ||||
|     public static nearestPoint(way, point: [number, number]){ | ||||
|     public static nearestPoint(way, point: [number, number]) { | ||||
|         return turf.nearestPointOnLine(way, point, {units: "kilometers"}); | ||||
|     } | ||||
| 
 | ||||
|     public static toCSV(features: any[]): string { | ||||
| 
 | ||||
|         const headerValuesSeen = new Set<string>(); | ||||
|         const headerValuesOrdered: string[] = [] | ||||
| 
 | ||||
|         function addH(key) { | ||||
|             if (!headerValuesSeen.has(key)) { | ||||
|                 headerValuesSeen.add(key) | ||||
|                 headerValuesOrdered.push(key) | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         addH("_lat") | ||||
|         addH("_lon") | ||||
| 
 | ||||
|         const lines: string[] = [] | ||||
| 
 | ||||
|         for (const feature of features) { | ||||
|             const properties = feature.properties; | ||||
|             for (const key in properties) { | ||||
|                 if (!properties.hasOwnProperty(key)) { | ||||
|                     continue; | ||||
|                 } | ||||
|                 addH(key) | ||||
| 
 | ||||
|             } | ||||
|         } | ||||
|         headerValuesOrdered.sort() | ||||
|         for (const feature of features) { | ||||
|             const properties = feature.properties; | ||||
|             let line = "" | ||||
|             for (const key of headerValuesOrdered) { | ||||
|                 const value = properties[key] | ||||
|                 if (value === undefined) { | ||||
|                     line += "," | ||||
|                 } else { | ||||
|                     line += JSON.stringify(value)+"," | ||||
|                 } | ||||
|             } | ||||
|             lines.push(line) | ||||
|         } | ||||
| 
 | ||||
|         return headerValuesOrdered.map(v => JSON.stringify(v)).join(",") + "\n" + lines.join("\n") | ||||
|     } | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue