karimbahgat/GeoVis

It cannot open shapefiles

Opened this issue · 3 comments

Hello.
I installed the package by the option B, imported it successfully but got an error on the very first line from the Instant Mapping section:
geovis.ViewShapefile("C:/shapefile.shp")

The error:

Traceback (most recent call last):
File "", line 1, in
File "./GeoVis-0.2.0\geovis__init__.py", line 2321, in ViewShapefile
File "./GeoVis-0.2.0\geovis__init__.py", line 1511, in init
File "./GeoVis-0.2.0\geovis__init__.py", line 1515, in NewImage
File "./GeoVis-0.2.0\geovis__init__.py", line 909, in NewImage
File "C:\Python27\lib\site-packages\PIL\Image.py", line 2014, in new
return Image()._new(core.new(mode, size))
TypeError: integer argument expected, got float

I tried many different shapefiles, also using Customized Maps lines, but never managed to open any.
I also tried to set the size myself:
mysize = 500, 500
geovis.ViewShapefile(polygonshp, mysize)

But then I got an error:

TypeError: ViewShapefile() takes exactly 1 argument (2 given)

Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32.
So how do I use the package? Thanks.

To get it working, edit init.py and modify line 907 from:
dimensions = (width, height)
to
dimensions = (int(width), int(height))

I also had some issues with pillow and conda... but that's a different story.
ContinuumIO/anaconda-issues#150

I encountered the "TypeError: integer argument expected, got float" at first time. I used Jupyter Notebook to write my python script. I read one answer from Karimbahgat on another Web Page to know that it may be caused by old version of PIL module from anaconda.

I used your way to edit two part of
"dimensions = (width, height)"
to
"dimensions = (int(width), int(height))"
of the init.py of geovis folder.

But after I implement the instant mapping sentence,
"geovis.ViewShapefile("hk_line.shp")".
I encounter another error problem.
I'm wondering why.

The error:

> rendering hk_line
> 0%,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,100%
>   |||||||||||||||||||||||||||||||||||||||||||||||||
>         task completed in 16.592139 seconds
> 
> ---------------------------------------------------------------------------
> KeyError                                  Traceback (most recent call last)
> <ipython-input-5-2ada0375bda9> in <module>()
> ----> 1 geovis.ViewShapefile("hk_line.shp")
> 
> /Users/chenzhong/GeoVis-0.2.0/geovis/__init__.py in ViewShapefile(shapefilepath, **customoptions)
>    2320     customoptions = _CheckOptions(customoptions)
>    2321     renderer = _Renderer()
> -> 2322     renderer.ViewShapefile(shapefilepath, customoptions)
>    2323 def SaveShapefileImage(shapefilepath, savepath, **customoptions):
>    2324     """
> 
> /Users/chenzhong/GeoVis-0.2.0/geovis/__init__.py in ViewShapefile(self, shapefilepath, customoptions)
>    1516     def ViewShapefile(self, shapefilepath, customoptions):
>    1517         self._RenderShapefile(shapefilepath, customoptions)
> -> 1518         self._RenderMapTitle(shapefilepath, customoptions)
>    1519         self._ViewRenderedShapefile()
>    1520     def SaveShapefileImage(self, shapefilepath, savepath, customoptions):
> 
> /Users/chenzhong/GeoVis-0.2.0/geovis/__init__.py in _RenderMapTitle(self, shapefilepath, customoptions)
>    1539         if customoptions.get("maptitle"):
>    1540             textoptions = _CheckTextOptions(dict([("textsize",0.0452)]))
> -> 1541             self._RenderText(0.5, 0.05, customoptions["maptitle"], textoptions)
>    1542     def _RenderText(self, relx, rely, text, textoptions):
>    1543         self.renderer.RenderText(relx, rely, text, textoptions)
> 
> /Users/chenzhong/GeoVis-0.2.0/geovis/__init__.py in _RenderText(self, relx, rely, text, textoptions)
>    1541             self._RenderText(0.5, 0.05, customoptions["maptitle"], textoptions)
>    1542     def _RenderText(self, relx, rely, text, textoptions):
> -> 1543         self.renderer.RenderText(relx, rely, text, textoptions)
>    1544     def _RenderRectangle(self, upperleft, bottomright, customoptions):
>    1545         customoptions = self._RelSizesToPixels(customoptions)
> 
> /Users/chenzhong/GeoVis-0.2.0/geovis/__init__.py in RenderText(self, relx, rely, text, options)
>     913         options["textsize"] = options["textsize"]*2
>     914         if not options.get("texteffect"):
> --> 915             self._BasicText(relx, rely, text, options)
>     916     def RenderRectangle(self, upperleft, bottomright, customoptions):
>     917         leftrelx, uprely = upperleft
> 
> /Users/chenzhong/GeoVis-0.2.0/geovis/__init__.py in _BasicText(self, relx, rely, text, options)
>    1022 draws basic text, no effects
>    1023 """
> -> 1024         fontlocation = self.sysfontfolders[OSSYSTEM]+self.fontfilenames[options["textfont"]]
>    1025         font = PIL.ImageFont.truetype(fontlocation, size=options["textsize"])
>    1026         fontwidth, fontheight = self.drawer.textsize(text, font)
> 
> KeyError: 'darwin'

The error happens when it is trying to render text. The global OSSYSTEM detects that you are on a mac (darwin), and tries to use it as a key to locate the system-specific font folder from the sysfontfolders attribute of the backend renderer class. But the error indicates that sysfontfolders does not contain a key named "darwin". Not sure why, because the source code for all the renderer classes have dict with a darwin key... Can you insert a print statement right before the error line to display the content of the sysfonfolders attribute?