Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin Igarashi committed Aug 15, 2020
0 parents commit 6d950d7
Show file tree
Hide file tree
Showing 19 changed files with 2,123 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: [JinIgarashi]
custom: ['https://www.paypal.me/jinigarashi']
106 changes: 106 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
public/tiles

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Start from ubuntu
FROM ubuntu:16.04

# Update repos and install dependencies
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get -y install \
build-essential \
libsqlite3-dev \
zlib1g-dev \
curl \
wget \
git \
nodejs \
npm

# Build tippecanoe
RUN mkdir -p /tmp/src
WORKDIR /tmp/src
RUN git clone https://github.com/mapbox/tippecanoe.git
WORKDIR /tmp/src/tippecanoe
RUN make \
&& make install

# Install Nodejs
RUN npm cache clean && npm install n -g && n stable \
&& n 12.18.1 && ln -sf /usr/local/bin/node /usr/bin/node

# Install postgis2mbtiles-docker
RUN mkdir -p /tmp/src
WORKDIR /tmp/src
COPY . /tmp/src
RUN npm install

RUN chmod a+x /tmp/src/entrypoint.sh
ENTRYPOINT ["./entrypoint.sh"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Jin IGARASHI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
144 changes: 144 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# vt-boilerplate
![](https://github.com/narwassco/vt/workflows/Node.js%20CI/badge.svg)
![GitHub](https://img.shields.io/github/license/watergis/vt-boilerplate)
![Docker Cloud Automated build](https://img.shields.io/docker/cloud/automated/narwassco/vt)
![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/narwassco/vt)

This is a template to manage vectortiles for water services providers in Github pages. You can create your own `vt` repository by using this template repository.

Please also refer to [watergis/awesome-vector-tiles](https://github.com/watergis/awesome-vector-tiles). There is some instruction guide how to use tools and host your vectortiles in Github pages as open data.

## Configuration
All the settings are in `config.js` and `config-search.js`, so please make sure your own settings on this file before producing vector tile.

Please put environment variable for database settings.
```
db_user=$db_user
db_password=$db_password
db_host=host.docker.internal
db_post=5432
```

## Create mbtiles
### Usage (Docker)

```
db_user=your user db_password=your password docker-compose up
```

Your mbtiles will be generated under `data` directory. Your GeoJSON for searching window will also be generated under `public` directory.

### Usage (Nodejs)

#### Requirements

This module uses [`tippecanoe`](https://github.com/mapbox/tippecanoe) to convert geojson files to mbtiles. Please make sure to install it before running.

for MacOS
```
$ brew install tippecanoe
```

for Ubuntu
```
$ git clone https://github.com/mapbox/tippecanoe.git
$ cd tippecanoe
$ make -j
$ make install
```

Then,

```
$ npm install
$ db_user=$db_user \
db_password=$db_password \
db_host=localhost \
db_port=5432 \
npm run create
```

There will be two files as follows.
- ./data/rwss.mbtile
- ./public/wss.geojson

## Deployment from local computer

### Extract pbf (mvt) tiles from mbtiles file
please configure `config-extact.js` file to adjust output directory path and input mbtiles path.

```
npm run extract
```

There will be vectortiles under `./public/tiles` directory.

### Deploy

```
npm run deploy
```

It will publish all the files under `public` directory to Github Pages.

## Deployment by using Github Action

First, you can just generate and push both `data/data.mbtiles` and `public/meter.geojson` to master repository.

```bash
# the below commands are the same with create_vt.bat (create_vt.sh)
# generate data.mbtiles and meter.geojson
docker-compose up
# push data.mbtiles and meter.geojson to Github
git add .
git commit -m "update vectortiles"
git push origin master
```

Then, you can use Github Action for `npm run extract` and `npm run deploy` process.

Here is the example of `.github/workflows/node.js.yml`. If you want to automate, please create it in your repository.

```yml
name: Node.js CI

on:
push:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm ci
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- run: npm run extract
- name: configure git and deploy
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
git config --global user.name "watergis+githubci"
git config --global user.email "[email protected]"
git remote set-url origin https://x-access-token:${NODE_AUTH_TOKEN}@github.com/{your organization name}/vt.git
npm run deploy
```
# License
This source code under the repository is licensed by
`MIT license`. You can use it freely for your purposes.

However, these data under [data](./data) and `gh-pages` branch are owned and maintained by `{your organization name}` in Kenya. It is under a [Creative Commons Attribution 4.0 International
License](http://creativecommons.org/licenses/by/4.0/), which is different from main repository. You can use this data freely, but please mention our credit `©{your organization name}` on attribution of your web application.

---
Copyright (c) 2020 Jin IGARASHI
6 changes: 6 additions & 0 deletions config-extract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
ghpages:{
tiles: __dirname + '/public/tiles'
},
mbtiles: __dirname + '/data/data.mbtiles',
}
48 changes: 48 additions & 0 deletions config-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require('dotenv').config();

module.exports = {
db: {
user:process.env.db_user,
password:process.env.db_password,
host:process.env.db_host,
post:process.env.db_port,
database:'{your database name}',
},
layers : [
{
name: 'meter',
geojsonFileName: __dirname + '/public/meter.geojson',
select:`
SELECT row_to_json(featurecollection) AS json FROM (
SELECT
'FeatureCollection' AS type,
array_to_json(array_agg(feature)) AS features
FROM (
SELECT
'Feature' AS type,
ST_AsGeoJSON(ST_TRANSFORM(x.geom,4326))::json AS geometry,
row_to_json((
SELECT p FROM (
SELECT
x.meterid as fid,
CASE WHEN x.connno=-1 THEN NULL ELSE LPAD(CAST(x.connno as text), 4, '0') || x.zonecd END as connno,
x.serialno,
b.name as customer,
c.name as village
) AS p
)) AS properties
FROM meter x
INNER JOIN metertype a
ON x.metertypeid = a.metertypeid
LEFT JOIN customer b
ON x.zonecd = b.zonecd
AND x.connno = b.connno
LEFT JOIN village c
on b.villageid = c.villageid
WHERE NOT ST_IsEmpty(x.geom) AND x.metertypeid = 1
) AS feature
) AS featurecollection
`
},
],
};
Loading

0 comments on commit 6d950d7

Please sign in to comment.