<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hello Ross<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I want to encourage you to use the latest version of pgRouting:<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Here starts the compilation on 2.1<br><a href="https://travis-ci.org/cvvergara/pgrouting/jobs/224015091#L1905">https://travis-ci.org/cvvergara/pgrouting/jobs/224015091#L1905</a><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Here starts the compilation of the latest 2.4<br><a href="https://travis-ci.org/pgRouting/pgrouting/jobs/214667949#L766">https://travis-ci.org/pgRouting/pgrouting/jobs/214667949#L766</a><br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I must say that in particular pgr_TRSP still has compilation problems (besides other issues) but thanks to some pull requests done by the community, in the 2.4 version it no longer crashes the server.<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">A lot of work has being done rewriting the functions: removing the warnings in linux, that are errors in other systems, and fixing other per function related issues.<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br>In 2.4 version some of the pgr_TRSP function related issues has being hidden by using wrappers to other functions that don't have turn restrictions. (mainly because the turn restriction query is optional), but I see that you are going to use restrictions, so you will still be using the original code.<br><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">I made a comparison of using the original code (the one in version 2.1) and using the wrapped pgr_TRSP, I must say this time I didn't review my comments so maybe they are outdated, but is automatically generated, so the results are the current results:<br><a href="https://github.com/pgRouting/pgrouting/tree/master/src/trsp/doc">https://github.com/pgRouting/pgrouting/tree/master/src/trsp/doc</a><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">That file uses the sample data:<br><a href="http://docs.pgrouting.org/2.4/en/sampledata.html">http://docs.pgrouting.org/2.4/en/sampledata.html</a><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Instructions to get the latest version:<br></div><div style="font-family:arial,helvetica,sans-serif" class="gmail_default"><a>​https://github.com/pgRouting/pgrouting/wiki/Notes-on-Download%2C-Installation-and-building-pgRouting​</a></div><br><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Regards<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Vicky<br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 20, 2017 at 10:49 AM, Stephen Woodbridge <span dir="ltr"><<a href="mailto:woodbri@swoodbridge.com" target="_blank">woodbri@swoodbridge.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 4/20/2017 6:49 AM, McDonaldR wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
Hi List,<br>
<br>
I’m running pgRouting 2.1 with PostGIS 2.2.2 on PostgreSQL 9.2.20.<br>
<br>
I have 16,000 pupils going to 57 schools.  I have a network with turn restrictions.  I have a function (below) that loops through all the pupils and calculates a TRSP route and updates the pupil table with the route cost.  I have some questions too.<br>
<br></span>
1.It’s going to take ~ 2 hours to process all the pupils.  Will it make things faster if I created, say, 4 functions that each processed a different set of pupils?  I have a multicore server and memory to spare. I have to run this for time and distance and also for all the pupils assigned an “optimally located” school. What’s the best/fastest way to do this?<br>
</blockquote>
<br>
Yes, this sounds reasonable.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2.I pre-processed the pupil data to assign each pupil the nearest node on the network. Some pupils in rural areas are a mile from the nearest node and are assigned the node at the end furthest from the school. How would I use the pgr_trsp with edges and edge position to create a position for each pupil at a point on the nearest edge?<br>
</blockquote>
<br>
Here is a function that might be useful, or you might modify it for your specific needs. tol is maximum search distance in degrees, you can estimate this degrees = meters/111120.0. It returns the edge_id, pos on the that edge and these can be used to args to trsp.<br>
<br>
-Steve W<br>
<br>
create or replace function pointToEdgePos(edge_table text, lon float8, lat float8, tol float8, OUT edge_id integer, OUT pos float8)<br>
    returns record as<br>
$body$<br>
-- ASSUMPTIONS<br>
-- * edge_table as columns "gid" and "geom"<br>
-- * edge_able.geom uses srid=4326<br>
declare<br>
    rr record;<br>
    pct float8;<br>
    pnt geometry;<br>
    geom geometry;<br>
<br>
begin<br>
    -- create a point from lon, lat<br>
    pnt := st_setsrid(st_makepoint(lon,la<wbr>t), 4326);<br>
<br>
    -- set the error condition<br>
    edge_id := null;<br>
    pos := -1.0;<br>
<br>
    -- find the closest edge within tol distance<br>
    execute 'select * from ' || _pgr_quote_ident(edge_table) ||<br>
            ' where st_dwithin(''' || pnt::text ||<br>
            '''::geometry, geom, ' || tol || ') order by st_distance(''' || pnt::text || '''::geometry, geom) asc limit 1' into rr;<br>
<br>
    if rr.geom is not null then<br>
        -- deal with MULTILINESTRINGS<br>
        geom := rr.geom;<br>
        if geometrytype(geom)='MULTILINES<wbr>TRING' THEN<br>
            geom := ST_GeometryN(geom, 1);<br>
        end if;<br>
<br>
        -- project the point onto the linestring<br>
        pos := st_line_locate_point(geom, pnt);<br>
        edge_id := rr.gid;<br>
    end if;<br>
<br>
end;<br>
$body$<br>
    language plpgsql stable;<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
CREATE OR REPLACE FUNCTION public.pupil_journeys()<br>
<br>
   RETURNS character varying AS<br>
<br>
$BODY$<br>
<br>
DECLARE<br>
<br>
   cur_pupil refcursor;<br>
<br>
   v_pid integer;<br>
<br>
   v_pnn integer;<br>
<br>
   v_snn integer;<br>
<br>
   v_cost double precision;<br>
<br>
   v_sql varchar(1000);<br>
<br>
BEGIN<br>
<br>
   RAISE NOTICE 'Processing pupil journeys...';<br>
<br>
   OPEN cur_pupil FOR EXECUTE format('SELECT pupilid, pupil_nn, school_nn FROM edn_pupilschoolroute WHERE pupil_NN IS NOT NULL');<br>
<br>
   LOOP<br>
<br>
   FETCH cur_pupil INTO v_pid, v_pnn, v_snn;<br>
<br>
   EXIT WHEN NOT FOUND;<br>
<br>
   SELECT SUM(cost) AS v_cost FROM pgr_trsp('<br>
<br>
                 SELECT ogc_fid AS id,<br>
<br>
                   source::integer,<br>
<br>
                   target::integer,<br>
<br>
                   cost_len::double precision AS cost,<br>
<br>
                   rcost_len::double precision AS reverse_cost<br>
<br>
                 FROM hw_roadlink'::text,<br>
<br>
                 v_pnn, --pupil_nn gets inserted here<br>
<br>
                 v_snn, --school_nn gets inserted here<br>
<br>
                 true,<br>
<br>
                 true,<br>
<br>
                 'select to_cost, teid as target_id, feid||coalesce('',''||via,''''<wbr>) as via_path from hw_nt_restrictions'::text) INTO v_cost;<br>
<br>
   -- insert route cost into pupil data table<br>
<br>
   v_sql:='UPDATE edn_pupilschoolroute SET p_dist = ' || v_cost || ' WHERE pupil_nn = ' || v_pnn || ' AND school_nn = ' || v_snn || ' AND pupilid = ' || v_pid;<br>
<br>
   EXECUTE v_sql;<br>
<br>
   END LOOP;<br>
<br>
   RETURN ‘Well, that worked!';<br>
<br>
   CLOSE cur_pupil;<br>
<br>
END;<br>
<br>
$BODY$<br>
<br>
   LANGUAGE plpgsql VOLATILE<br>
<br>
   COST 100;<br>
<br>
Thanks in advance<br>
<br>
Ross<br>
<br></div></div>
*Ross McDonald | *GIS Data Coordinator | Angus Council | Angus House, Orchardbank Business Park, Sylvie Way, Forfar DD8 1AT*| t: 01307 476419*<br>
<br>
This message is strictly confidential. If you have received this in error, please inform the sender and remove it from your system. If received in error you may not copy, print, forward or use it or any attachment in any way. This message is not capable of creating a legal contract or a binding representation and does not represent the views of Angus Council. Emails may be monitored for security and network management reasons.Messages containing inappropriate content may be intercepted. Angus Council does not accept any liability for any harm that may be caused to the recipient system or data on it by this message or any attachment.<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
Pgrouting-users mailing list<br>
<a href="mailto:Pgrouting-users@lists.osgeo.org" target="_blank">Pgrouting-users@lists.osgeo.or<wbr>g</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/pgrouting-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailma<wbr>n/listinfo/pgrouting-users</a><br>
<br>
</blockquote>
<br>
<br>
---<br>
This email has been checked for viruses by Avast antivirus software.<br>
<a href="https://www.avast.com/antivirus" rel="noreferrer" target="_blank">https://www.avast.com/antiviru<wbr>s</a><br>
<br>
______________________________<wbr>_________________<br>
Pgrouting-users mailing list<br>
<a href="mailto:Pgrouting-users@lists.osgeo.org" target="_blank">Pgrouting-users@lists.osgeo.or<wbr>g</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/pgrouting-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailma<wbr>n/listinfo/pgrouting-users</a></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><pre>Georepublic UG (haftungsbeschränkt)
Salzmannstraße 44, 
81739 München, Germany

Vicky Vergara
Operations Research

eMail: vicky@<a href="http://georepublic.de" target="_blank">georepublic.de</a>
Web: <a href="https://georepublic.info" target="_blank">https://georepublic.info</a>

Tel: +49 (089) 4161 7698-1
Fax: +49 (089) 4161 7698-9

Commercial register: Amtsgericht München, HRB 181428
CEO: Daniel Kastl

<span></span></pre></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</div>