def viaggi_to_json_txt(lista_viaggi, filename_output): lout = [] cc = countries.CountryChecker("borders/TM_WORLD_BORDERS-0.3.shp") for v in lista_viaggi: lv = [v.id_, v.tempo_inizio, v.tempo_fine] in_italy = True for p in v.punti: point = countries.Point(float(p.latitudine), float(p.longitudine)) if cc.getCountry( point) == None or cc.getCountry(point).iso != "IT": in_italy = False break lv.append([p.timestamp, p.latitudine, p.longitudine, p.velocita]) if in_italy: lout.append(lv) print len(lout) if len(lout) > 0: ftxtout = open(filename_output, "w") json.dump(lout, ftxtout) ftxtout.close() print filename_output
def prod_sq(): file_path = './second_data.txt' file_path1 = './geomap.txt' file_path2 = './sq_data.txt' with open(file_path2, 'w') as w: with open(file_path, 'r') as f: with open(file_path1, 'r') as g: lst = f.readlines() pos = g.readlines()[0].split() for s in pos: lat, lng = s.split(",") cc = countries.CountryChecker('TM_WORLD_BORDERS-0.3.shp') name = cc.getCountry(countries.Point(int(lat), int(lng))) flag = True for i in range(1, len(lst)): data = lst[i].split("\n")[0].split(",") if data[1] in str(name): w.write(str(i) + " ") flag = False break if flag: w.write("0 ") print("序列输出完成")
def getCountry(coord): copyshapes.filter_file( lambda x: x.GetField('REGION') == 150, 'TM_WORLD_BORDERS-0.3.shp', 'EUROPE.shp') cc = countries.CountryChecker('TM_WORLD_BORDERS-0.3.shp') country = cc.getCountry(countries.Point(coord[0], coord[1])) return country
def __init__(self): self.cc = countries.CountryChecker('geo-data/filtered.shp') """ Filter out the bad ones """ self.bad_ids = set([203007243, 325160483, 186456725, 345423903, 169523312, 1211153959, 186456725]) self.bad_tokensRegEx = re.compile( unicode(regex_or( r'Yelp', r'nowplaying', r'happy-hours', r'NowPlaying', r'via', r'4sq', r'rt', r'Goldmünzen', r'Nahrungseinheiten', r'gameinsight', r'androidgames', r'RT' ).decode('utf-8')), re.UNICODE)
def get_derived_covid_active_global(): """ Reads the global active cases dataset into a pandas dataframe. This is a derivative dataset. It is synthesized from confirmed and recovered cases. Lat/Lon is converted into ISO country codes and shape data for easier country identification Returns a pandas dataframe containing the sanitized data and timestep metadata """ cc = countries.CountryChecker('TM_WORLD_BORDERS-0.3.shp') shapes = Reader('ne_50m_admin_0_countries.shp') confirmed, timesteps_confirmed = get_covid_confirmed_global() shape_data_confirmed = transform_to_shape_data(confirmed, timesteps_confirmed, cc, shapes) recovered, timesteps_recovered = get_covid_recovered_global() shape_data_recovered = transform_to_shape_data(recovered, timesteps_recovered, cc, shapes) deaths, timesteps_deaths = get_covid_deaths_global() shape_data_deaths = transform_to_shape_data(deaths, timesteps_deaths, cc, shapes) shape_data_confirmed_count = shape_data_confirmed[[*timesteps_confirmed]] shape_data_recovered_count = shape_data_recovered[[*timesteps_recovered]] shape_data_deaths_count = shape_data_deaths[[*timesteps_deaths]] shape_data_con_min_rec = shape_data_confirmed_count.subtract( shape_data_recovered_count) shape_data_active_count = shape_data_con_min_rec.subtract( shape_data_deaths_count) shape_data_active_countries = shape_data_confirmed[['iso', 'shape']] shape_data_active = pd.concat( [shape_data_active_countries, shape_data_active_count], axis=1) return shape_data_active, timesteps_confirmed
def detect_landmarks(user_id): urls = [] response = vk_api.photos.get(owner_id=user_id,album_id="wall", rev=1, count=30) for photo in response['items']: for size in photo['sizes']: if size['width'] > 600 and size['height'] > 600: url = size['url'] urls.append(url) break result = {} # urls = ["https://sun9-4.userapi.com/impf/c604625/v604625712/265c9/WwBwt2_6ygk.jpg?size=1280x960&quality=96&proxy=1&sign=a1649aba17c875e482fbe4e2c069efb3","https://sun9-12.userapi.com/impf/c623900/v623900048/2a2f1/ezedrrOTrno.jpg?size=816x1088&quality=96&proxy=1&sign=b9f44a4a1b515f4173fc845019eb340b","https://sun9-56.userapi.com/impf/c841138/v841138048/3aa38/TiBv8n5E7UU.jpg?size=744x744&quality=96&proxy=1&sign=b80d93be964e670e8e935a091a54f309"] contents = ThreadPool(8).map(urlToContent, urls) countryList = [] tags_weight = 0 tags_count = 1 for content in contents: try: client = vision.ImageAnnotatorClient() # with io.open(path, 'rb') as image_file: # content = image_file.read() image = vision.Image(content=content) landmarkResponse = client.landmark_detection(image=image) landmarks = landmarkResponse.landmark_annotations labelsResponse = client.label_detection(image=image) labels = labelsResponse.label_annotations # return str(labelsResponse)+";"+str(landmarks) print('Labels:') # Получение объектов на картинке for label in labels: label = label.description if label in result: result[label] = result[label] + 1 else: result[label] = 1 try: weight = weights_photo_tagsD[label] print(weight) if weight is not None: tags_weight = tags_weight + weight tags_count = tags_count + 1 except Exception as e: pass print(label) print('Landmarks:') # Получение координат и названий городов for landmark in landmarks: print(landmark.description) for location in landmark.locations: lat_lng = location.lat_lng print('Latitude {}'.format(lat_lng.latitude)) print('Longitude {}'.format(lat_lng.longitude)) cc = countries.CountryChecker('/home/admin2/TM_WORLD_BORDERS-0.3.shp') country = cc.getCountry(countries.Point(lat_lng.latitude, lat_lng.longitude)).iso print(country) countryList.append(country) # print(country) except Exception as e: print("detect_landmarks error = " + str(e)) solvency = tags_weight / tags_count sorted_result = {} for key,value in reversed(sorted(result.items(), key=lambda kv: kv[1])): sorted_result[key] = value return str('{"tagsFromPhoto":' + str(sorted_result) + ', "countries": ' + str(countryList) + ', "solvency": ' + str(solvency) +'}').replace("'",'"');
import countries cc = countries.CountryChecker('TM_WORLD_BORDERS-0.3.shp') print(cc.getCountry(countries.Point(49.7821, 3.5708)).iso) print('test working')
# we'll use url_for to get some URLs for the app on the templates from flask import Flask, render_template, request, url_for, jsonify, send_file from multiprocessing import Process from make_map import make_map import countries # TODO Remove the following in production from scan_product_links import urls import os import math import wget import urllib import zipfile import sys app = Flask(__name__) country_checker = countries.CountryChecker("TM_WORLD_BORDERS-0.3.shx") # TODO Remove the following in production us_urls = urls("elevationproductslinks/13secondplots.csv") mx_ca_urls = urls("elevationproductslinks/1secondplots.csv") # Define a route for the default URL, which loads the form # TODO Remove the following route in production @app.route('/', methods=['GET']) def show_home(): return render_template('index.htm') @app.route('/send_square/', methods=['POST']) def respond(): data = request.get_json(force=True)
def in_switzerland(row): longitude = row['longitude'] latitude = row['latitude'] cc = countries.CountryChecker('TM_WORLD_BORDERS/TM_WORLD_BORDERS-0.3.shp') country = cc.getCountry(countries.Point(latitude, longitude)).iso return country