Quantcast
Channel: Question and Answer » pgrouting
Viewing all 47 articles
Browse latest View live

send viewparams geoserver using leaflet

$
0
0

I need to pass my longitudes and latitudes of origin and destination for a sql view in geoserver to get a WMS layer with the route.
I’ve performed in qgis to view and is working perfectly.

This is the view in geoserver:

enter image description here

This my code to add the layer on the map, I’m using leaflet.

function findRoute(){  
 route = L.tileLayer.wms("http://localhost:8888/geoserver/pgrouting/wms", {
     layers: 'pgrouting',
     viewparams: [x1:paramOrigemLng;y1:paramOrigemLat;x2:paramDestino1Lng;y2:paramDestino1Lat]
    });
}

Can anyone give me an example of layer viewparams the key format: value with leaflet because I’m not hitting the syntax.
I’m doing as the link: http://docs.geoserver.org/stable/en/user/data/database/sqlview.html


pgRouting: calculate many-to-one shortest paths

$
0
0

In a previous question on how to calculate many shortest paths, @dkastl pointed to the pgr_kdijkstra function, which allows to calculate each time the total cost of one source-to-many targets shortest paths, by giving an array of target nodes.

What I’d like to do is, to calculate the total cost of many sources-to-one target shortest paths. A solution could be to switch source and target, but then I’m actually calculating the total cost of a different chain of paths, given the fact I’m using a directed topology network.

@UnderDark already provided a solution for this problem, but, out of curiosity, my question is:

Is there a way of modifying the pgr_kdijkstra function such that you’re able to give an ‘array of sources’ and ‘one target’ as input?

Something like (given the example of pgRouting manual):

SELECT seq, id1 AS source, id2 AS target, cost FROM pgr_kdijkstraCost(
'SELECT id, source, target, cost FROM edge_table WHERE cost >= 0',
array[4,12], 10, false, false);

 seq | source | target | cost
-----+--------+--------+------
   0 |      4 |     10 |    4
   1 |     12 |     10 |    2

Thanks!

PgRouting: What index should have the restriction table

$
0
0

I have this tables to feed my routing engine using pgr_trsp:
vzla_rto have the links and nodes (650k)
vzla_restriction have the turn restrictions (10k)

CREATE TABLE map.vzla_restrictions
(
  rid integer NOT NULL,
  to_cost numeric,
  to_edge integer,
  from_edge integer,
  via text
);
CREATE INDEX vzla_restrictions_from_edge_idx ON map.vzla_restrictions USING btree (from_edge);
CREATE INDEX vzla_restrictions_to_edge_idx ON map.vzla_restrictions USING btree (to_edge);

I was checking table statistics and realize i put an effort to create index for vzla_rto, but looks like i didn’t enough for vzla_restrictions.

                    | seq_scan      | seq_tu_read     | idx_scan        | idx_tup_fetch | n_tup_ins
vzla_restrictions   | 1,672,959     | 16,848,370,089  |      -          | -             | 10071
vzla_rto            | 1,549         | 977,994,776     |  862,610,399    | 3,866,967,927 | 648968

So which index should i add to vzla_restrictions to help pgr_trsp()?

Shapefile to Network xml

$
0
0

I have a shapefile representing the US freight highway network available from Oak Ridge National Lab. I’m trying to prepare this as a .xml network for processing with MATSim. The output structure is very simple, something like

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE network SYSTEM "http://www.matsim.org/files/dtd/network_v1.dtd">
<network name="VISUM export national network 2007-11-28">

<!-- ====================================================================== -->

    <nodes>
        <node id="1000" x="730065.3125" y="220415.9531" type="2" origid="1000" />
        <node id="1001" x="731010.5" y="220146.2969" type="2" origid="1001" />
        .....
    </nodes>

<!-- ====================================================================== -->

    <links capperiod="01:00:00" effectivecellsize="7.5" effectivelanewidth="3.75">
        <link id="100365" from="226" to="227" length="921.0" freespeed="33.3333333333333" capacity="5600.0" permlanes="2.0" oneway="1" modes="car" origid="183" type="10" />
    ...
    </links>
<!-- ====================================================================== -->

</network>

Most users of MATSim pull data from OpenStreetMap using osmosis, but I have to use this network for a variety of reasons.

I have seen lots of suggestions in different places as to what I might try. Some of these include:

  1. v.net in GRASS
  2. shp2pgsql suggested by pgRouting tutorial
  3. manually with pgRouting, though this advice may be outdated?
  4. writing code through the sp and rgdal libraries in R to build a node and link structure.
  5. find someone with a TransCAD license to export the network ORNL provides along with the shapefile, though I don’t know TransCAD exports to .xml.

It seems that with options 1 – 3, I’ll then have to figure out a way to write the .xml from the database. Option 4 seems difficult, but mainly in terms of my time. I’m happy to learn something new, but I don’t want to invest a day towards option 1 only to find that option 3 would have been better.

Or is there a simpler way?


Post-script:

Someone asked the MATSim developers if they had a tool to do the shp -> xml conversion, but the answer was that shapefiles are too wild to build one.

No result from pgRoutingLayer tsp(euclid) algorithm

$
0
0

I use QGIS plugin pgRoutingLayer for displaying the shortest route. Dijkstra algorithm works fine.

I tried tsp (euclid) algorithm but it drew nothing (even no error message). I thought it may be something wrong with my data. So I uploaded pgRouting sample data into my database (http://docs.pgrouting.org/dev/doc/src/developer/sampledata.html) and tried tsp on them. But result was the same (no route and no error message).

So I debugged the pgRoutingLayer plugin, caught the sql query. It looks like this and it results in 0 records

SELECT seq, id1 AS internal, id2 AS node, cost FROM pgr_tsp('
               SELECT DISTINCT id, x, y FROM
                   (SELECT DISTINCT source AS id, x1::float8 AS x, y1::float8 AS y FROM edge_table
                   UNION
                   SELECT DISTINCT target AS id, x2::float8 AS x, y2::float8 AS y FROM edge_table)
                   AS node WHERE node.id IN (7,8,11)',
               2, 12)

I may be missing some basics, I am a routing newbie. Can anyone give me a hand please? Thanks.

How to create more networking osm

$
0
0

Using localhost page generated by osm2po roteamente noticed that the link is made to link even disabling snapping.

enter image description here

Logically thought to create more nodes in the network, but how can I do this without losing the topology of the data?

Using OpenStreetMap for simulation of commuter routes

$
0
0

I’m seeking some advice on how to build a simulation based on OpenStreetMap Data for my masterthesis. My knowledge of spatial data is very limited, since I come from another field of science, namely information systems. I have experience with object oriented programming, as well as mySQL as relational database.

The research goal is to evaluate if applications which inform the user of the current gasoline price actually have the potential to save money. So the idea is to simulate the routes people travel between their home and work by car and when the car needs gasoline to find the nearest gasoline station and refill. As Database I will use data from the www.zensus2011.de which can tell me from which administrative district people leave and to which administrative district they travel.

Within OSM I have the following Tags that can identify the administrative regions/districts which I need

  • de:amtlicher_gemeindeschluessel => integer
  • de:regionalschluessel => integer
  • admin_level => 6
  • boundary => administrative

So my idea is to use this data to generate random routes with a certain length based on other theses which describe how far people travel between home and work. One of the main problems which I could identify from reading the OSM wiki and other online posts is that the OSM data per se is not routable and needs to be transformed for that purpose. I for that I found two programs osm2pgrouting and OSM2PO. With the latter one I managed to import the map of Germany into a PostgreSQL Database. I also imported the OSM data using osm2pgsql with the “default.style” settings into another PostgreSQL Database. Now I’m a little overwhelmed by all the data and the way how to use this data.

But let’s continue with the idea. What I need to understand now is how the map data with all the information and the routing data can be connected to generate the routes.
What I thought of was: I use the administrative boundary to get a list of streets within this boundary, then randomly choose one as a starting point and do the same for the destination, calculate the route and save the route to a database for further use in the simulation. Still I need to find out a way to determine the start and destination points better, but for the beginning and understanding it would be fine with the above.

Some final words on the implementation of the simulation. Currently my plan is to use python and code the whole simulation, which I hope is feasible. I found two related works which I’m currently investigating namely MATSim and www.roaf.de. Also I’m still browsing other questions here which might help me understand the topic.

To summarize my questions:

  • Is the way I choose feasible?
  • How would SQL statements look like to connect the two Data sets?
  • Is it possible to save generated routes to a database?

Thank you for reading and I hope you guys can give me some advice on where to look at.

problem in pgRouting with data from google earth

$
0
0

Hello i am new in forum an in Postgesql,postgis and pgRouting.
I try to make a pgrouting for my city roads.

I use googlemaps to make a lines with coordinates of the roads and export the results in kml file.
example <MultiGeometry><LineString><coordinates>22.950164627408352,40.592917358186945 22.950657309819846,40.592514769916995</coordinates></LineString></MultiGeometry>

but i have problem with the insert in postgresql
The queries for table and make the geometry for roads.

 CREATE TABLE roads(
    "id" integer PRIMARY KEY,
        "Name" text NOT NULL,
    "Lenght (m)" numeric CHECK("Lenght (m)" > 0)
);

SELECT AddGeometryColumn('','roads','the_geom','4326','MULTILINESTRING',2);

After i use an insert like this but i have problem with MULTILINESTRING

    INSERT INTO roads VALUES(1,'Kwnn/nou Kanarh',1000,ST_SetSRID(ST_GeomFromKML('<MultiGeometry><LineString><coordinates> 
26.683023,37.7939654,0.0 26.6839457,37.7941011,0.0 26.6857266,37.7944063,0.0 26.687851,37.7948472,0.0 26.69034,37.7955084,0.0 26.6947603,37.7972888,0.0 26.6975284,37.7980687,0.0 26.6992879,37.7984926,0.0 26.701498,37.7993573,0.0 26.7026782,37.79989990000001,0.0 26.703794,37.8000355,0.0 26.7052317,37.8002729,0.0 26.7067122,37.8006375,0.0 26.7095018,37.8014089,0.0
</coordinates></LineString></MultiGeometry>'),4326));

Update After the inserts i create topology and other step from the
http://workshop.pgrouting.org/chapters/topology.html for make a pgRouting for the insert data but when i run the pgr_dijkstra the query is

SELECT seq, id1 AS node, id2 AS edge, cost FROM pgr_dijkstra('
            SELECT id AS id,
                     source::integer,
                     target::integer,
                     length::double precision AS cost
                     FROM roads',
            30, 60, false, false);

Give me this error ERROR: Target vertex was not found.
I dont find the reason


How to calculate fastest bicycle routes in Stockholm with QGIS?

$
0
0

Hello StackExchangers,

I would really appreciate if expert users could point out a few directions for me, this is what I wanna do:

Access an online map from my iPhone that gives me the possibility to find the fastest route from my current location to any given point in Stockholm, but heres the catch, a wanna add elevation data to my road network and lower the speed if it’s an uphill climb, that way calculating not only the shortest, but also the fastest route.

Can this be done? And if so, could someone outline the how’s?

My own thoughts, as a novice user of QGIS with pgRouting:
I’m thinking that I (A) have a .shapes of the roads in Stockholm, I’ll just have to make sure that all the driving directions, speeds, etc are correct. (B) A raster file with elevation details, (C) pgRouting that could do the shortest path algorithm or similar and (D), I’m sure there must be some way to connect to the map from Safari in my iPhone and make it ? But how the merge the raster with elevation and road .shape-layers and the iPhone-connectivity this is totally unknown land for me. All ideas are very appreciated!

Insert several gtfs feeds into the same postgis/pgrouting database

$
0
0

I want to import sevaral gtfs feeds into my postgis/pgrouting database so that I can route over all my gtfs feeds.

The problem is that the sources / destinations ids of my gtfs are likely to conflict.

How can I solve this conflict issue?

If do not want to use pgRouting then what?

$
0
0

Good evening fellow GISers,

I am interested in creating an online routing application. So supposing I have all the data I want into a postGIS database and loaded onto GeoServer and I am willing to use OpenLayers for front end, and of course I know routing algorithms like Djikstra or shortest path algorithms, what are my choices when it comes to do the actual routing.

I know many use pgRouting, and as many members of this community have told me I tried to learn it and use it. But what I want in my web app is more freedom. I want to change the algorithms and be able to whatever I imagine(academic reasearch-change the algorithms at some points).

So what are my choices ? SQL user defined functions? How to manipulate the data and find shortest paths? In few words how can I create a library/extension just like pgRouting? What languages do I need(if any) and other material? Any good tutorials?

Thanks beforehand to everybody for reading. I encourage you to answer to my question even if you only know a little bit of the answer.

dim :)

What does it mean when I get rows executed, but with no resulted table?

$
0
0

While applying the following tutorial: http://anitagraser.com/2011/02/09/creating-catchment-areas-with-pgrouting-and-qgis/ utilizing vector network which has been tested (and demonstrated functionality) for shortest path application, it returned the following message:

Query returned successfully: 1013 rows affected, 199 ms execution time

but returned no table as output!

The code I used is:

create table catchment_1 as
select
id,
the_geom,
(select sum(cost) from (
SELECT * FROM pgr_dijkstra(
'SELECT id, source, target, st_length(geom) as cost FROM schema.cvl',
1, 320, false, false
)) as foo ) as cost
from schema.cvl_vertices_pgr

I also tried passing “id” to the function instead of “320″ as per the tutorial but got the following msg:

ERROR: function pgr_dijkstra(unknown, integer, bigint, boolean, boolean) does not exist SQL state: 42883

Although, pgr_dijkstra is working well with other codes.. so, it’s one of the recognized functions in my installed pgRouting layer

I’m using QGIS 2.0.1 and pgRouting pg93-binaries-2.4.0

Get closest (source or target) of an edge from a point in postgres

$
0
0

I have a Postgres custom function that uses pgr_dijkstra to generate a route working. It works be passing the lat/lon of the start and destination points. I then find the closest segment vertice to that lat/lon point and use that in the pgr_dijkstra call.

snippit:
EXECUTE 'SELECT id::integer FROM trail_split_segs_vertices_pgr
ORDER BY the_geom <-> ST_GeometryFromText(''POINT('
|| x1 || ' ' || y1 || ')'',4326) LIMIT 1' INTO rec;
source := rec.id;

The problem is even though I may be moused over a specific segment, the closest vertex might belong to a different segment, since its doing the lookup based on distance.

the red point is the one I want, but I get the purple one since its closer

(the red point is the one I want, but I get the purple one since its closer)

I tried creating a different function to instead find the closest edge to the users lat/lon points rather than the closest vertex. But I have to choose if i’m going to use that edge’s source or target.

snippit
SELECT
id, source, target, geom, ST_Distance(
geom, ST_GeometryFromText(
'POINT(-123.036073 49.357152)', 4326
)
) AS dist
FROM
trail_split_segs
WHERE geom && ST_SetSRID(
'BOX3D(-123.036083 49.357142, -123.036063 49.357162)'::box3d, 4326
)
ORDER BY dist
LIMIT 1

The box created by this is very small, so pretty much will always select the correct edge, because I have the users mouse snap to the edges in the web interface.

What I want to do is select the edge source or target that is closest to the lat/lon point where the id of the edge has to be the same.

UPDATE
Zia’s response below helped set me on the right track, I modified his query.


WITH
point AS
(SELECT st_setsrid(st_makepoint(-123.0568528175354, 49.36230206100319), 4326) AS point),
line AS
(SELECT
geom AS line_geom
FROM
trail_split_segs, point
WHERE st_dwithin(geom, point, 0.00012)
ORDER BY geom <-> point
LIMIT 1)
SELECT
id, ST_AsText(the_geom) AS point_geom
FROM
trail_split_segs_vertices_pgr, line, point
WHERE st_dwithin(the_geom, line_geom, 0.00001)
ORDER BY the_geom <-> point
LIMIT 1;

How to use pgRouting in my case?

$
0
0

Suppose I have 6 bus route and a road network. After a user determines to me the starting point and the place he wants to go, I want to determine which of the bus routes is the best. How to use pgRouting so to route through the bus stop stops and the road together? How to use pgr Djikstra with the road network and the bus stop together?

Error of doing pgr_analyzeGraph

$
0
0

I just completed the command pgr_createTopology, but it fails to do pgr_analyzeGraph & pgr_createTopology. The error is as below: Anyone can give me an idea? Thanks

ERROR:  isring() should only be called on a LINE
CONTEXT:  SQL statement "SELECT count(*)  FROM public.fp 
                                 WHERE true   AND (true) and st_isRing(st_linemerge(the_geom))"
PL/pgSQL function pgr_analyzegraph(text,double precision,text,text,text,text,text) line 309 at EXECUTE statement

********** Error **********

ERROR: isring() should only be called on a LINE
SQL state: XX000
Context: SQL statement "SELECT count(*)  FROM public.fp 
                                 WHERE true   AND (true) and st_isRing(st_linemerge(the_geom))"
PL/pgSQL function pgr_analyzegraph(text,double precision,text,text,text,text,text) line 309 at EXECUTE statement

pgrouting query [closed]

$
0
0

I saw on the pgrouting workshop the following way to calculate a route:
http://workshop.pgrouting.org/chapters/advanced.html

SELECT seq, id1 AS node, id2 AS edge, cost FROM pgr_dijkstra('
                SELECT gid AS id,
                         source::integer,
                         target::integer,
                         length * c.cost AS cost
                        FROM ways, classes c
                        WHERE class_id = c.id',
                30, 60, false, false);

In the part :

length * c.cost AS cost

Is it possible to multiply the length with any value that I want to? (e.g length * otherTable.columnValue )

pgrouting with wms [closed]

$
0
0

I able to successfully perform pgrouting using wms but I am looking to show the cost (the length) on the webpage (not only the line on the map but the length of the line) some where in a div next to my map. I am I supposed to create a table out of the querry and use php to access them. Any idea.

Why pgRouting GUI panel may not work in QGIS?

$
0
0

What could be the reason behind the mal-functionality of the pgRouting Layer GUI panel?

In order to route shortest path via dijkstra function code I’m able to conduct the task using the following code:

SELECT seq, id1 AS node, id2 AS edge, cost, geom
FROM pgr_dijkstra(
'SELECT id, source, target, st_length(geom) as cost FROM schema.cvl',
1, 100, false, false
) as di
JOIN schema.cvl pt
ON di.id2 = pt.id ;

but unable to do the same using the pgRouting Layer GUI panel!

An error has occured while executing Python code: ………….

I searched for this error on the net and found out that it may happen because the database password is not saved.. So, I saved the password, but still getting same error when I try to locate source_id or target_id on the map

I’m using QGIS 2.0.1 and pgRouting pg93-binaries-2.0.0

Learning pg_routing – shortest_path error

$
0
0

I’m learning PostGIS and pg_routing to help in our project planning and grant applications at my transportation agency (we wanted to move beyond the limitations of the 1/4 mile walking buffer we use so frequently!).

I have been following underdark’s very helpful pg_routing tutorials but am having trouble running the shortest_path function in my own dataset:

function shortest_path(unknown, integer, bigint, boolean, boolean) does not exist
LINE 6:        SELECT * FROM shortest_path('
                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

CREATE TABLE catchment_facilities AS
SELECT
    id,
    the_geom,
    (SELECT sum(cost) FROM (
       SELECT * FROM shortest_path('
       SELECT objectid::int8 AS id,
          source::int4,
          target::int4,
          sweeptime::float8 AS cost
          FROM lionroute',
       55375,
       id,
       false,
       false)) AS foo ) AS cost
FROM lionroute_vertices_pgr;

From reading the forums I get the sense that one of my columns is not in the right format, but I can’t for the life of me figure out which one (‘id’ is int8). Any help would be much appreciated.

How to split linestrings where start/end points don't touch nearby lines

$
0
0

I am trying to figure out some basic routing with PostgreSQL/pgRouting and I’m struggling a bit.

Our network of linestrings are not topologically correct, tracks that should be connected don’t touch, or if they do, it’s by chance.
example linestrings

It is my understanding that to make a network topology for routing I will have to split all the tracks at each intersection or crossing. The problem is most the tracks end/start points don’t touch, though they are close.

So I’m looking for a way to either split the tracks into segments using a tolerance for points that touch or to modify the linestrings themselves, moving the end/start point to snap to the nearby line.

But I don’t know how to go about that?

I have this query for splitting the tracks, but it relies on points touching. It works for creating segments where the trail crosses another line, perfectly. But the ST_Touches() part is useless when there is no intersection.

CREATE TABLE trail_split_points as
SELECT DISTINCT ST_GeometryN(ST_Intersection(a.track, b.track), 1) as geom      
FROM
  trails as a, trails as b
WHERE ST_Touches(a.track, b.track)
OR ST_Crosses(a.track, b.track)    
AND a.id != b.id
GROUP BY ST_Intersection(a.track, b.track);

UPDATE

I determined I had no choice but to fix my tracks so they are all topologically correct. It was a bit of a pain to figure out, but I’ve mostly done that.

The first steep was to get the start and end point of each line and then see if there was a nearby point on another line within <5 meters. If there was then I move that point to that nearby point.

I then use some query to populate a table full of all the points where these lines touch or cross.

Then using that new point table generate new lines for each segment between points. This new table is the one used for routing. The one I created a network map and indexes on for pgRouting.

UPDATE 2

I was snapping the nearby trail to the line, but not creating a new point on that line at the intersection. This is how I managed to do that.

ST_LineMerge(
            ST_Union(
                ST_Line_Substring(track, 0, ST_Line_Locate_Point(track, ST_GeomFromText('".$point['newpoint']."', 4326))),
                ST_Line_Substring(track, ST_Line_Locate_Point(track, ST_GeomFromText('".$point['newpoint']."', 4326)), 1)
        ))
Viewing all 47 articles
Browse latest View live


Latest Images