diff --git a/NEWS.md b/NEWS.md index 51a73014ea0..a1a4eacecac 100644 --- a/NEWS.md +++ b/NEWS.md @@ -20,6 +20,7 @@ * pgr_findCloseEdges * Error messages adjustment. + * ``partial`` option is removed. * pgr_degree diff --git a/doc/src/pgRouting-concepts.rst b/doc/src/pgRouting-concepts.rst index 07177a3b5e9..f81cc4df3ff 100644 --- a/doc/src/pgRouting-concepts.rst +++ b/doc/src/pgRouting-concepts.rst @@ -1896,10 +1896,18 @@ To get faster results bound the queries to an area of interest of routing. In this example Use an inner query SQL that does not include some edges in the routing function and is within the area of the results. +Given this area: + .. literalinclude:: concepts.queries :start-after: -- performance1 :end-before: -- performance2 +Calculate a route: + +.. literalinclude:: concepts.queries + :start-after: -- performance2 + :end-before: -- performance3 + How to contribute ------------------------------------------------------------------------------- @@ -1917,7 +1925,7 @@ How to contribute * `Example `__ -.. rubric:: Adding Functionaity to pgRouting +.. rubric:: Adding Functionality to pgRouting Consult the `developer's documentation diff --git a/doc/src/sampledata.rst b/doc/src/sampledata.rst index 7535489873a..8b9e7df870c 100644 --- a/doc/src/sampledata.rst +++ b/doc/src/sampledata.rst @@ -15,8 +15,8 @@ Sample Data The documentation provides very simple example queries based on a small sample network that resembles a city. -To be able to execute the mayority of the examples queries, follow the -instructions bellow. +To be able to execute the majority of the examples queries, follow the +instructions below. .. contents:: :local: @@ -31,7 +31,7 @@ The following city is to be inserted into the database: .. figure:: /images/Fig1-originalData.png Information known at this point is the geometry of the edges, cost values, -cpacity values, category values and some locations that are not in the graph. +capacity values, category values and some locations that are not in the graph. The process to have working topology starts by inserting the edges. After that everything else is calculated. @@ -40,9 +40,9 @@ Edges ............................................................................... The database design for the documentation of pgRouting, keeps in the same row 2 -segments, one in the direction of the geometry and the second in the oposite -direction. Therfore some information has the ``reverse_`` prefix which -corresponds to the segment on the oposite direction of the geometry. +segments, one in the direction of the geometry and the second in the opposite +direction. Therefore some information has the ``reverse_`` prefix which +corresponds to the segment on the opposite direction of the geometry. .. list-table:: :width: 81 @@ -72,12 +72,12 @@ corresponds to the segment on the oposite direction of the geometry. * - ``x1`` - :math:`x` coordinate of the starting vertex of the geometry. - - For convinience it is saved on the table but can be calculated as + - For convenience it is saved on the table but can be calculated as ``ST_X(ST_StartPoint(geom))``. * - ``y2`` - :math:`y` coordinate of the ending vertex of the geometry. - - For convinience it is saved on the table but can be calculated as + - For convenience it is saved on the table but can be calculated as ``ST_Y(ST_EndPoint(geom))``. * - ``geom`` - The geometry of the segments. @@ -96,11 +96,11 @@ Starting on PostgreSQL 12:: ... Optionally indexes on different columns can be created. -The recomendation is to have +The recommendation is to have * ``id`` indexed. * ``source`` and ``target`` columns indexed to speed up pgRouting queries. -* ``geom`` indexed to speed up gemetry processes that might be needed in the +* ``geom`` indexed to speed up geometry processes that might be needed in the front end. For this small example the indexes are skipped, except for ``id`` @@ -197,27 +197,53 @@ will be stored on a table. * - ``pid`` - A unique identifier. * - ``edge_id`` - - Identifier of the edge nearest edge that allows an arrival to the point. + - Identifier of the nearest segment. * - ``side`` - - Is it on the left, right or both sides of the segment ``edge_id`` + - Is it on the left, right or both sides of the segment ``edge_id``. * - ``fraction`` - Where in the segment is the point located. * - ``geom`` - The geometry of the points. + * - ``distance`` + - The distance between ``geom`` and the segment ``edge_id``. + * - ``edge`` + - A segment that connects the ``geom`` of the point to the closest point + on the segment ``edge_id``. * - ``newPoint`` - - The geometry of the points moved on top of the segment. + - A point on segment ``edge_id`` that is the closest to ``geom``. .. literalinclude:: sampledata.queries :start-after: -- p1 :end-before: -- p2 -Points of interest fillup +Points of interest fill up +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Inserting the points of interest. + .. literalinclude:: sampledata.queries :start-after: -- p2 :end-before: -- p3 +Filling the rest of the table. + +.. literalinclude:: sampledata.queries + :start-after: -- p3 + :end-before: -- p4 + +Any other additional modification: In this manual, point :math:`6` can be +reached from both sides. + +.. literalinclude:: sampledata.queries + :start-after: -- p4 + :end-before: -- p5 + +The points of interest: + +.. literalinclude:: sampledata.queries + :start-after: -- p5 + :end-before: -- p6 + .. pois_end Support tables @@ -229,7 +255,7 @@ Combinations Many functions can be used with a combinations of ``(source, target)`` pairs when wanting a route from ``source`` to ``target``. -For convinence of this documentations, some combinations will be stored on a +For convenience of this documentation, some combinations will be stored on a table: .. literalinclude:: sampledata.queries @@ -347,7 +373,7 @@ https://www.sintef.no/projectweb/top/pdptw/li-lim-benchmark/ The vehicles ............................................................................... -There are 25 vehciles in the problem all with the same characteristics. +There are 25 vehicles in the problem all with the same characteristics. .. literalinclude:: lc101.queries :start-after: -- q1 @@ -366,7 +392,7 @@ order. The orders ............................................................................... -The original data needs to be converted to an appropiate table: +The original data needs to be converted to an appropriate table: .. literalinclude:: lc101.queries :start-after: -- q3 diff --git a/doc/utilities/pgr_findCloseEdges.rst b/doc/utilities/pgr_findCloseEdges.rst index 0cf77aa0fe0..d15a7652186 100644 --- a/doc/utilities/pgr_findCloseEdges.rst +++ b/doc/utilities/pgr_findCloseEdges.rst @@ -23,6 +23,7 @@ .. rubric:: Version 3.8.0 * Error messages adjustment. +* ``partial`` option is removed. .. rubric:: Version 3.4.0 @@ -37,7 +38,7 @@ point geometry. * The geometries must be in the same coordinate system (have the same SRID). * The code to do the calculations can be obtained for further specific adjustments needed by the application. -* ``EMTPY SET`` is returned on dryrun executions +* ``EMPTY SET`` is returned on dryrun executions |Boost| Boost Graph Inside @@ -51,13 +52,13 @@ Signatures | pgr_findCloseEdges(`Edges SQL`_, **point**, **tolerance**, [**options**]) | pgr_findCloseEdges(`Edges SQL`_, **points**, **tolerance**, [**options**]) - | **options:** ``[cap, partial, dryrun]`` + | **options:** ``[cap, dryrun]`` | Returns set of |result-find| | OR EMPTY SET .. index:: - single: findCloseEdges - Proposed ; One point - Proposed on 3.4 + single: findCloseEdges - Proposed ; One point - Proposed on 3.6 One point ............................................................................... @@ -66,33 +67,21 @@ One point :class: signatures | pgr_findCloseEdges(`Edges SQL`_, **point**, **tolerance**, [**options**]) - | **options:** [cap, partial, dryrun]`` + | **options:** ``[cap, dryrun]`` | Returns set of |result-find| | OR EMPTY SET -:Example: With default values +:Example: Get two close edges to points of interest with :math:`pid = 5` -* Default: ``cap => 1`` - - * Maximum one row answer. -* Default: ``partial => true`` - - * With less calculations as possible. -* Default: ``dryrun => false`` - - * Process query -* Returns - - * values on ``edge_id``, ``fraction``, ``side`` columns. - * ``NULL`` on ``distance``, ``geom``, ``edge`` columns. +* ``cap => 2`` .. literalinclude:: findCloseEdges.queries :start-after: -- q1 :end-before: -- q2 .. index:: - single: findCloseEdges - Proposed ; Many points - Proposed on 3.4 + single: findCloseEdges - Proposed ; Many points - Proposed on 3.6 Many points ............................................................................... @@ -101,26 +90,17 @@ Many points :class: signatures | pgr_findCloseEdges(`Edges SQL`_, **points**, **tolerance**, [**options**]) - | **options:** ``[cap, partial, dryrun]`` + | **options:** ``[cap, dryrun]`` | Returns set of |result-find| | OR EMPTY SET -:Example: Find at most :math:`2` edges close to all vertices on the points of - interest table. - -One answer per point, as small as possible. +:Example: For each points of interests, find the closest edge. .. literalinclude:: findCloseEdges.queries :start-after: -- q2 :end-before: -- q3 -Columns ``edge_id``, ``fraction``, ``side`` and ``geom`` are returned with -values. - -``geom`` contains the original point geometry to assist on deterpartialing to which -point geometry the row belongs to. - Parameters ------------------------------------------------------------------------------- @@ -162,12 +142,6 @@ Optional parameters - ``INTEGER`` - :math:`1` - Limit output rows - * - ``partial`` - - ``BOOLEAN`` - - ``true`` - - * When ``true`` only columns needed for :doc:`withPoints-category` are - calculated. - * When ``false`` all columns are calculated * - ``dryrun`` - ``BOOLEAN`` - ``false`` @@ -216,127 +190,26 @@ Returns set of |result-find| * When :math:`cap = 1`, it is the closest edge. * - ``fraction`` - ``FLOAT`` - - Value in <0,1> that indicates the relative postition from the first + - Value in <0,1> that indicates the relative position from the first end-point of the edge. * - ``side`` - ``CHAR`` - Value in ``[r, l]`` indicating if the point is: - * In the right ``r``. - * In the left ``l``. + * At the right ``r`` of the segment. * When the point is on the line it is considered to be on the right. + * At the left ``l`` of the segment. * - ``distance`` - ``FLOAT`` - - Distance from point to edge. - - * ``NULL`` when ``cap = 1`` on the `One point`_ signature + - Distance from the point to the edge. * - ``geom`` - ``geometry`` - - ``POINT`` geometry - - * `One Point`_: Contains the point on the edge that is ``fraction`` away - from the starting point of the edge. - * `Many Points`_: Contains the corresponding **original point** + - Original ``POINT`` geometry. * - ``edge`` - ``geometry`` - - ``LINESTRING`` geometry from the **original point** to the closest point - of the edge with identifier ``edge_id`` - - -.. rubric:: One point results - -* The green nodes is the **original point** -* The geometry ``geom`` is a point on the :math:`sp \rightarrow ep` edge. -* The geometry ``edge`` is a line that connects the **original point** with - ``geom`` - -.. graphviz:: - - digraph G { - splines=false; - subgraph cluster0 { - point [shape=circle;style=filled;color=green]; - geom [shape=point;color=black;size=0]; - sp, ep; - - edge[weight=0]; - point -> geom [dir=none; penwidth=0, color=red]; - edge[weight=2]; - sp -> geom -> ep [dir=none;penwidth=3 ]; - - {rank=same; point, geom} - } - - subgraph cluster1 { - point1 [shape=circle;style=filled;color=green;label=point]; - geom1 [shape=point;color=deepskyblue; xlabel="geom"; width=0.3]; - sp1 [label=sp]; ep1 [label=ep]; - - edge[weight=0]; - point1 -> geom1 [weight=0, penwidth=3, color=red, - label="edge"]; - edge[weight=2]; - sp1 -> geom1 -> ep1 [dir=none;weight=1, penwidth=3 ]; - - - geom1 -> point1 [dir=none;weight=0, penwidth=0, color=red]; - {rank=same; point1, geom1} - } - } - -.. rubric:: Many point results - -* The green nodes are the **original points** -* The geometry ``geom``, marked as **g1** and **g2** are the **original - points** -* The geometry ``edge``, marked as **edge1** and **edge2** is a line that - connects the **original point** with the closest point on the :math:`sp - \rightarrow ep` edge. - -.. graphviz:: - - digraph G { - splines = false; - subgraph cluster0 { - p1 [shape=circle;style=filled;color=green]; - g1 [shape=point;color=black;size=0]; - g2 [shape=point;color=black;size=0]; - sp, ep; - p2 [shape=circle;style=filled;color=green]; - - sp -> g1 [dir=none;weight=1, penwidth=3 ]; - g1 -> g2 [dir=none;weight=1, penwidth=3 ]; - g2 -> ep [weight=1, penwidth=3 ]; - - g2 -> p2 [dir=none;weight=0, penwidth=0, color=red, partiallen=3]; - p1 -> g1 [dir=none;weight=0, penwidth=0, color=red, partiallen=3]; - p1 -> {g1, g2} [dir=none;weight=0, penwidth=0, color=red;] - - {rank=same; p1; g1} - {rank=same; p2; g2} - } - subgraph cluster1 { - p3 [shape=circle;style=filled;color=deepskyblue;label=g1]; - g3 [shape=point;color=black;size=0]; - g4 [shape=point;color=black;size=0]; - sp1 [label=sp]; ep1 [label=ep]; - p4 [shape=circle;style=filled;color=deepskyblue;label=g2]; - - sp1 -> g3 [dir=none;weight=1, penwidth=3 ]; - g3 -> g4 [dir=none;weight=1, penwidth=3,len=10]; - g4 -> ep1 [weight=1, penwidth=3, len=10]; - - g4 -> p4 [dir=back;weight=0, penwidth=3, color=red, partiallen=3, - label="edge2"]; - p3 -> g3 [weight=0, penwidth=3, color=red, partiallen=3, - label="edge1"]; - p3 -> {g3, g4} [dir=none;weight=0, penwidth=0, color=red]; - - {rank=same; p3; g3} - {rank=same; p4; g4} - } - } + - ``LINESTRING`` geometry that connects the original **point** to the + closest point of the edge with identifier ``edge_id`` Additional Examples @@ -345,261 +218,128 @@ Additional Examples .. contents:: :local: -One point examples +One point in an edge ............................................................................... -At most two answers -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -* ``cap => 2`` - - * Maximum two row answer. -* Default: ``partial => true`` - - * With less calculations as possible. -* Default: ``dryrun => false`` - - * Process query - .. literalinclude:: findCloseEdges.queries - :start-after: -- o1 - :end-before: -- o2 - -.. rubric:: Understanding the result - -* ``NULL`` on ``geom``, ``edge`` -* ``edge_id`` identifier of the edge close to the **original point** - - * Two edges are withing :math:`0.5` distance units from the **original - point**: :math:`{5, 8}` -* For edge :math:`5`: - - * ``fraction``: The closest point from the **original point** is at the - :math:`0.8` fraction of the edge :math:`5`. - * ``side``: The **original point** is located to the left side of edge - :math:`5`. - * ``distance``: The **original point** is located :math:`0.1` length units - from edge :math:`5`. -* For edge :math:`8`: - - * ``fraction``: The closest point from the **original point** is at the - :math:`0.89..` fraction of the edge :math:`8`. - * ``side``: The **original point** is located to the right side of edge - :math:`8`. - * ``distance``: The **original point** is located :math:`0.19..` length units - from edge :math:`8`. - -One answer, all columns -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -* Default: ``cap => 1`` + :start-after: -- o0 + :end-before: -- o1 - * Maximum one row answer. -* ``partial => false`` - - * Calculate all columns -* Default: ``dryrun => false`` - - * Process query - -.. literalinclude:: findCloseEdges.queries - :start-after: -- o2 - :end-before: -- o3 - -.. rubric:: Understanding the result - -* ``edge_id`` identifier of the edge **closest** to the **original point** +.. graphviz:: - * From all edges within :math:`0.5` distance units from the **original - point**: :math:`{5}` is the closest one. -* For edge :math:`5`: + digraph D { + subgraph cluster0 { + label="data"; + point [shape=circle;style=filled;color=green;fontsize=8;width=0.3;fixedsize=true]; + point [pos="0,1.5!"] - * ``fraction``: The closest point from the **original point** is at the - :math:`0.8` fraction of the edge :math:`5`. - * ``side``: The **original point** is located to the left side of edge - :math:`5`. - * ``distance``: The **original point** is located :math:`0.1` length units - from edge :math:`5`. - * ``geom``: Contains the geometry of the closest point on edge :math:`5` from - the **original point**. - * ``edge``: Contains the ``LINESTRING`` geometry of the **original point** to - the closest point on on edge :math:`5` ``geom`` + sp, ep [shape=circle;fontsize=8;width=0.3;fixedsize=true]; + sp[pos="2,0!"] + ep[pos="2,3!"] -At most two answers with all columns -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + sp -> ep:s + } + subgraph cluster1 { + label="results"; + geom [shape=circle;style=filled;color=green;fontsize=8;width=0.3;fixedsize=true]; + geom [pos="3,1.5!"] -* ``cap => 2`` + np11 [shape=point;color=black;size=0;fontsize=8;fixedsize=true]; + np11 [pos="5,1.5!";xlabel="fraction=0.5"]; - * Maximum two row answer. -* ``partial => false`` + sp1, ep1 [shape=circle;fontsize=8;width=0.3;fixedsize=true]; + sp1[pos="5,0!"] + ep1[pos="5,3!"] - * Calculate all columns -* Default: ``dryrun => false`` + sp1:n -> np11:s [dir=none] + np11:n -> ep1:s - * Process query + geom -> np11 [color=red,label="edge"]; + } + } -.. literalinclude:: findCloseEdges.queries - :start-after: -- o3 - :end-before: -- o4 - -.. rubric:: Understanding the result: - -* ``edge_id`` identifier of the edge close to the **original point** - - * Two edges are withing :math:`0.5` distance units from the **original - point**: :math:`{5, 8}` -* For edge :math:`5`: - - * ``fraction``: The closest point from the **original point** is at the - :math:`0.8` fraction of the edge :math:`5`. - * ``side``: The **original point** is located to the left side of edge - :math:`5`. - * ``distance``: The **original point** is located :math:`0.1` length units - from edge :math:`5`. - * ``geom``: Contains the geometry of the closest point on edge :math:`5` from - the **original point**. - * ``edge``: Contains the ``LINESTRING`` geometry of the **original point** to - the closest point on on edge :math:`5` ``geom`` -* For edge :math:`8`: - - * ``fraction``: The closest point from the **original point** is at the - :math:`0.89..` fraction of the edge :math:`8`. - * ``side``: The **original point** is located to the right side of edge - :math:`8`. - * ``distance``: The **original point** is located :math:`0.19..` length units - from edge :math:`8`. - * ``geom``: Contains the geometry of the closest point on edge :math:`8` from - the **original point**. - * ``edge``: Contains the ``LINESTRING`` geometry of the **original point** to - the closest point on on edge :math:`8` ``geom`` +* The green node is the original point. +* ``geom`` has the value of the original point. +* The geometry ``edge`` is a line that connects the original point with the edge + :math:`sp \rightarrow ep` edge. +* The point is located at the left of the edge. One point dry run execution -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -* Returns ``EMPTY SET``. - +............................................................................... -* ``partial => true`` +Using the query from the previous example: - * Is ignored - * Because it is a **dry run** excecution, the code for all calculations are - shown on the PostgreSQL ``NOTICE``. +* Returns ``EMPTY SET``. * ``dryrun => true`` - * Do not process query - * Generate a PostgreSQL ``NOTICE`` with the code used to calculate all columns - - * ``cap`` and **original point** are used in the code + * Generates a PostgreSQL ``NOTICE`` with the code used. + * The generated code can be used as a starting base code for additional + requirements, like taking into consideration the SRID. .. literalinclude:: findCloseEdges.queries :start-after: -- o5 :end-before: -- o6 -Many points examples +Many points in an edge ............................................................................... -At most two answers per point -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -* ``cap => 2`` - - * Maximum two row answer. -* Default: ``partial => true`` - - * With less calculations as possible. -* Default: ``dryrun => false`` - - * Process query +* The green nodes are the **original points** +* The geometry ``geom``, marked as **g1** and **g2** are the **original + points** +* The geometry ``edge``, marked as **edge1** and **edge2** is a line that + connects the **original point** with the closest point on the :math:`sp + \rightarrow ep` edge. .. literalinclude:: findCloseEdges.queries - :start-after: -- m1 - :end-before: -- m2 - -.. rubric:: Understanding the result - -* ``NULL`` on ``edge`` -* ``edge_id`` identifier of the edge close to a **original point** (``geom``) - - * Two edges at most withing :math:`0.5` distance units from each of the - **original points**: - - * For ``POINT(1.8 0.4)`` and ``POINT(0.3 1.8)`` only one edge was found. - * For the rest of the points two edges were found. -* For point ``POINT(2.9 1.8)`` + :start-after: -- m0 + :end-before: -- m1 - * Edge :math:`5` is before :math:`8` therefore edge :math:`5` has the shortest - distance to ``POINT(2.9 1.8)``. - * For edge :math:`5`: - - * ``fraction``: The closest point from the **original point** is at the - :math:`0.8` fraction of the edge :math:`5`. - * ``side``: The **original point** is located to the left side of edge - :math:`5`. - * ``distance``: The **original point** is located :math:`0.1` length units - from edge :math:`5`. - * For edge :math:`8`: - - * ``fraction``: The closest point from the **original point** is at the - :math:`0.89..` fraction of the edge :math:`8`. - * ``side``: The **original point** is located to the right side of edge - :math:`8`. - * ``distance``: The **original point** is located :math:`0.19..` length - units from edge :math:`8`. - -One answer per point, all columns -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -* Default: ``cap => 1`` +.. graphviz:: - * Maximum one row answer. -* ``partial => false`` + digraph G { + subgraph cluster0 { + p1,p2 [shape=circle;style=filled;color=green;fontsize=8;width=0.3;fixedsize=true]; + p1 [pos="0,2!"] + p2 [pos="3,1!"] - * Calculate all columns -* Default: ``dryrun => false`` + sp, ep [shape=circle;fontsize=8;width=0.3;fixedsize=true]; + sp[pos="1,0!"] + ep[pos="1,3!"] - * Process query + sp -> ep:s + } -.. literalinclude:: findCloseEdges.queries - :start-after: -- m2 - :end-before: -- m3 + subgraph cluster1 { + g1, g2 [shape=circle;style=filled;color=green;fontsize=8;width=0.3;fixedsize=true]; + g1 [pos="4,2!"] + g2 [pos="7,1!"] -.. rubric:: Understanding the result + np11,np21 [shape=point;color=black;size=0;fontsize=8;fixedsize=true]; + np11 [pos="5,2!";xlabel="fraction=0.63"]; + np21 [pos="5,1!";xlabel="fraction=0.33"]; -* ``edge_id`` identifier of the edge **closest** to the **original point** + sp1, ep1 [shape=circle;fontsize=8;width=0.3;fixedsize=true]; + sp1[pos="5,0!"] + ep1[pos="5,3!"] - * From all edges within :math:`0.5` distance units from the **original - point**: :math:`{5}` is the closest one. -* For the **original point** ``POINT(2.9 1.8)`` + sp1:n -> np21:s [dir=none] + np21:n -> np11:s [dir=none] + np11:n -> ep1:s - * Edge :math:`5` is the closest edge to the **original point** - * ``fraction``: The closest point from the **original point** is at the - :math:`0.8` fraction of the edge :math:`5`. - * ``side``: The **original point** is located to the left side of edge - :math:`5`. - * ``distance``: The **original point** is located :math:`0.1` length units - from edge :math:`5`. - * ``geom``: Contains the geometry of the **original point** ``POINT(2.9 1.8)`` - * ``edge``: Contains the ``LINESTRING`` geometry of the **original point** - (``geom``) to the closest point on on edge. + g1 -> np11 [color=red;label="edge"]; + g2 -> np21 [color=red;label="edge"] + } + } Many points dry run execution -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +............................................................................... * Returns ``EMPTY SET``. - - -* ``partial => true`` - - * Is ignored - * Because it is a **dry run** excecution, the code for all calculations are - shown on the PostgreSQL ``NOTICE``. * ``dryrun => true`` * Do not process query * Generate a PostgreSQL ``NOTICE`` with the code used to calculate all columns - * ``cap`` and **original point** are used in the code - .. literalinclude:: findCloseEdges.queries :start-after: -- m4 :end-before: -- m5 @@ -622,14 +362,6 @@ Handling points outside the graph. :start-after: pois_start :end-before: pois_end -Connecting disconnected components -............................................................................... - -.. include:: pgRouting-concepts.rst - :start-after: connecting_graph_start - :end-before: connecting_graph_end - - See Also ------------------------------------------------------------------------------- diff --git a/docqueries/src/concepts.pg b/docqueries/src/concepts.pg index ca96938fdff..3ea5eae5073 100644 --- a/docqueries/src/concepts.pg +++ b/docqueries/src/concepts.pg @@ -10,9 +10,6 @@ FROM (VALUES (1, 1, 2, 5, 2), (2, 1, 3, -3, 4), (3, 2, 3, 7, -1)) AS t(id, source, target, cost, reverse_cost); /* -- g3 */ - - - DROP TABLE IF EXISTS wiki; /* -- q1 */ CREATE TABLE wiki ( @@ -183,7 +180,7 @@ SELECT edge_id, fraction, ST_AsText(edge) AS edge, id AS closest_vertex FROM pgr_findCloseEdges( $$SELECT id, geom FROM edges WHERE component = 1$$, (SELECT array_agg(geom) FROM vertices WHERE component = 2), - 2, partial => false) JOIN vertices USING (geom) ORDER BY distance LIMIT 1; + 2) JOIN vertices USING (geom) ORDER BY distance LIMIT 1; /* -- connect7 */ WITH info AS ( @@ -193,7 +190,7 @@ info AS ( FROM pgr_findCloseEdges( $$SELECT id, geom FROM edges WHERE component = 1$$, (SELECT array_agg(geom) FROM vertices WHERE component = 2), - 2, partial => false) AS ce + 2) AS ce JOIN vertices AS v USING (geom) JOIN edges AS e ON (edge_id = e.id) ORDER BY distance LIMIT 1), @@ -245,9 +242,17 @@ WHERE array_length(in_edges || out_edges, 1) = 2; /* -- contract3 */ /* -- performance1 */ -SELECT * FROM pgr_dijkstra($$ - SELECT id, source, target, cost, reverse_cost from edges - WHERE geom && (SELECT st_buffer(geom, 1) AS myarea - FROM edges WHERE id = 2)$$, - 1, 2); +SELECT id, source, target, cost, reverse_cost +FROM edges +WHERE geom && ( + SELECT st_buffer(geom, 1) as myarea + FROM edges where id = 6) ORDER BY id; /* -- performance2 */ +SELECT * FROM pgr_dijkstra($$ + SELECT id, source, target, cost, reverse_cost + FROM edges + WHERE geom && ( + SELECT st_buffer(geom, 1) AS myarea + FROM edges WHERE id = 6)$$, + 7, 8); +/* -- performance3 */ diff --git a/docqueries/src/concepts.result b/docqueries/src/concepts.result index aa3e79b7673..39b66bb980b 100644 --- a/docqueries/src/concepts.result +++ b/docqueries/src/concepts.result @@ -308,7 +308,7 @@ SELECT edge_id, fraction, ST_AsText(edge) AS edge, id AS closest_vertex FROM pgr_findCloseEdges( $$SELECT id, geom FROM edges WHERE component = 1$$, (SELECT array_agg(geom) FROM vertices WHERE component = 2), - 2, partial => false) JOIN vertices USING (geom) ORDER BY distance LIMIT 1; + 2) JOIN vertices USING (geom) ORDER BY distance LIMIT 1; edge_id | fraction | edge | closest_vertex ---------+----------+--------------------------------------+---------------- 14 | 0.5 | LINESTRING(1.999999999999 3.5,2 3.5) | 4 @@ -323,7 +323,7 @@ info AS ( FROM pgr_findCloseEdges( $$SELECT id, geom FROM edges WHERE component = 1$$, (SELECT array_agg(geom) FROM vertices WHERE component = 2), - 2, partial => false) AS ce + 2) AS ce JOIN vertices AS v USING (geom) JOIN edges AS e ON (edge_id = e.id) ORDER BY distance LIMIT 1), @@ -414,15 +414,39 @@ WHERE array_length(in_edges || out_edges, 1) = 2; /* -- contract3 */ /* -- performance1 */ +SELECT id, source, target, cost, reverse_cost +FROM edges +WHERE geom && ( + SELECT st_buffer(geom, 1) as myarea + FROM edges where id = 6) ORDER BY id; + id | source | target | cost | reverse_cost +----+--------+--------+------+-------------- + 1 | 5 | 6 | 1 | 1 + 2 | 6 | 10 | -1 | 1 + 4 | 6 | 7 | 1 | 1 + 6 | 1 | 3 | 1 | 1 + 7 | 3 | 7 | 1 | 1 + 8 | 7 | 11 | 1 | 1 + 10 | 7 | 8 | 1 | 1 + 12 | 8 | 12 | 1 | -1 + 14 | 8 | 9 | 1 | 1 + 23 | 4 | 8 | 0 | 0 +(10 rows) + +/* -- performance2 */ SELECT * FROM pgr_dijkstra($$ - SELECT id, source, target, cost, reverse_cost from edges - WHERE geom && (SELECT st_buffer(geom, 1) AS myarea - FROM edges WHERE id = 2)$$, - 1, 2); + SELECT id, source, target, cost, reverse_cost + FROM edges + WHERE geom && ( + SELECT st_buffer(geom, 1) AS myarea + FROM edges WHERE id = 6)$$, + 7, 8); seq | path_seq | start_vid | end_vid | node | edge | cost | agg_cost -----+----------+-----------+---------+------+------+------+---------- -(0 rows) + 1 | 1 | 7 | 8 | 7 | 10 | 1 | 0 + 2 | 2 | 7 | 8 | 8 | -1 | 0 | 1 +(2 rows) -/* -- performance2 */ +/* -- performance3 */ ROLLBACK; ROLLBACK diff --git a/docqueries/src/sampledata.result b/docqueries/src/sampledata.result index e2f362aa791..b0951777b49 100644 --- a/docqueries/src/sampledata.result +++ b/docqueries/src/sampledata.result @@ -156,18 +156,54 @@ CREATE TABLE pointsOfInterest( edge_id BIGINT, side CHAR, fraction FLOAT, + distance FLOAT, + edge geometry, + newPoint geometry, geom geometry); CREATE TABLE /* -- p2 */ -INSERT INTO pointsOfInterest (edge_id, side, fraction, geom) VALUES -(1, 'l' , 0.4, ST_POINT(1.8, 0.4)), -(15, 'r' , 0.4, ST_POINT(4.2, 2.4)), -(12, 'l' , 0.6, ST_POINT(2.6, 3.2)), -(6, 'r' , 0.3, ST_POINT(0.3, 1.8)), -(5, 'l' , 0.8, ST_POINT(2.9, 1.8)), -(4, 'b' , 0.7, ST_POINT(2.2, 1.7)); +INSERT INTO pointsOfInterest (geom) VALUES +(ST_Point(1.8, 0.4)), +(ST_Point(4.2, 2.4)), +(ST_Point(2.6, 3.2)), +(ST_Point(0.3, 1.8)), +(ST_Point(2.9, 1.8)), +(ST_Point(2.2, 1.7)); INSERT 0 6 /* -- p3 */ +UPDATE pointsofinterest SET + edge_id = poi.edge_id, + side = poi.side, + fraction = round(poi.fraction::numeric, 2), + distance = round(poi.distance::numeric, 2), + edge = poi.edge, + newPoint = ST_EndPoint(poi.edge) +FROM ( + SELECT * + FROM pgr_findCloseEdges( + $$SELECT id, geom FROM edges$$,(SELECT array_agg(geom) FROM pointsOfInterest), 0.5) ) AS poi +WHERE pointsOfInterest.geom = poi.geom; +UPDATE 6 +/* -- p4 */ +UPDATE pointsOfInterest SET side = 'b' WHERE pid = 6; +UPDATE 1 +/* -- p5 */ +SELECT + pid, ST_AsText(geom) geom, + edge_id, fraction AS frac, side, distance AS dist, + ST_AsText(edge) edge, ST_AsText(newPoint) newPoint +FROM pointsOfInterest; + pid | geom | edge_id | frac | side | dist | edge | newpoint +-----+----------------+---------+------+------+------+---------------------------+-------------- + 1 | POINT(1.8 0.4) | 1 | 0.4 | l | 0.2 | LINESTRING(1.8 0.4,2 0.4) | POINT(2 0.4) + 4 | POINT(0.3 1.8) | 6 | 0.3 | r | 0.2 | LINESTRING(0.3 1.8,0.3 2) | POINT(0.3 2) + 3 | POINT(2.6 3.2) | 12 | 0.6 | l | 0.2 | LINESTRING(2.6 3.2,2.6 3) | POINT(2.6 3) + 2 | POINT(4.2 2.4) | 15 | 0.4 | r | 0.2 | LINESTRING(4.2 2.4,4 2.4) | POINT(4 2.4) + 5 | POINT(2.9 1.8) | 5 | 0.8 | l | 0.1 | LINESTRING(2.9 1.8,3 1.8) | POINT(3 1.8) + 6 | POINT(2.2 1.7) | 4 | 0.7 | b | 0.2 | LINESTRING(2.2 1.7,2 1.7) | POINT(2 1.7) +(6 rows) + +/* -- p6 */ /* --POINTS CREATE end */ /* --COMBINATIONS CREATE start */ /* -- c1 */ diff --git a/docqueries/src/withPoints-category.result b/docqueries/src/withPoints-category.result index 20deee8b5b2..44e1f236cf6 100644 --- a/docqueries/src/withPoints-category.result +++ b/docqueries/src/withPoints-category.result @@ -7,9 +7,9 @@ SELECT pid, edge_id, fraction, side FROM pointsOfInterest; pid | edge_id | fraction | side -----+---------+----------+------ 1 | 1 | 0.4 | l - 2 | 15 | 0.4 | r - 3 | 12 | 0.6 | l 4 | 6 | 0.3 | r + 3 | 12 | 0.6 | l + 2 | 15 | 0.4 | r 5 | 5 | 0.8 | l 6 | 4 | 0.7 | b (6 rows) diff --git a/docqueries/utilities/findCloseEdges.pg b/docqueries/utilities/findCloseEdges.pg index c0aaf27194f..e46d13e32a3 100644 --- a/docqueries/utilities/findCloseEdges.pg +++ b/docqueries/utilities/findCloseEdges.pg @@ -1,45 +1,35 @@ -- CopyRight(c) pgRouting developers -- Creative Commons Attribution-Share Alike 3.0 License : https://creativecommons.org/licenses/by-sa/3.0/ +SET extra_float_digits=-3; /* -- q1 */ -SELECT * +SELECT + edge_id, fraction, side, distance, + distance, ST_AsText(geom) AS point, ST_AsText(edge) As edge FROM pgr_findCloseEdges( $$SELECT id, geom FROM edges$$, (SELECT geom FROM pointsOfInterest WHERE pid = 5), - 0.5); + 0.5, cap => 2); /* -- q2 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, ST_AsText(geom) AS original_point +SELECT +edge_id, fraction, side, distance, +ST_AsText(geom) AS point, +ST_AsText(edge) AS edge FROM pgr_findCloseEdges( $$SELECT id, geom FROM edges$$, (SELECT array_agg(geom) FROM pointsOfInterest), 0.5); /* -- q3 */ /* One point signature */ -/* -- o1 */ -SELECT * -FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT geom FROM pointsOfInterest WHERE pid = 5), - 0.5, cap => 2); -/* -- o2 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, round(distance::numeric, 3) AS distance, - ST_AsText(geom) AS new_point, - ST_AsText(edge) AS original_to_new_point +/* -- o0 */ +SELECT edge_id, fraction, side, distance, ST_AsText(geom) geom, ST_AsText(edge) edge FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT geom FROM pointsOfInterest WHERE pid = 5), - 0.5, partial => false); -/* -- o3 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, round(distance::numeric, 3) AS distance, - ST_AsText(geom) AS new_point, - ST_AsText(edge) AS original_to_new_point -FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT geom FROM pointsOfInterest WHERE pid = 5), - 0.5, cap => 2, partial => false); +$$SELECT 1 AS id, ST_MakeLine(ST_makePoint(2,0), ST_MakePoint(2,3)) AS geom$$, +ST_MakePoint(0,1.5), 5); +/* -- o1 */ /* -- o4 */ SELECT * FROM pgr_withPoints( $e$ SELECT * FROM edges $e$, - $p$ SELECT edge_id, round(fraction::numeric, 2) AS fraction, side + $p$ SELECT edge_id, fraction, side FROM pgr_findCloseEdges( $$SELECT id, geom FROM edges$$, (SELECT geom FROM pointsOfInterest WHERE pid = 5), @@ -47,44 +37,23 @@ SELECT * FROM pgr_withPoints( $p$, 1, ARRAY[-1, -2]); /* -- o5 */ -SELECT * +SELECT edge_id, fraction, side, distance, ST_AsText(geom) geom, ST_AsText(edge) edge FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT geom FROM pointsOfInterest WHERE pid = 5), - 0.5, - dryrun => true); +$$SELECT 1 AS id, ST_MakeLine(ST_makePoint(2,0), ST_MakePoint(2,3)) AS geom$$, +ST_MakePoint(0,1.5), 5, dryrun => true); /* -- o6 */ /* Many point signature */ -/* -- m1 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, round(distance::numeric, 3) AS distance, - ST_AsText(geom) AS geom_is_original, edge -FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT array_agg(geom) FROM pointsOfInterest), - 0.5, cap => 2); -/* -- m2 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, round(distance::numeric, 3) AS distance, - ST_AsText(geom) AS geom_is_original, - ST_AsText(edge) AS original_to_new_point -FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT array_agg(geom) FROM pointsOfInterest), - 0.5, partial => false); -/* -- m3 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, round(distance::numeric, 3) AS distance, - ST_AsText(geom) AS geom_is_original, - ST_AsText(edge) AS original_to_new_point +/* -- m0 */ +SELECT edge_id, fraction, side, distance, ST_AsText(geom) geom, ST_AsText(edge) edge FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT array_agg(geom) FROM pointsOfInterest), - 0.5, cap => 2, partial => false); +$$SELECT 1 AS id, ST_MakeLine(ST_makePoint(1,0), ST_MakePoint(1,3)) AS geom$$, +ARRAY[ST_MakePoint(0,2), ST_MakePoint(3,1)]::GEOMETRY[], 5); +/* -- m1 */ /* -- m4 */ -SELECT * +SELECT edge_id, fraction, side, distance, ST_AsText(geom) geom, ST_AsText(edge) edge FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT array_agg(geom) FROM pointsOfInterest), - 0.5, - dryrun => true); +$$SELECT 1 AS id, ST_MakeLine(ST_makePoint(1,0), ST_MakePoint(1,3)) AS geom$$, +ARRAY[ST_MakePoint(0,2), ST_MakePoint(3,1)]::GEOMETRY[], 5, dryrun=>true); /* -- m5 */ diff --git a/docqueries/utilities/findCloseEdges.result b/docqueries/utilities/findCloseEdges.result index 185071edbd1..1541de9cd6c 100644 --- a/docqueries/utilities/findCloseEdges.result +++ b/docqueries/utilities/findCloseEdges.result @@ -2,78 +2,58 @@ BEGIN; BEGIN SET client_min_messages TO NOTICE; SET +SET extra_float_digits=-3; +SET /* -- q1 */ -SELECT * +SELECT + edge_id, fraction, side, distance, + distance, ST_AsText(geom) AS point, ST_AsText(edge) As edge FROM pgr_findCloseEdges( $$SELECT id, geom FROM edges$$, (SELECT geom FROM pointsOfInterest WHERE pid = 5), - 0.5); - edge_id | fraction | side | distance | geom | edge ----------+----------+------+----------+------+------ - 5 | 0.8 | l | | | -(1 row) + 0.5, cap => 2); + edge_id | fraction | side | distance | distance | point | edge +---------+----------+------+----------+----------+----------------+--------------------------- + 5 | 0.8 | l | 0.1 | 0.1 | POINT(2.9 1.8) | LINESTRING(2.9 1.8,3 1.8) + 8 | 0.9 | r | 0.2 | 0.2 | POINT(2.9 1.8) | LINESTRING(2.9 1.8,2.9 2) +(2 rows) /* -- q2 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, ST_AsText(geom) AS original_point +SELECT +edge_id, fraction, side, distance, +ST_AsText(geom) AS point, +ST_AsText(edge) AS edge FROM pgr_findCloseEdges( $$SELECT id, geom FROM edges$$, (SELECT array_agg(geom) FROM pointsOfInterest), 0.5); - edge_id | fraction | side | original_point ----------+----------+------+---------------- - 1 | 0.40 | l | POINT(1.8 0.4) - 6 | 0.30 | r | POINT(0.3 1.8) - 12 | 0.60 | l | POINT(2.6 3.2) - 15 | 0.40 | r | POINT(4.2 2.4) - 5 | 0.80 | l | POINT(2.9 1.8) - 4 | 0.70 | r | POINT(2.2 1.7) + edge_id | fraction | side | distance | point | edge +---------+----------+------+----------+----------------+--------------------------- + 1 | 0.4 | l | 0.2 | POINT(1.8 0.4) | LINESTRING(1.8 0.4,2 0.4) + 6 | 0.3 | r | 0.2 | POINT(0.3 1.8) | LINESTRING(0.3 1.8,0.3 2) + 12 | 0.6 | l | 0.2 | POINT(2.6 3.2) | LINESTRING(2.6 3.2,2.6 3) + 15 | 0.4 | r | 0.2 | POINT(4.2 2.4) | LINESTRING(4.2 2.4,4 2.4) + 5 | 0.8 | l | 0.1 | POINT(2.9 1.8) | LINESTRING(2.9 1.8,3 1.8) + 4 | 0.7 | r | 0.2 | POINT(2.2 1.7) | LINESTRING(2.2 1.7,2 1.7) (6 rows) /* -- q3 */ /* One point signature */ -/* -- o1 */ -SELECT * +/* -- o0 */ +SELECT edge_id, fraction, side, distance, ST_AsText(geom) geom, ST_AsText(edge) edge FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT geom FROM pointsOfInterest WHERE pid = 5), - 0.5, cap => 2); - edge_id | fraction | side | distance | geom | edge ----------+--------------------+------+---------------------+------+------ - 5 | 0.8 | l | 0.10000000000000009 | | - 8 | 0.8999999999999999 | r | 0.19999999999999996 | | -(2 rows) - -/* -- o2 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, round(distance::numeric, 3) AS distance, - ST_AsText(geom) AS new_point, - ST_AsText(edge) AS original_to_new_point -FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT geom FROM pointsOfInterest WHERE pid = 5), - 0.5, partial => false); - edge_id | fraction | side | distance | new_point | original_to_new_point ----------+----------+------+----------+--------------+--------------------------- - 5 | 0.80 | l | 0.100 | POINT(3 1.8) | LINESTRING(2.9 1.8,3 1.8) +$$SELECT 1 AS id, ST_MakeLine(ST_makePoint(2,0), ST_MakePoint(2,3)) AS geom$$, +ST_MakePoint(0,1.5), 5); + edge_id | fraction | side | distance | geom | edge +---------+----------+------+----------+--------------+------------------------- + 1 | 0.5 | l | 2 | POINT(0 1.5) | LINESTRING(0 1.5,2 1.5) (1 row) -/* -- o3 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, round(distance::numeric, 3) AS distance, - ST_AsText(geom) AS new_point, - ST_AsText(edge) AS original_to_new_point -FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT geom FROM pointsOfInterest WHERE pid = 5), - 0.5, cap => 2, partial => false); - edge_id | fraction | side | distance | new_point | original_to_new_point ----------+----------+------+----------+--------------+--------------------------- - 5 | 0.80 | l | 0.100 | POINT(3 1.8) | LINESTRING(2.9 1.8,3 1.8) - 8 | 0.90 | r | 0.200 | POINT(2.9 2) | LINESTRING(2.9 1.8,2.9 2) -(2 rows) - +/* -- o1 */ /* -- o4 */ SELECT * FROM pgr_withPoints( $e$ SELECT * FROM edges $e$, - $p$ SELECT edge_id, round(fraction::numeric, 2) AS fraction, side + $p$ SELECT edge_id, fraction, side FROM pgr_findCloseEdges( $$SELECT id, geom FROM edges$$, (SELECT geom FROM pointsOfInterest WHERE pid = 5), @@ -97,31 +77,33 @@ SELECT * FROM pgr_withPoints( (12 rows) /* -- o5 */ -SELECT * +SELECT edge_id, fraction, side, distance, ST_AsText(geom) geom, ST_AsText(edge) edge FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT geom FROM pointsOfInterest WHERE pid = 5), - 0.5, - dryrun => true); +$$SELECT 1 AS id, ST_MakeLine(ST_makePoint(2,0), ST_MakePoint(2,3)) AS geom$$, +ST_MakePoint(0,1.5), 5, dryrun => true); NOTICE: - WITH - edges_sql AS (SELECT id, geom FROM edges), - point_sql AS (SELECT '01010000003333333333330740CDCCCCCCCCCCFC3F'::geometry AS point) - - SELECT - id::BIGINT AS edge_id, - ST_LineLocatePoint(geom, point) AS fraction, - CASE WHEN ST_Intersects(ST_Buffer(geom, 0.5, 'side=right endcap=flat'), point) - THEN 'r' - ELSE 'l' END::CHAR AS side, - - geom <-> point AS distance, - ST_ClosestPoint(geom, point) AS new_point, - ST_MakeLine(point, ST_ClosestPoint(geom, point)) AS new_line - - FROM edges_sql, point_sql - WHERE ST_DWithin(geom, point, 0.5) - ORDER BY geom <-> point LIMIT 1 +WITH +edges_sql AS (SELECT 1 AS id, ST_MakeLine(ST_makePoint(2,0), ST_MakePoint(2,3)) AS geom), +point_sql AS (SELECT unnest('{01010000000000000000000000000000000000F83F}'::geometry[]) AS point), +results AS ( + SELECT + id::BIGINT AS edge_id, + ST_LineLocatePoint(geom, point) AS fraction, + CASE WHEN ST_Intersects(ST_Buffer(geom, 5, 'side=right endcap=flat'), point) + THEN 'r' + ELSE 'l' END::CHAR AS side, + geom <-> point AS distance, + point, + ST_MakeLine(point, ST_ClosestPoint(geom, point)) AS new_line + FROM edges_sql, point_sql + WHERE ST_DWithin(geom, point, 5) + ORDER BY geom <-> point), +prepare_cap AS ( + SELECT row_number() OVER (PARTITION BY point ORDER BY point, distance) AS rn, * + FROM results) +SELECT edge_id, fraction, side, distance, point, new_line +FROM prepare_cap +WHERE rn <= 1 edge_id | fraction | side | distance | geom | edge ---------+----------+------+----------+------+------ @@ -129,90 +111,39 @@ NOTICE: /* -- o6 */ /* Many point signature */ -/* -- m1 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, round(distance::numeric, 3) AS distance, - ST_AsText(geom) AS geom_is_original, edge +/* -- m0 */ +SELECT edge_id, fraction, side, distance, ST_AsText(geom) geom, ST_AsText(edge) edge FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT array_agg(geom) FROM pointsOfInterest), - 0.5, cap => 2); - edge_id | fraction | side | distance | geom_is_original | edge ----------+----------+------+----------+------------------+------ - 1 | 0.40 | l | 0.200 | POINT(1.8 0.4) | - 6 | 0.30 | r | 0.200 | POINT(0.3 1.8) | - 12 | 0.60 | l | 0.200 | POINT(2.6 3.2) | - 11 | 1.00 | l | 0.447 | POINT(2.6 3.2) | - 15 | 0.40 | r | 0.200 | POINT(4.2 2.4) | - 9 | 1.00 | l | 0.447 | POINT(4.2 2.4) | - 5 | 0.80 | l | 0.100 | POINT(2.9 1.8) | - 8 | 0.90 | r | 0.200 | POINT(2.9 1.8) | - 4 | 0.70 | r | 0.200 | POINT(2.2 1.7) | - 8 | 0.20 | r | 0.300 | POINT(2.2 1.7) | -(10 rows) - -/* -- m2 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, round(distance::numeric, 3) AS distance, - ST_AsText(geom) AS geom_is_original, - ST_AsText(edge) AS original_to_new_point -FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT array_agg(geom) FROM pointsOfInterest), - 0.5, partial => false); - edge_id | fraction | side | distance | geom_is_original | original_to_new_point ----------+----------+------+----------+------------------+--------------------------- - 1 | 0.40 | l | 0.200 | POINT(1.8 0.4) | LINESTRING(1.8 0.4,2 0.4) - 6 | 0.30 | r | 0.200 | POINT(0.3 1.8) | LINESTRING(0.3 1.8,0.3 2) - 12 | 0.60 | l | 0.200 | POINT(2.6 3.2) | LINESTRING(2.6 3.2,2.6 3) - 15 | 0.40 | r | 0.200 | POINT(4.2 2.4) | LINESTRING(4.2 2.4,4 2.4) - 5 | 0.80 | l | 0.100 | POINT(2.9 1.8) | LINESTRING(2.9 1.8,3 1.8) - 4 | 0.70 | r | 0.200 | POINT(2.2 1.7) | LINESTRING(2.2 1.7,2 1.7) -(6 rows) - -/* -- m3 */ -SELECT edge_id, round(fraction::numeric, 2) AS fraction, side, round(distance::numeric, 3) AS distance, - ST_AsText(geom) AS geom_is_original, - ST_AsText(edge) AS original_to_new_point -FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT array_agg(geom) FROM pointsOfInterest), - 0.5, cap => 2, partial => false); - edge_id | fraction | side | distance | geom_is_original | original_to_new_point ----------+----------+------+----------+------------------+--------------------------- - 1 | 0.40 | l | 0.200 | POINT(1.8 0.4) | LINESTRING(1.8 0.4,2 0.4) - 6 | 0.30 | r | 0.200 | POINT(0.3 1.8) | LINESTRING(0.3 1.8,0.3 2) - 12 | 0.60 | l | 0.200 | POINT(2.6 3.2) | LINESTRING(2.6 3.2,2.6 3) - 11 | 1.00 | l | 0.447 | POINT(2.6 3.2) | LINESTRING(2.6 3.2,3 3) - 15 | 0.40 | r | 0.200 | POINT(4.2 2.4) | LINESTRING(4.2 2.4,4 2.4) - 9 | 1.00 | l | 0.447 | POINT(4.2 2.4) | LINESTRING(4.2 2.4,4 2) - 5 | 0.80 | l | 0.100 | POINT(2.9 1.8) | LINESTRING(2.9 1.8,3 1.8) - 8 | 0.90 | r | 0.200 | POINT(2.9 1.8) | LINESTRING(2.9 1.8,2.9 2) - 4 | 0.70 | r | 0.200 | POINT(2.2 1.7) | LINESTRING(2.2 1.7,2 1.7) - 8 | 0.20 | r | 0.300 | POINT(2.2 1.7) | LINESTRING(2.2 1.7,2.2 2) -(10 rows) +$$SELECT 1 AS id, ST_MakeLine(ST_makePoint(1,0), ST_MakePoint(1,3)) AS geom$$, +ARRAY[ST_MakePoint(0,2), ST_MakePoint(3,1)]::GEOMETRY[], 5); + edge_id | fraction | side | distance | geom | edge +---------+----------------+------+----------+------------+--------------------- + 1 | 0.666666666667 | l | 1 | POINT(0 2) | LINESTRING(0 2,1 2) + 1 | 0.333333333333 | r | 2 | POINT(3 1) | LINESTRING(3 1,1 1) +(2 rows) +/* -- m1 */ /* -- m4 */ -SELECT * +SELECT edge_id, fraction, side, distance, ST_AsText(geom) geom, ST_AsText(edge) edge FROM pgr_findCloseEdges( - $$SELECT id, geom FROM edges$$, - (SELECT array_agg(geom) FROM pointsOfInterest), - 0.5, - dryrun => true); +$$SELECT 1 AS id, ST_MakeLine(ST_makePoint(1,0), ST_MakePoint(1,3)) AS geom$$, +ARRAY[ST_MakePoint(0,2), ST_MakePoint(3,1)]::GEOMETRY[], 5, dryrun=>true); NOTICE: WITH -edges_sql AS (SELECT id, geom FROM edges), -point_sql AS (SELECT unnest('{0101000000CDCCCCCCCCCCFC3F9A9999999999D93F:0101000000CDCCCCCCCCCC10403333333333330340:0101000000CDCCCCCCCCCC04409A99999999990940:0101000000333333333333D33FCDCCCCCCCCCCFC3F:01010000003333333333330740CDCCCCCCCCCCFC3F:01010000009A99999999990140333333333333FB3F}'::geometry[]) AS point), +edges_sql AS (SELECT 1 AS id, ST_MakeLine(ST_makePoint(1,0), ST_MakePoint(1,3)) AS geom), +point_sql AS (SELECT unnest('{010100000000000000000000000000000000000040:01010000000000000000000840000000000000F03F}'::geometry[]) AS point), results AS ( SELECT id::BIGINT AS edge_id, ST_LineLocatePoint(geom, point) AS fraction, - CASE WHEN ST_Intersects(ST_Buffer(geom, 0.5, 'side=right endcap=flat'), point) + CASE WHEN ST_Intersects(ST_Buffer(geom, 5, 'side=right endcap=flat'), point) THEN 'r' ELSE 'l' END::CHAR AS side, geom <-> point AS distance, point, ST_MakeLine(point, ST_ClosestPoint(geom, point)) AS new_line FROM edges_sql, point_sql - WHERE ST_DWithin(geom, point, 0.5) + WHERE ST_DWithin(geom, point, 5) ORDER BY geom <-> point), prepare_cap AS ( SELECT row_number() OVER (PARTITION BY point ORDER BY point, distance) AS rn, * diff --git a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po index f463a0df583..0bf25ce56ea 100644 --- a/locale/en/LC_MESSAGES/pgrouting_doc_strings.po +++ b/locale/en/LC_MESSAGES/pgrouting_doc_strings.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: pgRouting v3.8\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-03-01 19:10+0000\n" +"POT-Creation-Date: 2025-03-02 19:54+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -4427,6 +4427,9 @@ msgstr "" msgid "pgr_findCloseEdges" msgstr "" +msgid "``partial`` option is removed." +msgstr "" + msgid "pgr_degree" msgstr "" @@ -6733,6 +6736,12 @@ msgid "" "in the routing function and is within the area of the results." msgstr "" +msgid "Given this area:" +msgstr "" + +msgid "Calculate a route:" +msgstr "" + msgid "How to contribute" msgstr "" @@ -6760,7 +6769,7 @@ msgid "" "parallel-edges-(KSP)>`__" msgstr "" -msgid "Adding Functionaity to pgRouting" +msgid "Adding Functionality to pgRouting" msgstr "" msgid "" @@ -11586,7 +11595,7 @@ msgid "" "adjustments needed by the application." msgstr "" -msgid "``EMTPY SET`` is returned on dryrun executions" +msgid "``EMPTY SET`` is returned on dryrun executions" msgstr "" msgid "pgr_findCloseEdges(`Edges SQL`_, **point**, **tolerance**, [**options**])" @@ -11595,7 +11604,7 @@ msgstr "" msgid "pgr_findCloseEdges(`Edges SQL`_, **points**, **tolerance**, [**options**])" msgstr "" -msgid "**options:** ``[cap, partial, dryrun]``" +msgid "**options:** ``[cap, dryrun]``" msgstr "" msgid "Returns set of |result-find|" @@ -11604,55 +11613,16 @@ msgstr "" msgid "One point" msgstr "" -msgid "**options:** [cap, partial, dryrun]``" -msgstr "" - -msgid "Default: ``cap => 1``" -msgstr "" - -msgid "Maximum one row answer." -msgstr "" - -msgid "Default: ``partial => true``" +msgid "Get two close edges to points of interest with :math:`pid = 5`" msgstr "" -msgid "With less calculations as possible." -msgstr "" - -msgid "Default: ``dryrun => false``" -msgstr "" - -msgid "Process query" -msgstr "" - -msgid "Returns" -msgstr "" - -msgid "values on ``edge_id``, ``fraction``, ``side`` columns." -msgstr "" - -msgid "``NULL`` on ``distance``, ``geom``, ``edge`` columns." +msgid "``cap => 2``" msgstr "" msgid "Many points" msgstr "" -msgid "" -"Find at most :math:`2` edges close to all vertices on the points of " -"interest table." -msgstr "" - -msgid "One answer per point, as small as possible." -msgstr "" - -msgid "" -"Columns ``edge_id``, ``fraction``, ``side`` and ``geom`` are returned " -"with values." -msgstr "" - -msgid "" -"``geom`` contains the original point geometry to assist on " -"deterpartialing to which point geometry the row belongs to." +msgid "For each points of interests, find the closest edge." msgstr "" msgid "**point**" @@ -11679,17 +11649,6 @@ msgstr "" msgid "Limit output rows" msgstr "" -msgid "``partial``" -msgstr "" - -msgid "" -"When ``true`` only columns needed for :doc:`withPoints-category` are " -"calculated." -msgstr "" - -msgid "When ``false`` all columns are calculated" -msgstr "" - msgid "When ``false`` calculations are performed." msgstr "" @@ -11705,203 +11664,91 @@ msgid "When :math:`cap = 1`, it is the closest edge." msgstr "" msgid "" -"Value in <0,1> that indicates the relative postition from the first end-" +"Value in <0,1> that indicates the relative position from the first end-" "point of the edge." msgstr "" msgid "Value in ``[r, l]`` indicating if the point is:" msgstr "" -msgid "In the right ``r``." -msgstr "" - -msgid "In the left ``l``." +msgid "At the right ``r`` of the segment." msgstr "" msgid "When the point is on the line it is considered to be on the right." msgstr "" -msgid "``distance``" -msgstr "" - -msgid "Distance from point to edge." -msgstr "" - -msgid "``NULL`` when ``cap = 1`` on the `One point`_ signature" -msgstr "" - -msgid "``POINT`` geometry" -msgstr "" - -msgid "" -"`One Point`_: Contains the point on the edge that is ``fraction`` away " -"from the starting point of the edge." -msgstr "" - -msgid "`Many Points`_: Contains the corresponding **original point**" -msgstr "" - -msgid "" -"``LINESTRING`` geometry from the **original point** to the closest point " -"of the edge with identifier ``edge_id``" -msgstr "" - -msgid "One point results" -msgstr "" - -msgid "The green nodes is the **original point**" -msgstr "" - -msgid "The geometry ``geom`` is a point on the :math:`sp \\rightarrow ep` edge." -msgstr "" - -msgid "" -"The geometry ``edge`` is a line that connects the **original point** with" -" ``geom``" -msgstr "" - -msgid "Many point results" -msgstr "" - -msgid "The green nodes are the **original points**" -msgstr "" - -msgid "" -"The geometry ``geom``, marked as **g1** and **g2** are the **original " -"points**" -msgstr "" - -msgid "" -"The geometry ``edge``, marked as **edge1** and **edge2** is a line that " -"connects the **original point** with the closest point on the :math:`sp " -"\\rightarrow ep` edge." -msgstr "" - -msgid "One point examples" -msgstr "" - -msgid "At most two answers" -msgstr "" - -msgid "``cap => 2``" -msgstr "" - -msgid "Maximum two row answer." -msgstr "" - -msgid "Understanding the result" +msgid "At the left ``l`` of the segment." msgstr "" -msgid "``NULL`` on ``geom``, ``edge``" -msgstr "" - -msgid "``edge_id`` identifier of the edge close to the **original point**" -msgstr "" - -#, python-brace-format -msgid "" -"Two edges are withing :math:`0.5` distance units from the **original " -"point**: :math:`{5, 8}`" +msgid "``distance``" msgstr "" -msgid "For edge :math:`5`:" +msgid "Distance from the point to the edge." msgstr "" -msgid "" -"``fraction``: The closest point from the **original point** is at the " -":math:`0.8` fraction of the edge :math:`5`." +msgid "Original ``POINT`` geometry." msgstr "" msgid "" -"``side``: The **original point** is located to the left side of edge " -":math:`5`." +"``LINESTRING`` geometry that connects the original **point** to the " +"closest point of the edge with identifier ``edge_id``" msgstr "" -msgid "" -"``distance``: The **original point** is located :math:`0.1` length units " -"from edge :math:`5`." +msgid "One point in an edge" msgstr "" -msgid "For edge :math:`8`:" +msgid "The green node is the original point." msgstr "" -msgid "" -"``fraction``: The closest point from the **original point** is at the " -":math:`0.89..` fraction of the edge :math:`8`." +msgid "``geom`` has the value of the original point." msgstr "" msgid "" -"``side``: The **original point** is located to the right side of edge " -":math:`8`." +"The geometry ``edge`` is a line that connects the original point with the" +" edge :math:`sp \\rightarrow ep` edge." msgstr "" -msgid "" -"``distance``: The **original point** is located :math:`0.19..` length " -"units from edge :math:`8`." +msgid "The point is located at the left of the edge." msgstr "" -msgid "One answer, all columns" -msgstr "" - -msgid "``partial => false``" +msgid "One point dry run execution" msgstr "" -msgid "Calculate all columns" +msgid "Using the query from the previous example:" msgstr "" -msgid "``edge_id`` identifier of the edge **closest** to the **original point**" +msgid "Returns ``EMPTY SET``." msgstr "" -#, python-brace-format -msgid "" -"From all edges within :math:`0.5` distance units from the **original " -"point**: :math:`{5}` is the closest one." +msgid "``dryrun => true``" msgstr "" -msgid "" -"``geom``: Contains the geometry of the closest point on edge :math:`5` " -"from the **original point**." +msgid "Generates a PostgreSQL ``NOTICE`` with the code used." msgstr "" msgid "" -"``edge``: Contains the ``LINESTRING`` geometry of the **original point** " -"to the closest point on on edge :math:`5` ``geom``" -msgstr "" - -msgid "At most two answers with all columns" +"The generated code can be used as a starting base code for additional " +"requirements, like taking into consideration the SRID." msgstr "" -msgid "Understanding the result:" +msgid "Many points in an edge" msgstr "" -msgid "" -"``geom``: Contains the geometry of the closest point on edge :math:`8` " -"from the **original point**." +msgid "The green nodes are the **original points**" msgstr "" msgid "" -"``edge``: Contains the ``LINESTRING`` geometry of the **original point** " -"to the closest point on on edge :math:`8` ``geom``" -msgstr "" - -msgid "One point dry run execution" -msgstr "" - -msgid "Returns ``EMPTY SET``." -msgstr "" - -msgid "``partial => true``" -msgstr "" - -msgid "Is ignored" +"The geometry ``geom``, marked as **g1** and **g2** are the **original " +"points**" msgstr "" msgid "" -"Because it is a **dry run** excecution, the code for all calculations are" -" shown on the PostgreSQL ``NOTICE``." +"The geometry ``edge``, marked as **edge1** and **edge2** is a line that " +"connects the **original point** with the closest point on the :math:`sp " +"\\rightarrow ep` edge." msgstr "" -msgid "``dryrun => true``" +msgid "Many points dry run execution" msgstr "" msgid "Do not process query" @@ -11912,64 +11759,6 @@ msgid "" "columns" msgstr "" -msgid "``cap`` and **original point** are used in the code" -msgstr "" - -msgid "Many points examples" -msgstr "" - -msgid "At most two answers per point" -msgstr "" - -msgid "``NULL`` on ``edge``" -msgstr "" - -msgid "" -"``edge_id`` identifier of the edge close to a **original point** " -"(``geom``)" -msgstr "" - -msgid "" -"Two edges at most withing :math:`0.5` distance units from each of the " -"**original points**:" -msgstr "" - -msgid "For ``POINT(1.8 0.4)`` and ``POINT(0.3 1.8)`` only one edge was found." -msgstr "" - -msgid "For the rest of the points two edges were found." -msgstr "" - -msgid "For point ``POINT(2.9 1.8)``" -msgstr "" - -msgid "" -"Edge :math:`5` is before :math:`8` therefore edge :math:`5` has the " -"shortest distance to ``POINT(2.9 1.8)``." -msgstr "" - -msgid "One answer per point, all columns" -msgstr "" - -msgid "For the **original point** ``POINT(2.9 1.8)``" -msgstr "" - -msgid "Edge :math:`5` is the closest edge to the **original point**" -msgstr "" - -msgid "" -"``geom``: Contains the geometry of the **original point** ``POINT(2.9 " -"1.8)``" -msgstr "" - -msgid "" -"``edge``: Contains the ``LINESTRING`` geometry of the **original point** " -"(``geom``) to the closest point on on edge." -msgstr "" - -msgid "Many points dry run execution" -msgstr "" - msgid "Find at most two routes to a given point" msgstr "" @@ -12004,10 +11793,10 @@ msgstr "" msgid "A unique identifier." msgstr "" -msgid "Identifier of the edge nearest edge that allows an arrival to the point." +msgid "Identifier of the nearest segment." msgstr "" -msgid "Is it on the left, right or both sides of the segment ``edge_id``" +msgid "Is it on the left, right or both sides of the segment ``edge_id``." msgstr "" msgid "Where in the segment is the point located." @@ -12016,13 +11805,35 @@ msgstr "" msgid "The geometry of the points." msgstr "" +msgid "The distance between ``geom`` and the segment ``edge_id``." +msgstr "" + +msgid "" +"A segment that connects the ``geom`` of the point to the closest point on" +" the segment ``edge_id``." +msgstr "" + msgid "``newPoint``" msgstr "" -msgid "The geometry of the points moved on top of the segment." +msgid "A point on segment ``edge_id`` that is the closest to ``geom``." +msgstr "" + +msgid "Points of interest fill up" +msgstr "" + +msgid "Inserting the points of interest." +msgstr "" + +msgid "Filling the rest of the table." +msgstr "" + +msgid "" +"Any other additional modification: In this manual, point :math:`6` can be" +" reached from both sides." msgstr "" -msgid "Points of interest fillup" +msgid "The points of interest:" msgstr "" msgid "``pgr_floydWarshall``" @@ -13625,7 +13436,7 @@ msgid "" "https://www.sintef.no/projectweb/top/pdptw/li-lim-benchmark/" msgstr "" -msgid "There are 25 vehciles in the problem all with the same characteristics." +msgid "There are 25 vehicles in the problem all with the same characteristics." msgstr "" msgid "The original orders" @@ -13636,7 +13447,7 @@ msgid "" "same order." msgstr "" -msgid "The original data needs to be converted to an appropiate table:" +msgid "The original data needs to be converted to an appropriate table:" msgstr "" msgid "The query" @@ -17860,8 +17671,8 @@ msgstr "" msgid "" "The documentation provides very simple example queries based on a small " -"sample network that resembles a city. To be able to execute the mayority " -"of the examples queries, follow the instructions bellow." +"sample network that resembles a city. To be able to execute the majority " +"of the examples queries, follow the instructions below." msgstr "" msgid "Main graph" @@ -17875,7 +17686,7 @@ msgstr "" msgid "" "Information known at this point is the geometry of the edges, cost " -"values, cpacity values, category values and some locations that are not " +"values, capacity values, category values and some locations that are not " "in the graph." msgstr "" @@ -17890,8 +17701,8 @@ msgstr "" msgid "" "The database design for the documentation of pgRouting, keeps in the same" " row 2 segments, one in the direction of the geometry and the second in " -"the oposite direction. Therfore some information has the ``reverse_`` " -"prefix which corresponds to the segment on the oposite direction of the " +"the opposite direction. Therefore some information has the ``reverse_`` " +"prefix which corresponds to the segment on the opposite direction of the " "geometry." msgstr "" @@ -17923,7 +17734,7 @@ msgid ":math:`x` coordinate of the starting vertex of the geometry." msgstr "" msgid "" -"For convinience it is saved on the table but can be calculated as " +"For convenience it is saved on the table but can be calculated as " "``ST_X(ST_StartPoint(geom))``." msgstr "" @@ -17931,7 +17742,7 @@ msgid ":math:`y` coordinate of the ending vertex of the geometry." msgstr "" msgid "" -"For convinience it is saved on the table but can be calculated as " +"For convenience it is saved on the table but can be calculated as " "``ST_Y(ST_EndPoint(geom))``." msgstr "" @@ -17942,8 +17753,8 @@ msgid "Starting on PostgreSQL 12::" msgstr "" msgid "" -"Optionally indexes on different columns can be created. The recomendation" -" is to have" +"Optionally indexes on different columns can be created. The " +"recommendation is to have" msgstr "" msgid "``id`` indexed." @@ -17953,7 +17764,7 @@ msgid "``source`` and ``target`` columns indexed to speed up pgRouting queries." msgstr "" msgid "" -"``geom`` indexed to speed up gemetry processes that might be needed in " +"``geom`` indexed to speed up geometry processes that might be needed in " "the front end." msgstr "" @@ -18022,7 +17833,7 @@ msgid "" msgstr "" msgid "" -"For convinence of this documentations, some combinations will be stored " +"For convenience of this documentation, some combinations will be stored " "on a table:" msgstr "" diff --git a/locale/pot/pgrouting_doc_strings.pot b/locale/pot/pgrouting_doc_strings.pot index 25b34fae473..c05eb3a25db 100644 --- a/locale/pot/pgrouting_doc_strings.pot +++ b/locale/pot/pgrouting_doc_strings.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: pgRouting v3.8\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-03-01 19:10+0000\n" +"POT-Creation-Date: 2025-03-02 19:54+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -3949,6 +3949,9 @@ msgstr "" msgid "pgr_findCloseEdges" msgstr "" +msgid "``partial`` option is removed." +msgstr "" + msgid "pgr_degree" msgstr "" @@ -5884,6 +5887,12 @@ msgstr "" msgid "In this example Use an inner query SQL that does not include some edges in the routing function and is within the area of the results." msgstr "" +msgid "Given this area:" +msgstr "" + +msgid "Calculate a route:" +msgstr "" + msgid "How to contribute" msgstr "" @@ -5905,7 +5914,7 @@ msgstr "" msgid "`Example `__" msgstr "" -msgid "Adding Functionaity to pgRouting" +msgid "Adding Functionality to pgRouting" msgstr "" msgid "Consult the `developer's documentation `__" @@ -9859,7 +9868,7 @@ msgstr "" msgid "The code to do the calculations can be obtained for further specific adjustments needed by the application." msgstr "" -msgid "``EMTPY SET`` is returned on dryrun executions" +msgid "``EMPTY SET`` is returned on dryrun executions" msgstr "" msgid "pgr_findCloseEdges(`Edges SQL`_, **point**, **tolerance**, [**options**])" @@ -9868,7 +9877,7 @@ msgstr "" msgid "pgr_findCloseEdges(`Edges SQL`_, **points**, **tolerance**, [**options**])" msgstr "" -msgid "**options:** ``[cap, partial, dryrun]``" +msgid "**options:** ``[cap, dryrun]``" msgstr "" msgid "Returns set of |result-find|" @@ -9877,49 +9886,16 @@ msgstr "" msgid "One point" msgstr "" -msgid "**options:** [cap, partial, dryrun]``" -msgstr "" - -msgid "Default: ``cap => 1``" -msgstr "" - -msgid "Maximum one row answer." -msgstr "" - -msgid "Default: ``partial => true``" -msgstr "" - -msgid "With less calculations as possible." -msgstr "" - -msgid "Default: ``dryrun => false``" -msgstr "" - -msgid "Process query" -msgstr "" - -msgid "Returns" -msgstr "" - -msgid "values on ``edge_id``, ``fraction``, ``side`` columns." +msgid "Get two close edges to points of interest with :math:`pid = 5`" msgstr "" -msgid "``NULL`` on ``distance``, ``geom``, ``edge`` columns." +msgid "``cap => 2``" msgstr "" msgid "Many points" msgstr "" -msgid "Find at most :math:`2` edges close to all vertices on the points of interest table." -msgstr "" - -msgid "One answer per point, as small as possible." -msgstr "" - -msgid "Columns ``edge_id``, ``fraction``, ``side`` and ``geom`` are returned with values." -msgstr "" - -msgid "``geom`` contains the original point geometry to assist on deterpartialing to which point geometry the row belongs to." +msgid "For each points of interests, find the closest edge." msgstr "" msgid "**point**" @@ -9946,15 +9922,6 @@ msgstr "" msgid "Limit output rows" msgstr "" -msgid "``partial``" -msgstr "" - -msgid "When ``true`` only columns needed for :doc:`withPoints-category` are calculated." -msgstr "" - -msgid "When ``false`` all columns are calculated" -msgstr "" - msgid "When ``false`` calculations are performed." msgstr "" @@ -9967,217 +9934,85 @@ msgstr "" msgid "When :math:`cap = 1`, it is the closest edge." msgstr "" -msgid "Value in <0,1> that indicates the relative postition from the first end-point of the edge." +msgid "Value in <0,1> that indicates the relative position from the first end-point of the edge." msgstr "" msgid "Value in ``[r, l]`` indicating if the point is:" msgstr "" -msgid "In the right ``r``." -msgstr "" - -msgid "In the left ``l``." +msgid "At the right ``r`` of the segment." msgstr "" msgid "When the point is on the line it is considered to be on the right." msgstr "" -msgid "``distance``" -msgstr "" - -msgid "Distance from point to edge." -msgstr "" - -msgid "``NULL`` when ``cap = 1`` on the `One point`_ signature" -msgstr "" - -msgid "``POINT`` geometry" -msgstr "" - -msgid "`One Point`_: Contains the point on the edge that is ``fraction`` away from the starting point of the edge." -msgstr "" - -msgid "`Many Points`_: Contains the corresponding **original point**" -msgstr "" - -msgid "``LINESTRING`` geometry from the **original point** to the closest point of the edge with identifier ``edge_id``" -msgstr "" - -msgid "One point results" -msgstr "" - -msgid "The green nodes is the **original point**" -msgstr "" - -msgid "The geometry ``geom`` is a point on the :math:`sp \\rightarrow ep` edge." -msgstr "" - -msgid "The geometry ``edge`` is a line that connects the **original point** with ``geom``" -msgstr "" - -msgid "Many point results" -msgstr "" - -msgid "The green nodes are the **original points**" -msgstr "" - -msgid "The geometry ``geom``, marked as **g1** and **g2** are the **original points**" -msgstr "" - -msgid "The geometry ``edge``, marked as **edge1** and **edge2** is a line that connects the **original point** with the closest point on the :math:`sp \\rightarrow ep` edge." -msgstr "" - -msgid "One point examples" -msgstr "" - -msgid "At most two answers" -msgstr "" - -msgid "``cap => 2``" -msgstr "" - -msgid "Maximum two row answer." -msgstr "" - -msgid "Understanding the result" -msgstr "" - -msgid "``NULL`` on ``geom``, ``edge``" -msgstr "" - -msgid "``edge_id`` identifier of the edge close to the **original point**" -msgstr "" - -msgid "Two edges are withing :math:`0.5` distance units from the **original point**: :math:`{5, 8}`" -msgstr "" - -msgid "For edge :math:`5`:" -msgstr "" - -msgid "``fraction``: The closest point from the **original point** is at the :math:`0.8` fraction of the edge :math:`5`." -msgstr "" - -msgid "``side``: The **original point** is located to the left side of edge :math:`5`." -msgstr "" - -msgid "``distance``: The **original point** is located :math:`0.1` length units from edge :math:`5`." -msgstr "" - -msgid "For edge :math:`8`:" -msgstr "" - -msgid "``fraction``: The closest point from the **original point** is at the :math:`0.89..` fraction of the edge :math:`8`." -msgstr "" - -msgid "``side``: The **original point** is located to the right side of edge :math:`8`." +msgid "At the left ``l`` of the segment." msgstr "" -msgid "``distance``: The **original point** is located :math:`0.19..` length units from edge :math:`8`." -msgstr "" - -msgid "One answer, all columns" -msgstr "" - -msgid "``partial => false``" -msgstr "" - -msgid "Calculate all columns" +msgid "``distance``" msgstr "" -msgid "``edge_id`` identifier of the edge **closest** to the **original point**" +msgid "Distance from the point to the edge." msgstr "" -msgid "From all edges within :math:`0.5` distance units from the **original point**: :math:`{5}` is the closest one." +msgid "Original ``POINT`` geometry." msgstr "" -msgid "``geom``: Contains the geometry of the closest point on edge :math:`5` from the **original point**." +msgid "``LINESTRING`` geometry that connects the original **point** to the closest point of the edge with identifier ``edge_id``" msgstr "" -msgid "``edge``: Contains the ``LINESTRING`` geometry of the **original point** to the closest point on on edge :math:`5` ``geom``" +msgid "One point in an edge" msgstr "" -msgid "At most two answers with all columns" +msgid "The green node is the original point." msgstr "" -msgid "Understanding the result:" +msgid "``geom`` has the value of the original point." msgstr "" -msgid "``geom``: Contains the geometry of the closest point on edge :math:`8` from the **original point**." +msgid "The geometry ``edge`` is a line that connects the original point with the edge :math:`sp \\rightarrow ep` edge." msgstr "" -msgid "``edge``: Contains the ``LINESTRING`` geometry of the **original point** to the closest point on on edge :math:`8` ``geom``" +msgid "The point is located at the left of the edge." msgstr "" msgid "One point dry run execution" msgstr "" -msgid "Returns ``EMPTY SET``." -msgstr "" - -msgid "``partial => true``" +msgid "Using the query from the previous example:" msgstr "" -msgid "Is ignored" -msgstr "" - -msgid "Because it is a **dry run** excecution, the code for all calculations are shown on the PostgreSQL ``NOTICE``." +msgid "Returns ``EMPTY SET``." msgstr "" msgid "``dryrun => true``" msgstr "" -msgid "Do not process query" -msgstr "" - -msgid "Generate a PostgreSQL ``NOTICE`` with the code used to calculate all columns" -msgstr "" - -msgid "``cap`` and **original point** are used in the code" -msgstr "" - -msgid "Many points examples" -msgstr "" - -msgid "At most two answers per point" -msgstr "" - -msgid "``NULL`` on ``edge``" -msgstr "" - -msgid "``edge_id`` identifier of the edge close to a **original point** (``geom``)" -msgstr "" - -msgid "Two edges at most withing :math:`0.5` distance units from each of the **original points**:" -msgstr "" - -msgid "For ``POINT(1.8 0.4)`` and ``POINT(0.3 1.8)`` only one edge was found." -msgstr "" - -msgid "For the rest of the points two edges were found." +msgid "Generates a PostgreSQL ``NOTICE`` with the code used." msgstr "" -msgid "For point ``POINT(2.9 1.8)``" +msgid "The generated code can be used as a starting base code for additional requirements, like taking into consideration the SRID." msgstr "" -msgid "Edge :math:`5` is before :math:`8` therefore edge :math:`5` has the shortest distance to ``POINT(2.9 1.8)``." +msgid "Many points in an edge" msgstr "" -msgid "One answer per point, all columns" +msgid "The green nodes are the **original points**" msgstr "" -msgid "For the **original point** ``POINT(2.9 1.8)``" +msgid "The geometry ``geom``, marked as **g1** and **g2** are the **original points**" msgstr "" -msgid "Edge :math:`5` is the closest edge to the **original point**" +msgid "The geometry ``edge``, marked as **edge1** and **edge2** is a line that connects the **original point** with the closest point on the :math:`sp \\rightarrow ep` edge." msgstr "" -msgid "``geom``: Contains the geometry of the **original point** ``POINT(2.9 1.8)``" +msgid "Many points dry run execution" msgstr "" -msgid "``edge``: Contains the ``LINESTRING`` geometry of the **original point** (``geom``) to the closest point on on edge." +msgid "Do not process query" msgstr "" -msgid "Many points dry run execution" +msgid "Generate a PostgreSQL ``NOTICE`` with the code used to calculate all columns" msgstr "" msgid "Find at most two routes to a given point" @@ -10207,10 +10042,10 @@ msgstr "" msgid "A unique identifier." msgstr "" -msgid "Identifier of the edge nearest edge that allows an arrival to the point." +msgid "Identifier of the nearest segment." msgstr "" -msgid "Is it on the left, right or both sides of the segment ``edge_id``" +msgid "Is it on the left, right or both sides of the segment ``edge_id``." msgstr "" msgid "Where in the segment is the point located." @@ -10219,13 +10054,31 @@ msgstr "" msgid "The geometry of the points." msgstr "" +msgid "The distance between ``geom`` and the segment ``edge_id``." +msgstr "" + +msgid "A segment that connects the ``geom`` of the point to the closest point on the segment ``edge_id``." +msgstr "" + msgid "``newPoint``" msgstr "" -msgid "The geometry of the points moved on top of the segment." +msgid "A point on segment ``edge_id`` that is the closest to ``geom``." +msgstr "" + +msgid "Points of interest fill up" +msgstr "" + +msgid "Inserting the points of interest." +msgstr "" + +msgid "Filling the rest of the table." +msgstr "" + +msgid "Any other additional modification: In this manual, point :math:`6` can be reached from both sides." msgstr "" -msgid "Points of interest fillup" +msgid "The points of interest:" msgstr "" msgid "``pgr_floydWarshall``" @@ -11560,7 +11413,7 @@ msgstr "" msgid "This data example **lc101** is from data published at https://www.sintef.no/projectweb/top/pdptw/li-lim-benchmark/" msgstr "" -msgid "There are 25 vehciles in the problem all with the same characteristics." +msgid "There are 25 vehicles in the problem all with the same characteristics." msgstr "" msgid "The original orders" @@ -11569,7 +11422,7 @@ msgstr "" msgid "The data comes in different rows for the pickup and the delivery of the same order." msgstr "" -msgid "The original data needs to be converted to an appropiate table:" +msgid "The original data needs to be converted to an appropriate table:" msgstr "" msgid "The query" @@ -14941,7 +14794,7 @@ msgstr "" msgid "Sample Data" msgstr "" -msgid "The documentation provides very simple example queries based on a small sample network that resembles a city. To be able to execute the mayority of the examples queries, follow the instructions bellow." +msgid "The documentation provides very simple example queries based on a small sample network that resembles a city. To be able to execute the majority of the examples queries, follow the instructions below." msgstr "" msgid "Main graph" @@ -14953,7 +14806,7 @@ msgstr "" msgid "The following city is to be inserted into the database:" msgstr "" -msgid "Information known at this point is the geometry of the edges, cost values, cpacity values, category values and some locations that are not in the graph." +msgid "Information known at this point is the geometry of the edges, cost values, capacity values, category values and some locations that are not in the graph." msgstr "" msgid "The process to have working topology starts by inserting the edges. After that everything else is calculated." @@ -14962,7 +14815,7 @@ msgstr "" msgid "Edges" msgstr "" -msgid "The database design for the documentation of pgRouting, keeps in the same row 2 segments, one in the direction of the geometry and the second in the oposite direction. Therfore some information has the ``reverse_`` prefix which corresponds to the segment on the oposite direction of the geometry." +msgid "The database design for the documentation of pgRouting, keeps in the same row 2 segments, one in the direction of the geometry and the second in the opposite direction. Therefore some information has the ``reverse_`` prefix which corresponds to the segment on the opposite direction of the geometry." msgstr "" msgid "Identifier of the starting vertex of the geometry ``geom``." @@ -14992,13 +14845,13 @@ msgstr "" msgid ":math:`x` coordinate of the starting vertex of the geometry." msgstr "" -msgid "For convinience it is saved on the table but can be calculated as ``ST_X(ST_StartPoint(geom))``." +msgid "For convenience it is saved on the table but can be calculated as ``ST_X(ST_StartPoint(geom))``." msgstr "" msgid ":math:`y` coordinate of the ending vertex of the geometry." msgstr "" -msgid "For convinience it is saved on the table but can be calculated as ``ST_Y(ST_EndPoint(geom))``." +msgid "For convenience it is saved on the table but can be calculated as ``ST_Y(ST_EndPoint(geom))``." msgstr "" msgid "The geometry of the segments." @@ -15007,7 +14860,7 @@ msgstr "" msgid "Starting on PostgreSQL 12::" msgstr "" -msgid "Optionally indexes on different columns can be created. The recomendation is to have" +msgid "Optionally indexes on different columns can be created. The recommendation is to have" msgstr "" msgid "``id`` indexed." @@ -15016,7 +14869,7 @@ msgstr "" msgid "``source`` and ``target`` columns indexed to speed up pgRouting queries." msgstr "" -msgid "``geom`` indexed to speed up gemetry processes that might be needed in the front end." +msgid "``geom`` indexed to speed up geometry processes that might be needed in the front end." msgstr "" msgid "For this small example the indexes are skipped, except for ``id``" @@ -15070,7 +14923,7 @@ msgstr "" msgid "Many functions can be used with a combinations of ``(source, target)`` pairs when wanting a route from ``source`` to ``target``." msgstr "" -msgid "For convinence of this documentations, some combinations will be stored on a table:" +msgid "For convenience of this documentation, some combinations will be stored on a table:" msgstr "" msgid "Inserting the data:" diff --git a/pgtap/topology/degree/edge_cases.pg b/pgtap/topology/degree/edge_cases.pg index 39fe52c0d5c..e7cdd91880f 100644 --- a/pgtap/topology/degree/edge_cases.pg +++ b/pgtap/topology/degree/edge_cases.pg @@ -104,16 +104,15 @@ BEGIN PREPARE empty_graph AS SELECT * FROM pgr_degree('SELECT id FROM edges WHERE id > 20', 'SELECT * FROM vertices') ORDER BY node; - RETURN QUERY - SELECT CASE WHEN min_version('3.8.0') THEN - collect_tap( - is_empty('empty_graph', 'is empty: Empty edges give 0 count on all vertices so none is in result') - ) + + IF min_version('3.8.0') THEN + PERFORM todo(1, 'Currently is not empty'); + RETURN QUERY + SELECT is_empty('empty_graph', 'is empty: Empty edges give 0 count on all vertices so none is in result'); ELSE - collect_tap( - results_eq('empty_graph', 'SELECT generate_series (1,17)::BIGINT, 0::BIGINT', 'Empty edges give 0 count') - ) - END; + RETURN QUERY + SELECT results_eq('empty_graph', 'SELECT generate_series (1,17)::BIGINT, 0::BIGINT', 'Empty edges give 0 count'); + END IF; END; $BODY$ diff --git a/pgtap/utilities/findCloseEdges/edge_cases.pg b/pgtap/utilities/findCloseEdges/edge_cases.pg index 0c634c2f5ca..94ab01788e0 100644 --- a/pgtap/utilities/findCloseEdges/edge_cases.pg +++ b/pgtap/utilities/findCloseEdges/edge_cases.pg @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. BEGIN; UPDATE edges SET cost = sign(cost), reverse_cost = sign(reverse_cost); -SELECT CASE WHEN min_version('3.4.0') THEN plan(16) ELSE plan(1) END; +SELECT CASE WHEN min_version('3.8.0') THEN plan(33) WHEN min_version('3.4.0') THEN plan(34) ELSE plan(1) END; SET client_min_messages TO 'WARNING'; @@ -58,7 +58,7 @@ BEGIN RETURN QUERY SELECT lives_ok('query_1', 'With defaults'); RETURN QUERY SELECT lives_ok('query_2', 'two rows'); RETURN QUERY SELECT lives_ok('query_3', 'dryrun'); - RETURN QUERY SELECT is_empty('query_3', 'dryrun'); + RETURN QUERY SELECT is_empty('query_3', 'dryrun results empty'); RETURN QUERY SELECT column_missing('err1', 'geom'); RETURN QUERY SELECT column_missing('err2', 'id'); @@ -85,7 +85,7 @@ BEGIN RETURN QUERY SELECT lives_ok('query_4', 'With defaults'); RETURN QUERY SELECT lives_ok('query_5', 'two rows'); RETURN QUERY SELECT lives_ok('query_6', 'dryrun'); - RETURN QUERY SELECT is_empty('query_6', 'dryrun'); + RETURN QUERY SELECT is_empty('query_6', 'dryrun results empty'); RETURN QUERY SELECT column_missing('err3', 'geom'); RETURN QUERY SELECT column_missing('err4', 'id'); @@ -97,6 +97,84 @@ BEGIN 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM bar), 0.5)$$, '42P01', 'relation "bar" does not exist'); + IF min_version('4.0.0') THEN + RETURN QUERY SELECT skip(1, 'Signatures with partial flag is removed on 4.0.0'); + RETURN; + END IF; + + -- Test with partial flag + RETURN QUERY SELECT is_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, true, true)$$, 'One geom: partial,dryrun = true,true'); + RETURN QUERY SELECT isnt_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, true, false)$$, 'One geom: partial,dryrun = true,false'); + RETURN QUERY SELECT is_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, false, true)$$, 'One geom: partial,dryrun = false,true'); + RETURN QUERY SELECT isnt_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, false, false)$$, 'One geom: partial,dryrun = false,false'); + + RETURN QUERY SELECT is_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, 1, true, true)$$, 'Many geom: partial,dryrun = true,true'); + RETURN QUERY SELECT isnt_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, 1, true, false)$$, 'Many geom: partial,dryrun = true,false'); + RETURN QUERY SELECT is_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, 1, false, true)$$, 'Many geom: partial,dryrun = false,true'); + RETURN QUERY SELECT isnt_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, 1, false, false)$$, 'Many geom: partial,dryrun = false,false'); + + RETURN QUERY SELECT + CASE WHEN min_version('3.8.0') THEN + collect_tap( + throws_ok($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, partial => true) WHERE distance IS NOT NULL$$, + '42883','function pgr_findcloseedges(unknown, geometry, numeric, integer, partial => boolean) does not exist', 'throws: One geom, with cap value, naming partial => true'), + throws_ok($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, partial => true) WHERE distance IS NOT NULL$$, + '42883','function pgr_findcloseedges(unknown, geometry, numeric, partial => boolean) does not exist', 'throws: One geom, without cap value naming partial => true'), + isnt_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, true, false) WHERE distance IS NOT NULL$$, 'partial, One geom: isnt_empty distance'), + isnt_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, true, false) WHERE geom IS NOT NULL$$, 'partial, One geom: isnt_empty geom'), + isnt_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, true, false) WHERE edge IS NOT NULL$$, 'partial, One geom: isnt_empty edge'), + + throws_ok($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, 1, partial => true) WHERE distance IS NOT NULL$$, + '42883','function pgr_findcloseedges(unknown, geometry[], numeric, integer, partial => boolean) does not exist', 'throws: Many geom, with cap value, naming partial => true'), + throws_ok($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, partial => true) WHERE distance IS NOT NULL$$, + '42883','function pgr_findcloseedges(unknown, geometry[], numeric, partial => boolean) does not exist', 'throws: Many geom, without cap value naming partial => true'), + isnt_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, 1, true, false) WHERE distance IS NOT NULL$$, 'partial, Many geom: isnt_empty distance'), + isnt_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, 1, true, false) WHERE edge IS NOT NULL$$, 'partial, Many geom: isnt_empty edge') + ) + + ELSE + collect_tap( + lives_ok($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, partial => true) WHERE distance IS NOT NULL$$, 'One geom, with cap value, naming partial => true'), + lives_ok($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, partial => true) WHERE distance IS NOT NULL$$, 'One geom, without cap value, naming partial => true'), + is_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, true, false) WHERE distance IS NOT NULL$$, 'partial, One geom: is_empty distance'), + is_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, true, false) WHERE geom IS NOT NULL$$, 'partial, One geom: is_empty geom'), + is_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT geom FROM pointsOfInterest WHERE pid = 5), 0.5, 1, true, false) WHERE edge IS NOT NULL$$, 'partial, One geom: is_empty edge'), + + lives_ok($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, 1, partial => true) WHERE distance IS NOT NULL$$, 'Many geom, with cap value, naming partial => true'), + lives_ok($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, partial => true) WHERE distance IS NOT NULL$$, 'Many geom, without cap value, naming partial => true'), + isnt_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, 1, true, false) WHERE distance IS NOT NULL$$, 'partial, Many geom: isnt_empty distance'), + isnt_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, 1, true, false) WHERE geom IS NOT NULL$$, 'partial, Many geom: isnt_empty geom'), + is_empty($$SELECT * FROM pgr_findCloseEdges( + 'SELECT id, geom FROM edges', (SELECT array_agg(geom) FROM pointsOfInterest), 0.5, 1, true, false) WHERE edge IS NOT NULL$$, 'partial, Many geom: is_empty edge') + ) + END; + END; $BODY$ LANGUAGE plpgsql; diff --git a/pgtap/utilities/findCloseEdges/types_check.pg b/pgtap/utilities/findCloseEdges/types_check.pg index 58d8c0e17f8..b022f60b3b9 100644 --- a/pgtap/utilities/findCloseEdges/types_check.pg +++ b/pgtap/utilities/findCloseEdges/types_check.pg @@ -42,26 +42,45 @@ BEGIN SELECT function_returns('pgr_findcloseedges', ARRAY['text', 'geometry[]','double precision','integer','boolean','boolean'],'setof record'); + IF min_version('3.8.0') THEN - RETURN QUERY SELECT set_eq( - $$SELECT proargnames from pg_proc where proname = 'pgr_findcloseedges'$$, - $$SELECT '{"","","","cap","partial","dryrun","edge_id","fraction","side","distance","geom","edge"}'::TEXT[] $$); + RETURN QUERY SELECT bag_eq( + $$SELECT proargnames from pg_proc where proname = 'pgr_findcloseedges'$$, + $$VALUES + ('{"","","","cap","dryrun","edge_id","fraction","side","distance","geom","edge"}'::TEXT[]), + ('{"","","","cap","dryrun","edge_id","fraction","side","distance","geom","edge"}'::TEXT[]), + ('{"","","","cap","partial","dryrun","edge_id","fraction","side","distance","geom","edge"}'::TEXT[]), + ('{"","","","cap","partial","dryrun","edge_id","fraction","side","distance","geom","edge"}'::TEXT[]) + $$, + 'proargnames'); - /* pgtap does not like geometry type, this is a workaround */ - RETURN QUERY - SELECT set_eq( - $$WITH a AS (SELECT unnest(proallargtypes) FROM pg_proc WHERE proname = 'pgr_findcloseedges') - SELECT typname FROM a JOIN pg_type ON(oid = unnest)$$, - $$VALUES - ('bool'), - ('int4'), - ('text'), - ('float8'), - ('geometry'), - ('_geometry'), - ('int8'), - ('bpchar') - $$); + RETURN QUERY + SELECT function_types('pgr_findcloseedges', + $$ VALUES + ('{text,_geometry,float8,int4,bool,int8,float8,bpchar,float8,geometry,geometry}'::TEXT[]), + ('{text,geometry,float8,int4,bool,int8,float8,bpchar,float8,geometry,geometry}'::TEXT[]), + ('{text,geometry,float8,int4,bool,bool,int8,float8,bpchar,float8,geometry,geometry}'::TEXT[]), + ('{text,_geometry,float8,int4,bool,bool,int8,float8,bpchar,float8,geometry,geometry}'::TEXT[]) + $$); + + ELSE + + RETURN QUERY SELECT bag_eq( + $$SELECT proargnames from pg_proc where proname = 'pgr_findcloseedges'$$, + $$VALUES + ('{"","","","cap","partial","dryrun","edge_id","fraction","side","distance","geom","edge"}'::TEXT[]), + ('{"","","","cap","partial","dryrun","edge_id","fraction","side","distance","geom","edge"}'::TEXT[]) + $$, + 'proargnames'); + + RETURN QUERY + SELECT function_types('pgr_findcloseedges', + $$ VALUES + ('{text,geometry,float8,int4,bool,bool,int8,float8,bpchar,float8,geometry,geometry}'::TEXT[]), + ('{text,_geometry,float8,int4,bool,bool,int8,float8,bpchar,float8,geometry,geometry}'::TEXT[]) + $$); + + END IF; END $BODY$ diff --git a/sql/scripts/build-extension-update-files.pl b/sql/scripts/build-extension-update-files.pl index 84894310b48..b92a5b70cf9 100755 --- a/sql/scripts/build-extension-update-files.pl +++ b/sql/scripts/build-extension-update-files.pl @@ -269,6 +269,12 @@ sub generate_upgrade_script { push @commands, drop_special_case_function("pgr_kruskaldd(text,anyarray,double precision)"); } + # updating to 3.7+ + if ($old_mayor == 3 && $old_minor < 8) { + push @commands, drop_special_case_function("pgr_findcloseedges(text,geometry,double precision,integer,boolean,boolean)"); + push @commands, drop_special_case_function("pgr_findcloseedges(text,geometry[],double precision,integer,boolean,boolean)"); + } + } #------------------------------------ @@ -283,9 +289,9 @@ sub generate_upgrade_script { } # UGH! someone change the definition of the TYPE or reused an existing - # TYPE name which is VERY BAD because other poeple might be dependent + # TYPE name which is VERY BAD because other people might be dependent # on the old TYPE so we can DROP TYPE CASCADE; or we might drop - # a user's function. So juse DIE and maybe someone can resolve this + # a user's function. So just DIE and maybe someone can resolve this die "ERROR: pgrouting TYPE changed! Cannot continue!\n" if $err; diff --git a/sql/sigs/pgrouting--3.8.sig b/sql/sigs/pgrouting--3.8.sig index 460e9e69d68..02537609497 100644 --- a/sql/sigs/pgrouting--3.8.sig +++ b/sql/sigs/pgrouting--3.8.sig @@ -160,6 +160,8 @@ _pgr_edwardmoore(text,text,boolean) pgr_edwardmoore(text,text,boolean) _pgr_endpoint(geometry) pgr_extractvertices(text,boolean) +pgr_findcloseedges(text,geometry,double precision,integer,boolean) +pgr_findcloseedges(text,geometry[],double precision,integer,boolean) pgr_findcloseedges(text,geometry,double precision,integer,boolean,boolean) pgr_findcloseedges(text,geometry[],double precision,integer,boolean,boolean) _pgr_floydwarshall(text,boolean) diff --git a/sql/utilities/findCloseEdges.sql b/sql/utilities/findCloseEdges.sql index 87869712abe..abd4a489346 100644 --- a/sql/utilities/findCloseEdges.sql +++ b/sql/utilities/findCloseEdges.sql @@ -1,7 +1,7 @@ /*PGR-GNU***************************************************************** -Copyright (c) 2022 Celia Virginia Vergara Castillo -Mail: vicky at georepublic dot de +Copyright (c) 2025 Celia Virginia Vergara Castillo +Mail: vicky at erosion.dev ------ @@ -21,14 +21,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ********************************************************************PGR-GNU*/ ---v3.4 +--v3.8 CREATE FUNCTION pgr_findCloseEdges( TEXT, - geometry, + geometry[], FLOAT, cap INTEGER DEFAULT 1, - partial BOOLEAN DEFAULT true, - dryrun BOOLEAN DEFAULT false, + dryrun BOOLEAN default false, OUT edge_id BIGINT, OUT fraction FLOAT, @@ -39,6 +38,10 @@ CREATE FUNCTION pgr_findCloseEdges( returns SETOF RECORD AS $BODY$ DECLARE + geom_arr geometry[] := $2; + tolerance FLOAT := $3; + cap INTEGER := $4; + dryrun BOOLEAN := $5; edges_SQL TEXT; has_id BOOLEAN; has_geom BOOLEAN; @@ -49,126 +52,12 @@ DECLARE BEGIN - IF ($3 < 0) THEN - RAISE EXCEPTION 'Invalid value for tolerance'; + IF (tolerance < 0) THEN + RAISE EXCEPTION 'Invalid value for "tolerance"'; END IF; - IF (cap <= 0) THEN - RAISE EXCEPTION 'Invalid value for cap'; - END IF; - - BEGIN - edges_sql := _pgr_checkQuery($1); - has_id := _pgr_checkColumn(edges_sql, 'id', 'ANY-INTEGER', false, dryrun => dryrun); - has_geom := _pgr_checkColumn(edges_sql, 'geom', 'geometry', false, dryrun => dryrun); - EXCEPTION WHEN OTHERS THEN - GET STACKED DIAGNOSTICS sqlhint = PG_EXCEPTION_HINT; - RAISE EXCEPTION '%', SQLERRM USING HINT = sqlhint, ERRCODE = SQLSTATE; - END; - - ret_query = format( - $q$ - WITH - edges_sql AS (%1$s), - point_sql AS (SELECT %2$L::geometry AS point) - - SELECT - id::BIGINT AS edge_id, - ST_LineLocatePoint(geom, point) AS fraction, - CASE WHEN ST_Intersects(ST_Buffer(geom, %3$s, 'side=right endcap=flat'), point) - THEN 'r' - ELSE 'l' END::CHAR AS side, - $q$, edges_sql, $2, $3); - - ret_query_end = format( - $q$ - FROM edges_sql, point_sql - WHERE ST_DWithin(geom, point, %1$s) - ORDER BY geom <-> point LIMIT %2$s - $q$, $3, cap); - - IF partial AND cap = 1 AND NOT dryrun THEN - /* one answer and partialimal columns */ - - ret_query = - ret_query - || $q$ - NULL::FLOAT, - NULL::geometry, - NULL::geometry - $q$ - || ret_query_end; - - ELSIF partial AND NOT dryrun THEN - /* more than one answer and partialimal columns - * needs distance info for further sorting by use - */ - - ret_query = - ret_query - || $q$ - geom <-> point AS distance, - NULL::geometry, - NULL::geometry - $q$ - || ret_query_end; - - ELSE - /* More than one answer and all columns, or dryrun*/ - - ret_query = - ret_query - || $q$ - geom <-> point AS distance, - ST_ClosestPoint(geom, point) AS new_point, - ST_MakeLine(point, ST_ClosestPoint(geom, point)) AS new_line - $q$ - || ret_query_end; - - END IF; - - IF dryrun THEN - RAISE NOTICE '%', ret_query; - RETURN; - END IF; - - RETURN query EXECUTE ret_query; - -END; -$BODY$ -LANGUAGE PLPGSQL VOLATILE STRICT -COST 5; - ---v3.4 -CREATE FUNCTION pgr_findCloseEdges( - TEXT, - geometry[], - FLOAT, - cap INTEGER DEFAULT 1, - partial BOOLEAN DEFAULT true, - dryrun BOOLEAN DEFAULT false, - - OUT edge_id BIGINT, - OUT fraction FLOAT, - OUT side CHAR, - OUT distance FLOAT, - OUT geom geometry, - OUT edge geometry) -returns SETOF RECORD AS -$BODY$ -DECLARE - edges_SQL TEXT; - has_id BOOLEAN; - has_geom BOOLEAN; - ret_query TEXT; - ret_query_end TEXT; - - sqlhint TEXT; - -BEGIN - - IF ($3 < 0) THEN - RAISE EXCEPTION 'Invalid value for tolerance'; + IF (cap < 0) THEN + RAISE EXCEPTION 'Invalid value for "cap"'; END IF; BEGIN @@ -194,7 +83,7 @@ results AS ( ELSE 'l' END::CHAR AS side, geom <-> point AS distance, point, - $q$, edges_sql, $2, $3); + $q$, edges_sql, geom_arr, tolerance); ret_query_end = format( $q$ @@ -207,22 +96,12 @@ prepare_cap AS ( SELECT edge_id, fraction, side, distance, point, new_line FROM prepare_cap WHERE rn <= %2$s - $q$, $3, cap); - - IF partial AND NOT dryrun THEN - - ret_query = ret_query - || $q$NULL::geometry AS new_line$q$ - || ret_query_end; - - ELSE + $q$, tolerance, cap); ret_query = ret_query || $q$ST_MakeLine(point, ST_ClosestPoint(geom, point)) AS new_line $q$ || ret_query_end; - END IF; - IF dryrun THEN RAISE NOTICE '%', ret_query; RETURN; @@ -235,31 +114,98 @@ $BODY$ LANGUAGE PLPGSQL VOLATILE STRICT COST 5; --- COMMENTS -COMMENT ON FUNCTION pgr_findCloseEdges(TEXT, GEOMETRY, FLOAT, INTEGER, BOOLEAN, BOOLEAN) -IS 'pgr_findCloseEdges(One Point) +COMMENT ON FUNCTION pgr_findCloseEdges(TEXT, GEOMETRY[], FLOAT, INTEGER, BOOLEAN) +IS 'pgr_findCloseEdges(Many Points) - Parameters: - Edges SQL with columns: id, geom - - POINT geometry + - Array of POINT geometries - Maximum separation between geometries - Optional Parameters - cap => 1: at most one answer - - partial => true: do minimal calculations - dryrun => false: do not output code - Documentation: - ${PROJECT_DOC_LINK}/pgr_findCloseEdges.html '; -COMMENT ON FUNCTION pgr_findCloseEdges(TEXT, GEOMETRY, FLOAT, INTEGER, BOOLEAN, BOOLEAN) -IS 'pgr_findCloseEdges(Many Points) +--v3.8 +CREATE FUNCTION pgr_findCloseEdges( + TEXT, + geometry, + FLOAT, + cap INTEGER DEFAULT 1, + dryrun BOOLEAN default false, + OUT edge_id BIGINT, + OUT fraction FLOAT, + OUT side CHAR, + OUT distance FLOAT, + OUT geom geometry, + OUT edge geometry) +returns SETOF RECORD AS +$BODY$ + SELECT edge_id, fraction, side, distance, geom, edge + FROM pgr_findCloseEdges($1, ARRAY[$2]::GEOMETRY[], $3, cap, dryrun); +$BODY$ +LANGUAGE SQL VOLATILE STRICT COST 5; + +COMMENT ON FUNCTION pgr_findCloseEdges(TEXT, GEOMETRY, FLOAT, INTEGER, BOOLEAN) +IS 'pgr_findCloseEdges(One Point) - Parameters: - Edges SQL with columns: id, geom - - Array of POINT geometries + - POINT geometry - Maximum separation between geometries - Optional Parameters - cap => 1: at most one answer - - partial => true: do minimal calculations - dryrun => false: do not output code - Documentation: - ${PROJECT_DOC_LINK}/pgr_findCloseEdges.html '; + +--v3.4 +CREATE FUNCTION pgr_findCloseEdges( + TEXT, + geometry, + FLOAT, + cap INTEGER, + partial BOOLEAN, + dryrun BOOLEAN, + + OUT edge_id BIGINT, + OUT fraction FLOAT, + OUT side CHAR, + OUT distance FLOAT, + OUT geom geometry, + OUT edge geometry) +returns SETOF RECORD AS +$BODY$ + SELECT edge_id, fraction, side, distance, geom, edge + FROM pgr_findCloseEdges($1, ARRAY[$2]::GEOMETRY[], $3, cap, dryrun); +$BODY$ +LANGUAGE SQL VOLATILE STRICT COST 5; + +COMMENT ON FUNCTION pgr_findCloseEdges(TEXT, GEOMETRY, FLOAT, INTEGER, BOOLEAN, BOOLEAN) +IS 'pgr_findCloseEdges deprecated signature on v3.8.0'; + +--v3.4 +CREATE FUNCTION pgr_findCloseEdges( + TEXT, + geometry[], + FLOAT, + cap INTEGER, + partial BOOLEAN, + dryrun BOOLEAN, + + OUT edge_id BIGINT, + OUT fraction FLOAT, + OUT side CHAR, + OUT distance FLOAT, + OUT geom geometry, + OUT edge geometry) +returns SETOF RECORD AS +$BODY$ + SELECT edge_id, fraction, side, distance, geom, edge + FROM pgr_findCloseEdges($1, $2, $3, cap, dryrun); +$BODY$ +LANGUAGE SQL VOLATILE STRICT COST 5; + +COMMENT ON FUNCTION pgr_findCloseEdges(TEXT, GEOMETRY[], FLOAT, INTEGER, BOOLEAN, BOOLEAN) +IS 'pgr_findCloseEdges deprecated signature on v3.8.0'; diff --git a/tools/testers/general_pgtap_tests.sql b/tools/testers/general_pgtap_tests.sql index 465c1b4015c..fa9c9f82cb7 100644 --- a/tools/testers/general_pgtap_tests.sql +++ b/tools/testers/general_pgtap_tests.sql @@ -49,3 +49,19 @@ $BODY$ collect_tap(throws_ok($1, 'P0001', 'relation "' || $2 || '" does not exist')) END; $BODY$ LANGUAGE SQL; + +CREATE OR REPLACE FUNCTION function_types(TEXT, TEXT) +RETURNS TEXT AS +$BODY$ + SELECT set_eq(format($$ + WITH + a AS ( + SELECT oid, u.name, u.idx + FROM pg_proc p CROSS JOIN unnest(p.proallargtypes) + WITH ordinality as u(name, idx) + WHERE p.proname = '%1$s'), + b AS ( + SELECT a.*, t.typname FROM a JOIN pg_type As t on (t.oid = a.name)) + SELECT array_agg(typname ORDER BY idx) FROM b GROUP BY oid + $$, $1), $2, $1 || ': Function types'); +$BODY$ LANGUAGE SQL; diff --git a/tools/testers/sampledata.sql b/tools/testers/sampledata.sql index 231ae32e724..543926c547a 100644 --- a/tools/testers/sampledata.sql +++ b/tools/testers/sampledata.sql @@ -93,16 +93,40 @@ CREATE TABLE pointsOfInterest( edge_id BIGINT, side CHAR, fraction FLOAT, + distance FLOAT, + edge geometry, + newPoint geometry, geom geometry); /* -- p2 */ -INSERT INTO pointsOfInterest (edge_id, side, fraction, geom) VALUES -(1, 'l' , 0.4, ST_POINT(1.8, 0.4)), -(15, 'r' , 0.4, ST_POINT(4.2, 2.4)), -(12, 'l' , 0.6, ST_POINT(2.6, 3.2)), -(6, 'r' , 0.3, ST_POINT(0.3, 1.8)), -(5, 'l' , 0.8, ST_POINT(2.9, 1.8)), -(4, 'b' , 0.7, ST_POINT(2.2, 1.7)); +INSERT INTO pointsOfInterest (geom) VALUES +(ST_Point(1.8, 0.4)), +(ST_Point(4.2, 2.4)), +(ST_Point(2.6, 3.2)), +(ST_Point(0.3, 1.8)), +(ST_Point(2.9, 1.8)), +(ST_Point(2.2, 1.7)); /* -- p3 */ +UPDATE pointsofinterest SET + edge_id = poi.edge_id, + side = poi.side, + fraction = round(poi.fraction::numeric, 2), + distance = round(poi.distance::numeric, 2), + edge = poi.edge, + newPoint = ST_EndPoint(poi.edge) +FROM ( + SELECT * + FROM pgr_findCloseEdges( + $$SELECT id, geom FROM edges$$,(SELECT array_agg(geom) FROM pointsOfInterest), 0.5) ) AS poi +WHERE pointsOfInterest.geom = poi.geom; +/* -- p4 */ +UPDATE pointsOfInterest SET side = 'b' WHERE pid = 6; +/* -- p5 */ +SELECT + pid, ST_AsText(geom) geom, + edge_id, fraction AS frac, side, distance AS dist, + ST_AsText(edge) edge, ST_AsText(newPoint) newPoint +FROM pointsOfInterest; +/* -- p6 */ /* --POINTS CREATE end */ /* --COMBINATIONS CREATE start */