Can dimensions be skipped in queries against R/R*/X-Trees? - geospatial

Let's say we have a 4 dimensional tree with dimensions longitude, latitude, altitude and for illustration purposes, price.
Can we query against longitude and latitude and optionally against either altitude and/or price?

Yes, obviously you can do that. For window queries, just ignore the dimensions or query with an infinite rectangle in that dimension. For range or knn, use a distance function that skips these dimensions.
However, for range/kNN queries, a distance function using both latitude/longitude and e.g. price is nontirival to define. Euclidean distance obviously is not very sensible, as $1 is not the same "distance" as 1 degree in latitude.
The R*-Trees in ELKI should support this out of the box AFAICT. If you query the tree with a projected distance, it will use only these attributes.

Related

Accurate direct distance between two points (latitude, longitude, and altitude)

First of all, thanks for reading. I have Vincenty working in Excel(VBA) already, and want to do this in Excel, but this is a math question, not a coding question. By the way, I'll readily cop up front to the fact that ellipsoids are way over my head.
I'm looking to calculate accurate direct distance between two objects, given their latitude, longitude and altitude. Vincenty was an interesting start, but two issues:
(a) Vincenty is the distance along the ellipsoid, and I would need the chord length.
(b) Vincenty doesn't account for elevation, and the distance between points increases as elevation increases.
It would be easy to take Vincenty as my horizontal distance, and use the elevation difference to solve for the slope, but that doesn't seem accurate.
Maybe this should just be solving for the line between points on concentric circles (i.e. the lower elevation versus the higher elevation) except what Earth radius to use? I mean, it's an ellipsoid, so...?
My distances will typically be 10 - 40 miles, but millimeter precision is required.
Point me in the right direction? Thanks! ~Mike

Cartesian to Latitude/Longitude

I have a 3D model of a 10km x 10km topographic map which I've imported from sketch-up , the model is just a bunch of X,Y,Z points (where X+ is the north and Z+ is straight up, perpendicular to the ground)
I know the Latitude Longitude values of the (0,0,0) point. So given a X,Y,Z point how do I get its Latitude Longitude values?
I need to be pretty accurate so you can't assume the earth is a perfect sphere (you can however assume it's an ellipsoid)
For best accuracy you need to know what map projection the map was drawn in. You should be able to find that out from the map. For example in the UK the Ordnance Survey maps use the OSGB36 datum, and the projection is Transverse mercator. The projection tells you how to convert geographic (lat,long for the datum ellipsoid) coordinates to map coordinates (easting and northing) and how to do the reverse calculation, which is pretty much what you want.
If you don't know the projection, the next best thing would be if you could find out -- again from the map, they are often written on it -- the scale-factor and convergence of the projection at some points on the map. The point is that there is usually a slowly spatially varying difference between map north (the direction the north axis points in) and true north (the direction of the north pole from a point, the direction of the latitude axis) and there is always a slowly spatiallty varying scale factor, the ratio of a distance in map coordinates and the true distance. Note that this not the same thing as the scale of the printed map (an inch to a mile or whatever), it is a property of the projection.
Over a 10km square, it would be reasonably accurate to treat both the scale and convergence as constants. Then given an x,y point you compute the map bearing from 0,0 using
b = atan2(x,y)
and convert this to a true bearing by subtracting the convergence.
You also compute the map distance by
r = hypot(x,y)*S
where S is the scale of the map, e.g. if your a change of 1 in x coordinates represents a distance of 100m, S is 100
and convert r to a true distance by dividing by the scale-factor.
Finally you want to compute the lat,long a given distance and bearing from a given point (the lat,long of 0,0). An accurate way to do this is to use Vincenty's formulae.
One thing to note here is that the scale and convergence, if quoted on the map will be relative to the ellipoid used in construction of the map, so you will be computing lat,long coordinates for that ellipsoid.

excel matching lat and long points

I want to extract a distance value for a number of points from a table of values that have a latitude, longitude and distance point. I have a table that follows a train line along a path and has points every ~20 metres with the kilometre points associated from which i want to extract the distance value.
Lookup Table
I have another table, Reference table, that is positional data of a train every 3-5 minutes along the same path as the lookup table, so the lat and long points wont be the same. I need to search through the lookup table to find the closest lat and long point on the path and extract the associated distance. I am able to find the closest point for the latitude and longitude individually, but because the path is windy, the expected values do not match. I have gone through some of the points that are different to what is expected and in some cases, the distance associated with the latitude is correct, but in others, the distance associated with the longitude is correct.
Reference table
The highlighted values in the reference table are values that did not agree to what they should be, as shown in the lookup table (the same colour refers to the value found in the lookup table). The bold values are points that agreed, which is what i am hoping to achieve for all points. The kilometer points in the Reference table are correct, but i had to manually adjust the equations to use the correct value.
This is the equation that i use to extract the distance. (column J)
=IF(MATCH(MIN(ABS(LookupTable-ReferenceLatitude)),ABS(LookupTable-ReferenceLatitude),0)=MATCH(MIN(ABS(LookupTable-ReferenceLongitude)),ABS(LookupTable-ReferenceLongitude),0), TRUE:extract Distance, FALSE: ??? [both points should agree] )
currently i manually adjust the FALSE condition to extract the distance from the lat or long value as required.
My question is, is there a way to ensure both the latitude and longitude are matched to get the correct distance? and what should be used in the FALSE case for the calculation?
I fave found a solution, quite a complicated one really. First the reasoning, the correct points can be found by finding the minimum distance between your reference points and the lookup points. The minimum distance between the two points will then give you the desired lat, log and associated distance.
I found the spherical law of cosines equation (the least complex one) that allows you to calculate the distance between two points. You can then use MATCH() to find the row of your point and then INDEX() to extract the distance value.
Here is the MATCH() equation
=MATCH(MIN(ABS(2*ATAN2(SQRT(1-(SIN(RADIANS((refLat-lookupLatArray)/2))*SIN(RADIANS((refLat-lookupLatArray)/2))+COS(RADIANS(refLat))*COS(RADIANS(lookupLatArray))*SIN(RADIANS((refLong-lookupLonArray)/2))*SIN(RADIANS((refLong-lookupLonArray)/2)))),SQRT(SIN(RADIANS((refLat-lookupLatArray)/2))*SIN(RADIANS((refLat-lookupLatArray)/2))+COS(RADIANS(refLat))*COS(RADIANS(lookupLatArray))*SIN(RADIANS((refLong-lookupLonArray)/2))*SIN(RADIANS((refLong-lookupLonArray)/2))))*6371)),ABS(2*ATAN2(SQRT(1-(SIN(RADIANS((refLat2-lookupLatArray)/2))*SIN(RADIANS((refLat-lookupLatArray)/2))+COS(RADIANS(refLat))*COS(RADIANS(lookupLatArray))*SIN(RADIANS((refLong2-lookupLonArray)/2))*SIN(RADIANS((refLong-lookupLonArray)/2)))),SQRT(SIN(RADIANS((refLat-lookupLatArray/2))*SIN(RADIANS((refLat-lookupLatArray)/2))+COS(RADIANS(refLat))*COS(RADIANS(lookupLatArray))*SIN(RADIANS((refLong-lookupLonArray/2))*SIN(RADIANS((refLong-lookupLonArray)/2))))*6371),0)

Excel formula to calculate the distance between multiple points using lat/lon coordinates

I'm currently drawing up a mock database schema with two tables: Booking and Waypoint.
Booking stores the taxi booking information.
Waypoint stores the pickup and drop off points during the journey, along with the lat lon position. Each sequence is a stop in the journey.
How would I calculate the distance between the different stops in each journey (using the lat/lon data) in Excel?
Is there a way to programmatically define this in Excel, i.e. so that a formula can be placed into the mileage column (Booking table), lookup the matching sequence (via bookingId) for that journey in the Waypoint table and return a result?
Example 1:
A journey with 2 stops:
1 1 1 MK4 4FL, 2, Levens Hall Drive, Westcroft, Milton Keynes 52.002529 -0.797623
2 1 2 MK2 2RD, 55, Westfield Road, Bletchley, Milton Keynes 51.992571 -0.72753
4.1 miles according to Google, entry made in mileage column in Booking table where id = 1
Example 2:
A journey with 3 stops:
6 3 1 MK7 7DT, 2, Spearmint Close, Walnut Tree, Milton Keynes 52.017486 -0.690113
7 3 2 MK18 1JL, H S B C, Market Hill, Buckingham 52.000674 -0.987062
8 3 1 MK17 0FE, 1, Maids Close, Mursley, Milton Keynes 52.040622 -0.759417
27.7 miles according to Google, entry made in mileage column in Booking table where id = 3
If you want to find the distance between two points just use this formula and you will get the result in Km, just convert to miles if needed.
Point A: LAT1, LONG1
Point B: LAT2, LONG2
ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-lat2)) *COS(RADIANS(long1-long2)))*6371
Regards
Until quite recently, accurate maps were constructed by triangulation, which in essence is the application of Pythagoras’s Theorem. For the distance between any pair of co-ordinates take the square root of the sum of the square of the difference in x co-ordinates and the square of the difference in y co-ordinates. The x and y co-ordinates must however be in the same units (eg miles) which involves factoring the latitude and longitude values. This can be complicated because the factor for longitude depends upon latitude (walking all round the North Pole is less far than walking around the Equator) but in your case a factor for 52o North should serve. From this the results (which might be checked here) are around 20% different from the examples you give (in the second case, with pairing IDs 6 and 7 and adding that result to the result from pairing IDs 7 and 8).
Since you say accuracy is not important, and assuming distances are small (say less than 1000 miles) you can use the loxodromic distance.
For this, compute the difference of latitutes (dlat) and difference of longitudes (dlon). If there were any chance (unlikely) that you're crossing meridian 180º, take modulo 360º to ensure the difference of longitudes is between -180º and 180º. Also compute average latitude (alat).
Then compute:
distance= 60*sqrt(dlat^2 + (dlon*cos(alat))^2)
This distance is in nautical miles. Apply conversions as needed.
EXPLANATION: This takes advantage of the fact that one nautical mile is, by definition, always equal to one minute-arc of latitude. The cosine corresponds to the fact that meridians get closer to each other as they approach the poles. The rest is just application of Pythagoras theorem -- which requires that the relevant portion of the globe be flat, which is of course only a good approximation for small distances.
It all depends on what the distance is and what accuracy you require. Calculations based on "Earth locally flat" model will not provide great results for long distances but for short distance they may be ok. Models assuming Earth is a perfect sphere (e.g. Haversine formula) give better accuracy but they still do not produce geodesic grade results.
See Geodesics on an ellipsoid for more details.
One of the high accuracy (fraction of a mm) solutions is known as Vincenty's formulae. For my Excel VBA implementation look here https://github.com/tdjastrzebski/Vincenty-Excel

Given a latitude / longitude to a certain number of decimal places, how to tell the area covered (in metres)?

If i have a position specified in latitude and longitude, then it can cover a box, depending on how many digits of accuracy are in the position.
For example, given a position of 55.0° N, 3.0° W (i.e. to 1 decimal place), and assuming a truncation (as opposed to rounding), this could cover anything that's 55.01° to 55.09°. This would cover the area in this box: http://www.openstreetmap.org/?minlat=55.0&maxlat=55.1&maxlon=-3.0&minlon=-3.1&box=yes
Is there anyway to calculate the area of that box? I only want to do this once, so a simple website that provides this calculation would suffice.
The main reason I want to do this is because I have a position to a very high number of decimal places, and I want to see how precise it is.
While the Earth isn't exactly spherical you can treat it as such for these calculations.
The North/South calculation is relatively simple as there are 180° from pole to pole and the distance is 20,014 km (Source) so one degree == 20014/180 = 111.19 km.
The East/West calculation is more difficult as it depends on the latitude. The Equatorial distance is 40,076 km (Source) so one degree = 40076/360 = 111.32 km. The circumference at the poles is (by definition) 0 km. So you can calculate the circumference at any latitude by trigonometry (circumference * sin(latitude)).
I have written an online geodesic area calculator which is available at
http://geographiclib.sf.net/cgi-bin/Planimeter. Enter in the four
corners of your box (counter clockwise) and it will give its area.

Resources