def mr_cell_to_html(obsv, cells, out_fname): c_lat, c_lng = obsv[0][0], obsv[0][1] html = const_prefix % (c_lat, c_lng) html += ( "function addInfoW(marker, message){\n" "var infoW = new google.maps.InfoWindow({content:message});\n" "google.maps.event.addListener(marker, 'click', function () {infoW.open(map, marker);});\n" "}\n") for rid, point in enumerate(obsv): lat, lng = ets.wgs2gcj(point[0], point[1]) marker = '{lat:%s, lng:%s}' % (lat, lng) html += const_marker % (rid, marker) html += const_marker_info % (rid, '%d.0 %d.0' % (point[2], point[3])) for ids, info in cells.iteritems(): lat, lng = ets.wgs2gcj(info[1], info[2]) marker = '{lat:%s, lng:%s}' % (lat, lng) idx = int(info[0]) if idx == -1: continue html += const_circle % (idx, colors[idx % (len(colors))], colors[idx % (len(colors))], marker, 50) html += const_marker_title % (idx + rid, marker, 'Cell Tower (%s,%s)' % (ids[0], ids[1])) html += const_marker_info % (idx + rid, '[%d]' % idx) # html += 'marker_' + str(idx + rid) + '.click();\n\n' # print idx, '\t', ids html += const_suffix with open(out_fname, 'w') as o_file: o_file.write(html)
def wgs2gcj(inputfile, outputfile): data = read_geojson(inputfile) for feature in data['features']: if feature['geometry']['type'] == 'LineString': # 2D array #feature = data['features'][100] pts = feature['geometry']['coordinates'] for i in range(len(pts)): temp = eviltransform.wgs2gcj(pts[i][1], pts[i][0]) pts[i] = [temp[1], temp[0]] with open(outputfile, 'w') as outfile: json.dump(data, outfile)
def pd_to_html(df, out_fname): c_lng, c_lat = df.iloc[0]['Longitude'], df.iloc[0]['Latitude'] html = const_prefix % (c_lat, c_lng) for i in range(len(df)): lng, lat = df.iloc[i]['Longitude'], df.iloc[i]['Latitude'] # print 'O:(%s, %s)' % (lat, lng) lat, lng = ets.wgs2gcj(lat, lng) # print 'N:(%s, %s)' % (lat, lng) marker = '{lat:%s, lng:%s}' % (lat, lng) html += const_marker % (i, marker) html += const_suffix with open(out_fname, 'w') as o_file: o_file.write(html)
def test_z_speed(self): n = 100000 tests = ( ('wgs2gcj', lambda: eviltransform.wgs2gcj(TESTS[0][0], TESTS[0][1])), ('gcj2wgs', lambda: eviltransform.gcj2wgs(TESTS[0][0], TESTS[0][1])), ('gcj2wgs_exact', lambda: eviltransform.gcj2wgs_exact(TESTS[0][0], TESTS[0][1])), ('distance', lambda: eviltransform.distance(*TESTS[0]))) print('\n' + '=' * 30) for name, func in tests: sec = timeit.timeit(func, number=n) print('%s\t%.2f ns/op' % (name, sec * 1e9 / n))
def test_z_speed(self): n = 100000 tests = ( ('wgs2gcj', lambda: eviltransform.wgs2gcj(TESTS[0][0], TESTS[0][1])), ('gcj2wgs', lambda: eviltransform.gcj2wgs(TESTS[0][0], TESTS[0][1])), ('gcj2wgs_exact', lambda: eviltransform.gcj2wgs_exact(TESTS[0][0], TESTS[0][1])), ('distance', lambda: eviltransform.distance(*TESTS[0])) ) print('\n' + '='*30) for name, func in tests: sec = timeit.timeit(func, number=n) print('%s\t%.2f ns/op' % (name, sec * 1e9 / n))
def edges_to_html(edges, out_fname): c_lat, c_lng = edges[edges.keys()[0]][0] html = const_prefix % (c_lat, c_lng) rid = 0 for e_id, points in edges.iteritems(): p_str = [] coors = '[' for idx, point in enumerate(points): lat, lng = float(point[0]), float(point[1]) lat, lng = ets.wgs2gcj(lat, lng) marker = '{lat:%s, lng:%s}' % (lat, lng) p_str.append(marker) coors += ', '.join(p_str) + ']\n' html += const_coor % (rid, coors) html += const_path % (rid, 'coor_' + str(rid), colors[0]) html += 'path_%d' % rid + '.setMap(map);\n\n' rid += 1 html += const_suffix with open(out_fname, 'w') as o_file: o_file.write(html)
import logging import numpy as np import math logging.basicConfig( level=logging.INFO, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s') logger = logging.getLogger(__name__) # DIDI data schema NAMES = ['driverid', 'orderid', 'timestamp', 'lon', 'lat'] # Study area pts_WGS = [(34.241, 108.943), (34.241, 108.9415), (34.234, 108.9415), (34.234, 108.943)] pts_GCJ = [eviltransform.wgs2gcj(p, q) for (p, q) in pts_WGS] pts = pd.DataFrame(pts_GCJ, columns=['lat', 'lon']) lat_min = pts.lat.min() lat_max = pts.lat.max() lon_min = pts.lon.min() lon_max = pts.lon.max() # Mid-point of the East-West study area ref_lon = (lon_min + lon_max) / 2.0 # Parameter (in meters) to determine trip direction THRESHOLD = 200 def fetch(filename, bbox, threshold):
x = [] y = [] dx = [] dy = [] s = [] fig = plt.subplots(nrows=1, figsize=(7.5, 5.25)) for utm_x in range(0, 8000000, 100000): for utm_y in range(0, 5000000, 100000): wgs_longitude, wgs_latitude = basemap(utm_x, utm_y, inverse=True) wgs_x, wgs_y = basemap(wgs_longitude, wgs_latitude) gcj_latitude, gcj_longitude = eviltransform.wgs2gcj( wgs_latitude, wgs_longitude) gxj_x, gxj_y = basemap(gcj_longitude, gcj_latitude) x.append(wgs_x) y.append(wgs_y) dx.append(wgs_x - gxj_x) dy.append(wgs_y - gxj_y) s.append(math.hypot(wgs_x - gxj_x, wgs_y - gxj_y)) basemap.drawmapboundary(fill_color='#000000') basemap.fillcontinents(color='#444444', lake_color='None') basemap.drawmeridians(range(0, 171, 5)) basemap.drawparallels(range(0, 81, 5)) basemap.drawcountries(linewidth=1, zorder=11) quiver_ref = basemap.quiver(x,
def switch_wgs2gcj(self): self.lat, self.lng = eviltransform.wgs2gcj(self.lat, self.lng)
def gps2gd(data): location = Munch(data) lat, lng = map(float, [location.lat, location.lng]) gd_lat, gd_lng = eviltransform.wgs2gcj(lat, lng) data.update(gd_lat=gd_lat, gd_lng=gd_lng)
def wgs2gcj(wgsLat, wgsLng): gcjLoc = eviltransform.wgs2gcj(wgsLat, wgsLng) return {'lat': gcjLoc[0], 'lon': gcjLoc[1]}
def test_wgs2gcj(self): for wgsLat, wgsLng, gcjLat, gcjLng in TESTS: ret = eviltransform.wgs2gcj(wgsLat, wgsLng) self.assertAlmostEqual(ret[0], gcjLat, 6) self.assertAlmostEqual(ret[1], gcjLng, 6)
import csv import eviltransform from geopy.distance import distance csv_filename = 'empirical-data.csv' with open(csv_filename, newline='') as csv_file: csv_reader = csv.DictReader(csv_file, delimiter=',') for row in csv_reader: # Skip provinces that do not use GCJ-02 on Google Maps if row['City'] in ['Hong Kong', 'Macau', 'Taipei']: continue # Retrieve and compute coordinates wgs84_coord = (float(row['WGS84 Lat']), float(row['WGS84 Lon'])) empirical_coord = (float(row['GCJ-02 Lat']), float(row['GCJ-02 Lon'])) eviltrans_coord = eviltransform.wgs2gcj(wgs84_coord[0], wgs84_coord[1]) # Calculate distance between eviltransform and my sampled coordinate d = distance(eviltrans_coord, empirical_coord).meters print((row['City'] + ':').ljust(15) + str(d) + ' metres')
def wsg2gcj(latitude, longitude): gcj_lat, gcj_lng = eviltransform.wgs2gcj(latitude, longitude) return gcj_lat, gcj_lng