def testGrid(): geocoder = what3words.Geocoder(api_key) sw = what3words.Coordinates(52.208867, 0.117540) ne = what3words.Coordinates(52.207988, 0.116126) bb = what3words.BoundingBox(sw, ne) result = geocoder.grid_section(bb) assert result['lines'] is not None
def testConvertTo3wa(): geocoder = what3words.Geocoder(api_key) result = geocoder.convert_to_3wa(what3words.Coordinates(lat, lng)) assert result['language'] == 'en' assert result['words'] == 'daring.lion.race' assert result['coordinates']['lat'] == lat assert result['coordinates']['lng'] == lng
def Get_w3w(df): W3W_API_KEY = 'YOUR_API_KEY_GOES_HERE' g = what3words.Geocoder(W3W_API_KEY) for i in range(0, len(df)): res = g.convert_to_3wa(what3words.Coordinates(df.iloc[i]['lat'], df.iloc[i]['lon'])) df.set_value(i, 'what3words', res['words']) return df
def locate(name): data = False static_data = { "GOOGLE_API": app.config["GOOGLE_API"], "W3W_API": app.config["W3W_API"], "url_valid": True } # Ensure track ID has been issued exists = db.session.query( Track.name).filter_by(name=name).scalar() is not None if not exists: static_data["url_valid"] = False else: # Ensure track ID has not expired yet track_time = db.session.query( Track.create_time).filter_by(name=name).scalar() track_time_db = date_parser.parse(track_time.strftime('%c')) current_time = dt.utcnow() difference = current_time - track_time_db if difference.days >= 3: static_data["url_valid"] = False # Recieve track data from client if request.method == "POST": # Parse position object return data = request.get_json(force=True) data["timeStamp"] = date_parser.parse( data["timeStamp"].split("GMT")[0]) # Insert extra info about request data["ip"] = request.remote_addr data["track_id"] = db.session.query(Track.id).filter_by(name=name) geocoder = what3words.Geocoder(app.config["W3W_API"]) w3w = geocoder.convert_to_3wa( what3words.Coordinates(data["latitude"], data["longitude"])) data["w3w"] = w3w["words"] # Add message to user location_insert = Location(**data) try: db.session.add(location_insert) db.session.commit() except Exception as e: print(e) sys.stdout.flush() return render_template("locate.html", title='Locate', static_data=static_data, data=data) return render_template("locate.html", title='Locate', static_data=static_data, data=data)
def portam(self, point): self.point = QgsPointXY(point) # self.point = self.toMapCoordinates(point) xMon = self.point.x() #??? yMon = self.point.y() #??? self.transformacio = QgsCoordinateTransform( QgsCoordinateReferenceSystem("EPSG:25831"), QgsCoordinateReferenceSystem("EPSG:4326"), QgsProject.instance()) self.puntTransformat = self.transformacio.transform(self.point) self.parent.pucMoure = False # streetView = 'https://www.google.com/maps/@{},{},3a,75y,0h,75t'.format(self.puntTransformat.y(),puntTransformat.x()) # streetView = 'https://www.google.com/maps/@{},{},2a/data=!3m1!1e3'.format(puntTransformat.y(),puntTransformat.x()) self.parent.urlStreetView = "https://maps.google.com/maps?layer=c&cbll={},{}".format( self.puntTransformat.y(), self.puntTransformat.x()) self.parent.urlGoogleMaps = 'https://www.google.com/maps/@{},{},2a/data=!3m1!1e3'.format( self.puntTransformat.y(), self.puntTransformat.x()) self.parent.urlStreetMaps = "https://www.openstreetmap.org/#map=16/{}/{}".format( self.puntTransformat.y(), self.puntTransformat.x()) self.parent.qbrowser.browser.setUrl(QUrl(self.parent.urlStreetView)) self.parent.qbrowser.show() self.parent.show() try: import what3words geocoder = what3words.Geocoder("HTD7LNB9") palabras = geocoder.convert_to_3wa(what3words.Coordinates( self.puntTransformat.y(), self.puntTransformat.x()), language='es') # coordenadas = geocoder.convert_to_coordinates('agudo.lista.caja') print(palabras['words']) except: print('No va 3 words') # self.parent.boto.move(40, 5) # self.m.setCenter(QgsPointXY(event.x()-30,event.y()-30)) self.canvas.scene().removeItem(self.parent.m) self.parent.m = QgsVertexMarker(self.canvas) self.parent.m.setCenter(QgsPointXY(self.point.x(), self.point.y())) self.parent.m.setColor(QColor(255, 0, 0)) self.parent.m.setIconSize(15) self.parent.m.setIconType( QgsVertexMarker.ICON_BOX) # or ICON_CROSS, ICON_X self.parent.m.setPenWidth(3) self.parent.m.show() self.moureBoto = False
def respond(s, xml): ts = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ') request = parseCoT(xml) print(ts, request) if request["cmd"] in commands: print(request["lat"], request["lon"]) if (abs(request["lat"]) + abs(request["lon"])) < 1.0: s.sendall( geochat( "Set your location (%.1f,%.1f )before requesting a conversion!" % (request["lat"], request["lon"]), request["atakuid"])) return s.sendall( geochat( "Tranforming location %.5f, %.5f..." % (request["lat"], request["lon"]), request["atakuid"])) # WHAT 3 WORDS if request["cmd"] == "w3w": res = geocoder.convert_to_3wa( what3words.Coordinates(request["lat"], request["lon"])) if "words" in res: s.sendall(geochat(res["words"], request["atakuid"])) else: print(res) s.sendall(geochat(res["error"]["message"], request["atakuid"])) # OSGB / EPSG if request["cmd"] == "os": bng = latlong2grid(request["lat"], request["lon"]) print(bng) s.sendall(geochat(str(bng), request["atakuid"])) else: s.sendall( geochat( "Available services. Ensure you have set your lat/lon either manually or with a GPS", request["atakuid"])) c = 0 while c < len(commands): s.sendall( geochat(commands[c] + ": " + helpers[c], request["atakuid"])) c += 1
# coding: utf8 import what3words from os import environ api_key = environ['W3W_API_KEY'] geocoder = what3words.Geocoder(api_key) ## convert_to_coordinates ######### res = geocoder.convert_to_coordinates('prom.cape.pump', 'geojson') print(res) print('\n') ## convert_to_3wa ######### coordinates = what3words.Coordinates(51.484463, -0.195405) res = geocoder.convert_to_3wa(coordinates) print(res) print('\n') ## grid_section ######### sw = what3words.Coordinates(52.207988, 0.116126) ne = what3words.Coordinates(52.208867, 0.117540) bb = what3words.BoundingBox(sw, ne) res = geocoder.grid_section(bb) print(res) print('\n') ## grid_section ######### res = geocoder.available_languages()
import sys ##### define inputs ##### input_file = 'mn_county_centroids.txt' output_file = 'mn_county_centroids_out.csv' ##### inputs complete ##### # request API key api_key = input('Input what3words API key: ') # connect to public API geocoder = what3words.Geocoder(api_key) # read in set of coordinates df = pd.read_csv(input_file, sep='\t', skiprows=1, names=('stand', 'long', 'lat')) df['what3words'] = None # iterate through values for index, row in df.iterrows(): # convert coordinates to what3words res = geocoder.convert_to_3wa( what3words.Coordinates(df['lat'][index], df['long'][index])) df['what3words'][index] = res['words'] # write dataframe to file df.to_csv(output_file)