Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AGIC 2014 - Online GIS Mapping Without GIS Servers

James Fee
September 23, 2014

AGIC 2014 - Online GIS Mapping Without GIS Servers

James Fee

September 23, 2014
Tweet

More Decks by James Fee

Other Decks in Technology

Transcript

  1. WHO DAT OVER THERE? Sheldon McGee Web Developer Build in

    the physical world with wood Arduino and Pi are cool AFOL GDG Organizer
  2. WHY NO GIS SERVERS? They are slow They are can

    be expensive to license They require you to use .NET, Java, C++ They are middleware Not the future
  3. EMAIL ARRIVES: Dear GIS Guy, I want to put data

    on a map and share it with people. I need this done immediately and it must look like the Google Maps. Dan the Engineer
  4. STEPS TO GET GIS SERVER RUNNING 1. Find setup disks

    or download from web 2. Check with IT guy to see if server is available 3. Install prerequisites such as TomCat 4. Apply patches 5. Try and get administration settings to work 6. Attempt to add data sources for maps 7. Realize you forgot to do step 4 above 8. Then...
  5. TILING TileMill + MBTiles GeoServer and GeoWebCache Esri ArcGIS Mapnik

    (for those who roll their own) Google/OSM/etc
  6. GEOJSON GEOJSON IS A FORMAT FOR ENCODING A VARIETY OF

    GEOGRAPHIC DATA STRUCTURES. { "type": "Feature", "geometry": { "type": "Point", "coordinates": [‐112.46, 34.54] }, "properties": { "name": "Prescott, Arizona" } }
  7. LOADING DATA INTO POSTGIS // Make your database PostGIS Aware

    psql ‐U username ‐d mygisdb CREATE EXTENSION POSTGIS; // Use magic, free, cross‐platform tool to export shape to sql shp2pgsql ‐s 4326 AZBoundary.shp AZBoundary > sql/AZBoundary.sql // import that into our database psql ‐h localhost ‐d mygisdb ‐U postgres ‐f sql/AZBoundary.sql // pull data out as GeOjSoN SELECT ST_AsGeoJson(ST_Transform(b.geom,4326)) as geojson
  8. SETTING UP NODE.JS // Don't need the latest but most

    people install from source on Linux wget ‐N http://nodejs.org/dist/node‐latest.tar.gz tar xzvf node‐latest.tar.gz && cd node‐v* // On Red Hat/Cent/Fedora? Use epel yum install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel‐release‐6‐8.noarch.rpm yum install nodejs npm ‐‐enablerepo=epel
  9. NO! NOT THAT KIND OF SETUP! SETTING UP NODE.JS //get

    the repo . . . maybe put it in /var/www? git clone https://github.com/tooshel/node‐gis‐server //install dependancies . . . there are only two npm install
  10. NODE.JS Line by line! var pg = require('pg'); var geojson

    = require('../helpers/geojson'); var jsonp = require('../helpers/jsonp'); var settings = require('../settings'); module.exports.controller = function(app) { /* enable CORS */ app.all('*', function(req, res, next) { res.header('Access‐Control‐Allow‐Origin', '*'); res.header('Access‐Control‐Allow‐Headers', 'X‐Requested‐With'); next(); }); app.get('/vector/:schema/:table/:geom/intersect', function(req, res, next) { var queryshape = ' {"type": "Point", "coordinates": [' + req.query['lng'] + ',' + req.query[ var geom = req.params.geom.toLowerCase(); if ((geom != 'features') && (geom != 'geometry') && (geom != 'all')) {
  11. HOSTING THE APPLICATION //Install pm2 (globally) npm install ‐g pm2

    //use pm2 to start the server, it's listening on port 3000 pm2 start server.js //you should probably put it all behind nginx and proxy to 3000 //but in this case just used some iptables magic iptables ‐t nat ‐A PREROUTING ‐i eth0 ‐p tcp ‐‐dport 80 ‐j REDIRECT ‐‐to‐port 3000
  12. USING GEOJSON WITH GOOGLE MAPS: Google Maps Javascript API v3

    Data Layer map.data.loadGeoJson('http://localhost/prescott.json');
  13. LEAFLET TOO! L.geoJson(geojsonFeature).addTo(map); AND OPENLAYERS . . . var vectorSource

    = new ol.source.GeoJSON(......... .loadGeoJson, .geoJson, .GeoJSON . . . WE ARE ALL INDEPENDENT THINKERS
  14. CONS? More DOM elements . . . can be slow

    . . . but not forever Mobile?
  15. which was a fork of which was a fork of

    FORK IT ON GITHUB https://github.com/tooshel/node-gis-server/ https://github.com/ManoMarks/node-gis-server/ https://github.com/geobabbler/node-gis-server/ SHARING IS CARING
  16. END QUESTIONS? Or if you are shy catch us on

    twitter: @cageyjames @tooshel