I have a Database with GeoCoordinates of every Zipcode in a Decimal form (e.g. 5099755, 928690)
I want to do an area search based on these values, but in the formula that I'v found, I should pass the Lat and Lon values as Double.
How can I convert these "decimal" values to "double" values?
If GeoPoints is the GeoCoordinates variable
double lat = GeoPoints.getLattitude(); or double lat = GeoPoints.getLattitudeE6;
double lon = GeoPoints.getLongitude(); or double lat = GeoPoints.getLongitudeE6;
I think we need to know what sort of coordinate system your numbers are in - they look like they might be UTM (universal transverse mercator), but if so, there should also be a 'Zone' parameter (e.g. 55H). This document describes how to convert from UTM to DMS (and provides parameters for the various geographic datums) and also provides Javascript which you should be able to convert into Java pretty easily.
Also, have a look at this stackoverflow post, which talks about java packages which can do coordinate system conversion.
Then again, maybe your code wants data in exactly the format they're already in, in which case all you need to do is cast your decimals to doubles.
Related
We have the following method declaration in our api:
Call<WeatherResult> getWeatherPredictions(#Query("lat") double latitude, #Query("lon") double longitude);
Now the API that we consume is rather "simple" as it just sends back 400s when its not happy with the given latitude or longitude. They could easily "patch" the values on their end but they won't.
My question now is, does anybody know how doubles are converted by retrofit2? I quickly looked at the source code but kind not find anything there.
My question now is, does anybody know how doubles are converted by
retrofit2?
They are using String#valueOf(Object). Query is an interface. You can find it here. The documentation states:
Values are converted to strings using {#link String#valueOf(Object)}
and then URL encoded.
I have a string representation of a point in a given CRS (namely, EPSG:3035), such as "N10160E21266". I'd like to parse it using GeoTools to create a DirectPosition, or any another X/Y representation (in order to transform it from a CRS to another CRS; I have a MathTransform at hand).
Is there a parse method already implemented somewhere in GeoTools?
It's probably not difficult to create a custom one, but this may be error-prone and I'm not a GIS specialist (how to properly handle north/easting etc).
That is not a well known representation so there will be no standard parser. It shouldn't be too hard to write one that returns a DirectPosition or a JTS.Point.
The only geographic issue that you need to bear in mind is that epsg:3035 stores east as X and north as Y (which in this case is what you'd expect). You'll need to check the axis order of your target projection.
I am working on an Android app that uses the GPS. I would like to know if there is a way I can throw out GPS Location data if the "new location" (point C) is too far away from line segment AB. I am using the Point to Line Segment formula found on Wikipedia.
So far, the code I have is returning NaN when I try to use Latitude and Longitude coordinates.
private void verifyGPSLocation(Location start, Location end, Location current){
final double errorValue = 0.0000216;
double normalLength = Math.hypot(end.getLatitude() - start.getLatitude(), end.getLongitude() - start.getLongitude());
double ret = Math.abs(((current.getLatitude() - start.getLatitude()) * (end.getLongitude() - start.getLongitude()) - (end.getLatitude() - start.getLatitude()))/normalLength );
Log.e("Coooooord", normalLength+"--"+ret);
}
This is my first post so please let me know if I have not done this correctly or with enough information. Thanks for your help, I love this site!
I think the formula you are using to find the distance between 2 geographic points is too simplistic. Due to the curvature of the earth, the formula is a bit more complicated.
Have a look here, this provides a more accurate approximation.
There is a Javascript example too, so you can easily change it to Java with a few syntactical tweaks.
After clarification, you seem to be looking for the distance of a point to a path on the earth between two locations. Check out the cross-track distance variation in the link above.
Your distance algorithm is wrong. It doesn't account for the curvature of the Earth- lines of longitude are closer at higher latitudes, further at lower ones. Use the Location.distanceTo function.
I know there are web services out that have this information, however they can be limited to per day requests. I have about 114,000 records I need zip codes for. I have a data base full of zip codes with there lat and longs. However I am not sure how I can calculate the given lat and long against the zip code lat and long.
Basically I need to cross reference the given address lat and long against the supplied zip code lat and long. I can either use PHP, Java, or MySQL Procedure or just a calculation.
I can give you a stepping stone but thats about it, in this case.
$distance = 10;
$latitude = 37.295092;
$longitude = -121.896490;
$sql = "SELECT loc.*, (((acos(sin(($latitude*pi()/180)) * sin((`latitude`*pi()/180))+cos(($latitude*pi()/180)) * cos((`latitude`*pi()/180)) * cos((($longitude - `longitude`)*pi()/180))))*180/pi())*60*1.1515) AS `distance` FROM table_with_lonlat_ref loc HAVING distance < $distance"
if you create a query that does a JOIN between the 2 tables you have and reduce the distance to 1 or 2, you could in concept come up with just about all the lat/lon combinations you need. Or you could also find a DB that has all the US zipcodes, that also has lat/lon then query over one table to insert into another based on the matched zipcodes. I have such a zipcode DB somewhere.
also might I suggest http://www.maxmind.com/app/geolite its never complete less you wanna pay for it and it changes up every so often but. From this you can get almost nearly every combination of lat/lon possible to use as your reference point based on IP of a visitor (its off a little in some cases as the IP may steam from a hub a town or 2 away. But its better than nothing, gives you only limits your server can handle, and no worry about API restrictions outside of usage terms from maxmind.
Anyway all in all, Ive been using this combination for a while on a number of sites and have yet to come up with much problems to date. Well I know its not a direct answer to your question but I hope it leads you to a solution
Since you already have a database of lats and longs, I'm going to assume it describes a set of rectangular regions from (latA, lonA) to (latB, lonB), each with an associated zip code. I'll also assume (or recommend) that you've indexed those four fields.
Your query can fairly easily match whether a coordinate (coordA, coordB) fits within the two ranges describing that rectangle.
update coords set zip_code=(
select zip_code from zip_codes
where coords.coordA >= zip_codes.latA
and coords.coordA <= zip_codes.latB
and coords.coordB >= zip_codes.lonA
and coords.coordB <= zip_codes.lonB
limit 1
)
Caviat: You should verify whether latA < latB and lonA < lonB in your zip code database, and verify that you're using the same coordinate system in both tables. You may need to make adjustments, either through a conversion or by changing the operators appropriately.
I am looking for a way to calculate approximate distance between two UK postcodes (distance in the straight line is good enough) for analysing data. Preferably easily accessible from java, but C#, native C++ etc. are fine as well.
First, you need to translate the postcode into useful coordinates. For example, the Easting and Northing values from a Postcode lookup table, like the one from here: http://www.doogal.co.uk/UKPostcodes.php
These Easting and Northing are UK Ordnance Survey grid coordinates in metres from the OS map origin.
Convert them into Kilometres by dividing by 1000
Then use a simple Pythagoros triangle formula. Say the two points have Easting and Northing values (in kilometres) of E1, N1 and E2, N2
Distance between them in Kilometres = Square root of ( abs(E1-E2)^2 + abs(N1-M2)^2 )
The following question answers the exact same question only in PHP specifically:
Using PHP and google Maps Api to work out distance between 2 post codes (UK)
It leverages a web service API though, so you should be able to use any basic rest api to leverage it (I'm sure there are well documented options in Java, C# and C++).