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": { "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~*", "osmTags": "resources~*",
"isOsmCache": false "isOsmCache": false
}, },
@ -142,4 +143,4 @@
"en": "A layer showing the OpenStreetMap Communities", "en": "A layer showing the OpenStreetMap Communities",
"de": "Eine Ebene aller OpenStreetMap-Communities" "de": "Eine Ebene aller OpenStreetMap-Communities"
} }
} }

View file

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