Clipping updates the id to be unique, use sliced community index

This commit is contained in:
Pieter Vander Vennet 2023-01-26 02:17:53 +01:00
parent de08dba5c7
commit 1d11cbcf3b
2 changed files with 34 additions and 3 deletions

View file

@ -11,7 +11,8 @@
}
},
"source": {
"geoJson": "https://raw.githubusercontent.com/osmlab/osm-community-index/main/dist/completeFeatureCollection.json",
"geoJson": "https://raw.githubusercontent.com/pietervdvn/MapComplete-data/main/community_index/tile_{z}_{x}_{y}.geojson",
"geoJsonZoomLevel": 6,
"osmTags": "resources~*",
"isOsmCache": false
},

View file

@ -134,20 +134,40 @@ class Slice extends Script {
}
delete f.bbox
}
const maxNumberOfTiles = Math.pow(2, zoomlevel) * Math.pow(2, zoomlevel)
let handled = 0
TiledFeatureSource.createHierarchy(StaticFeatureSource.fromGeojson(allFeatures), {
minZoomLevel: zoomlevel,
maxZoomLevel: zoomlevel,
maxFeatureCount: Number.MAX_VALUE,
registerTile: (tile) => {
handled = handled + 1
const path = `${outputDirectory}/tile_${tile.z}_${tile.x}_${tile.y}.geojson`
const box = BBox.fromTile(tile.z, tile.x, tile.y)
let features = tile.features.data.map((ff) => ff.feature)
if (doSlice) {
features = Utils.NoNull(
features.map((f) => {
const bbox = box.asGeoJson({})
const properties = {
...f.properties,
id:
(f.properties?.id ?? "") +
"_" +
tile.z +
"_" +
tile.x +
"_" +
tile.y,
}
if (GeoOperations.completelyWithin(bbox, f)) {
bbox.properties = properties
return bbox
}
const intersection = GeoOperations.intersect(f, box.asGeoJson({}))
if (intersection) {
intersection.properties = f.properties
intersection.properties = properties
}
return intersection
})
@ -156,6 +176,15 @@ class Slice extends Script {
features.forEach((f) => {
delete f.bbox
})
if (features.length === 0) {
ScriptUtils.erasableLog(
handled + "/" + maxNumberOfTiles,
"Not writing ",
path,
": no features"
)
return
}
fs.writeFileSync(
path,
JSON.stringify(
@ -168,6 +197,7 @@ class Slice extends Script {
)
)
ScriptUtils.erasableLog(
handled + "/" + maxNumberOfTiles,
"Written ",
path,
"which has ",