Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorIlya Zverev <zverik@textual.ru>2016-08-19 17:07:00 +0300
committerIlya Zverev <zverik@textual.ru>2016-08-19 17:07:00 +0300
commitd0fde4e7106e49b7dee5d22395f4620bc6a0d163 (patch)
tree0f28400612a4561d4c5b98fbab314498b79c60a6 /tools
parent1fda4161d9a948847707a852ebad018c89faee1a (diff)
[booking] Fix chinese coordinates
Diffstat (limited to 'tools')
-rwxr-xr-xtools/python/booking_hotels.py7
-rw-r--r--tools/python/eviltransform.py149
-rwxr-xr-xtools/unix/generate_mwm.sh1
3 files changed, 157 insertions, 0 deletions
diff --git a/tools/python/booking_hotels.py b/tools/python/booking_hotels.py
index 059f2cb26c..4456b48754 100755
--- a/tools/python/booking_hotels.py
+++ b/tools/python/booking_hotels.py
@@ -12,6 +12,7 @@ import os
import pickle
import time
import urllib2
+import eviltransform
# Initialize logging.
logging.basicConfig(level=logging.DEBUG, format='[%(asctime)s] %(levelname)s: %(message)s')
@@ -135,6 +136,12 @@ def translate(source, output):
with open(filename, 'rb') as fd:
data += pickle.load(fd)
+ # Fix chinese coordinates
+ for hotel in data:
+ if hotel['countrycode'] == 'cn' and 'location' in hotel:
+ hotel['location']['latitude'], hotel['location']['longitude'] = eviltransform.gcj2wgs_exact(
+ float(hotel['location']['latitude']), float(hotel['location']['longitude']))
+
# Dict of dicts city_id -> { currency -> [prices] }
cities = defaultdict(lambda: defaultdict(list))
diff --git a/tools/python/eviltransform.py b/tools/python/eviltransform.py
new file mode 100644
index 0000000000..670ac93fbe
--- /dev/null
+++ b/tools/python/eviltransform.py
@@ -0,0 +1,149 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Source: https://github.com/googollee/eviltransform
+# Published under 2-clause BSD license
+# Copyright (c) 2015, Googol Lee <i@googol.im>, @gutenye, @xingxing, @bewantbe,
+# @GhostFlying, @larryli, @gumblex,@lbt05, @chenweiyj
+
+import math
+
+
+__all__ = ['wgs2gcj', 'gcj2wgs', 'gcj2wgs_exact',
+ 'distance', 'gcj2bd', 'bd2gcj', 'wgs2bd', 'bd2wgs']
+
+earthR = 6378137.0
+
+def outOfChina(lat, lng):
+ return not (72.004 <= lng <= 137.8347 and 0.8293 <= lat <= 55.8271)
+
+
+def transform(x, y):
+ xy = x * y
+ absX = math.sqrt(abs(x))
+ xPi = x * math.pi
+ yPi = y * math.pi
+ d = 20.0*math.sin(6.0*xPi) + 20.0*math.sin(2.0*xPi)
+
+ lat = d
+ lng = d
+
+ lat += 20.0*math.sin(yPi) + 40.0*math.sin(yPi/3.0)
+ lng += 20.0*math.sin(xPi) + 40.0*math.sin(xPi/3.0)
+
+ lat += 160.0*math.sin(yPi/12.0) + 320*math.sin(yPi/30.0)
+ lng += 150.0*math.sin(xPi/12.0) + 300.0*math.sin(xPi/30.0)
+
+ lat *= 2.0 / 3.0
+ lng *= 2.0 / 3.0
+
+ lat += -100.0 + 2.0*x + 3.0*y + 0.2*y*y + 0.1*xy + 0.2*absX
+ lng += 300.0 + x + 2.0*y + 0.1*x*x + 0.1*xy + 0.1*absX
+
+ return lat, lng
+
+
+def delta(lat, lng):
+ ee = 0.00669342162296594323
+ dLat, dLng = transform(lng-105.0, lat-35.0)
+ radLat = lat / 180.0 * math.pi
+ magic = math.sin(radLat)
+ magic = 1 - ee * magic * magic
+ sqrtMagic = math.sqrt(magic)
+ dLat = (dLat * 180.0) / ((earthR * (1 - ee)) / (magic * sqrtMagic) * math.pi)
+ dLng = (dLng * 180.0) / (earthR / sqrtMagic * math.cos(radLat) * math.pi)
+ return dLat, dLng
+
+
+def wgs2gcj(wgsLat, wgsLng):
+ if outOfChina(wgsLat, wgsLng):
+ return wgsLat, wgsLng
+ else:
+ dlat, dlng = delta(wgsLat, wgsLng)
+ return wgsLat + dlat, wgsLng + dlng
+
+
+def gcj2wgs(gcjLat, gcjLng):
+ if outOfChina(gcjLat, gcjLng):
+ return gcjLat, gcjLng
+ else:
+ dlat, dlng = delta(gcjLat, gcjLng)
+ return gcjLat - dlat, gcjLng - dlng
+
+
+def gcj2wgs_exact(gcjLat, gcjLng):
+ initDelta = 0.01
+ threshold = 0.000001
+ dLat = dLng = initDelta
+ mLat = gcjLat - dLat
+ mLng = gcjLng - dLng
+ pLat = gcjLat + dLat
+ pLng = gcjLng + dLng
+ for i in range(30):
+ wgsLat = (mLat + pLat) / 2
+ wgsLng = (mLng + pLng) / 2
+ tmplat, tmplng = wgs2gcj(wgsLat, wgsLng)
+ dLat = tmplat - gcjLat
+ dLng = tmplng - gcjLng
+ if abs(dLat) < threshold and abs(dLng) < threshold:
+ return wgsLat, wgsLng
+ if dLat > 0:
+ pLat = wgsLat
+ else:
+ mLat = wgsLat
+ if dLng > 0:
+ pLng = wgsLng
+ else:
+ mLng = wgsLng
+ return wgsLat, wgsLng
+
+
+def distance(latA, lngA, latB, lngB):
+ pi180 = math.pi / 180
+ arcLatA = latA * pi180
+ arcLatB = latB * pi180
+ x = (math.cos(arcLatA) * math.cos(arcLatB) *
+ math.cos((lngA - lngB) * pi180))
+ y = math.sin(arcLatA) * math.sin(arcLatB)
+ s = x + y
+ if s > 1:
+ s = 1
+ if s < -1:
+ s = -1
+ alpha = math.acos(s)
+ distance = alpha * earthR
+ return distance
+
+
+def gcj2bd(gcjLat, gcjLng):
+ if outOfChina(gcjLat, gcjLng):
+ return gcjLat, gcjLng
+
+ x = gcjLng
+ y = gcjLat
+ z = math.hypot(x, y) + 0.00002 * math.sin(y * math.pi)
+ theta = math.atan2(y, x) + 0.000003 * math.cos(x * math.pi)
+ bdLng = z * math.cos(theta) + 0.0065
+ bdLat = z * math.sin(theta) + 0.006
+ return bdLat, bdLng
+
+
+def bd2gcj(bdLat, bdLng):
+ if outOfChina(bdLat, bdLng):
+ return bdLat, bdLng
+
+ x = bdLng - 0.0065
+ y = bdLat - 0.006
+ z = math.hypot(x, y) - 0.00002 * math.sin(y * math.pi)
+ theta = math.atan2(y, x) - 0.000003 * math.cos(x * math.pi)
+ gcjLng = z * math.cos(theta)
+ gcjLat = z * math.sin(theta)
+ return gcjLat, gcjLng
+
+
+def wgs2bd(wgsLat, wgsLng):
+ return gcj2bd(*wgs2gcj(wgsLat, wgsLng))
+
+
+def bd2wgs(bdLat, bdLng):
+ return gcj2wgs(*bd2gcj(bdLat, bdLng))
diff --git a/tools/unix/generate_mwm.sh b/tools/unix/generate_mwm.sh
index 1efeff906c..b36907135b 100755
--- a/tools/unix/generate_mwm.sh
+++ b/tools/unix/generate_mwm.sh
@@ -78,6 +78,7 @@ trap "rm -rf \"${INTDIR}\"" EXIT SIGINT SIGTERM
# Create MWM file
INTDIR_FLAG="--intermediate_data_path=$INTDIR/ --node_storage=map"
GENERATE_EVERYTHING='--generate_features=true --generate_geometry=true --generate_index=true --generate_search_index=true'
+[ -n "${HOTELS-}" ] && GENERATE_EVERYTHING="$GENERATE_EVERYTHING --booking_data=$HOTELS"
COASTS="${COASTS-WorldCoasts.geom}"
if [ -f "$COASTS" ]; then
if [ ! -f "$TBORDERS/$BASE_NAME.poly" ]; then