I am busy with building a kind of 'track' player for GPS Tracks.
I have in my database all the positions of a certain track (latitude, longitude, altitude, time).
I am able to display the whole track on a map and move the marker along that track (see http://89.188.9.68/nl/gebruikers/track/trackid/101/#.T5AbauxNs1Y). At the left you have somewher 'starten!!!!'. If you hit that he will move along the track but based on distance.
My goal is that I could move based on time. Final goal is that I have 2 markers, 2 tracks and that I could play it and see the difference between the 2 markers. If i use distance it will be for both the same, but I would see where person 1 (track 1) was and where person 2 was at that moment.
Anyone any idea how i could make this work? Or any idea how this is possible? One of my ideas is that I ask for every movement the position of a certain person (asking it to the database), but isn't that too heavy?
Currently I use v3, but if you think v2 is better for this, i could always switch ;)
Thanks!
I can only think of setInterval actually counting time ticks, as shown here
http://jsfiddle.net/KSp4j/
You mentioned querying a database, yet in your example all the points are in the source. What I show needs the data already loaded in the HTML file. I use a format:
[
[time 1st pt. arrived, lat, lng]
[time 2nd pt. arrived, lat, lng]
[time 3rd pt. arrived, lat, lng]
...
]
and check the elapsed time with array's time.
Related
I'm simulating the operation of a railroad.
I have a table with train departure time, departure location, and arrival location data. Locations are given using longitude and latitude coordinates.
I created my rail yards on the GIS map using their coordinates.
I can make the trains depart following the schedules in the table and the correct departure location.
But I can't get them to go to the right destination.
When trying to use the moveTo block you can only indicate a single destination. In my simulator, each train will go to a different yard.
How can I perform this movement using a data table and geographic coordinates?
Some pertinent remarks:
I'm not using the rail library. I'm working in the GIS space with routes determined by Anylogic itself. I didn't design or import railroads.
For this reason, I'm using the "source" and "moveTo" blocks from the process modeling library.
In the "moveTo" block I didn't find options that allow me to use the longitude and latitude data of the destination and which are stored in the data table (as I do in the "source" block).
Whenever I try to insert some code that does this, Anylogic returns saying the error:
"Exception during discrete event execution:
root:
Non-unique value in the database!"
It is better to rather use an agent-based approach for this kind of movement instead of doing it using move to blocks. It is hard to explain here but do some more tutorial examples and you will understand. You want the agents to move at a specific time and in a process flow modelling approach unless you use delay or hold blocks agents will flow from one block to the next as soon as there is space.
Here is an example of how to do it using the agent-based approach using your setup.
I have an agent called Trem with a dynamic event to move it to a specific location.
Now we populate the dynamic events with data from the database at the start of the model using the code below.
List<Tuple> rows = selectFrom(db_table)
.list();
for (Tuple row : rows) {
//What is the start time of the movement
double timeToTripBegin = dateToTime(row.get( db_table.trip_begin_time ));
//Lets create a new movement event to trigger the movement in the future
create_MoveToLocation(timeToTripBegin,
row.get( db_table.latitude_chegada ),
row.get( db_table.longitude_chegada ));
}
These events will then trigger the required movement for us when the event executes.
I would like to calculate the number of unique kilometers of roadways in my city. More generally, I wish to sum the distance of every road within a bound, for simplicity a rectangle will do.
Is this possible using the Google Maps suite of APIs? If so, how would you go about doing it? If anyone has any resources related to this type of problem, I would be interested in reading them regardless of language (or even solutions with other mapping tools).
Bonus points: A general solution to this problem that can be applied to the pre set "cities" (example) that appear in Google Maps with well defined city limits.
You can use OpenStreetMap to calculate the total road length of a specific country or geographic area. There are multiple solutions available, based on multiple similar questions already asked.
Approach 1 from Total road length in Kilometers for a country at help.openstreetmap.org:
Use the Perl script osm-length-2.pl. There is an example at a mailing list post.
Approach 2 from Actual road length of exported map at help.openstreetmap.org:
Import your data (the planet or an country or area extract) into a PostGIS database, then use the following queries proposed by Frederik Ramm:
SELECT way AS clip
INTO clipping_polygon
FROM planet_osm_polygon
WHERE boundary='administrative' AND admin_level='8' and name='My City';
SELECT name, highway, ST_INTERSECTION(way, clip)
INTO clipped_roads
FROM planet_osm_line, clipping_polygon
WHERE ST_INTERSECTS(way, clip) AND highway IS NOT NULL;
SELECT highway, SUM(ST_LENGTH(way::geography))
FROM clipped_roads
GROUP BY highway;
I have a list of Points-of-Interest (e.g. car rest areas).
The user selects the Starting Point and the Ending Point.
This generates a route.
How can I programmatically filter the POIs that are close (e.g. 50 meters distance from the road) that route?
Can Google Maps SDK or OSRM offer this functionality?
Thank you,
Nick
1. You have to find the distance from one POI to the road.
In order to accomplish this, you have to store your road in a mathematical fashion:
You can sample equidistant points of your road and store them in an array (more practical, less precise) and then calculate the distance of the POI from every point in the array, then save the minor result and repeat the whole process for every POIs.
You can store a road in a function (more and more complex, but more precise). Now that you have this function, you can calculate same distance from your POI, take the minimum value and repeat for all POIs.
2. Google Distance Matrix can actually do this
With this Api you can calculate distance till 2500 origins * destinations points.
The result will give you an array of rows, with each row corresponding
to an origin, and each element within that row corresponds to a pairing of the origin with a destination value.
Example of a request:
https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=32.777211,35.021250&destinations=32.778663,35.015757&key=YOURAPIKEY
This is very useful to your goal, because lets you specify more than one points of which calculates distance.
I'll find a route between two places, for example using google maps. I'd like to divide the route to kilometers (two following places will be at a distance of 1 km), and get GPS coordinations of these places. This is because then I'll be able to get exacly the coordinations of, for example, 5th kilometer on the route. Could you please advice me how to achieve it?
This is extremely nontrivial. Is say your best bet is to find an algorithm to load the bearing between two points, then one to load a coordinate given a start point, distance, and bearing. This could give you it, but only if the data contained only straight lines. Since I assume the Google Maps API only gives you the turns the user has to make, this approach will be inaccurate when there are bends in roads. You'd need GIS data for roads and what will undoubtedly turn into a complicated algorithm to find something like this. It's definitely doable, but that's l how I'd start. Look into the Census TIGER road data, it should help.
Unless, of course, I'm wrong and the API does actually give enough points to cleanly map it, in which case those functions should be easy to find and implement.
This will only work if you have the polyline as a sequence of lat/lon (or other) coordinates, wherever you get that from.
Then you start at the beginning an iterate through the lines (point[i], point[i+1]).
THis distance you calculate with standard API.
while itersting you sum up the distance.
Once you exceed the 1000m, you know that the splitting point (the 1000m marker) is at line segment [i,i+1].
To calculate the exact position where on the line that is, you take the total summed meters from previous segment, and the value of this segment and do a linear interpolation.
The working code is a bit complexer: there can be multiple markes within one segement.
But first find out where you get the polyline from, whitou that it will not work.
I would like to find all points that are within N miles of a given area.
E.g. the area is California: Find all points that are within 50 miles of the border of California (not the middle of California).
When using Google Maps the distance is calculated using 'the middle' of the given location, but I need to calculate the distance using the borders of the given location. The location could be any zip code, city or country.
Could that be done by drawing a polygon using California's coordinates on a map and calculate the distance to location B using the points of the polygon?
Is there a more elegant solution to this? Any ideas?
Thanks!
I'm not sure if I understand your requirements completely, but I will give it a try with different interpretations:
1. You want to filter own map points:
This can be done with any GIS or a own service that offers a call like my_points_in_area(bbox). Bbox means here boundingbox and is the 2x lat/lon pair describing the rectangle around your given centerpoint. If you want to be accurate and really just deliver whats within 100km, you might need to test the distance to the POIs once more, as the rectangle will also include points that are a bit more far away.
2. You want to filter OSM data:
You might use a reverse-geocoding service as Nominatim to get informations about points of interests that are within this distance: http://wiki.openstreetmap.org/wiki/Nominatim
Otherwise import the OSM data using osmosis to a PostGIS DB. AFAIK there is (currently) no DB tool for Oracle: http://wiki.openstreetmap.org/wiki/Oracle
I'm sorry if I missed your question, but then please add more details :)