Git Product home page Git Product logo

lrm-pgrouting's Introduction

Leaflet Routing Machine / pgRouting

Extends Leaflet Routing Machine with support for pgRouting.

Some brief instructions follow below, but the Leaflet Routing Machine tutorial on alternative routers is recommended.

Installing

Install nodejs/iojs, clone this repository and execute:

npm install
./scripts/build.sh

Put the script after Leaflet and Leaflet Routing Machine has been loaded.

To use with for example Browserify:

npm install --save lrm-pgrouting

Setup backend environment

Setup Database environment

Setup sample database

createdb -U postgres muko
psql -U postgres -d muko -c "CREATE EXTENSION postgis;"
psql -U postgres -d muko -c "CREATE EXTENSION pgrouting;"
psql -U postgres -d muko -f data/muko_2po_4pgr.sql

Add wrapper PL/pgSQL script to the sample database

psql -U postgres -d muko -f sql/routing_via_points.sql

Setup GeoServer environment

CORS setting (Tomcat)

  1. Add following lines into geoserver/WEB-INF/web.xml - <web-app> node.
<filter>
  <filter-name>CorsFilter</filter-name>
  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
  <init-param>
    <param-name>cors.allowed.origins</param-name>
    <param-value>*</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>CorsFilter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

See http://stackoverflow.com/questions/22363192/cors-tomcat-geoserver for more details.

  1. Restart Tomcat service.

Setup sample workspace/store/layer

  1. Access to http://localhost:8080/geoserver.
  2. Click "Workspaces", then "Add new workspace".
  3. Fill the form with:
  • Name: pgrouting
  • Namespace URI: http://pgrouting.org
  1. Press the "Submit" button.
  2. Click "Stores", then "Add new Store".
  3. Choose "PostGIS" and fill the form with:
  • Basic Store Info:
    • Workspace: pgrouting
    • Data Source Name: muko
  • Connection Parameters:
    • host: localhost
    • port: 5432
    • database: muko
    • schema: public
    • user: postgres
    • password: ``
  1. Press the "Save" button.
  2. Click "Layers", then "Add a new resource".
  3. Select the newly created workspace and store pair: pgrouting:muko
  4. Click "Configure new SQL view...".
  5. Name the view muko and fill the "SQL statements" with:
SELECT
    seq,
    gid,
    name,
    heading,
    cost,
    geom,
    distance,
    point_type AS "pointType"
FROM
    routing.viaPoints(
        '%points%',
        'muko_2po_4pgr',
        'id',
        'geom_way',
        'osm_name',
        'source',
        'target',
        'cost',
        'reverse_cost',
        4326
    )
ORDER BY seq
  1. In the "SQL view parameters", click "Guess parameters from SQL", then fill with:
  • Name: points
  • Default value: ``
  • Validation regular expression: ^[\d\.,\|]+$
  1. In the "Attributes", click "Refresh", then change geom column "Type" to LineString and "SRID" to 4326.
  2. Press the "Save" button.
  3. In "Edit Layer" page, fill with:
  • Coordinate Reference Systems:
    • Declared SRS: EPSG:4326
    • SRS handling: Force declared
  • Bounding Boxes:
    • Lat/Lon Bounding Box:
      • Min X: -180
      • Min Y: -90
      • Max X: 180
      • Max Y: 90
  1. Press the "Save" button.

Using

There's a single class exported by this module, L.Routing.PgRouting. It implements the IRouter interface. Use it to replace Leaflet Routing Machine's default OSRM router implementation:

var L = require('leaflet');
require('leaflet-routing-machine');
require('lrm-pgrouting'); // This will tack on the class to the L.Routing namespace

L.Routing.control({
    router: new L.Routing.PgRouting('your GeoServer WFS layer type name'),
}).addTo(map);

Note that you will need to pass an existing GeoServer WFS layer type name to the constructor.

lrm-pgrouting's People

Contributors

luizfonseca avatar perliedman avatar sanak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lrm-pgrouting's Issues

SQL Error When Adjacent Waypoints are On Same Edge

Hi, and thanks for this add on, I've found it very useful and have had a lot of fun with it. I am running into a problem though: whenever I have two adjacent waypoints on the same edge (or start and end on the same edge with no other waypoints between), the viapoints function fails with the following error:

ERROR: consistency check on SPI tuple count failed
SQL state: XX000
Context: PL/pgSQL function routing.viapoints(text,character varying,character varying,character varying,character varying,character varying,character varying,character varying,character varying,integer) line 69 at FOR over EXECUTE statement

Any thoughts on what might be causing this or what to do about it?

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.