Пример #1
0
 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))
Пример #2
0
 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))
Пример #3
0
    def get_track_json(self, trip_info):
        """Downloads the JSON for the GPS track"""
        import json

        url = SixFeetDownloader._FOOT_BASE_URL + SixFeetDownloader._TRACK_JSON_URL.format(trip_info.id)
        doc, from_cache = self.track_downloader.download(url)
        try:
            points_json = json.loads(doc)
        except:
            logging.warning("Couldn't parse json for trip {0}".format(trip_info.id))
            points_json = []

        points = []

        for p in points_json:
            p[1], p[2] = eviltransform.gcj2wgs(p[1], p[2])
            points.append(tripdb.GpsTrackPoint(p[1], p[2], p[3], p[0], p[4], p[5]))

        return points, from_cache
Пример #4
0
if not os.path.exists(exportDir):
	os.makedirs(exportDir)

# load places csv file and download directions
with open(inputFileName) as csvInput, open(exportDir + inputFileName, 'wb') as csvOutput:
	csvReader = csv.DictReader(csvInput)
	fieldnames = csvReader.fieldnames + ['filename', 'duration', 'distance']
	csvWriter = csv.DictWriter(csvOutput, fieldnames)
	csvWriter.writeheader()
	for index, row in enumerate(csvReader):
		# set up json output file
		jsonFileName = jsonDir + 'file_%s.json' % index
		startPlace = row['startLng'] + "," + row['startLat']
		endPlace = row['endLng'] + "," + row['endLat']
		# print row['startLat'], row['startLng'], row['endLat'], row['endLng']
		startLatLng = eviltransform.gcj2wgs(float(row['startLat']), float(row['startLng']))
		endLatLng = eviltransform.gcj2wgs(float(row['endLat']), float(row['endLng']))
		subprocess.Popen("curl -o " + jsonFileName + " 'http://restapi.amap.com/v3/direction/" + direction_mode + "?origin=" + startPlace + "&destination=" + endPlace + "&output=json&key=" + access_token + "'", shell=True, stdout=subprocess.PIPE).stdout.read()
		
		# coverts json to csv
		with open(jsonFileName) as jsonFile:
			jsonData = json.load(jsonFile)
			jsonRoute = jsonData['route']['paths'][0]
			duration = jsonRoute['duration']
			distance = jsonRoute['distance']
			steps = jsonRoute['steps']

			# create a new csv for processing
			csvFileName = 'file_%s.csv' % index
			with open(exportDir+csvFileName, 'wb') as processinCSV:
				processingCSVWriter = csv.DictWriter(processinCSV, ['latitude', 'longitude'])
Пример #5
0
 def test_gcj2wgs(self):
     for wgsLat, wgsLng, gcjLat, gcjLng in TESTS:
         ret = eviltransform.gcj2wgs(gcjLat, gcjLng)
         self.assertLess(
             eviltransform.distance(ret[0], ret[1], wgsLat, wgsLng), 5)
Пример #6
0
 def test_gcj2wgs(self):
     for wgsLat, wgsLng, gcjLat, gcjLng in TESTS:
         ret = eviltransform.gcj2wgs(gcjLat, gcjLng)
         self.assertLess(eviltransform.distance(
             ret[0], ret[1], wgsLat, wgsLng), 5)