Skip to content

Commit

Permalink
Merge pull request #18 from geolonia/create-tiles-json
Browse files Browse the repository at this point in the history
Tiles.json を生成
  • Loading branch information
naogify authored Dec 14, 2023
2 parents a2122e5 + e4ae248 commit e1b15aa
Show file tree
Hide file tree
Showing 5 changed files with 1,143 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.github
.env.test
README.md
action.yml
58 changes: 58 additions & 0 deletions bin/createTilesJson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const fs = require('fs');
const path = require('path');
const sqlite3 = require('sqlite3');
const { open } = require("sqlite");

async function main() {
const mbtilesPath = process.argv[2];

const basename = path.basename(mbtilesPath, ".mbtiles");
const db = await open({
filename: mbtilesPath,
driver: sqlite3.Database,
});

const {value} = await db.get("SELECT value FROM metadata WHERE name = 'json'");
const theJSON = JSON.parse(value);
delete theJSON['tilestats'];

await db.run(
"UPDATE metadata SET value = ? WHERE name = 'json'",
[
JSON.stringify(theJSON),
],
);

await db.run(
"DELETE FROM metadata WHERE name IN ('generator_options', 'generator', 'strategies')",
);

const metadataRows = await db.all("SELECT * FROM metadata");
const metadataOut = {
"tilejson": "3.0.0",
};
for (const row of metadataRows) {
if (row.name === "json") {
const json = JSON.parse(row.value);
for (const key of Object.keys(json)) {
metadataOut[key] = json[key];
}
} else {
let val = row.value;
if (row.name === 'bounds' || row.name === 'center') {
val = row.value.split(",").map((v) => parseFloat(v));
} else if (row.name === 'minzoom' || row.name === 'maxzoom') {
val = parseInt(row.value, 10);
}
metadataOut[row.name] = val;
}
}
await fs.promises.writeFile(path.join(path.dirname(mbtilesPath), `${basename}.json`), JSON.stringify(metadataOut, null, 2));

await db.close();
}

main().catch(err => {
console.error(err);
process.exit(1);
});
5 changes: 4 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
set -e

npm install

ls

echo "INPUT_DIR: $INPUT_DIR"

find ./ -name "napi-v6-linux-glibc-arm64/";

node ./bin/excel2geojson.js $INPUT_DIR
node ./bin/geojson2mbtiles.js $INPUT_DIR
node ./bin/createTilesJson.js ./smart-city-data-v1.mbtiles

ls $INPUT_DIR
ls


exit 0
Loading

0 comments on commit e1b15aa

Please sign in to comment.