I am a student using osmnx to process some data. I have lat and long of a point somewhere on a road (it is sure that the point lies on a road), is there a way by which I can find the path distance between the nearest intersection and that point?
Related
I have this specific use case I can't figure out how to implement.
I need to trace a route route from a starting point to a random distance from that point.
The goal is to for instance suggest a route to the users can take if they want to walk 10km from their starting point or any point on a map.
Any ideas? or is there any free/paid service for such usecase?
Thank you for your help
One approach you could try is creating an isodistance polygon, then randomly choosing a direction from the center and find the intersection with the shape.
This blog post generates an isodistance shape by calculating the distance to a grid of nearby points, then producing a concave hull around the perimeter.
https://blog.mapbox.com/dive-deeper-into-isodistances-c90bd5df9215
You could then randomly select a direction and draw a line to intersection that shape. One approach to that is to draw a line from the center to north, and then http://turfjs.org/docs/#transformRotate a random angle.
Then use https://turfjs.org/docs/#lineIntersect to find the intersection point.
is there anyone know what is the relationship between ['x'], ['y'] and ['lon'] and ['lat']? If I know a node's ['lon'] and ['lat'], how I can plot this node on the street map?
I can use the G.node[22258] find the detail information of a node, like
{
'x':319101.513
'y': 4427916
'osmid':
'ref':
'lon':'-81.11861'
'lat':'39.982066'
}
But I would like to plot a node on the map. I know the latitude and longtitude of this node, but it seems I need to know the 'x' and 'y'.
You can use ox.get_nearest_node to get the node from lat/long.
Use ox.get_nearest_node(G, (39.982066, -81.11861)) to get a nearest node
Use ox.plot_graph_route(G, [ox.get_nearest_node(G, (39.982066, -81.11861))]) to plot the node on map
As far as my knowledge goes, x-y are projected coordinates while lat-long is geographic coordinates expressed in decimal degrees. The projected coordinates are dependent on the projection itself which varies from place to place. What is needed here, I believe, is a transformation of the lat long into the desired projected coordinate system.
Here is a piece of code that does this transformation (from WGS 84 to Spherical Mercator).
While these do not reveal your x and y, I am sure this is the sort of calculation one needs to apply to get their desired result. You may try out other projections relevant to, say the US. For example, I transform to epsg 3112 for Australia. When I do that, I can directly apply euclidian geometry to obtain distances in metres.
Links: https://spatialreference.org/ref/epsg/wgs-84/, https://epsg.io/3857
from pyproj import Proj, transform
inProj = Proj(init='epsg:4326')
outProj = Proj(init='epsg:3857')
x1,y1 = -81.11861,39.982066
x2,y2 = transform(inProj,outProj,x1,y1)
print (x2,y2)
Output:
-9030082.35905815 4863336.501637128
I have a set of origin-destination coordinates that I want to calculate the shortest paths between them.
My origin-destination coordinates are sometimes located in the middle of a long straight-line road. However, the shortest path calculated by OSMnx/networkx will not consider that mid-edge to nearest-node path.
Is there any ready function in OSMnx or networkx that I can use to find shortest path that originates/ends in the middle of the road?
If there is no such function, I am thinking of using the following steps.
Get nearest edges of origin and destination
Get nodes of those nearest edges: let's say (a,b) for origin, and (c,d) for destination
Calculate distance of 4 possible combinations: a->c, a->d, b->c, b->d
Project origin/destination onto their nearest edges: let's call them o1 and e1
Calculate distance o1->a, o1->b, e1->c, e1->d
Add (5) distance to (3): to get
o1->a->c->e1
o1->a->d->e1
o1->b->c->e1
o1->b->d->e1
Select path with smallest distance
OSMnx produces a networkx graph object for routing/analysis. As you note, networkx shortest path calculation takes an origin and a destination node, so trying to calculate a shortest graph path from an edge midpoint won't work.
A couple things you could try:
try to set simplify=False when you create the graph to retain as many nodes in the middle of streets as possible.
if that doesn't work, you could try to subdivide edges (with greater than some threshold length) into 50 meter chunks or somesuch to discretize them with more nodes.
See also: https://stackoverflow.com/a/55601732/7321942
I have the ephemeris for an Earth observing satellite from a TLE, so I can get the location of the satellite (lat/lon). The documentation has a nice example for the ISS, showing how that is done.
However, what I am actually after is the location of the point of the Earth's surface that the satellite's sensor is pointing at. Assume that the sensor is pointing perpendicular to the flight direction, so I should be able to calculate the azimuth direction using the satellite's inclination. Then I have an idea of the angle the satellite's sensor is using to point to the ground. Some simple geometry should give me the altitude I need.
The question is now: How do I string these two things together? The compute(observer) calculation example returns altitude and azimuth for a location (lat/lon). However, I could not find anything that does that the other way around. Any thoughts how to go about this? Any clues are much appreciated.
I am looking for how to calculate the distance along a path in a binary array.
I imported a map as a matrix in matlab. There is a binary image of a river crossing two cities. I only found out how to calculate the distance from the river points to the nearest city but I don't manage to compute the shortest distance along the river.
I made a vector with the indices of all river points but I don't know how to get the distance to the nearest city from that...
Image
So I am looking for the shortest distance through the red line towards one of the light blue points it crosses !
Thnx
If I understand you in the right way it is not very difficult: Just do a dfs or bfs (8-neighbourhood) starting at each river-town and add sqrt(2) if you go diagonal and 1 if you go to a 4-neighbour. At each river pixel you can finally decide by taking the minimum value. You can develop it further stopping at river pixels with already smaller distance to another city...
I really hope I got you in the right way :)