How to calculate the neighbouring grids on geohash. Algorithms required - node.js

Hi I am working with a database with an implementation of geohash
So as shown above, as the zoom level goes down (6 zoom levels), more of abcd gets inserted into each grid. I have represented them as a rigid grid; however, the central point is different for all the grids. So for example, distance from a to b will not be the same as distance from a to c.
If it was a rigid grid, I can just get the closest four neighbouring grids; however, I cannot do that as the distances vary and the closest neighbours are not necessarily orthogonal. Only information that I have from the database is the centra point of each grid and the geohash key e.g. aa, ab, etc..
How will I find girds that are just north, west, east and south of each grid for every zoom level? (have 6 zoom levels)

As you can see a cell that ends in, for example, d, has a cell with the same prefix but ending in b north of it. This allows you to set up a mapping table.
In the cases where, like cb going north, you end up at ad, the trick is to recognize that going north from *b you need to look at the previous character (in this case, the c), go north from that character (a) and add the south-most edge of that column (d).
In short, it's a matter of implementing some mapping tables and some logic to deal with the edges.

Related

Soccer positions (i.e. Defender, Midfielder, Forward) is there any order

I am unable to understand if is there any order in soccer position or is just random because I have to answer whether it is ordinal data or not
Firstly the variable involved here is categorical and in the rules of football there is no certain order that is associated with the given positions.
Like ->
Defender, Mid-Fielder and Forward
Forward, Mid - Fielder and Defender
Hence, Soccer positions is a nominal scale of measurement.

Distance between straight lines

I work in the oil & gas industry and I'm seeking advice about how to calculate the minimum distance between a set of wells (the wells are drawn as straight lines on a map). My goal is for each individual well to have a unique "spacing" value (measured in feet) which is basically the straight-line horizontal distance to the closest wellbore on a map. Below is a simple example of what I'm trying to accomplish (assume the pipe | symbol is a wellbore and the dashes are the distance between the wells)
|--|---|-|
In the drawing above we have 4 wells. The 1st well (starting from the far left) would have a spacing value of 2 (since there are 2 dashes to the closest well), the 2nd well would also have a value of 2 (since the closest well is the one to the far left which is two spaces away), the 3rd well would have a value of 1, and the 4th well would have a value of 1.
Now imagine that I have hundreds of these wells (each with latitude/longitude points that describe the start & end points of each well) and I have them all mapped in TIBCO Spotfire (scattered across Texas). Do you guys know if it would even be possible to automate a calculation like the above? I would also like to build in a rule that says the max distance between wells is 2640 ft (half of a mile).
Any ideas are appreciated!
I think you should be able to do this without any R or iron python.
Within Spotfire, you can calculate the distance in miles between 2 points using the formula below (substitute 6371 for 3958.756 to get the answer in kilometres).
GreatCircleDistance([Lat 1],[Lon 1],[Lat 2],[Lon 2]) * 3958.756
For your use case, you could cross join your table of locations, so that you have a row for every possible location combination, then calculate the distance between them using the formula above. After that, it should be pretty straight forward to find each wells closest pair.

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

Find angles of polygon using only known distances

I've got a mesh of points, but simplified I've got 5 points with 2 being primary points.
All distances from A and B to any other points are known ( C, D, E ), but the distance from A and B is not known. Neither are the location of these points, only the distances. Although A can be considered the origin (0,0).
Is it possible to find the internal angles and then consequently the distance between point A and B.
Otherwise how would this scenario need to be modified in order to find this distance.
Or is there simply just not enough information known?
The actual scenario can have more points with distances from points A and B known, but I've just tried to simplify here.
No. Lets fix A at (0,0) and B along the horizontal axis. Each two leg pair ACB, AEB and ADB can flex its elbow joint to allow for any position of B along the horizontal axis.
Given an AB distance then all the angles and points are uniquely defined. But if AB is unknown then the shape can fold on itself.

Line Segments from a point

I have a point p, and 2 line segments in a 2D plane. Point p is a location of view from where camera is looking towards the line segments. I want to check if line segment 1 is partially or fully hidden behind the line 2, when looking from the point P.
I think the question is whether the second line is "masked" by the first line.
Let say you camera point is C, and your segments are A1,A2 and B1,B2.
I would compute the cross products CA1xCB1 and CA2xCB2. The sign gives you if the point if the B1 point is on the left or the right of the CA1 line. It depends on how your triangles CA1A2 and CB1B2 are oriented (they must be oriented the same, they are many ways to do that).
You can then use the sign to know if you are in the following cases:
CA1xCB1 is negative or CA2xCB2 is positive, then partially visible
the opposite, then hidden.
You can also compute CA1xCB2 and CA2xCB1 to have fined grained cases.
slurdge's answer is a good start, but it's a bit more complicated than that.
If line segment 2 is closer to C than line segment 1, it could still be visible, e.g.
A1-------A2
B1-B2
C
Here B1 and B2 are "within" the A1A2 sector, but are not hidden.
The hardest one to work out is if B1 is 'between' A1 and A2, but closer to the camera, while B2 is 'not between' A1 and A2, but further from the camera:
B2
A1-----A2
B1
C
B1B2 could clip the edge of the line segment, thus rendering a small portion of B1B2 hidden (or maybe not!). I think you would have to find the intersection of A1A2 and B1B2 to check whether this actually happens.

Resources