--- \o/ ---
Sent from my phone

On Aug 22, 2010, at 6:20 AM, simon blackmore <[email protected]> wrote:

Oh. How stupid am I !
I think all my woes were simply down to naming my test file Cairo.py. I will not do that again.

Actually Mapnik installation was perfect, but the tangle came when I started trying to install Postgis, osm2pgsql.
Thats when I used brew etc.

Sorry to be such a newb but I think cairo is all ready to go but I seem to be producing 4k blanks with the following code.
Am I doing something equally stupid again.

Thanks so much for your help.

Simon


import mapnik
import cairo

mapfile = 'osm.xml'
map_output = 'mapfile.pdf'
projection = '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgri...@null +no_defs +over'

mapnik_map = mapnik.Map(1000, 500)
mapnik.load_map(mapnik_map, mapfile)
bbox = mapnik.Envelope(-2.4, 53.4, -2.1, 53.6)

Those coordinates are in long/lat but your map srs is Mercator. You need to pass Mercator coordinates. Or change you map srs to +init=epsg:4326 (a shorthand for long lat)

mapnik_map.zoom_to_box(bbox)
file = open(map_output, 'wb')
surface = cairo.PDFSurface(file.name, mapnik_map.width, mapnik_map.height)
mapnik.render(mapnik_map, surface)
surface.finish()





Ya so you are falling into a few ditches with clashing names.

That 'mapnik' folder you downloaded from openstreetmaps svn is just the stylesheet for rendering osm data with Mapnik (it really should be renamed to prevent honest folks like yourself from being rightly confused). Rename that folder to something like 'osm-stylesheets' to avoid python finding that folder and confusing it with the actual Mapnik installation.

Also you must have a file in there that you named 'cairo.py'. In short never do that because when your current working directory is the one containing that file it will be assumed by python to be Cairo rather than the actual Cairo module. So basically a tricky problem we all get burned by and hopefully only have to learn once.

Dane

--- \o/ ---
Sent from my phone

On Aug 21, 2010, at 8:19 PM, simon blackmore <[email protected]> wrote:

Thanks for your help Dane,

Ah I see Cairo is there. Appologies, I think I got confused somewhere.
Removed the macport install now : )

'/Library/Frameworks/Mapnik.framework/Versions/Current/Python/ System/2.5/site-packages/mapnik/__init__.py'

What is really confusing me is that the package I installed from the following "installing Mapnik" instructions..

"If you haven't already done so, export the Mapnik stuff from the OSM subversion repository:

svn export http://svn.openstreetmap.org/applications/rendering/ mapnik
cd mapnik"

Is here.
/usr/local/Cellar/mapnik/

So currently this is where I edit the xml files, keep the shape files etc.

But as far as I can make out I only have the one Unix Executable and thats in the framework. If I move it, I can no longer use Mapnik.

So Mapnik seems to be running fine.

But when I try to import Cairo I get this error.

>>> import mapnik
>>> import cairo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/mapnik/cairo.py", line 19, in <module>
surface = cairo.SVGSurface(file.name, mapnik_map.width, mapnik_map.height)
AttributeError: 'module' object has no attribute 'SVGSurface'
>>>

However if I start python from home$

No problem.
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairo
>>>


Basically I think I have misunderstood where the Mapnik folder with xml files should be kept.

Any help would be much appreciated.

Many thanks

Simon








to see where your mapnik is coming from. I recommend only installing mapnik and cairo from one source, and the binary installer above should work on a vanilla osx system without homebrew or macports. I recommend uninstalling all things that you installed with those package managers relating to Mapnik and Cairo. If the binary installer did not work alone, post why.

I wanted to give Cairo a try so I followed the Mapnik instructions through Macports and now
that lives here

/opt etc.

When I run the Mapnik svg example script I get this error.

File "./cairo.py", line 8, in <module>
  import cairo
File "/usr/local/Cellar/mapnik/cairo.py", line 19, in <module>
surface = cairo.SVGSurface(file.name, mapnik_map.width, mapnik_map.height)
AttributeError: 'module' object has no attribute 'SVGSurface'

So I guess Mapnik is not finding the Cairo files.

Any ideas what I can do to get my Mapnik files to find them?

Would some sort of symbolic link do it or do I need to try and reinstall Mapnik ?

Thanks for your help

Simon



_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users



_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to