geo

HAVERSINE distance in BigQuery?

喜夏-厌秋 提交于 2019-11-26 23:22:31
问题 I'm looking for a way to get HAVERSINE() in BigQuery. For example, how to get the closest weather stations to an arbitrary point? 回答1: 2019 update: BigQuery now has a native ST_DISTANCE() function, which is more accurate than Haversine. For example: #standardSQL CREATE TEMP FUNCTION RADIANS(x FLOAT64) AS ( ACOS(-1) * x / 180 ); CREATE TEMP FUNCTION RADIANS_TO_KM(x FLOAT64) AS ( 111.045 * 180 * x / ACOS(-1) ); CREATE TEMP FUNCTION HAVERSINE(lat1 FLOAT64, long1 FLOAT64, lat2 FLOAT64, long2

Pre-projected geometry v getting the browser to do it (aka efficiency v flexibility)

狂风中的少年 提交于 2019-11-26 22:08:31
问题 To improve the performance of my online maps, especially on smartphones, I'm following Mike Bostock's advice to prepare the geodata as much as possible before uploading it to the server (as per his command-line cartography). For example, I'm projecting the TopoJSON data, usually via d3.geoConicEqualArea() , at the command line rather than making the viewer's browser do this grunt work when loading the map. However, I also want to use methods like .scale , .fitSize , .fitExtent and .translate

Get nearest places on Google Maps, using MySQL spatial data

五迷三道 提交于 2019-11-26 21:47:39
I have a database with a list of stores with latitudes and longitudes of each. So based on the current (lat, lng) location that I input, I would like to get a list of items from those within some radius like 1 km, 5km etc? What should be the algorithm? I need the PHP code for algorithm itself. Gaurav You just need use following query. For example, you have input latitude and longitude 37 and -122 in degrees. And you want to search for users within 25 miles from current given latitude and longitude. SELECT item1, item2, ( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) ) * cos( radians(

Geo redis实现附近的车辆/人

柔情痞子 提交于 2019-11-26 21:13:11
前段时间业务需要实现一个用户查看附近车辆的服务:用户根据自己的定位坐标(经度、纬度)来快速搜索到附近的车辆,可以根据半径进行搜索。 根据需求也制定了几个技术方案,思路是这样的:将用户的坐标跟数据库中各个车辆的最新坐标进行距离计算,找到指定距离内的车辆并按照距离从小到大排序返回给业务。这种方法需要找到每辆车的最新定位,数据库中车辆定位数庞大,查询时数据库压力较大,并且每辆车需要计算一次距离,整个流程的耗时耗费数据库资源可想而知。考虑第二种方案,因为现在业务所有车辆的最新定位都保存在缓存中(memcached),可以采用把所有车辆的定位先从缓存中拿出来,然后进行距离计算,这种方法同样存在问题,就是操作缓存过于频繁。 以上两种方案,都是通过计算距离来判断的,后来发现geohash算法在这方面很高效(geohash原理参加 http://blog.jobbole.com/80633/ )。于是将该思路应用到以上两个方案中,无非是多保存一份每个定位点的geohash值,然后根据该hash值来进行排序找到附近的车(当然该hash值在数据库中做索引)。沿着这个思路的技术实现也考虑了一些,等技术实现(具体实现思路就不啰嗦了)基本考虑好的时候,突然发现redis 自带的geo api能够完美地解决该问题。于是,啥也别说,直接使用现成的就好啦。 闲聊结束,直接操作,按照步骤来就能轻松搞定: 一

How to perform bilinear interpolation in Python

人走茶凉 提交于 2019-11-26 19:52:07
问题 I would like to perform blinear interpolation using python. Example gps point for which I want to interpolate height is: B = 54.4786674627 L = 17.0470721369 using four adjacent points with known coordinates and height values: n = [(54.5, 17.041667, 31.993), (54.5, 17.083333, 31.911), (54.458333, 17.041667, 31.945), (54.458333, 17.083333, 31.866)] z01 z11 z z00 z10 and here's my primitive attempt: import math z00 = n[0][2] z01 = n[1][2] z10 = n[2][2] z11 = n[3][2] c = 0.016667 #grid spacing x0

Calculate the center point of multiple latitude/longitude coordinate pairs

泪湿孤枕 提交于 2019-11-26 19:17:53
Given a set of latitude and longitude points, how can I calculate the latitude and longitude of the center point of that set (aka a point that would center a view on all points)? EDIT: Python solution I've used: Convert lat/lon (must be in radians) to Cartesian coordinates for each location. X = cos(lat) * cos(lon) Y = cos(lat) * sin(lon) Z = sin(lat) Compute average x, y and z coordinates. x = (x1 + x2 + ... + xn) / n y = (y1 + y2 + ... + yn) / n z = (z1 + z2 + ... + zn) / n Convert average x, y, z coordinate to latitude and longitude. Lon = atan2(y, x) Hyp = sqrt(x * x + y * y) Lat = atan2(z

Querying within longitude and latitude in MySQL

大兔子大兔子 提交于 2019-11-26 18:49:44
问题 Before asking for specific code examples, I just wanted to ask whether it is possible to make a query something like this pseudo code: select items from table where lat/lon = -within x miles of a certain lat/lon point- Is that doable? Or do I have to jump through some hoops? Any good approaches that could be recommended would be great! 回答1: You should search for the Haversine formula, but a good start could be: Creating a Store Locator with PHP, MySQL & Google Maps - See Section 'Finding

Formulas to Calculate Geo Proximity

馋奶兔 提交于 2019-11-26 18:10:52
I need to implement a Geo proximity search in my application but I'm very confused regarding the correct formula to use. After some searches in the Web and in StackOverflow I found that the solutions are: Use the Haversine Formula Use the Great-Circle Distance Formula Use a Spatial Search Engine in the Database Option #3 is really not an option for me ATM. Now I'm a little confused since I always though that the Great-Circle Distance Formula and Haversine Formula were synonymous but apparently I was wrong? The above screen shot was taken from the awesome Geo (proximity) Search with MySQL paper

Google Maps API 3 fitBounds padding - ensure markers are not obscured by overlaid controls

↘锁芯ラ 提交于 2019-11-26 18:10:50
问题 I'd like to be able add padding to a map view after calling a map.fitBounds(), so all markers can be visible regardless of map controls or things like sliding panels that would cover markers when opened. Leaftlet has an option to add padding to fitBounds, but Google Maps does not. Sometimes the northmost markers partially hide above the viewport. The westmost markers also often lay under the zoom slider. With API 2 it was possible to form a virtual viewport by reducing given paddings from the

Getting distance between two points based on latitude/longitude

别来无恙 提交于 2019-11-26 14:58:22
I tried implementing this formula: http://andrew.hedges.name/experiments/haversine/ The aplet does good for the two points I am testing: Yet my code is not working. from math import sin, cos, sqrt, atan2 R = 6373.0 lat1 = 52.2296756 lon1 = 21.0122287 lat2 = 52.406374 lon2 = 16.9251681 dlon = lon2 - lon1 dlat = lat2 - lat1 a = (sin(dlat/2))**2 + cos(lat1) * cos(lat2) * (sin(dlon/2))**2 c = 2 * atan2(sqrt(a), sqrt(1-a)) distance = R * c print "Result", distance print "Should be", 278.546 The distance it returns is 5447.05546147 . Why? Edit: Just as a note, if you just need a quick and easy way