예제 #1
0
 def test_translate_decreasing_lat_and_lon(self):
     initial_point = LatLon(45, 45)
     expected_point = LatLon(44.9980984, 44.99779783)
     delta_tuple = (-211.3263391, -173.6395534)
     self.assertAlmostEqual(
         initial_point.translate(delta_tuple).lat, expected_point.lat)
     self.assertAlmostEqual(
         initial_point.translate(delta_tuple).lon, expected_point.lon)
예제 #2
0
 def test_translate(self):
     initial_point = LatLon(45, 45)
     expected_point = LatLon(45.0039935, 45.00182566)
     delta_tuple = (443.8065667, 143.9373575)
     self.assertAlmostEqual(
         initial_point.translate(delta_tuple).lat, expected_point.lat)
     self.assertAlmostEqual(
         initial_point.translate(delta_tuple).lon, expected_point.lon)
예제 #3
0
 def test_translate_decreasing_lon(self):
     initial_point = LatLon(45, 45)
     expected_point = LatLon(45.00250709, 44.99860589)
     delta_tuple = (278.6178914, -109.9165341)
     self.assertAlmostEqual(
         initial_point.translate(delta_tuple).lat, expected_point.lat)
     self.assertAlmostEqual(
         initial_point.translate(delta_tuple).lon, expected_point.lon)
예제 #4
0
 def test_eq_is_commutative(self):
     point = LatLon(25, 190)
     equivalent_point = LatLon(25, -170)
     not_equivalent_point = LatLon(35, -170)
     self.assertEqual(point, equivalent_point)
     self.assertEqual(equivalent_point, point)
     self.assertNotEqual(point, not_equivalent_point)
     self.assertNotEqual(not_equivalent_point, point)
예제 #5
0
 def test_translate_decreasing_lat(self):
     initial_point = LatLon(45, 45)
     expected_point = LatLon(44.99818284, 45.00489128)
     delta_tuple = (-201.9322713, 385.6743932)
     self.assertAlmostEqual(
         initial_point.translate(delta_tuple).lat, expected_point.lat)
     self.assertAlmostEqual(
         initial_point.translate(delta_tuple).lon, expected_point.lon)
예제 #6
0
 def test_delta_in_meters_decreasing_lat(self):
     initial_point = LatLon(10, 65)
     final_point = LatLon(9, 65)
     expected_delta = (-110598.9407, 0.0000000002)
     self.assertAlmostEqual(initial_point.delta_in_meters(final_point)[0],
                            expected_delta[0],
                            places=4)
     self.assertAlmostEqual(initial_point.delta_in_meters(final_point)[1],
                            expected_delta[1],
                            places=4)
예제 #7
0
 def test_delta_in_meters_decreasing_lon(self):
     initial_point = LatLon(10, 65)
     final_point = LatLon(10, 64)
     expected_delta = (166.1395712, -109633.7978)
     self.assertAlmostEqual(initial_point.delta_in_meters(final_point)[0],
                            expected_delta[0],
                            places=4)
     self.assertAlmostEqual(initial_point.delta_in_meters(final_point)[1],
                            expected_delta[1],
                            places=4)
예제 #8
0
 def test_delta_in_meters_with_no_displacement(self):
     initial_point = LatLon(10, 65)
     final_point = LatLon(10, 65)
     expected_delta = (0, 0)
     self.assertAlmostEqual(initial_point.delta_in_meters(final_point)[0],
                            expected_delta[0],
                            places=4)
     self.assertAlmostEqual(initial_point.delta_in_meters(final_point)[1],
                            expected_delta[1],
                            places=4)
예제 #9
0
 def test_delta_in_meters_increasing_lat(self):
     initial_point = LatLon(10, 65)
     final_point = LatLon(11, 65)
     expected_delta = (110605.5709, 0.0000000002)
     self.assertAlmostEqual(initial_point.delta_in_meters(final_point)[0],
                            expected_delta[0],
                            places=4)
     self.assertAlmostEqual(initial_point.delta_in_meters(final_point)[1],
                            expected_delta[1],
                            places=4)
예제 #10
0
 def test_is_inside_in_the_boundary(self):
     self.assertTrue(
         LatLon(45, -10).is_inside(LatLon(45, -20), LatLon(10, 10)))
     self.assertTrue(
         LatLon(45, -10).is_inside(LatLon(40, -10), LatLon(50, 10)))
     # in the corner
     self.assertTrue(
         LatLon(45, -10).is_inside(LatLon(45, -10), LatLon(50, 10)))
예제 #11
0
 def test_midpoint(self):
     self.assertEqual(
         LatLon(60, 80).midpoint(LatLon(20, 20)), LatLon(40, 50))
     # with midpoint on the 0 meridian
     self.assertEqual(
         LatLon(-15, 80).midpoint(LatLon(15, -80)), LatLon(0, 0))
     # with midpoint on the 180 meridian
     self.assertEqual(
         LatLon(-15, 100).midpoint(LatLon(15, -100)), LatLon(0, 180))
예제 #12
0
    def _buid_city(self):
        city = City()

        # Get origin of the map (we use the center)
        tree = ET.parse(self.osm_map)
        bounds = tree.find('bounds').attrib
        self.bounds = {
            'origin': LatLon(float(bounds['minlat']), float(bounds['minlon'])),
            'corner': LatLon(float(bounds['maxlat']), float(bounds['maxlon']))
        }

        self.map_origin = self.bounds['origin'].midpoint(self.bounds['corner'])

        logger.debug("Map Origin: {0}".format(self.map_origin))

        # Calculate bounding box based on lat/lon
        min_xy = self._translate_coords(self.bounds['origin'])
        max_xy = self._translate_coords(self.bounds['corner'])
        self.bounding_box = BoundingBox(min_xy, max_xy)

        self.bounds['size'] = abs(min_xy) * 2

        logger.debug("Bound box size {0}".format(self.bounds['size']))
        logger.debug("Bounding box from {0} to {1}".format(
            self.bounds['origin'], self.bounds['corner']))

        # Parse OSM map
        self.parser = OSMParser(coords_callback=self._get_coords,
                                ways_callback=self._get_ways)
        self.parser.parse(self.osm_map)

        logger.debug("Number of ways: {}".format(len(self.osm_ways)))
        logger.debug("Number of coords: {}".format(len(self.osm_coords)))

        # Ground plane
        city.set_ground_plane(
            GroundPlane(max(self.bounds['size'].x, self.bounds['size'].y),
                        Point(0, 0, 0)))

        self._create_roads(city)
        self._create_intersections(city)
        # self._create_buildings(city)

        city.trim_roads()

        return city
예제 #13
0
 def _get_coords(self, coords):
     ''' OSM parser callback for the coords '''
     # osmid: OSM id for the node
     # lat, lon: latitude and longitude of the node
     for osmid, lon, lat in coords:
         lat_lon = LatLon(lat, lon)
         self.osm_coords[osmid] = {
             'lat_lon': lat_lon,
             'point': self._translate_coords(lat_lon)
         }
예제 #14
0
 def test_midpont_with_midpoint_near_180_meridian(self):
     # midpoint with positive longitude
     self.assertEqual(
         LatLon(20, -160).midpoint(LatLon(40, 140)), LatLon(30, 170))
     # midpoint with negative longitude
     self.assertEqual(
         LatLon(20, -100).midpoint(LatLon(40, 160)), LatLon(30, -150))
예제 #15
0
 def _create_buildings(self, city):
     '''
     Iterate the ways to find the buildings data and create model buildings
     with it.
     '''
     for key, value in self.osm_ways.iteritems():
         tags = value['tags']
         if 'building' in tags:
             vertices = []
             for ref in value['refs']:
                 ref_lat = self.osm_coords[ref]['lat']
                 ref_lon = self.osm_coords[ref]['lon']
                 ref_pair = LatLon(ref_lat, ref_lon)
                 vertex = self._translate_coords(ref_pair)
                 vertices.append(vertex)
             if 'height' in value:
                 height = value['height']
             else:
                 height = 20
             building = Building(Point(0, 0, 0), vertices, height=height)
             city.add_building(building)
예제 #16
0
 def test_sum(self):
     point = LatLon(1, 2)
     point_to_sum = LatLon(3, 4)
     expected_result = LatLon(4, 6)
     self.assertEqual(point.sum(point_to_sum), expected_result)
예제 #17
0
 def test_normalize_on_creation(self):
     # bad lat and lon
     self.assertEqual(LatLon(100, 190).lat, 80)
     self.assertEqual(LatLon(100, 190).lon, 10)
     # lon = -180
     self.assertEqual(LatLon(25, -180).lat, 25)
     self.assertEqual(LatLon(25, -180).lon, 180)
     # already normalized point
     self.assertEqual(LatLon(45, 90).lat, 45)
     self.assertEqual(LatLon(45, 90).lon, 90)
     # lat = lon = 360
     self.assertEqual(LatLon(360, 360).lat, 0)
     self.assertEqual(LatLon(360, 360).lon, 0)
     # negative lat ad lon
     self.assertEqual(LatLon(-100, -30).lat, -80)
     self.assertEqual(LatLon(-100, -30).lon, 150)
     # normalize to negative lat and lon values
     self.assertEqual(LatLon(190, 30).lat, -10)
     self.assertEqual(LatLon(190, 30).lon, -150)
예제 #18
0
 def test_eq_in_south_pole(self):
     point_at_south_pole = LatLon(-90, 27)
     point_at_south_pole_with_different_longitude = LatLon(-90, 3)
     self.assertEqual(point_at_south_pole,
                      point_at_south_pole_with_different_longitude)
예제 #19
0
 def test_eq_in_north_pole(self):
     point_at_north_pole = LatLon(90, 7)
     point_at_north_pole_with_different_longitude = LatLon(90, 54)
     self.assertEqual(point_at_north_pole,
                      point_at_north_pole_with_different_longitude)
예제 #20
0
 def test_eq_between_maximal_and_minimal_longitude(self):
     point_with_lon_180 = LatLon(25, 180)
     point_with_same_lat_and_lon_minus180 = LatLon(25, -180)
     self.assertEqual(point_with_lon_180,
                      point_with_same_lat_and_lon_minus180)
예제 #21
0
 def _generate_rndf(self, city):
     self.generator = RNDFGenerator(city, LatLon(10, 65))
     self.generated_contents = self.generator.generate()
예제 #22
0
 def test_eq_on_different_objects(self):
     point = LatLon(0, 0)
     different_point = LatLon(1, 2)
     self.assertFalse(point == different_point)
예제 #23
0
 def test_eq_on_non_identical_objects(self):
     point = LatLon(0, 0)
     other_point_with_same_lat_and_lon = LatLon(0, 0)
     self.assertTrue(point == other_point_with_same_lat_and_lon)
예제 #24
0
 def test_eq_on_identical_objects(self):
     point = LatLon(0, 0)
     self.assertTrue(point == point)
예제 #25
0
 def test_sum_exceeding_maximal_latitud(self):
     point = LatLon(45, 30)
     point_to_sum = LatLon(60, 20)
     expected_result = LatLon(75, -130)
     self.assertEqual(point.sum(point_to_sum), expected_result)
예제 #26
0
 def test_is_inside(self):
     # when it is inside
     self.assertTrue(
         LatLon(0, 0).is_inside(LatLon(-10, -10), LatLon(10, 10)))
     self.assertTrue(
         LatLon(0, 180).is_inside(LatLon(-10, -170), LatLon(10, 170)))
     # when it is not inside
     self.assertIsNone(
         LatLon(0, 0).is_inside(LatLon(-20, -20), LatLon(-40, -40)))
     self.assertIsNone(
         LatLon(30, 45).is_inside(LatLon(40, 40), LatLon(20, 10)))
예제 #27
0
 def test_midpoint_of_equal_points(self):
     self.assertEqual(
         LatLon(35, 80).midpoint(LatLon(35, 80)), LatLon(35, 80))
     self.assertEqual(
         LatLon(40, 165).midpoint(LatLon(40, 165)), LatLon(40, 165))
예제 #28
0
 def test_midpoint_of_points_on_the_same_parallel(self):
     self.assertEqual(
         LatLon(30, -110).midpoint(LatLon(30, -90)), LatLon(30, -100))
예제 #29
0
 def test_midpoint_of_points_on_the_same_meridian(self):
     self.assertEqual(
         LatLon(-10, 80).midpoint(LatLon(-30, 80)), LatLon(-20, 80))
예제 #30
0
 def test_translate_zero(self):
     point = LatLon(35, 20)
     self.assertEqual(point, point.translate((0, 0)))