karimbahgat / GeoVis

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

Zillow data #1

Open petulla opened 10 years ago

petulla commented 10 years ago

hi

I tried your package. I get:

TypeError: integer argument expected, got float

When trying to load Zillow's neighborhood shape data. Thanks!

karimbahgat commented 10 years ago

Hi Petulla. I know errors like these can be frustrating, so I'm very glad you took the extra step to ask for help :)

I'll need some more info to help you though:

1) The most important is that you post the rest of the error message, or at least tell me which line nr of code it says the TypeError occured on?

2) The version of GeoVis you are using, did you download the "cutting edge" version using the zipfile download button to the right of the GeoVis main page, or did you download a "stable" release from the "releases" page and if so v0.1 or v0.2?

3) If you could, it would also be helpful if you post the entire code that produced the problem, or that you tell me which steps you went through and which approach you were using?

By the way, which of the Zillow neighbourhood shapefiles did you use; for which state? I tried making a map of the California shapefile using GeoVis and it worked fine, so I don't think it has to do with the data format or projection at least. (Later on when we get it working, remember that GeoVis doesn't automatically zoom to your shapefile, you will have to do this manually using the .SetMapZoom() method).

petulla commented 10 years ago

The run code: geovis.ViewShapefile("ZillowNeighborhoods-NY.shp") The version seems to be 0.2 The error:

TypeError                                 Traceback (most recent call last)
<ipython-input-9-935a2a9c055d> in <module>()
----> 1 geovis.ViewShapefile("ZillowNeighborhoods-NY.shp")

/Users/Petulla/anaconda/python.app/Contents/lib/python2.7/geovis/__init__.py in ViewShapefile(shapefilepath, **customoptions)
   2319 """
   2320     customoptions = _CheckOptions(customoptions)
-> 2321     renderer = _Renderer()
   2322     renderer.ViewShapefile(shapefilepath, customoptions)
   2323 def SaveShapefileImage(shapefilepath, savepath, **customoptions):

/Users/Petulla/anaconda/python.app/Contents/lib/python2.7/geovis/__init__.py in __init__(self)
   1509             self.renderer = _PyCairo_Renderer()
   1510         #automatically create blank image
-> 1511         self.NewImage()
   1512         self.layers = dict()
   1513     #custom methods

/Users/Petulla/anaconda/python.app/Contents/lib/python2.7/geovis/__init__.py in NewImage(self)
   1513     #custom methods
   1514     def NewImage(self):
-> 1515         self.renderer.NewImage()
   1516     def ViewShapefile(self, shapefilepath, customoptions):
   1517         self._RenderShapefile(shapefilepath, customoptions)

/Users/Petulla/anaconda/python.app/Contents/lib/python2.7/geovis/__init__.py in NewImage(self)
    907         background = MAPBACKGROUND
    908         dimensions = (width, height)
--> 909         self.img = PIL.Image.new(mode, dimensions, background)
    910         self.drawer = PIL.ImageDraw.Draw(self.img)
    911     def RenderText(self, relx, rely, text, options):

/Users/Petulla/anaconda/lib/python2.7/site-packages/PIL/Image.pyc in new(mode, size, color)
   1753     if color is None:
   1754         # don't initialize
-> 1755         return Image()._new(core.new(mode, size))
   1756 
   1757     if isStringType(color):

TypeError: integer argument expected, got float
karimbahgat commented 10 years ago

Great. I'm going to start to looking over it the next few days, but in the meanwhile, if you could also write the exact code that you are trying to use, and which state shapefile you are using. That way I can try to reproduce, and fix, the problem on my computer.

petulla commented 10 years ago

So I wrote the code above the output. The file is the New York shp file here: http://www.zillow.com/howto/api/neighborhood-boundaries.htm

karimbahgat commented 10 years ago

Hi again, thanks for being patient with me. Finally got around to looking at it, and it seems that it's just a silly error where the mapwidth and height are passed as floats when creating the PIL image, but should be integers. In the PIL version I was developing on, this was only a deprecation warning, but you probably have a newer PIL version so that's why it raised a full error.

Anyway, quickly fixed it by forcing them to be integers before sending to PIL, and synced with the main repo. So if you redownload GeoVis from the newest current repo and try again it should be fine. Could you confirm whether this solved the issue?

As a sidenote, remember that just visualizing the map like that will use a global zoom extent, so in order to more fully visualize the very tiny neighborhood data you will need to use the .SetMapZoom() function. For the future I'll have to see if I can make the map automatically zoom to the data extents.

karimbahgat commented 10 years ago

Alright Petulla, thanks for sharing this issue :) Let me know if the problem persists. Closing the issue now since I'm pretty sure I fixed it.

petulla commented 10 years ago

So I just tried it again, and it gave me the same error..


TypeError                                 Traceback (most recent call last)
<ipython-input-2-935a2a9c055d> in <module>()
----> 1 geovis.ViewShapefile("ZillowNeighborhoods-NY.shp")

/Users/Petulla/anaconda/python.app/Contents/lib/python2.7/geovis/__init__.py in ViewShapefile(shapefilepath, **customoptions)
   2319 """
   2320     customoptions = _CheckOptions(customoptions)
-> 2321     renderer = _Renderer()
   2322     renderer.ViewShapefile(shapefilepath, customoptions)
   2323 def SaveShapefileImage(shapefilepath, savepath, **customoptions):

/Users/Petulla/anaconda/python.app/Contents/lib/python2.7/geovis/__init__.py in __init__(self)
   1509             self.renderer = _PyCairo_Renderer()
   1510         #automatically create blank image
-> 1511         self.NewImage()
   1512         self.layers = dict()
   1513     #custom methods

/Users/Petulla/anaconda/python.app/Contents/lib/python2.7/geovis/__init__.py in NewImage(self)
   1513     #custom methods
   1514     def NewImage(self):
-> 1515         self.renderer.NewImage()
   1516     def ViewShapefile(self, shapefilepath, customoptions):
   1517         self._RenderShapefile(shapefilepath, customoptions)

/Users/Petulla/anaconda/python.app/Contents/lib/python2.7/geovis/__init__.py in NewImage(self)
    907         background = MAPBACKGROUND
    908         dimensions = (width, height)
--> 909         self.img = PIL.Image.new(mode, dimensions, background)
    910         self.drawer = PIL.ImageDraw.Draw(self.img)
    911     def RenderText(self, relx, rely, text, options):

/Users/SamPetulla/anaconda/lib/python2.7/site-packages/PIL/Image.pyc in new(mode, size, color)
   1753     if color is None:
   1754         # don't initialize
-> 1755         return Image()._new(core.new(mode, size))
   1756 
   1757     if isStringType(color):

TypeError: integer argument expected, got float
karimbahgat commented 10 years ago

Hi again,

That's odd. Are you sure you downloaded the latest code repository?

Well the error happens inside the PIL package in the code that says "return Image()._new(core.new(mode, size))". So there are really only two possible errors, mode, which I'm pretty sure is a string like "RGBA" or "L" or size which is a tuple of width and height, so the latter must be it since the error is with float and integer.

Just to be entirely sure could you update your version of GeoVis from the main repository by clicking "download zip" on the right side of the GeoVis page (not from the "releases") page, delete your old GeoVis folder and replace it with the new one? Then try again.

It's hard for me to reproduce your problem bc you seem to have an Anaconda pre-packaged Python installation. If you're still having problems, could you check and tell me which PIL version you have installed? And which OS (Windows 7, Mac...)? If you could it would also be helpful if you went into the file /Users/SamPetulla/anaconda/lib/python2.7/site-packages/PIL/Image.pyc and added a line right before the error on line 909 and write "print mode, size" and tell me what you get when you try running again.

Best,