Location Count issue in Java program - java

I a working on GPS location where i need to convert latitude and longitude in corresponding address. I have a database of all latitude and longitude(more than 1,50,000 data) with its actual landmark i.e. address in one master table.
We have installed GPS device on many vehicles which is moving across all geographic location. Every 2 minute this device sends the actual position in term of latitude and longitude, i get this latitude and longitude and maps to our Master table and check near by which landmark from our master table. For doing this calculation i do some mathematical operation to add some delta value to latitude and longitude get from vehicle and then find the nearest search from my master table, once we find we show vehicle is 5 KM from XYZ location, we get XYZ location from master table which is nearest point.
This program basically takes lot of time to calculate the location, since we have 10,000 GPS devices installed on Vehicle and every device send GPS data in 2 minute, so you may imagine how much data we do get.
Could you please help me to fix this issue and make it very scalable and fast.
Thanks in advance.

How about using a GIS layer on your db? Something like PostGIS adds a new layer to sql with just that kind of functinality. From an FAQ:
3.7. What is the best way to find all objects within a radius of another object?
To use the database most efficiently, it is best to do radius queries
which combine the radius test with a bounding box test: the bounding
box test uses the spatial index, giving fast access to a subset of
data which the radius test is then applied to.
The ST_DWithin(geometry, geometry, distance) function is a handy way
of performing an indexed distance search. It works by creating a
search rectangle large enough to enclose the distance radius, then
performing an exact distance search on the indexed subset of results.
For example, to find all objects with 100 meters of POINT(1000 1000)
the following query would work well:
SELECT * FROM geotable WHERE ST_DWithin(geocolumn, 'POINT(1000
1000)', 100.0);

Related

Find distance using gps coordinate to next vertex

I am creating a Bus arrival prediction system using Java and Postgres.There is fixed route for each bus, so we are storing whole driving route as LineString in postgres.
There are 3 bus stoppage, and each bus stop lat lon is also stored as LineString in routes table.
There is one more table which have stoppage name and lat lon details.
stoppage_details Table
Stoppage 1 - lat1,lon1
Stoppage 2 - lat2,lon2
Stoppage 3 - lat3,lon3
I am looking Postgres function to solve below problem.
How can I get total distance(660m) of route using LineString(Start
point lat lon and End point lat lon).
There is GPS System installed in each bus which send data at every
30 sec.I am using ST_ClosestPoint function to find nearest vertex
from LineString. How can I find the distance between vertex and next
and previous stoppage using LineString.
Or Can someone suggest any other approach to solve above problem.
if p1 through p8 are a linestring geometry in srid:4326 (long/lat) then you can get it length with st_length(line::geography) in meters.
is a little more complicated but there are various approaches to it. For example you can use the linear referencing function to project your GPS point onto the line string and get the percentage along that where 0 is the start and 1.0 is the end. If you take each stoppage point and get its percentage the same way (maybe store it in your table also) then find the stoppage point less than the GPS percentage and greater than the GPS percentage will give you the adjacent stoppage points. Linear referencing function give you the ability to extract a substring based on a start and stop percentage of you linestring and you can get the length of each of them for your distances before and after the GPS point.

How to get speed and acceleration from trajectory data?

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.

longitude and latitude points change for the same place

I am Android developer.
I am getting the longitude and latitude point of a place but for the same place these values changes and the third decimal varies.
My main purpose is to detect a place so it works only
when all these values of longitude and latitude matches so they must
be constant.
My questions are:
What is the reason for this variation?
Is there any method by which ti make these values remain constant for a specific place?
The phone's GPS isn't very accurate. That is, it is very accurate for navigate in your car, but missing by 20 meters is not unheard of.
To figure out if you're in the same place, you should calculate the distance between your current location and the place's coordinates. If it's lower than a threshold (try to find one that makes sense) - you're there.
Try using the GPS for more accurate data, but know that they will not be the same values everytime, but not very different either
You can look at the accuracy as well. The Location class has a getAccuracy() method -- if your accuracy decreased from the last method, it may be that the person went inside and lost line-of-sight to the sky.
As I have said before in other posts, I recommend using Google's Play Location service rather than the pure GPS. You can also use an isBetterLocation method as documented here.
As stated above, the GPS inherent accuracy isn't the best. For an idea of how the decimal places show accuracy levels, see the Wikipedia page
In short, the third decimal place results in an accuracy differential of 43-111 meters, depending on your position on the globe. So I would either look at some other method of refining the data, or implementing some sort of threshold processing.

How to get nearest places (that are user entered) based on current location?

I am building an Android application where users can find nearest places according to their current location and also, be able to add places into the database. I understand that I will have to use long and lat in my database but I really don't know how to compare the current location against the places in the database. How would I even search it because I would potentially have to go through the entire database systematically pulling out each geo point and then comparing it against the user location?
Example:
Say users have entered 10 places in London and 1000 other places all around the world and a person in London is using the application and wants to find places that are nearest to them based on their current location. How would I search for these 10 places among 1000s of other places in the database? Performing distanceTo() a 1000 times is unnecessary.
Any advice, guides, tutorials, references would be great.
Thanks in advance.
EDIT:
This is my idea so far.
Get the longitude and latitude of the location, which could either have been searched, the current location or the location that the user has tapped on the screen.
With Long/Lat of said location - get the place description of the place from reverse geocoding with the getFromLocation method.
With place description, search database based on address string.
This is what I have right now but again this doesn't seem to be reliable. There must be a simpler way to query the database given the long/lat of a location and return back a complete list of the nearest spots.
If you are using latitude and longitude, this should be pretty simple. Let's say the coordinates of the individual are roughly: 49°N, 2°E.
To find all locations with 1 square degree of lat/long, you would just select all locations that satisfied the following criteria:
Latitude >= 48°N and <= 50°N
.. and ..
Longitude >= 1°E and <= 3°E
It's pretty simple.
There's a table on Wikipedia that explains how much decimal degrees are 1 kilometer etc. And the coordinates that you receive from Google are in decimal degrees.
https://en.wikipedia.org/wiki/Decimal_degrees
If you have any more questions on how to calculate etc, just ask :)
Basically you just need to check if the places latitude is higher than
currentLocationLatitude - rangeInDecimalDegrees
and smaller than
currentLocationLatitude + rangeInDecimalDegrees

coordinates based search

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.

Categories