This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZES: Rework highway data download, refactor property enhancement
Rework the way we add the `FMC:length` to the GeoJSON: Before, we did it by iterating over all ways to add the length based on a huge array. Now we have the length as part of the properties right from overpass, BUT we need to manually create our GeoJSON, since osmtogeojson does not support the output of overpass convert. (For some reasons, we don't need to cut the results to a bbox anymore after switching to convert.) Related refactorings: - Add the custom property links (OSM + Mapillary) up front when we create our main GeoJson - Rename the custom category property - Disable the addLengthFromOverpassStats method/file since we don't use it anymore
- Loading branch information
Showing
13 changed files
with
174 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Feature } from "./types" | ||
|
||
export const addCategoryProperty = ( | ||
features: Feature[], | ||
filterMethodName: string | ||
) => { | ||
features.forEach((feature) => { | ||
feature.properties["FMC:category"] = filterMethodName | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
68 changes: 68 additions & 0 deletions
68
ZESPlus/utils/overpassToGeoJson/overpassComposeToGeoJson.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import fs from "fs" | ||
import { areaKeys } from "../../AreaOfInterest/areas.constant" | ||
import { addLinkProperties } from "../transpose/addLinkProperties" | ||
import { processingDateProperty } from "../transpose/addProcessingDateProperty" | ||
import { FeatureCollection } from "../types" | ||
import { writeFile } from "../writeFile" | ||
import { OverpassToGeoJson } from "./types" | ||
|
||
export const overpassComposeToGeoJson = ({ | ||
readFile, | ||
outputFolder, | ||
fileNamePart, | ||
filterCallback, | ||
areaCallback, | ||
}: OverpassToGeoJson) => { | ||
fs.readFile(readFile, "utf8", (err, _data) => { | ||
if (err) { | ||
console.error(err) | ||
return | ||
} | ||
console.log( | ||
"overpassComposeToGeoJson()", | ||
"Parse, Transform, Enhance and Write file" | ||
) | ||
console.time(`overpassComposeToGeoJson(): Transform, enhance, write`) | ||
|
||
const rawJsonData = JSON.parse(_data) | ||
const geoJsonData = { | ||
type: "FeatureCollection", | ||
generator: rawJsonData.generator, | ||
copyright: rawJsonData.osm3s.copyright, | ||
timestamp: rawJsonData.osm3s.timestamp_osm_base, | ||
features: rawJsonData.elements.map((element) => { | ||
// `__type` is a helper that we add in `1-download-highways/download.ts` > `compose`` | ||
// to re-generate the full GeoJSON osmId. Afterwards, we can clean it up. | ||
const osmId = `${element.tags.__type}/${element.id}` | ||
delete element.tags.__type | ||
|
||
return { | ||
type: "Feature", | ||
properties: { | ||
"@id": osmId, | ||
...element.tags, | ||
...processingDateProperty, | ||
}, | ||
geometry: element.geometry, | ||
id: osmId, | ||
} | ||
}), | ||
} as FeatureCollection | ||
|
||
// addProcessingDateProperty(geoJsonData.features) // Done via spread operator above | ||
addLinkProperties(geoJsonData.features) | ||
filterCallback && filterCallback(geoJsonData) | ||
areaCallback && | ||
areaKeys.forEach((areaKey) => areaCallback(areaKey, geoJsonData)) | ||
|
||
writeFile({ | ||
dataString: JSON.stringify(geoJsonData, null, 2), | ||
dataLength: geoJsonData.features.length, | ||
outputFolder: outputFolder, | ||
fileNamePart: fileNamePart, | ||
format: "geojson", | ||
}) | ||
|
||
console.timeEnd(`overpassComposeToGeoJson(): Transform, enhance, write`) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import fs from "fs" | ||
import osmtogeojson from "osmtogeojson" | ||
import { areaKeys } from "../../AreaOfInterest/areas.constant" | ||
import { addLinkProperties } from "../transpose/addLinkProperties" | ||
import { addProcessingDateProperty } from "../transpose/addProcessingDateProperty" | ||
import { FeatureCollection } from "../types" | ||
import { writeFile } from "../writeFile" | ||
import { OverpassToGeoJson } from "./types" | ||
|
||
export const overpassJsonToGeoJson = ({ | ||
readFile, | ||
outputFolder, | ||
fileNamePart, | ||
filterCallback, | ||
areaCallback, | ||
}: OverpassToGeoJson) => { | ||
fs.readFile(readFile, "utf8", (err, _data) => { | ||
if (err) { | ||
console.error(err) | ||
return | ||
} | ||
console.log( | ||
"overpassJsonToGeoJson():", | ||
"Parse, Transform, Enhance and Write file" | ||
) | ||
|
||
const rawJsonData = JSON.parse(_data) | ||
const geoJsonData = osmtogeojson(rawJsonData) as FeatureCollection | ||
|
||
addProcessingDateProperty(geoJsonData.features) | ||
addLinkProperties(geoJsonData.features) | ||
filterCallback && filterCallback(geoJsonData) | ||
areaCallback && | ||
areaKeys.forEach((areaKey) => areaCallback(areaKey, geoJsonData)) | ||
|
||
writeFile({ | ||
dataString: JSON.stringify(geoJsonData, null, 2), | ||
dataLength: geoJsonData.features.length, | ||
outputFolder: outputFolder, | ||
fileNamePart: fileNamePart, | ||
format: "geojson", | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { FeatureCollection } from "../types" | ||
|
||
export type AreaCallbackProps = ( | ||
areaKey: string, | ||
geoJson: FeatureCollection | ||
) => void | ||
|
||
export type OverpassToGeoJson = { | ||
readFile: string | ||
outputFolder: string | ||
fileNamePart: string | ||
filterCallback?: (geoJson: FeatureCollection) => void | ||
areaCallback?: AreaCallbackProps | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Feature } from "../types" | ||
|
||
const processingDateCreatedAt = new Date() | ||
.toISOString() | ||
.slice(0, 16) | ||
.replace("T", " ") | ||
|
||
export const processingDateProperty = { | ||
"FMC:DataCreatedAndProcessedAt": `${processingDateCreatedAt}`, | ||
} | ||
|
||
export const addProcessingDateProperty = (features: Feature[]) => { | ||
console.time("addProcessingDateProperty()") | ||
|
||
features.forEach((feature) => { | ||
feature.properties = { ...feature.properties, ...processingDateProperty } | ||
}) | ||
|
||
console.timeEnd("addProcessingDateProperty()") | ||
} |
This file was deleted.
Oops, something went wrong.