OSMNx: How to return OSM roads using graph_from_point even if its extreme end nodes are not within the distance - networkx

I want to fetch the road network inside the blue circle. But i am not able to do so as its far end nodes are well beyond 100 meter from the point.
lng,lat=8.89458178871303, 41.657804855447374
road_filter = '["highway"~"secondary"]'
G=ox.graph_from_point((lat, lng),custom_filter=road_filter,dist=100)

G=ox.graph_from_point((lat, lng),custom_filter=road_filter,dist=100,simplify=False,retain_all=True,truncate_by_edge=True)
simplify=False and truncate_by_edge=True did the trick.

Related

Anylogic - restrict agents from going into specific GIS region

I'm currently working on a model where agents move to random points in the ocean on a GIS map. However, I want them to path in such a way that they do not collide with any islands on the map. I was thinking about creating GIS regions using the perimeter of the islands and was hoping there was some access restriction option for GIS regions. However, this does not seem to be a feature yet.
Does anyone have any tips on how to make agents avoid entering certain regions while moving towards a point on a GIS map? Thanks.
Create GISRoutes and move along those
One option is to generate the routes and then assess if they do overlap an island. If they do then you change that part of the route. See code example below, note I did not do all the math to create a new route that goes around the island... You believe you can do this yourself. It is going to be a piece of work, so I did not test this or develop the completed solution.
GISRoute route = main.map.getRoute(currentLat, currentLong, toLat, toLong);
List<GISMarkupSegment> segementsToKeep = new ArrayList<GISMarkupSegment>()
SegmentForLoop:
for (int i = 0; i < route.getSegmentCount(); i++) {
GISMarkupSegment segment = route.getSegment(i);
// Check if the segmeent is too close to an island, if within 100m then we adjust the segment and stop adding segeents
for (Pair<Double, Double> pair:main.LatLongPointsOIfIslands) {
double distance = Math.sqrt(segment.getDistanceSq(new Point(pair.getFirst(), pair.getSecond())));
if (distance < 100) {
segment.setEnd(pair.getFirst() + 100, pair.getSecond()+100);
break SegmentForLoop:
}
segementsToKeep.add(segment);
}
}
GISRoute routeUpToIsland = new GISRoute(main, segementsToKeep);
//TODO
// Create a new route around the island
// Add the segements of this new route to segementsToKeep
LatLongPointsOIfIslands is a collection of Pair<Double,Double> which is just lat and long combinations of all the GIS points of the island perimeters
I hope this helps or puts you on the right direction.
Alterantively you can investigate alternative routing providers

Improve start/destination matching for HERE FLEET Route API

we are using the HERE FLEET route calculation API to calculate a route between two points.
Our URL looks like this:
https://cre.api.here.com/2/calculateroute.json?app_id=XXX&app_code=XXX&storage=readonly&overlays=OVERLAYf0134c87a6404690aab2994d73c03824&waypoint0=geo!48.331953,10.904123;50&waypoint1=geo!48.380098,10.902750;50&mode=fastest;truck;traffic:disabled&language=de-de&routeattributes=sh
As you can see, we are using a radius for our waypoints (in this example: 50 meters).
This requests fails with following error message:
Cannot match 48.331953/10.904123 onto a road link with 50.0m search radius
The next logical step would be, to start the same request again, but for example with a radius of 100 meters, instead of 50 meters.
I think, this is kind of ugly, because I have to start multiple requests (at the beginnig with a small radius and later with larger radius) to calculate a single route.
Is it possible, to tell the API, that it should handle the right radius by itself (it could start with a really smart radius (5meters) and increase it further and further to find the right road link)?
Thanks for your help!
Simon
Remove the radius and leave only the coordinate. I tried and it worked.

Google maps snap to road for walking - Swift

I have an iOS app that is using the Google Maps SDK. I track a user as they walk or run then use those coordinates to plot their course along the road using snap to roads.
I have found however the snap to roads uses the direction of the road to plot the course so when it comes to roundabouts the course follows this around even if the user was on the inside of the block.
Is there a way to use snap to roads (or directions) that allows for walking tracks and follows the shortest distance?
Thanks
Looking at the documentation, snap to road is not for walking...
The snapToRoads method takes up to 100 GPS points collected along a route, and returns a similar set of data, with the points snapped to the most likely roads the vehicle was traveling along.
but well.. what you can do it to compare the points, and if the returned points are "some" distance faraway then the original point, you know that this points should be inside the block.

How would i find the connector of minimum wieght between two patches which have multiple connectors?

It is important that the minimum connectors are found between two origin and destination pairs. This is not the basis for a full blown model but rather a process that must take place in order for my model to run (my model is a road network in which road users initially follow the optimum route until the traffic density on a chosen route causes an individual vehicle to change the route that is being taken to minimise the time of travel between an origin and a destination).
The problem I have is that I am not sure how to go about finding the minimum connector while the connector patches are being placed down between two origin and destination patches during the time period when the network is being built.
Here is an example of a network that has been built. The orange square is where the cars will be destroyed and the blue square is where the cars are created and will then begin to flow around the network along the roads (dark grey). What I want to be able to do is to find the minimum road distance between the blue and orange squares as the network is being drawn out so that the cars can flow along the path of minimum weight between the blue and orange patch to replicate how users might get from a to b while using a road network. How could I do this?
Thanks.

Calculate nearest point of KML polygon for iPhone app

I have a series of nature reserves that need to be plotted, as polygon overlays, on a map using the coordinates contained within KML data. I’ve found a tutorial on the Apple website for displaying KML overlays on map instances.
The problem is that the reserves vary in size greatly - from a small pond right up to several hundred kilometers in size. As a result I can’t use the coordinates of the center point to find the nearest reserves. Instead I need to calculate the nearest point of the reserves polygon to find the nearest one. With the data in KML - how would I go about trying to achieve this?
I've only managed to find one other person ask this and no one had replied :(
Well, there are a couple different solutions depending on your needs. The higher the accuracy required, the more work required. I like Phil's meanRadius parameter idea. That would give you a rough idea of which polygon is closest and would be pretty easy to calculate. This idea works best if the polygons are "circlish". If the polygon are very irregular in shape, this idea loses it's accuracy.
From a math standpoint, here is what you want to do. Loop through all points of all polygons. Calculate the distance from those points to your current coordinate. Then just keep track of which one is closest. There is one final wrinkle. Imagine a two points making a line segment that is very long. You are located one meter away from the midpoint of the line. Well, the distance to these two points is very large, while, in fact you are very close to the polygon. You will need to calculate the distance from your coordinate to every possible line segment which you can do in a variety of manners which are outlined here:
http://www.worsleyschool.net/science/files/linepoint/distance.html
Finally, you need to ask yourself, am I in any polygons? If you're 10 meters away from a point on a polygon, but are, in fact, inside the polygon, obviously, you need to consider that. The best way to do that is to use a ray casting algorithm:
http://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm