def testMapWithStyle(self): result = svgis.map(self.shp, style=self.css, scale=1000, crs=self.projection, bounds=self.bounds, clip=None) self.assertIn(self.css, result) style = 'tmp.css' with open(style, 'w') as w: w.write(self.css) try: result = svgis.map(self.shp, style=[style], scale=1000, crs=self.projection, bounds=self.bounds, clip=None) self.assertIn(self.css, result) finally: os.remove('tmp.css')
def testMap(self): # pylint: disable=duplicate-code a = svgis.map(self.shp, scale=1000, crs=self.projection, bounds=self.bounds, clip=False) with open('a.svg', 'w') as A: A.write(a) try: result = minidom.parseString(a).getElementsByTagName('svg').item(0) fixture = minidom.parse( self.fixture).getElementsByTagName('svg').item(0) result_vb = [ float(x) for x in result.attributes.get('viewBox').value.split(',') ] fixture_vb = [ float(x) for x in fixture.attributes.get('viewBox').value.split(',') ] for r, f in zip(result_vb, fixture_vb): self.assertAlmostEqual(r, f, 5, 'viewbox doesnt match fixture') finally: os.remove("a.svg")
def testMapFunc(self): args = { "scale": 1000, "padding": 10, "inline_css": True, "clip": False, 'crs': 'EPSG:32117', } result = svgis.map([self.file], (-80, 40, -71, 45.1), **args) self.assertIn(svgis.STYLE, result) doc = minidom.parseString(result) for poly in doc.getElementsByTagName('polygon'): style = poly.getAttribute('style') assert 'fill:none' in style assert 'stroke-linejoin:round' in style
def testMapProjFile(self): a = svgis.map(self.shp, scale=1000, crs='tests/fixtures/test.proj4', bounds=self.bounds, clip=False) result = minidom.parseString(a).getElementsByTagName('svg').item(0) fixture = minidom.parse( self.fixture).getElementsByTagName('svg').item(0) result_vb = [ float(x) for x in result.attributes.get('viewBox').value.split(',') ] fixture_vb = [ float(x) for x in fixture.attributes.get('viewBox').value.split(',') ] for r, f in zip(result_vb, fixture_vb): self.assertAlmostEqual(r, f, 5)
def testMapFunc(self): args = { "scale": 10, "precision": 1, "padding": 10, "inline": True, "clip": False, "crs": "EPSG:2790", } result = svgis.map(self.chi_files, (-80, 40, -71, 45.1), **args) self.assertIn(svgis.STYLE, result) doc = minidom.parseString(result) for poly in doc.getElementsByTagName('polygon'): self.assertIn('polygon', poly.toxml()) self.assertIn('style', poly.toxml()) style = poly.getAttribute('style') self.assertIn('fill:none', style) self.assertIn('stroke-linejoin:round', style) # check that points have 1 decimal place points = poly.getAttribute('points') x, y = points.split(' ').pop(0).split(',') assert len(x[x.index('.') + 1 : ]) == 1 assert len(y[y.index('.') + 1 : ]) == 1
def testMapFunc(self): args = { "scale": 10, "precision": 1, "padding": 10, "inline": True, "clip": False, "crs": "EPSG:2790", } result = svgis.map(self.chi_files, (-80, 40, -71, 45.1), **args) self.assertIn(svgis.STYLE, result) doc = minidom.parseString(result) for poly in doc.getElementsByTagName('polygon'): self.assertIn('polygon', poly.toxml()) self.assertIn('style', poly.toxml()) style = poly.getAttribute('style') self.assertIn('fill:none', style) self.assertIn('stroke-linejoin:round', style) # check that points have 1 decimal place points = poly.getAttribute('points') x, y = points.split(' ').pop(0).split(',') assert len(x[x.index('.') + 1 :]) == 1 assert len(y[y.index('.') + 1 :]) == 1
#!/usr/bin/env python # -*- coding: utf-8 -*- # This file is part of svgis. # https://github.com/fitnr/svgis # Licensed under the GNU General Public License v3 (GPLv3) license: # http://www.opensource.org/licenses/GNU General Public License v3 (GPLv3)-license # Copyright (c) 2016, Neil Freeman <*****@*****.**> try: from svgis import svgis except ImportError: from build.lib.svgis import svgis if __name__ == '__main__': shp = 'tests/test_data/cb_2014_us_nation_20m.shp' css = 'polygon{fill:green}' PROJECTION = '+proj=lcc +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs' BOUNDS = (-124.0, 20.5, -64.0, 49.0) svgis.map(shp, style=css, scale=1000, crs=PROJECTION, bounds=BOUNDS, clip=True, inline=True)