File: mapnik_test_data_test.py

package info (click to toggle)
python-mapnik 1%3A0.0~20240222-5ab32f020-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,364 kB
  • sloc: python: 11,685; cpp: 5,776; sh: 242; makefile: 10
file content (43 lines) | stat: -rw-r--r-- 1,564 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
from glob import glob
import mapnik

plugin_mapping = {
    '.csv': ['csv'],
    '.json': ['geojson', 'ogr'],
    '.tif': ['gdal'],
    #'.tif' : ['gdal','raster'],
    '.kml': ['ogr'],
    '.gpx': ['ogr'],
    '.vrt': ['gdal']
}


def test_opening_data():
    # https://github.com/mapbox/mapnik-test-data
    # cd tests/data
    # git clone --depth 1 https://github.com/mapbox/mapnik-test-data
    if os.path.exists('../data/mapnik-test-data/'):
        files = glob('../data/mapnik-test-data/data/*/*.*')
        for filepath in files:
            ext = os.path.splitext(filepath)[1]
            if plugin_mapping.get(ext):
                # print 'testing opening %s' % filepath
                if 'topo' in filepath:
                    kwargs = {'type': 'ogr', 'file': filepath}
                    kwargs['layer_by_index'] = 0
                    try:
                        mapnik.Datasource(**kwargs)
                    except Exception as e:
                        print('could not open, %s: %s' % (kwargs, e))
                else:
                    for plugin in plugin_mapping[ext]:
                        kwargs = {'type': plugin, 'file': filepath}
                        if plugin == 'ogr':
                            kwargs['layer_by_index'] = 0
                        try:
                            mapnik.Datasource(**kwargs)
                        except Exception as e:
                            print('could not open, %s: %s' % (kwargs, e))
            # else:
            #    print 'skipping opening %s' % filepath