Exemplo n.º 1
0
 def get_near(cls, location, range_km=5):
     centre = point.Point(location)
     all_stuff = cls.get_all()
     for stuff in all_stuff:
         d = stuff.distance(centre)
         if d < range_km:
             yield stuff
Exemplo n.º 2
0
def add_min_dist(df):
    """ Dada una tabla con columnas ('LOCATION', 'LAT', 'LONG') agrega columna
        'MIN_DIST' con la minima distancia de cada LOCATION a otra. """
    print('Adding MIN_DIST...')
    df = df.set_index('LOCATION')
    df = df[~df['LAT'].isna() & ~df['LONG'].isna()]
    min_dist_data = []
    for location_1, r_1 in df.iterrows():
        min_dist_location = ''
        min_dist = 10000000
        for location_2, r_2 in df.iterrows():
            p_1 = point.Point(latitude=r_1['LAT'], longitude=r_1['LONG'])
            p_2 = point.Point(latitude=r_2['LAT'], longitude=r_2['LONG'])
            dist = distance.distance(p_1, p_2).km
            if location_1 != location_2 and min_dist > dist:
                min_dist = dist
                min_dist_location = location_2
        assert min_dist_location != ''
        min_dist_data.append(min_dist)
    df['MIN_DIST'] = pd.Series(index=df.index, data=min_dist_data)
    return df.reset_index()
Exemplo n.º 3
0
def midpoint(a, b):
    a_lat, a_lon = radians(a.latitude), radians(a.longitude)
    b_lat, b_lon = radians(b.latitude), radians(b.longitude)
    delta_lon = b_lon - a_lon
    B_x = cos(b_lat) * cos(delta_lon)
    B_y = cos(b_lat) * sin(delta_lon)
    mid_lat = atan2(
        sin(a_lat) + sin(b_lat),
        sqrt(((cos(a_lat) + B_x)**2 + B_y**2))
    )
    mid_lon = a_lon + atan2(B_y, cos(a_lat) + B_x)
    # Normalise
    mid_lon = (mid_lon + 3*pi) % (2*pi) - pi
    return gp.Point(latitude=degrees(mid_lat), longitude=degrees(mid_lon))
Exemplo n.º 4
0
    def wgs84_to_latlon(self, lat, lon):
        def split(number):
            nstr = str(number)
            gap2 = 2
            if "." in nstr:
                gap2 = 3 + len(nstr.split(".")[1])
            gap1 = gap2 + 2
            return nstr[:-gap1] or "0", nstr[-gap1:-gap2], nstr[-gap2:]

        lat1, lat2, lat3 = split(lat)
        lon1, lon2, lon3 = split(lon)
        lat = "%s %s' %s\" %s" % (lat1, lat2, lat3, "N" if lat > 0 else "S")
        lon = "%s %s' %s\" %s" % (lon1, lon2, lon3, "E" if lon > 0 else "W")
        lat, lon, alt = point.Point("%s; %s" % (lat, lon))
        return lat, lon
Exemplo n.º 5
0
 def __init__(self, spatial={}):
     for name in self.MAP_FIELDS:
         setattr(self, name, self._urlencode_safe_str(spatial.get(name)))
     if self.name and not self.coordinates:
         try:
             p = point.Point(self.name)
             # Latitude and longitude by List index
             coords = ', '.join([str(p[0]), str(p[1])])
         except ValueError:
             # If there are no legitimate coordinates in the Place name
             coords = ""
         if coords:
             self.coordinates = coords
             self.name = None
             self.set_name()
Exemplo n.º 6
0
def create_coordinate(start_coord: tp.Tuple[float, float], x_offset: float,
                      y_offset: float) -> tp.Tuple[float, float]:
    """
    create a coordinate from a given starting point by shifting it a given x_offset in km and y_offset in km
    :param start_coord: tp.Tuple[float, float]
    :param x_offset: float, length in km
    :param y_offset: float, length in km
    :return: tp.Tuple[float, float]
    """
    start = p.Point(*start_coord)

    dy = geodesic(kilometers=y_offset)
    dx = geodesic(kilometers=x_offset)

    final = dy.destination(dx.destination(start, bearing=90),
                           bearing=0)  # 90 = East, 0 = North...
    return final.longitude, final.latitude
Exemplo n.º 7
0
 def point(self):
     return point.Point(self.coordinates[1], self.coordinates[0])
Exemplo n.º 8
0
from matplotlib import pyplot, mpl
import numpy as np
from geopy import point, distance
from plot_utils import *
from file_utils import *

# str = input("Enter your input: ");
# print("Received input is : ", str)

#------------------------------------------------------------------------------ 
# File Directory
#------------------------------------------------------------------------------ 
indir = '/home/ruffin/Documents/Data/in/'
outdir = '/home/ruffin/Documents/Data/out/'
# reference = point.Point(40.442635758, -79.943065017, 257)
reference = point.Point(40.443874, -79.945517, 272)

#------------------------------------------------------------------------------ 
# Check output directory can be dumped to
#------------------------------------------------------------------------------ 
indir = checkDir(indir,'r')
outdir = checkDir(outdir,'r')

#------------------------------------------------------------------------------ 
# Get log gps file name
#------------------------------------------------------------------------------ 
posFile = findFile(outdir,'.pos')

#------------------------------------------------------------------------------ 
# Parse data from log file
#------------------------------------------------------------------------------ 
Exemplo n.º 9
0
df = pd.read_csv("location-data.txt")

dis_list = []  #list to store the distances
dis_index_list = []  #list to store the indexs of the distances
loc1 = (0, 0)

for i in range(
        len(df)
):  #loop throught data frame and compute the distances from the origin(loc1) to the specified location
    lat = df.at[
        i, 'Latitude']  #grab the latitude from the index i in the dataframe
    longi = df.at[
        i, 'Longitude']  #grab the longitude from the index i in the dataframe
    try:
        pt = point.Point(
            lat + ',' +
            longi)  #create a single point from the latitudes and longitudes
        dis_list.append(
            distance.distance(loc1, pt)
        )  #calculate the distance from the origin to the point and append to the list
        dis_index_list.append(
            i
        )  #append the index of the distance so they will match when joined with the originial dataframe
    except ValueError:  #If the latitudes or longitudes are out of range, it is dropped from the dataframe
        df.drop(index=i, inplace=True)

dis_df = pd.DataFrame()  #Create a dataframe of the distances
dis_df['Index'] = dis_index_list
dis_df['Distance km'] = dis_list

complete_df = df.join(dis_df.set_index(
Exemplo n.º 10
0
 def __init__(self, bottom_right_lon, bottom_right_lat, top_left_lon,
              top_left_lat):
     self.__south_east__ = point.Point(latitude=bottom_right_lat,
                                       longitude=bottom_right_lon)
     self.__north_west__ = point.Point(latitude=top_left_lat,
                                       longitude=top_left_lon)
Exemplo n.º 11
0
def CheckStreet(point,edges2,axe):
    """
    
    """
    global shortest ,closest_street,closest_street_2,street_2_counter,second_shortest_line,answer_streets
    intersection = False
    intersection_streets =[]
    answer =""
    shortest_distance=0.000
    on_line = False
    shortest = 100
    shortest_line = LineString([(0, 0), (1, 1)])
    second_shortest_line = LineString([(0, 0), (1, 1)])
    print edges2['highway'][1]
    for line in edges2.geometry:
##        print line.boundary
##        print "yolo"
        if (isBetween(line,point_gp)):
            on_line = True
            closest_street_2 = answer
            answer = FilterContains(line,edges2)
            break
        else:
            x,y= zip(*list((p.x, p.y) for p in line.boundary))
            a = gp.Point(longitude = x[0],latitude=y[0])
            b = gp.Point(longitude=x[1],latitude=y[1])
            temp = distance(midpoint(a, b), point_gp)
            if( (distance(a,point_gp) < threshold or distance(b,point_gp)<threshold) and distance(midpoint(a,b),point_gp)>threshold):
                print "here" ,FilterContains(line,edges2)
                
                intersection = True
                if FilterContains(line,edges2) not in intersection_streets:
                    intersection_streets.append(FilterContains(line,edges2))
                
            if (shortest == temp):
                print "equal! and the distance to edge is " ,distance(a,point_gp),distance(b,point_gp)
                pyplot.plot(x,y,color = "green",zorder=5)
                if (closest_street_2 != answer):
                    closest_street_2 = answer
                    second_shortest_line = line

                answer = FilterContains(line,edges2)
                print "=======";print answer
                if answer not in answer_streets:answer_streets[str(answer)] =1
                else: answer_streets[str(answer)] +=1
                
            elif (shortest > temp):
                answer_streets = {}
                shortest = temp
                shortest_line = line
                if (closest_street_2 != answer):
                    closest_street_2 = answer
                answer = FilterContains(line,edges2)
                if answer not in answer_streets:answer_streets[str(answer)] =1
                else: answer_streets[str(answer)] +=1

    print answer_streets
    print intersection_streets
    if intersection == True :
        answer =  ' & '.join(intersection_streets)
        
##    if (len(answer_streets)>0):               
##        highest = max(answer_streets.values())
##        answer =([k for k, v in answer_streets.items() if v == highest])
    
        print "FINAL ANSWER: "
    print shortest
    if (shortest > 0.01):
        print "HOOOOOOHHHHHAAAAAAAAA~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
        print closest_street_2
        print point.hausdorff_distance(shortest_line)
        print "Second shortest:"
        print point.hausdorff_distance(second_shortest_line)
                                         
    answer = "say '" + answer+"'"
    system(answer)
Exemplo n.º 12
0
"""
Initialization variables for the device
"""
epsilon = sys.float_info.epsilon
shortest = 500.000000000000000000000000
closest_street=""
closest_street_2 = ""
street_2_counter =0
on_line = False
shortest_line = LineString([(0, 0), (1, 1)])
second_shortest_line = LineString([(0, 0), (1, 1)])
fillmore_point = Point(-122.435076,37.791517)
location_point = Point(-122.434286,37.790951)
clay_point = Point(-122.432635,37.791110)
webster_point = Point( 0,0)
point_gp = gp.Point(latitude =0,longitude=0)
point=Point( -122.433423,37.789927)
##Latitude and longitude of the box of area covered on the map
left = -83.7410
right = -83.73698
top = 42.28126
bottom = 42.27850
angle = 1.5 #-9.5 for sf
threshold = (distance((top,left),(bottom,right)).kilometers-1.05 )/10

print threshold

ser = serial.Serial("/dev/tty.usbmodem146101", baudrate="115200",timeout=0.001)
## Data frames for API commands
all_up_frame = bytearray([0x1B,0x16,0x02])
success_frame = bytearray([0x1B,0x51])