{"id":13425876,"url":"https://github.com/watergis/postgis2mbtiles","last_synced_at":"2025-04-28T15:40:31.567Z","repository":{"id":109406614,"uuid":"280809536","full_name":"watergis/postgis2mbtiles","owner":"watergis","description":"A module extracting the data from PostGIS to mbtiles by using tippecanoe.","archived":false,"fork":false,"pushed_at":"2023-06-22T14:32:45.000Z","size":75,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-22T04:05:13.047Z","etag":null,"topics":["mbtiles","postgis","vector-tile"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/watergis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":["JinIgarashi"],"open_collective":"watergis","custom":["https://www.paypal.me/jinigarashi"]}},"created_at":"2020-07-19T06:50:08.000Z","updated_at":"2025-04-05T02:29:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"89455ca7-081d-45e1-b7be-6e634eb57464","html_url":"https://github.com/watergis/postgis2mbtiles","commit_stats":{"total_commits":15,"total_committers":2,"mean_commits":7.5,"dds":"0.19999999999999996","last_synced_commit":"824243b22435df757e142153a6d66e33f71e4236"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watergis%2Fpostgis2mbtiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watergis%2Fpostgis2mbtiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watergis%2Fpostgis2mbtiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/watergis%2Fpostgis2mbtiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/watergis","download_url":"https://codeload.github.com/watergis/postgis2mbtiles/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250985893,"owners_count":21518399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mbtiles","postgis","vector-tile"],"created_at":"2024-07-31T00:01:21.040Z","updated_at":"2025-04-28T15:40:31.532Z","avatar_url":"https://github.com/watergis.png","language":"JavaScript","funding_links":["https://github.com/sponsors/JinIgarashi","https://opencollective.com/watergis","https://www.paypal.me/jinigarashi"],"categories":["JavaScript","Lincense","3. Deploy Vector Tile to gh-pages"],"sub_categories":["1. Source Code"],"readme":"# postgis2mbtiles\n![](https://github.com/watergis/postgis2mbtiles/workflows/Node.js%20Package/badge.svg)\n![GitHub](https://img.shields.io/github/license/watergis/postgis2mbtiles)\n\nA module extracting the data from PostGIS to Geojson.\n\nI created this module because I wanted to extract PostGIS data as GeoJSON format in order to use it for Mapbox Vector Tile.\n\nAfter using this module to extract your data, you can upload GeoJSON data to [Mapbox Studio](https://studio.mapbox.com) as a Tileset.\n\nThen, you can create style file for your vector tile and enjoy it!\n\n## Preparation\nThis module uses [`tippecanoe`](https://github.com/mapbox/tippecanoe) to convert geojson files to mbtiles. Please make sure to install it before running.\n\nfor MacOS\n```\n$ brew install tippecanoe\n```\n\nfor Ubuntu\n```\n$ git clone https://github.com/mapbox/tippecanoe.git\n$ cd tippecanoe\n$ make -j\n$ make install\n```\n\n\n## Installation\n\n```sh\n$ npm install @watergis/postgis2mbtiles\n```\n\n## Example\n\n```\n$ npm run test\n```\n\n## Usage\nSee also [test.js](./test/test.js)\n```js\nconst {postgis2mbtiles} = require('postgis2mbtiles');\nconst config = require('./config');\n\nconst pg2json = new postgis2mbtiles(config);\npg2json.run().then(res=\u003e{\n    console.log(res);\n}).catch(err=\u003e{\n    console.log(err);\n})\n```\nThis module will return MBTiles file paths which are exported in your directory.\n\n\n## Configuration\n\n### Dababase Connection\nPlease put your PostGIS database settings as follow under `config.js`.\n```js\ndb: {\n    user:'postgres',\n    password:'Your password',\n    host:'localhost',\n    port:5432,\n    database:'Your database name',\n},\n```\n\n### mbtiles's Setting\n```js\nmbtiles: __dirname + '/narok.mbtiles',\n```\n\n### Layers' Setting\n```js\nlayers: [\n    //Put your layer definition here.\n    ]\n```\n\nEach layer definition should include the following information.\nThe below is just an example of Pipeline Layer.\n```js\n    name: 'pipeline', //Layer Name\n    geojsonFileName: __dirname + '/pipeline.geojson', //Temporary working file path\n    //The following SQL is the most important one which is able to extract PostGIS data as GeoJSON format.\n    select: `\n    SELECT row_to_json(featurecollection) AS json FROM (\n        SELECT\n            'FeatureCollection' AS type,\n            array_to_json(array_agg(feature)) AS features\n        FROM (\n            SELECT\n            'Feature' AS type,\n            ST_AsGeoJSON(ST_TRANSFORM(ST_MakeValid(x.geom),4326))::json AS geometry,\n            row_to_json((\n                SELECT p FROM (\n                SELECT\n                    x.pipeid as fid,\n                    a.name as pipetype,\n                    x.pipesize,\n                    b.name as material,\n                    x.constructiondate,\n                    x.insertdate,\n                    x.updatedate,\n                    x.isjica\n                ) AS p\n            )) AS properties\n            FROM pipenet x\n            INNER JOIN pipetype a\n            ON x.pipetypeid = a.pipetypeid\n            INNER JOIN material b\n            ON x.materialid = b.materialid\n            WHERE NOT ST_IsEmpty(x.geom)\n        ) AS feature\n        ) AS featurecollection\n    `\n},\n```\n\n```\ncopyright (c) 2020 Jin IGARASHI\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatergis%2Fpostgis2mbtiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwatergis%2Fpostgis2mbtiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwatergis%2Fpostgis2mbtiles/lists"}