Ejemplo n.º 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)
Ejemplo n.º 2
0
    def doFileConversion(self, path):
        ''' Test conversion results for named file.
        '''
        geojson = transformers.shapefile2geojson(path)

        #
        # Is it GeoJSON?
        #
        self.assertEqual(geojson['type'], 'FeatureCollection')

        if 'lake-man-' in path:
            self.assertEqual(len(geojson['features']), 6)
            self.assertEqual(set([f['geometry']['type'] for f in geojson['features']]), set(['LineString']))

        elif 'lake-points-' in path:
            self.assertEqual(len(geojson['features']), 5)
            self.assertEqual(set([f['geometry']['type'] for f in geojson['features']]), set(['Point']))

        #
        # Does it cover the expected geographic area?
        #
        lons, lats = [], []

        for f in geojson['features']:
            if f['geometry']['type'] == 'LineString':
                lons.extend([x for (x, y) in f['geometry']['coordinates']])
                lats.extend([y for (x, y) in f['geometry']['coordinates']])
            elif f['geometry']['type'] == 'Point':
                lons.append(f['geometry']['coordinates'][0])
                lats.append(f['geometry']['coordinates'][1])

        self.assertTrue(37.8007 < min(lats) and max(lats) < 37.8044)
        self.assertTrue(-122.2593 < min(lons) and max(lons) < -122.2567)
Ejemplo n.º 3
0
    def test_segments_conversion_Nested(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-man-Nested.zip'))
        geojson = transformers.shapefile2geojson(join(self.tmp, path))

        m, converted_geojson = transformers.segments_transform(geojson, None)
        self.assertEqual(len(m), 2)
Ejemplo n.º 4
0
    def test_segments_conversion_Nested(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-man-Nested.zip'))
        geojson = transformers.shapefile2geojson(join(self.tmp, path))

        m, converted_geojson = transformers.segments_transform(geojson, None)
        self.assertEqual(len(m), 2)
Ejemplo n.º 5
0
    def test_segments_conversion_San_Antonio(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-man-San-Antonio.zip'))
        geojson = transformers.shapefile2geojson(join(self.tmp, path))

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

        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']['Name'] for f in geojson['features']]
        self.assertEqual(converted_names, expected_names)

        converted_foots = [
            f['properties']['foot'] for f in converted_geojson['features']
        ]
        expected_foots = [None for f in geojson['features']]
        self.assertEqual(converted_foots, expected_foots)

        converted_bikes = [
            f['properties']['bicycle'] for f in converted_geojson['features']
        ]
        expected_bikes = [None for f in geojson['features']]
        self.assertEqual(converted_bikes, expected_bikes)

        converted_horses = [
            f['properties']['horse'] for f in converted_geojson['features']
        ]
        expected_horses = [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 = [None for f in geojson['features']]
        self.assertEqual(converted_skis, expected_skis)

        converted_wheelchairs = [
            f['properties']['wheelchair']
            for f in converted_geojson['features']
        ]
        expected_wheelchairs = [None for f in geojson['features']]
        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)
Ejemplo n.º 6
0
    def test_trailheads_conversion_Ohio(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-points-Ohio.zip'))
        geojson = transformers.shapefile2geojson(join(self.tmp, path))

        m, converted_geojson = transformers.trailheads_transform(geojson, None)

        self.assertEqual(len(m), 1)

        converted_ids = [f['properties']['id'] for f in converted_geojson['features']]
        expected_ids = [f['properties']['id'] for f in geojson['features']]
        self.assertEqual(converted_ids, expected_ids)

        converted_names = [f['properties']['name'] for f in converted_geojson['features']]
        expected_names = [f['properties']['name'] for f in geojson['features']]
        self.assertEqual(converted_names, expected_names)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
    def test_segments_conversion_Santa_Clara(self):
        """ Test overall segments conversion.
        """
        path = unzip(join(self.tmp, "lake-man-Santa-Clara.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 = [f["properties"]["OBJECTID"] for f in geojson["features"]]
        self.assertEqual(converted_ids, expected_ids)

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

        uses = {"hiking": "yes", "hiking/equestrian": "yes", "hiking/equestrian/bicycling": "yes"}
        converted_foots = [f["properties"]["foot"] for f in converted_geojson["features"]]
        expected_foots = [uses.get(f["properties"]["PUBUSE"], None) for f in geojson["features"]]
        self.assertEqual(converted_foots, expected_foots)

        uses = {"hiking": "no", "hiking/equestrian": "no", "hiking/equestrian/bicycling": "yes"}
        converted_bikes = [f["properties"]["bicycle"] for f in converted_geojson["features"]]
        expected_bikes = [uses.get(f["properties"]["PUBUSE"], None) for f in geojson["features"]]
        self.assertEqual(converted_bikes, expected_bikes)

        uses = {"hiking": "no", "hiking/equestrian": "yes", "hiking/equestrian/bicycling": "yes"}
        converted_horses = [f["properties"]["horse"] for f in converted_geojson["features"]]
        expected_horses = [uses.get(f["properties"]["PUBUSE"], 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 = ["no" for f in geojson["features"]]
        self.assertEqual(converted_skis, expected_skis)

        converted_wheelchairs = [f["properties"]["wheelchair"] for f in converted_geojson["features"]]
        expected_wheelchairs = [None for f in geojson["features"]]
        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)
Ejemplo n.º 10
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)

        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)
Ejemplo n.º 11
0
    def test_segments_conversion_Santa_Clara(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-man-Santa-Clara.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 = [str(f['properties']['OBJECTID']) for f in geojson['features']]
        self.assertEqual(converted_ids, expected_ids)

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

        uses = {'hiking': 'yes', 'hiking/equestrian': 'yes', 'hiking/equestrian/bicycling': 'yes'}
        converted_foots = [f['properties']['foot'] for f in converted_geojson['features']]
        expected_foots = [uses.get(f['properties']['PUBUSE'], None) for f in geojson['features']]
        self.assertEqual(converted_foots, expected_foots)

        uses = {'hiking': 'no', 'hiking/equestrian': 'no', 'hiking/equestrian/bicycling': 'yes'}
        converted_bikes = [f['properties']['bicycle'] for f in converted_geojson['features']]
        expected_bikes = [uses.get(f['properties']['PUBUSE'], None) for f in geojson['features']]
        self.assertEqual(converted_bikes, expected_bikes)

        uses = {'hiking': 'no', 'hiking/equestrian': 'yes', 'hiking/equestrian/bicycling': 'yes'}
        converted_horses = [f['properties']['horse'] for f in converted_geojson['features']]
        expected_horses = [uses.get(f['properties']['PUBUSE'], 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 = ['no' for f in geojson['features']]
        self.assertEqual(converted_skis, expected_skis)

        converted_wheelchairs = [f['properties']['wheelchair'] for f in converted_geojson['features']]
        expected_wheelchairs = [None for f in geojson['features']]
        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)
Ejemplo n.º 12
0
    def test_trailheads_conversion_Ohio(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-points-Ohio.zip'))
        geojson = transformers.shapefile2geojson(join(self.tmp, path))

        m, converted_geojson = transformers.trailheads_transform(geojson, None)

        self.assertEqual(len(m), 1)

        converted_ids = [
            f['properties']['id'] for f in converted_geojson['features']
        ]
        expected_ids = [f['properties']['id'] for f in geojson['features']]
        self.assertEqual(converted_ids, expected_ids)

        converted_names = [
            f['properties']['name'] for f in converted_geojson['features']
        ]
        expected_names = [f['properties']['name'] for f in geojson['features']]
        self.assertEqual(converted_names, expected_names)
Ejemplo n.º 13
0
    def test_segments_conversion_San_Antonio(self):
        """ Test overall segments conversion.
        """
        path = unzip(join(self.tmp, "lake-man-San-Antonio.zip"))
        geojson = transformers.shapefile2geojson(join(self.tmp, path))

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

        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"]["Name"] for f in geojson["features"]]
        self.assertEqual(converted_names, expected_names)

        converted_foots = [f["properties"]["foot"] for f in converted_geojson["features"]]
        expected_foots = [None for f in geojson["features"]]
        self.assertEqual(converted_foots, expected_foots)

        converted_bikes = [f["properties"]["bicycle"] for f in converted_geojson["features"]]
        expected_bikes = [None for f in geojson["features"]]
        self.assertEqual(converted_bikes, expected_bikes)

        converted_horses = [f["properties"]["horse"] for f in converted_geojson["features"]]
        expected_horses = [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 = [None for f in geojson["features"]]
        self.assertEqual(converted_skis, expected_skis)

        converted_wheelchairs = [f["properties"]["wheelchair"] for f in converted_geojson["features"]]
        expected_wheelchairs = [None for f in geojson["features"]]
        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)
Ejemplo n.º 14
0
    def test_segments_conversion_Portland(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-man-Portland.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 = [f['properties']['TRAILID'] for f in geojson['features']]
        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)

        converted_foots = [f['properties']['foot'] for f in converted_geojson['features']]
        expected_foots = ['yes' for f in geojson['features']]
        self.assertEqual(converted_foots, expected_foots)

        converted_bikes = [f['properties']['bicycle'] for f in converted_geojson['features']]
        expected_bikes = ['yes' for f in geojson['features']]
        self.assertEqual(converted_bikes, expected_bikes)

        converted_horses = [f['properties']['horse'] for f in converted_geojson['features']]
        expected_horses = [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 = [None for f in geojson['features']]
        self.assertEqual(converted_skis, expected_skis)

        converted_wheelchairs = [f['properties']['wheelchair'] for f in converted_geojson['features']]
        expected_wheelchairs = [None for f in geojson['features']]
        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)
Ejemplo n.º 15
0
    def test_segments_conversion_San_Antonio(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-man-San-Antonio.zip'))
        geojson = transformers.shapefile2geojson(join(self.tmp, path))

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

        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']['Name'] for f in geojson['features']]
        self.assertEqual(converted_names, expected_names)

        converted_foots = [f['properties']['foot'] for f in converted_geojson['features']]
        expected_foots = [None for f in geojson['features']]
        self.assertEqual(converted_foots, expected_foots)

        converted_bikes = [f['properties']['bicycle'] for f in converted_geojson['features']]
        expected_bikes = [None for f in geojson['features']]
        self.assertEqual(converted_bikes, expected_bikes)

        converted_horses = [f['properties']['horse'] for f in converted_geojson['features']]
        expected_horses = [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 = [None for f in geojson['features']]
        self.assertEqual(converted_skis, expected_skis)

        converted_wheelchairs = [f['properties']['wheelchair'] for f in converted_geojson['features']]
        expected_wheelchairs = [None for f in geojson['features']]
        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)
Ejemplo n.º 16
0
    def test_segments_conversion_Portland(self):
        """ Test overall segments conversion.
        """
        path = unzip(join(self.tmp, "lake-man-Portland.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 = [f["properties"]["TRAILID"] for f in geojson["features"]]
        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)

        converted_foots = [f["properties"]["foot"] for f in converted_geojson["features"]]
        expected_foots = ["yes" for f in geojson["features"]]
        self.assertEqual(converted_foots, expected_foots)

        converted_bikes = [f["properties"]["bicycle"] for f in converted_geojson["features"]]
        expected_bikes = ["yes" for f in geojson["features"]]
        self.assertEqual(converted_bikes, expected_bikes)

        converted_horses = [f["properties"]["horse"] for f in converted_geojson["features"]]
        expected_horses = [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 = [None for f in geojson["features"]]
        self.assertEqual(converted_skis, expected_skis)

        converted_wheelchairs = [f["properties"]["wheelchair"] for f in converted_geojson["features"]]
        expected_wheelchairs = [None for f in geojson["features"]]
        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)
Ejemplo n.º 17
0
    def doFileConversion(self, path):
        """ Test conversion results for named file.
        """
        geojson = transformers.shapefile2geojson(path)

        #
        # Is it GeoJSON?
        #
        self.assertEqual(geojson["type"], "FeatureCollection")
        self.assertEqual(len(geojson["features"]), 6)
        self.assertEqual(set([f["geometry"]["type"] for f in geojson["features"]]), set(["LineString"]))

        #
        # Does it cover the expected geographic area?
        #
        lons, lats = [], []

        for f in geojson["features"]:
            lons.extend([x for (x, y) in f["geometry"]["coordinates"]])
            lats.extend([y for (x, y) in f["geometry"]["coordinates"]])

        self.assertTrue(37.80071 < min(lats) and max(lats) < 37.80436)
        self.assertTrue(-122.25925 < min(lons) and max(lons) < -122.25671)
Ejemplo n.º 18
0
    def doFileConversion(self, path):
        ''' Test conversion results for named file.
        '''
        geojson = transformers.shapefile2geojson(path)

        #
        # Is it GeoJSON?
        #
        self.assertEqual(geojson['type'], 'FeatureCollection')

        if 'lake-man-' in path:
            self.assertEqual(len(geojson['features']), 6)
            self.assertEqual(
                set([f['geometry']['type'] for f in geojson['features']]),
                set(['LineString']))

        elif 'lake-points-' in path:
            self.assertEqual(len(geojson['features']), 5)
            self.assertEqual(
                set([f['geometry']['type'] for f in geojson['features']]),
                set(['Point']))

        #
        # Does it cover the expected geographic area?
        #
        lons, lats = [], []

        for f in geojson['features']:
            if f['geometry']['type'] == 'LineString':
                lons.extend([x for (x, y) in f['geometry']['coordinates']])
                lats.extend([y for (x, y) in f['geometry']['coordinates']])
            elif f['geometry']['type'] == 'Point':
                lons.append(f['geometry']['coordinates'][0])
                lats.append(f['geometry']['coordinates'][1])

        self.assertTrue(37.8007 < min(lats) and max(lats) < 37.8044)
        self.assertTrue(-122.2593 < min(lons) and max(lons) < -122.2567)
Ejemplo n.º 19
0
    def test_segments_conversion_Santa_Clara(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-man-Santa-Clara.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 = [
            str(f['properties']['OBJECTID']) for f in geojson['features']
        ]
        self.assertEqual(converted_ids, expected_ids)

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

        uses = {
            'hiking': 'yes',
            'hiking/equestrian': 'yes',
            'hiking/equestrian/bicycling': 'yes'
        }
        converted_foots = [
            f['properties']['foot'] for f in converted_geojson['features']
        ]
        expected_foots = [
            uses.get(f['properties']['PUBUSE'], None)
            for f in geojson['features']
        ]
        self.assertEqual(converted_foots, expected_foots)

        uses = {
            'hiking': 'no',
            'hiking/equestrian': 'no',
            'hiking/equestrian/bicycling': 'yes'
        }
        converted_bikes = [
            f['properties']['bicycle'] for f in converted_geojson['features']
        ]
        expected_bikes = [
            uses.get(f['properties']['PUBUSE'], None)
            for f in geojson['features']
        ]
        self.assertEqual(converted_bikes, expected_bikes)

        uses = {
            'hiking': 'no',
            'hiking/equestrian': 'yes',
            'hiking/equestrian/bicycling': 'yes'
        }
        converted_horses = [
            f['properties']['horse'] for f in converted_geojson['features']
        ]
        expected_horses = [
            uses.get(f['properties']['PUBUSE'], 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 = ['no' for f in geojson['features']]
        self.assertEqual(converted_skis, expected_skis)

        converted_wheelchairs = [
            f['properties']['wheelchair']
            for f in converted_geojson['features']
        ]
        expected_wheelchairs = [None for f in geojson['features']]
        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)
Ejemplo n.º 20
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)
Ejemplo n.º 21
0
    def test_segments_conversion_Portland(self):
        ''' Test overall segments conversion.
        '''
        path = unzip(join(self.tmp, 'lake-man-Portland.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 = [
            f['properties']['TRAILID'] for f in geojson['features']
        ]
        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)

        converted_foots = [
            f['properties']['foot'] for f in converted_geojson['features']
        ]
        expected_foots = ['yes' for f in geojson['features']]
        self.assertEqual(converted_foots, expected_foots)

        converted_bikes = [
            f['properties']['bicycle'] for f in converted_geojson['features']
        ]
        expected_bikes = ['yes' for f in geojson['features']]
        self.assertEqual(converted_bikes, expected_bikes)

        converted_horses = [
            f['properties']['horse'] for f in converted_geojson['features']
        ]
        expected_horses = [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 = [None for f in geojson['features']]
        self.assertEqual(converted_skis, expected_skis)

        converted_wheelchairs = [
            f['properties']['wheelchair']
            for f in converted_geojson['features']
        ]
        expected_wheelchairs = [None for f in geojson['features']]
        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)