コード例 #1
0
	def test_equal_distance_between_points(self):

		#Distance should be the same, no matter the order the points are inputted
		distance1 = gu.calculate_distance_between_points(self.reference1[0], self.reference1[1], self.reference2[0],self.reference2[1])
		distance2 = gu.calculate_distance_between_points(self.reference2[0], self.reference2[1], self.reference1[0],self.reference1[1])

		self.assertEqual(distance2, distance1)
コード例 #2
0
    def __init__(self, address = None):

        if address:
            if not self._is_in_chicago(address):
                raise ValueError('Address not in Chicago')

        else:
            self.get_address()

        self.formatted_address = self.address_info['formatted_address']
        self.lat,self.lon = self._get_address_lat_lon()
        self.district = get_district_from_lat_lon((self.lat,self.lon))
        self.street_address = self._get_street_address()

        police_station_lat, police_station_lon  = get_police_station_coordinates(self.district)
        self.distance_to_police_station = calculate_distance_between_points(self.lat,self.lon, police_station_lat, police_station_lon)

        self.summary = None
コード例 #3
0
ファイル: statistics.py プロジェクト: mx419/final_project
    def _get_data_crime_circle(self,fullDataCrime):
        """ Receives a non-filtered DF
        Computes the database of the points inside the circle by filtering them by distance 
        :param fullDataCrime
        """        
        #Getting boundaries
        boundaries = self._get_circle_boundaries()

        districts = fullDataCrime['District'].unique()        
        
        if len(districts)== 0:
            raise ValueError("There are no districts in data")        

        district_polygons = {dist: du.get_polygon(dist) for dist in districts}

        districts_to_search = []
        
        #Filtering districts where the circle has values, to optimize time
        for bound in boundaries:
            for dist in district_polygons.keys():
                if dist not in districts_to_search: 
                    if gu.return_points_in_polygon([bound],district_polygons[dist]):
                        districts_to_search.append(dist)

        dataframe = fullDataCrime[fullDataCrime['District'].isin(districts_to_search)]

        #Getting the points inside of circle by distance (less equal than 1 mile)
        index_of_entries_in_circle = []

        for entry in dataframe.index:
            lat, lon = dataframe.ix[entry].Latitude, dataframe.ix[entry].Longitude

            if gu.calculate_distance_between_points(self.address.lat, self.address.lon, lat, lon) <= 1:
                index_of_entries_in_circle.append(entry)

        return dataframe.ix[index_of_entries_in_circle]