Giter Club home page Giter Club logo

postgis2geojson's Introduction

postgis2geojson

GitHub

This module is to extract GeoJSON files by SQL from PostGIS database.

Install

npm install @watergis/postgis2geojson

Usage

const {postgis2geojson} = require('@watergis/postgis2geojson');
const config = require('./config');

const pg2json = new postgis2geojson(config);
pg2json.run().then(res=>{
    console.log(res);
}).catch(err=>{
    console.log(err);
})

config.js

module.exports = {
    db: {
        user:process.env.DB_USER,
        password:process.env.DB_PASSWORD,
        host:process.env.DB_HOST,
        port:process.env.DB_PORT,
        database:'narwassco',
    },
    layers : [
      {
          name: 'pipeline',
          geojsonFileName: export_dir + '/pipeline.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(ST_MakeValid(x.geom),4326))::json AS geometry,
                  row_to_json((
                    SELECT p FROM (
                      SELECT
                        x.pipeid as fid,
                        a.name as pipetype,
                        x.pipesize,
                        b.name as material,
                        x.constructiondate,
                        x.insertdate,
                        x.updatedate,
                        x."Town"
                    ) AS p
                  )) AS properties
                FROM pipenet x
                INNER JOIN pipetype a
                ON x.pipetypeid = a.pipetypeid
                INNER JOIN material b
                ON x.materialid = b.materialid
                WHERE NOT ST_IsEmpty(x.geom)
              ) AS feature
            ) AS featurecollection
          `
      },
    ]
}

See the test module under test directory.

Build

npm run build

Test

npm run test

postgis2geojson's People

Contributors

jinigarashi avatar

Stargazers

 avatar Thomas Gratier avatar

Watchers

James Cloos avatar  avatar

Forkers

hugoce79

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.