Example #1
0
    def test_segments_conversion_Boulder_County(self):
        ''' Test overall segments conversion.
        '''

        copy('test-files/Boulder_County_Trails.zip', self.tmp)

        path = unzip(join(self.tmp, 'Boulder_County_Trails.zip'))
        geojson = transformers.shapefile2geojson(join(self.tmp, path))

        m, converted_geojson = transformers.segments_transform(geojson, None)
        # self.assertEqual(len(m), 2)

        # converted_ids = [f['properties']['id'] for f in converted_geojson['features']]
        # expected_ids = map(str, range(1, len(converted_ids) + 1))
        # self.assertEqual(converted_ids, expected_ids)

        converted_names = [f['properties']['name'] for f in converted_geojson['features']]
        expected_names = [f['properties']['trailname'] for f in geojson['features']]
        self.assertEqual(converted_names, expected_names)

        self.assertEqual(converted_names.count('Coal Creek Trail'),12)

        named_trails = make_named_trails(converted_geojson['features'])
        coal_creek = [t['name'] for t in named_trails if t['name'] == 'Coal Creek Trail']
        willows = [t['name'] for t in named_trails if t['name'] == 'Willows Trail']
        ninetyfifth = [t['name'] for t in named_trails if t['name'] == '95th Street']
        niwot = [t['name'] for t in named_trails if t['name'] == 'Niwot Trail System']

        expected = [1,1,1,1]
        actual = [len(willows),len(niwot),len(coal_creek),len(ninetyfifth)]
        self.assertEqual(actual,expected)
Example #2
0
    def test_segments_conversion_GGNRA(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-man-GGNRA.zip'))
        geojson = transformers.shapefile2geojson(join(self.tmp, path))

        m, converted_geojson = transformers.segments_transform(geojson, None)
        self.assertEqual(len(m), 2)

        converted_ids = [f['properties']['id'] for f in converted_geojson['features']]
        expected_ids = map(str, range(1, len(converted_ids) + 1))
        self.assertEqual(converted_ids, expected_ids)

        converted_names = [f['properties']['name'] for f in converted_geojson['features']]
        expected_names = [f['properties']['trail_name'] for f in geojson['features']]
        self.assertEqual(converted_names, expected_names)

        named_trails = make_named_trails(converted_geojson['features'])
        self.assertEqual(len(named_trails), 4)

        uses = {'Multi-Use': 'yes', 'Hiking': 'yes', 'Hiking and Horses': 'yes'}
        converted_foots = [f['properties']['foot'] for f in converted_geojson['features']]
        expected_foots = [uses.get(f['properties']['use_type'], None) for f in geojson['features']]
        self.assertEqual(converted_foots, expected_foots)

        uses = {'Multi-Use': 'yes', 'Hiking': 'no', 'Hiking and Horses': 'no'}
        converted_bikes = [f['properties']['bicycle'] for f in converted_geojson['features']]
        expected_bikes = [uses.get(f['properties']['use_type'], None) for f in geojson['features']]
        self.assertEqual(converted_bikes, expected_bikes)

        uses = {'Multi-Use': 'no', 'Hiking': 'no', 'Hiking and Horses': 'yes'}
        converted_horses = [f['properties']['horse'] for f in converted_geojson['features']]
        expected_horses = [uses.get(f['properties']['use_type'], None) for f in geojson['features']]
        self.assertEqual(converted_horses, expected_horses)

        converted_skis = [f['properties']['ski'] for f in converted_geojson['features']]
        expected_skis = ['yes', 'no', 'yes', 'yes', None, 'yes']
        self.assertEqual(converted_skis, expected_skis)

        converted_wheelchairs = [f['properties']['wheelchair'] for f in converted_geojson['features']]
        expected_wheelchairs = [None] * 6
        self.assertEqual(converted_wheelchairs, expected_wheelchairs)

        converted_motor_vehicles = [f['properties']['motor_vehicles'] for f in converted_geojson['features']]
        expected_motor_vehicles = [None for f in geojson['features']]
        self.assertEqual(converted_motor_vehicles, expected_motor_vehicles)
Example #3
0
    def test_segments_conversion_Boulder_County(self):
        ''' Test overall segments conversion.
        '''

        copy('test-files/Boulder_County_Trails.zip', self.tmp)

        path = unzip(join(self.tmp, 'Boulder_County_Trails.zip'))
        geojson = transformers.shapefile2geojson(join(self.tmp, path))

        m, converted_geojson = transformers.segments_transform(geojson, None)
        # self.assertEqual(len(m), 2)

        # converted_ids = [f['properties']['id'] for f in converted_geojson['features']]
        # expected_ids = map(str, range(1, len(converted_ids) + 1))
        # self.assertEqual(converted_ids, expected_ids)

        converted_names = [
            f['properties']['name'] for f in converted_geojson['features']
        ]
        expected_names = [
            f['properties']['trailname'] for f in geojson['features']
        ]
        self.assertEqual(converted_names, expected_names)

        self.assertEqual(converted_names.count('Coal Creek Trail'), 12)

        named_trails = make_named_trails(converted_geojson['features'])
        coal_creek = [
            t['name'] for t in named_trails if t['name'] == 'Coal Creek Trail'
        ]
        willows = [
            t['name'] for t in named_trails if t['name'] == 'Willows Trail'
        ]
        ninetyfifth = [
            t['name'] for t in named_trails if t['name'] == '95th Street'
        ]
        niwot = [
            t['name'] for t in named_trails
            if t['name'] == 'Niwot Trail System'
        ]

        expected = [1, 1, 1, 1]
        actual = [len(willows), len(niwot), len(coal_creek), len(ninetyfifth)]
        self.assertEqual(actual, expected)
Example #4
0
    def test_segments_conversion_GGNRA(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-man-GGNRA.zip'))
        geojson = transformers.shapefile2geojson(join(self.tmp, path))

        m, converted_geojson = transformers.segments_transform(geojson, None)
        self.assertEqual(len(m), 2)

        converted_ids = [
            f['properties']['id'] for f in converted_geojson['features']
        ]
        expected_ids = map(str, range(1, len(converted_ids) + 1))
        self.assertEqual(converted_ids, expected_ids)

        converted_names = [
            f['properties']['name'] for f in converted_geojson['features']
        ]
        expected_names = [
            f['properties']['trail_name'] for f in geojson['features']
        ]
        self.assertEqual(converted_names, expected_names)

        named_trails = make_named_trails(converted_geojson['features'])
        self.assertEqual(len(named_trails), 4)

        uses = {
            'Multi-Use': 'yes',
            'Hiking': 'yes',
            'Hiking and Horses': 'yes'
        }
        converted_foots = [
            f['properties']['foot'] for f in converted_geojson['features']
        ]
        expected_foots = [
            uses.get(f['properties']['use_type'], None)
            for f in geojson['features']
        ]
        self.assertEqual(converted_foots, expected_foots)

        uses = {'Multi-Use': 'yes', 'Hiking': 'no', 'Hiking and Horses': 'no'}
        converted_bikes = [
            f['properties']['bicycle'] for f in converted_geojson['features']
        ]
        expected_bikes = [
            uses.get(f['properties']['use_type'], None)
            for f in geojson['features']
        ]
        self.assertEqual(converted_bikes, expected_bikes)

        uses = {'Multi-Use': 'no', 'Hiking': 'no', 'Hiking and Horses': 'yes'}
        converted_horses = [
            f['properties']['horse'] for f in converted_geojson['features']
        ]
        expected_horses = [
            uses.get(f['properties']['use_type'], None)
            for f in geojson['features']
        ]
        self.assertEqual(converted_horses, expected_horses)

        converted_skis = [
            f['properties']['ski'] for f in converted_geojson['features']
        ]
        expected_skis = ['yes', 'no', 'yes', 'yes', None, 'yes']
        self.assertEqual(converted_skis, expected_skis)

        converted_wheelchairs = [
            f['properties']['wheelchair']
            for f in converted_geojson['features']
        ]
        expected_wheelchairs = [None] * 6
        self.assertEqual(converted_wheelchairs, expected_wheelchairs)

        converted_motor_vehicles = [
            f['properties']['motor_vehicles']
            for f in converted_geojson['features']
        ]
        expected_motor_vehicles = [None for f in geojson['features']]
        self.assertEqual(converted_motor_vehicles, expected_motor_vehicles)