I am using Java to develop a project. I have got some trajectory data by applying a spatial query. My question is, how can I get speed and acceleration for these trajectory data? Does java has useful library to do so?
for more information: points has (x,y,z,t)
no java has not.
speed is distance per time.
to calculate distance you can use the haversine formula, asuming x,y are in latitude longitude. z is ignored.
Depending on the plattform (e.g Android) there is a lib for that,
otherwise search for haversine distance.
Related
Does google's distance matrix api considers "elevation" while showing distance between two latitude-longitude points?
Suppose first person is at upper level at an airport, second person is standing at lower level on same airport in same line, will the distance shown by google's distance matrix api be considering this vertical distance between both persons?
No, but it sounds like you're considering using this API for something it was not built for.
The Google Distance Matrix API will return route distances, be it driving, walking, bicycling or public transportation. The distance (and duration) in each element in a response Distance Matrix API would be that of the route found by the Google Directions API.
It does not calculate straight-line (or geodesic) distances. You can use the Haversine formula.
While the Directions API does find indoor routes for walking directions, this is only available for directions to/from Google MAps places, those that have a Place ID. An arbitraty position in an arbitrary building level cannot be expressed in a Place ID.
Distances from Google Maps (and APIs) do take elevation into account, e.g. this route is 2.1 Km even though it looks like barely 1.5 Km. on the map.
Besides all that, the elevation differences within a building would be tiny compared to the driving distance between them. If you are looking for distances between people inside buildings, you're better off with straight-line distances corrected with average floor elevation (3-5 m.) factored in.
FastVehicleRoutingTransportCostsMatrix
I am having adjacency Matrix of time ,taken from Mapbox . Mapbox distance API . I don't have the distance Matrix .How can I calculate cost ?
A quick scan of the documentation suggests that the "Distance API" is only capable of returning travel times... how illogical!
Using this API I would say there is no way to do this, but perhaps building your matrix via the Directions API would be possible. The only thing you could do would be to estimate an average driving speed and calculate the estimated distance. But adding .setCostPerDistance with this estimate would have no bearing on the solution because all you do is inflate the travel costs by a fixed factor.
If your issue is that JSprit is throwing errors because both a distance and time matrix are required for a custom matrix (I don't remember), just make fake distances and don't set a cost parameter per distance (or 0 cost).
So, your options are to stick to Mapbox Distance API and not consider cost per distance, or switch API to one that gives you both distance and time. One option would be hosting your own Graphhopper server, and there are simple quick-start guides available to do this. Jsprit and Graphhopper have teamed up, and it is also bundled into ODL Studio.
I am developing a web page where users can create activities and others find them via a search function. When you create an activity you must specify the exact location where it will take place, assisted by google maps I retrieve the latitude and longitude. Now, when doing a search I want to have the functionality to find all activities close to a specified location(also assisted by google maps).
So I have a set of activities with coordinates, the coordinates of a point I want to find activities nearby, and I want to return activities that are no more than, lets say, 5 km(or miles or whatever you prefer) away from this point.
I am having this idea in my head that this can be solved by calculating max/min latitude and longitude, and use these as parameters in an sql-query where I use a where clause for filtering...The problem I'm facing here is firstly calculating these max/min values, secondly in an circular area(with radius 5km), and not a rectangular
Would appreciate any input here!
Thanks!:)
Coordinates you get are probably not x and y but latitude and longitude; you will need spherical distance unless all your points are within rather small radius, e.g. few hundred miles.
If you have many points, direct exhaustive search becomes too slow, spherical or not. Fortunately, GIS extensions available both for MySQL and for Postgres. Commercial DBs also have spatial extensions. These make searches for nearby objects efficient.
Calculate the boundary latitudes and longitudes.
Use the inverse http://en.wikipedia.org/wiki/Haversine_formula
Select everything where the latitude is between your two values for that, and similarly for longitude. If you're not using a spatial index, beware of edge cases on your sphere (a most excellent pun!): crossing 0, 90, or 180 degrees may result in impossible criteria.
Either in your SQL server or your app, execute the Haversine formula against your results. You must have the rectangular bounding values to prevent a table scan, but results in the rectangle will include results outside of your circle.
If you actually stop to think about it, your rectangle and your circle are both misshapen... but that's not really relevant anyway.
Also, check out this, which will expand on distance measuring and mention some other ideas: http://www.movable-type.co.uk/scripts/gis-faq-5.1.html
Hope this can help you.
Get nearest places on Google Maps, using MySQL spatial data
However this is MySQl query. You can convert it as your requirement.
I am developing a desktop application and I have two point (latitude, longitude). How can I get the distance between these two points? I have looked at the API and most of them are javascript or web based. I am not developing a web page. How can I do this in java?
I want a road distance, not a straight distance
If you've got the latitude and longitude, you can use the Haversine formula to calculate the distance between them - assuming you want "straight line" distance.
EDIT: Okay, now you've actually told us what you want, I suspect you need to use the Directions API. You'll need to make a web request to the appropriate URL with your parameters, specifying either XML or JSON output - which you'll then need to parse.
Note that "JSON" != "Javascript-based". Think of JSON as a data serialization format which just happens to be executable Javascript.
A quick Google gave me this: http://www.postalcodeworld.com/samples/distance.java.html Looks like this is a pretty good implementation of what you need using the Haversine Formula I think.
This Great Circle Distance code above is probaby OK for most apps. If you need great deal of precision, though, be aware that it may fail in some edge cases due to the earth not being a perfect sphere. In that case you're talking about more complicated algorithms.
I need to obtain the velocity of an android device, based on the accelerometer values. I made a code that allows me to get the accelerometer values, and then I calculate the velocity, using the formula:
v = v0 + at. (vector calculation)
My problem is that my velocity only increases and never decreases. I think the problem is that the device never gets an negative acceleration.
Can you help me with this?
Obtaining velocity from the accelerometers might not be possible (forget reliable) because at constant speed there will be no acceleration (other than gravity). You might be better off obtaining GPS location data and their associated time samples and computing velocity by distance over time.
Are you subtracting out the force of gravity? The device is always accelerating -- even if it is just sitting on your desk, it is accelerating at 9.8 m/s^2 away from the center of the Earth.
You can use a combination of the accelerometer and the digital compass, in phones that have them, to determine a speed and direction as mentioned in this post.
If all you need to do is determine if the person is walking, all you need is the accelerometer. Just process its output for foot steps.
There are plenty of tutorials on the web for detecting foot steps with an accelerometer.
There an app note here: http://www.analog.com/library/analogDialogue/archives/41-03/pedometer.html that gives a decent mathematical background and an example algorithm. Its of course up to you to extract the math and rewrite it for Android (the example code is written in C). I don't currently know of an open source android library with a footstep detection algorithm.
If you implement something, I would like to get the code, don't forget to post back the results.