Code Monkey home page Code Monkey logo

postgis-preview's Introduction

#PostGIS Preview A lightweight node api and frontend for quicky previewing PostGIS queries. Pull Requests Welcomed! See TODOs below, real issues coming shortly.

preview

###Why I needed to be able to test out PostGIS queries in a local environment and iterate quickly. CartoDB provides this functionality, giving users a SQL pane and a map view to quickly see the geometries returned from the database (This UI and SQL preview workflow are inspired by the CartoDB editor)

I asked on twitter if anyone had solutions to this problem, and reponses included:

  • Run queries in pgadmin and use ST_asGeoJson(), copy and paste the geojson into geojson.io
  • Use QGIS dbmanager. This works, but requires a few clicks once the data are returned to add them to the map.
  • Use various command line tools that show previews in the terminal or send the results to geojson.io programmatically.

###How it works The express.js app has a single endpoint: /sql that is passed a SQL query q as a url parameter. That query is passed to PostGIS using the pg-promise module. The resulting data are transformed into topojson using a modified dbgeo module (modified to include parsing WKB using the WKX module), and the response is sent to the frontend.

The frontend is a simple bootstrap layout with a leaflet map, cartodb basemaps, a table, and a SQL pane. The topojson from the API is parsed using omnivore by Mapbox, and added to the map as an L.geoJson layer with generic styling.

How to Use

  • Clone this repo
  • Have a PostGIS instance running somewhere that the node app can talk to
  • Edit config.sample.js to include your database connection details, rename it config.js
  • Install dependencies npm install
  • Run the express app node server.js
  • Load the frontend http://localhost:3000
  • Query like a boss

Notes

  • PostGIS preview expects your geometry column to be called geom, and that it contains WGS84 geometries

###Todo

  • ERROR HANDLING EVERYWHERE

  • Add Tabular View

  • Add Simple Infowindow with all attributes

  • Add SQL Syntax Highlighting (Codemirror?)

  • Add recent queries and forward/backward arrows

  • Add url hash to remember data vs. map view

  • Add client-side data export as CSV, geoJSON, etc

postgis-preview's People

Contributors

jwalgran avatar vitaly-t avatar

Watchers

 avatar

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.