Skip to content

Commit

Permalink
Add option to getGeojsonsFromRawData()
Browse files Browse the repository at this point in the history
Modifies the function getGeojsonsFromRawData() so that it accepts a new option parameter, continueOnMissingGeojson.
When generateNodesIfNotFound is false and continueOnMissingGeojson true, the function will just go to the next geojson and print a warning if a feature that is in the osm raw data is not in the geojson data.
Previously, the only option was to throw an error and interrupt the process.
  • Loading branch information
GabrielBruno24 committed Jan 23, 2025
1 parent a53af89 commit e4072fd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,15 @@ export default class OsmDataPreparationNonResidential {
const allPoIBuildings: PoiBuilding[] = osmGeojsonService.getGeojsonsFromRawData(
this._osmGeojsonData,
allOsmBuildings,
{ generateNodesIfNotFound: true }
{ generateNodesIfNotFound: true, continueOnMissingGeojson: false }
);

const allBuildingPartsRaw = this._osmRawData.queryOr(queryBuildingPartsFromOsm);
const allBuildingParts: SingleGeoFeature[] = osmGeojsonService
.getGeojsonsFromRawData(this._osmGeojsonData, allBuildingPartsRaw, { generateNodesIfNotFound: true })
.getGeojsonsFromRawData(this._osmGeojsonData, allBuildingPartsRaw, {
generateNodesIfNotFound: true,
continueOnMissingGeojson: false
})
.map((part) => part.geojson);

console.log('=== Map shop and main entrances to each building... ===');
Expand All @@ -176,7 +179,10 @@ export default class OsmDataPreparationNonResidential {
entrances.length === 0
? undefined
: osmGeojsonService
.getGeojsonsFromRawData(this._osmGeojsonData, entrances, { generateNodesIfNotFound: true })
.getGeojsonsFromRawData(this._osmGeojsonData, entrances, {
generateNodesIfNotFound: true,
continueOnMissingGeojson: true
})
.map((entrance) => entrance.geojson as GeoJSON.Feature<GeoJSON.Point>);
// Get building parts
building.parts = findOverlappingFeatures(building.geojson, allBuildingParts);
Expand All @@ -197,7 +203,8 @@ export default class OsmDataPreparationNonResidential {
.filter((poi) => getCategoryFromProperty(poi.tags || {}).length !== 0);
const allOsmPoisGeojson = osmGeojsonService
.getGeojsonsFromRawData(this._osmGeojsonData, allOsmPoisFeatures, {
generateNodesIfNotFound: true
generateNodesIfNotFound: true,
continueOnMissingGeojson: true
})
.map((poi) => poi.geojson);

Expand Down Expand Up @@ -279,7 +286,8 @@ export default class OsmDataPreparationNonResidential {
}
return toPoi(
osmGeojsonService.getGeojsonsFromRawData(this._osmGeojsonData, [entrances[0]], {
generateNodesIfNotFound: true
generateNodesIfNotFound: true,
continueOnMissingGeojson: false
})[0].geojson.geometry as GeoJSON.Point,
poi,
{
Expand Down Expand Up @@ -365,7 +373,8 @@ export default class OsmDataPreparationNonResidential {
}
return toPoi(
osmGeojsonService.getGeojsonsFromRawData(this._osmGeojsonData, [entrances[0]], {
generateNodesIfNotFound: true
generateNodesIfNotFound: true,
continueOnMissingGeojson: false
})[0].geojson.geometry as GeoJSON.Point,
poi,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export default class OsmDataPreparationResidential {
const allOsmResidentialBuildings = osmRawData.queryOr(queryResidentialBuildingsFromOsm);
const residentialBuildings = osmGeojsonService.getGeojsonsFromRawData(
osmGeojsonData,
allOsmResidentialBuildings
allOsmResidentialBuildings,
{ generateNodesIfNotFound: false, continueOnMissingGeojson: true }
);

// For each building, get its entrances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('getGeojsonsFromRawData', () => {
{ type: 'node' as const, id: '1234', lon: -73, lat: 45 },
{ type: 'node' as const, id: '2345', lon: -73.1, lat: 45.1, tags: { test: ['foo'], abc: ['foo', 'bar'] } }
]
expect(osmGeojsonService.getGeojsonsFromRawData(geojsonData, rawData, { generateNodesIfNotFound: true })).toEqual([
expect(osmGeojsonService.getGeojsonsFromRawData(geojsonData, rawData, { generateNodesIfNotFound: true, continueOnMissingGeojson: false })).toEqual([
{
geojson:
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ const unsplitTags = (tags: { [key: string]: string[] | undefined }): { [key: str
const getGeojsonsFromRawData = (
geojsonData: DataGeojson,
features: OsmRawDataType[],
options: { generateNodesIfNotFound: boolean } = { generateNodesIfNotFound: false }
options: { generateNodesIfNotFound: boolean; continueOnMissingGeojson: boolean } = {
generateNodesIfNotFound: false,
continueOnMissingGeojson: false
}
): { geojson: SingleGeoFeature; raw: OsmRawDataType }[] => {
const geojsonFeatures: { geojson: SingleGeoFeature; raw: OsmRawDataType }[] = [];
for (let i = 0; i < features.length; i++) {
Expand All @@ -298,13 +301,17 @@ const getGeojsonsFromRawData = (
features[i].type,
features[i].id
);
throw 'Missing OSM geojson';
if (options.continueOnMissingGeojson) {
continue;
} else {
throw 'Missing OSM geojson';
}
}
} else if (geojson.geometry.type === 'GeometryCollection') {
console.log('Building ' + geojson.id + ' is of unsupported type GeometryCollection');
throw 'Unsupported geometry type for building';
}
geojsonFeatures[i] = { geojson: geojson as SingleGeoFeature, raw: features[i] };
geojsonFeatures.push({ geojson: geojson as SingleGeoFeature, raw: features[i] });
}
return geojsonFeatures;
};
Expand Down

0 comments on commit e4072fd

Please sign in to comment.