Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin IGARASHI committed Aug 8, 2020
0 parents commit ab8cdde
Show file tree
Hide file tree
Showing 18 changed files with 2,617 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

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 "narwassco+githubci"
git config --global user.email "narwassco+githubci@users.noreply.github.com"
git remote set-url origin https://x-access-token:${NODE_AUTH_TOKEN}@github.com/narwassco/vt.git
npm run deploy
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 Narok Water and Sewerage Services Co., Ltd.

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.
96 changes: 96 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# vt
![](https://github.com/narwassco/vt/workflows/Node.js%20CI/badge.svg)
![GitHub](https://img.shields.io/github/license/narwassco/vt)
![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 to manage vectortiles for Narok Water in Github pages.

## 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.

### 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

## 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.

# Using Github Action

We can use Github Action for `npm run extract` and `npm run deploy` process.

So, you can just push `data/narok.mbtiles` and `public/meter.geojson` to master repository.

# 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 `Narok Water and Sewerage Services Company (NARWASSCO)` 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 `©NARWASSCO,Ltd.` on attribution of your web application.

---
Copyright (c) 2020 Narok Water and Sewerage Services Co., Ltd.
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/narok.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:'narwassco',
},
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 ab8cdde

Please sign in to comment.