karimbahgat / GeoVis

Python module to visualize shapefiles on a map
MIT License
38 stars 13 forks source link

KeyError: 'linux' #4

Closed glepore70 closed 9 years ago

glepore70 commented 9 years ago

I'm getting the error below, any ideas? Look like the code doesn't support linux, since it only looks in Windows directories for fonts.

lepore@lepore-desktop:/media/bigmedia/old/nara/shapefile$ python test.py

rendering blockgroups 0%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,100% ||||||||||||||||||||||||||||||||||||||||||||||||| task completed in 0.084586 seconds

Traceback (most recent call last): File "test.py", line 2, in geovis.ViewShapefile("blockgroups.shp") File "/home/lepore/.local/lib/python2.7/site-packages/geovis/init.py", line 2593, in ViewShapefile renderer.ViewShapefile(shapefilepath, customoptions) File "/home/lepore/.local/lib/python2.7/site-packages/geovis/init.py", line 1784, in ViewShapefile self._RenderMapTitle(shapefilepath, customoptions) File "/home/lepore/.local/lib/python2.7/site-packages/geovis/init.py", line 1807, in _RenderMapTitle self._RenderText(0.5, 0.05, customoptions["maptitle"], textoptions) File "/home/lepore/.local/lib/python2.7/site-packages/geovis/init.py", line 1809, in _RenderText self.renderer.RenderText(relx, rely, text, textoptions) File "/home/lepore/.local/lib/python2.7/site-packages/geovis/init.py", line 956, in RenderText self._BasicText(relx, rely, text, options) File "/home/lepore/.local/lib/python2.7/site-packages/geovis/init.py", line 1065, in _BasicText fontlocation = self.sysfontfolders[OSSYSTEM]+self.fontfilenames[options["textfont"]] KeyError: 'linux'

karimbahgat commented 9 years ago

You're right, I never used it on anything besides windows so I never added the folder lookups for other systems. Updated the code now with what I understand to be the default font folders for linux and mac. Just redownload the latest code from github and let me know if it still does not work or if the folders are wrong.

glepore70 commented 9 years ago

That got me past the initial error, now I'm running into an error where aggdraw is looking in the wrong location for fonts. It seems the fix is to re-install aggdraw with a custom FREETYPE font location defined, but I don't really want to do that. Thanks anyway.

rendering blockgroups 0%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,100% ||||||||||||||||||||||||||||||||||||||||||||||||| task completed in 0.082135 seconds

Traceback (most recent call last): File "test.py", line 2, in geovis.ViewShapefile("blockgroups.shp") File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 2599, in ViewShapefile renderer.ViewShapefile(shapefilepath, customoptions) File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 1790, in ViewShapefile self._RenderMapTitle(shapefilepath, customoptions) File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 1813, in _RenderMapTitle self._RenderText(0.5, 0.05, customoptions["maptitle"], textoptions) File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 1815, in _RenderText self.renderer.RenderText(relx, rely, text, textoptions) File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 1456, in RenderText self._BasicText(relx, rely, text, options) File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 1490, in _BasicText font = aggdraw.Font(color=options["textcolor"], file=fontlocation, size=options["textsize"], opacity=options["textopacity"]) IOError: cannot load font (no text renderer)

karimbahgat commented 9 years ago

Actually your new error is not related to the location of fonts at all, it just means that you cant draw text using the aggdraw renderer because you didnt install it with the freetype lib as you say. Instead just use a different renderer, so for instance:

geovis.SetRenderingOptions('PIL')

Or:

geovis.SetRenderingOptions('pycairo')

glepore70 commented 9 years ago

Getting a bit further, but no luck with either PIL or pycairo:

rendering blockgroups 0%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,100% ||||||||||||||||||||||||||||||||||||||||||||||||| task completed in 0.34003 seconds

Traceback (most recent call last): File "test.py", line 3, in geovis.ViewShapefile("blockgroups.shp") File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 2599, in ViewShapefile renderer.ViewShapefile(shapefilepath, customoptions) File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 1790, in ViewShapefile self._RenderMapTitle(shapefilepath, customoptions) File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 1813, in _RenderMapTitle self._RenderText(0.5, 0.05, customoptions["maptitle"], textoptions) File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 1815, in _RenderText self.renderer.RenderText(relx, rely, text, textoptions) File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 958, in RenderText self._BasicText(relx, rely, text, options) File "/media/bigmedia/old/nara/shapefile/geovis/init.py", line 1068, in _BasicText font = PIL.ImageFont.truetype(fontlocation, size=options["textsize"]) File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 260, in truetype return FreeTypeFont(font, size, index, encoding) File "/usr/lib/python2.7/dist-packages/PIL/ImageFont.py", line 140, in init self.font = core.getfont(font, size, index, encoding) IOError: cannot open resource lepore@lepore-desktop:/media/bigmedia/old/nara/shapefile$ python test.py

rendering blockgroups 0%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,100% ||||||||||||||||||||||||||||||||||||||||||||||||| task completed in 0.358922 seconds

Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 810, in *bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 763, in run self.__target(_self.__args, _self.kwargs) File "/media/bigmedia/old/nara/shapefile/geovis/init**.py", line 1883, in ViewInTkinter resizedimg = self.renderer.img.resize((viewimgwidth,viewimgheight), PIL.Image.ANTIALIAS) AttributeError: 'cairo.ImageSurface' object has no attribute 'resize'