Creating graph for pgRouting with PostGIS? - pgrouting

Let the line A (0.98,0.562,3.27536,5.9723) and line B (3.33221,5.899287,10.7656,9.653627). Does pgrouting take a point near (3.27536,5.9723) or (3.33221,5.899287) as a node? Really theses two points are just one, they have only a little error range.

When you build your graph
Creating graph for pgrouting
you need to specify a snapping range. This way the point that are really close will snapped into the same node..
SELECT assign_vertex_id(table_name, snapping_range, geometry_column_name, edge_id_column_name);
example
SELECT assign_vertex_id('ways', 0.00001, 'the_geom', 'gid');

Related

Geopoints: From Single Coordinate to Bounds on map

I try to figure out how to come from a single given coordinate (lat/lon) to the nearest bounds which enclose this coordinate on a map e.g. streets or sea.
Here two examples to give you a better understanding of what I mean:
What i tried already or thought about:
Setting up a Nominatim server and search for the given coordinate via the reverse-function to get the bbox and/or the geojson polygon of this coordinate. -> this only works when the given coordinate is within a POI or for example directly on a street.
Writing an algorithm to walk in all 4 or 8 directions (n/e/s/w) and 'stop' when the map layer/surface changes (change = stop for this direction and mark a bounding-point)
Building up an image-recognition system using TensorFlow to detect the different colors and 'draw' the polygon. Worked with TensorFlow a couple of times but this seems to be the most tricky solution to implement (but at my current understanding the most precise one)
Does someone of you have any other ideas to get a solution for this problem? Would appreciate any kind of approaches
Cheers!
If I got your question right, you might wanna first select all polygons in which the given point is inside of using ST_Contains, and then compute the distance to this point using ST_Distance. If you ORDER BY distance and LIMIT to 1 result you'll get the nearest polygon, e.g.
Data Sample
CREATE TABLE t (gid int, geom geometry);
INSERT INTO t VALUES
(1,'POLYGON((-4.47 54.26,-4.44 54.28,-4.41 54.24,-4.46 54.23,-4.47 54.26))'),
(2,'POLYGON((-4.48 54.25,-4.40 54.25,-4.41 54.23,-4.48 54.23,-4.48 54.25))'),
(3,'POLYGON((-4.53 54.23,-4.44 54.29,-4.38 54.22,-4.53 54.23))');
Query
SELECT gid,ST_AsText(geom) FROM t
WHERE ST_Contains(geom,ST_MakePoint(-4.45, 54.25))
ORDER BY ST_Distance(geom,ST_MakePoint(-4.45, 54.25))
LIMIT 1;
gid | st_astext
-----+------------------------------------------------------------------------
1 | POLYGON((-4.47 54.26,-4.44 54.28,-4.41 54.24,-4.46 54.23,-4.47 54.26))
(1 Zeile)

Why ST_Intersection from Postgis returns multilinestring for self-intersecting linestrings?

I am trying on PostgreSQL with the extension Postgis to get the geometry of a gps_trace that intersects a box, then i want to get one linestring for each distinct part of the trace in the box. In the following example with 1 trace and 1 box , that would mean ST_intersection returns me a multilinestring with 2 linestrings inside, so that i can extract each of them with ST_Dump()
The geometries are in epsg 4326, I use the request SELECT ST_Intersection(gps_traces.geom, grid.box)
FROM gps_traces, grid
But as a result, i get a multilestring with 34 geometries inside. After zooming a little, i discovered that when the line self-intersects, it seems to consider and register each part as a separate linestring although at the beginning, the trace was a linestring in one go.
I am extremely surprised of this behavior, and didn't find any documentation on the subject nor topics that talked about it, so i'm asking here how is build the geometry resulting from an intersection and why I get this behavior ?
This is the first time i get to use stackoverflow, so I apologize if some elements are missing

GraphHopper: disable OSM ways collapsing

I need to match gpx file which contains track, that goes straight way, which consists of a few different OSM ways, going one after another with the same angle.
In Graphhopper answer there is a points field, that contains only start and end point of moving.
But I need to get all inner points of OSM ways on that straight way.
if angle in the geometry of one OSM way or angle between previous OSM way and next OSM way changes, graphhopper includes points of angle change in points field
Is there any url option or server config, that can enable
getting all the inner start and end points of OSM ways, disable OSM ways collapsing?
The source code exploation shows, that there is no way to disable OSM ways collapsing without code modification

Creating Postgis Polygon using ST_ConcaveHull from Geometry Points

I have a postgis 2.2 table with 20 columns of type geometry(Point,4326)
I'd like to generate a polygon which covers the outer boundary of the points - it seems like ST_ConcaveHull is a good option, but I can't see how to do it without first converting my points back to text (which seems to be missing the point).
Is st_concavehull the right option, and how do I go about constructing the query?
Thanks!
You first need to collect your points, then pass this collection to ST_ConcaveHull:
ST_ConcaveHull(ST_Collect(geom), 1)
Per the ST_ConcaveHull documentation:
Although it is not an aggregate - you can use it in conjunction with ST_Collect or ST_Union to get the concave hull of a set of points/linestring/polygons ST_ConcaveHull(ST_Collect(somepointfield), 0.80).

Geoserver - How do I draw a geodesic line that represents the great circle between two points

I'm using Geoserver version 2.1.1, Postgres 9 and PostGIS 2.0
What I want to achieve should (i think!) be quite straight forward. I want to render on a map a line that represents the Great Circle between two cities on the earths surface.
My database contains the city locations represented as geography points defined as latitude and lonfitude pairs.
I have a layer defining an SQL view in Geoserver which retrieves a linestring (st_makeline) from the two coordinates for the specified cities. I'm having to type cast the geographies to geometries to get this to work.
But when I draw the returned line on a map what i get is a straight line and not the curved line that I am expecting.
Can someone tell me how I should be going about this?
Thanks!
PostGIS offers mainly "constructors" of the base geometries point, linestring and polygone, like ST_MakeLine.
And what yo uwant to do depends also on the coordinate reference system you use when displaying your map layers.
Here's a nice trick about great circles or parts of:
https://gis.stackexchange.com/questions/5204/curved-point-to-point-route-maps
Yours, Stefan
P.S. Here's some related stuff:
Drawing circles on a sphere
And here's some math:
http://www.mathworks.ch/matlabcentral/newsreader/view_thread/277881
I had a similar problem in cartodb (which also uses PostGIS); I wanted to get curved lines from straight lines. Maybe this post can help.