Archive for the ‘python’ tag
Compiling a 64 bit Version of PyISAPIe
Welcome to a veritable novella. I’ll jump straight to the end – there is no happy outcome, as yet, to this post there is a happy outcome! I have compiled a 64 bit PyISAPIe DLL (a program that runs Python at high speed under IIS), and it is up and running on Windows Server 2008 and IIS7. Many thanks to Phillip Stabon, the creator of PyISAPIe, for additional help, and for the latest version of PyISAPIe which makes compilation for different set ups much easier.
Some background information – I’ve not done any C++ for 10 years (and even then my most advanced program was to finish off a code sample on a hotel register for pirates – of the traditional kind). Also I’ve never used Subversion. Hence there are lots of pictures, and every step is detailed. If there’s anything missing let me know.
I’m not sure why I started doing this – the performance of Python using 32-bit version is fine, and since I started working on this Phillip Stabon, has mentioned he will be making a 64 bit DLL himself. However as there are many different versions of Python around, and different GIS tools rely on different versions it seemed a good idea to document how to do this from scratch.
In this example I’m using Visual Studio 2008, and a number of other tools that are detailed as I go along. I’ve also got the 64 bit compilation tools installed. There are a few notes from Phillip on compiling it for Windows 64-bit in the discussion lists (see quoted text underneath the post). Since this post was first published there is a newer discussion in the forums.
Anyway “How to Compile PyISAPIe for a 64-bit Server in 5 Easy Steps!”…
Read the rest of this entry »
Automated Diagrams and Documentation
As I previously wrote, one of the ways to get through the task of documenting a project is to turn the documentation process into a coding project. Documentation sometimes seems pointless as the likelihood of anyone other than yourself reading it are low to nil.
To increase the chances pretty pictures always help. If they are also useful then the documentation starts to have real value. Up until now I’ve been using Microsoft’s Visio, but recently I tried out a couple of online tools.
Class Diagrams
The MapServer Mapscript documentation currently uses of diagrams made from ASCII text to illustrate relationships between classes. I’m not sure if these were generated automatically, but the images now appear a little dated. They do however have the advantage over an image of being able to copy and paste class names.
+-------+ 0..* 1 +-------+ | Class | <--------> | Layer | +-------+ +-------+
I tried to recreate these diagrams using the online service http://yuml.me/. On the site you enter your model description using a fairly basic syntax. From then on the same diagram can be accessed using different URLs, which are used to control display and formatting options.
The diagram above was created using the syntax below. You can play around with this sample by clicking here.
[Hashtable]1..1->1[Class{bg:yellow}],
[Label ]0..1->1[Class],
[Style]0..*->1[Class],
[Class]0..*->1[Layer{bg:green}]
Reboot to Refresh Environment Variables
I wasn’t aware that if you change Windows environment variables that are used by IIS then you need to reboot the machine for the changes to take effect. As described by David Wong
This is because NT services like IIS inherit their environment from services.exe, which does not get updated when you change system environment until you reboot.
This knowledge may save a couple of hours of frustration if you are running Python scripts on IIS through PyISAPIe.
Setting Up Python on IIS7
I had already configured Python to run through the Apache webserver on my development server, but after a few issues on the production server (Apache freezing / crashing) I wanted to test running Python scripts with IIS7. The principle aim was to run TileCache through IIS rather than requiring Apache.
Why Not CGI?
While IIS 7 has Fast-CGI installed (see this IIS forum), even better performance can be achieved using ISAPI. This answer from ServerFault has a good summary on why ISAPI should be preferred over than CGI. Not only performance should be considered – maintenance should also be taken into account. If a web master or hosting service is familiar with IIS then they are also likely to be familiar with ISAPI.
From the PyISAPIe site:
The reason ISAPI applications have the capability of being better than CGI or FastCGI applications is mostly due to its tight integration with the web server environment. Instead of initializing an entire program from scratch (in this case, the Python interpreter) every time a request is made for a page, an ISAPI extension only has to provide a function that is called upon every request. For interpreting Python scripts on a per-request basis, this means that the interpreter can be initialized once and used many times, creating a very noticeable performance gain.
Read the rest of this entry »
Running Python through Apache
I’m trying (and having) to start using Python more and more due to its ubiquity in the OpenSource GIS world. There are a number of add-ons and libraries for MapServer that require Python to function properly and/or quickly. It is also widely used for scripting both MapServer objects and for raster manipulation using GDAL. I initially set up Python under Apache to run the Tilecache tile server.
According to the ModPython site – “Python will run many times faster than traditional CGI and will have access to advanced features such as ability to retain database connections.”
Mod_python is an Apache module that embeds the Python interpreter within the server, and can be downloaded from their site. There are versions for both Unix and Windows, which makes it ideal for MapServer for Windows (MS4W). Ironically after saying that using Python for web applications is many times faster than CGI, the ModPython download page uses CGI..
Mapfish JavaScript Toolbox
Mapfish is an open-source web mapping framework built using the Pylons Python web framework for “creating web services that allow querying and editing of geographic objects.” However the server-side functionality of the system I am currently working on is already handled by SQL Server 2008 Spatial and MapServer. What interested me more was that Mapfish “provides a complete RIA-oriented (Rich Internet Application) JavaScript toolbox.”
A couple of examples of the front-end interface can be found at the EU Inspire Geoportal, and the Marbled Murrelet Mashup. The Mapfish client combines three frameworks into one OpenLayers, GeoExt, and ExtJS.
The client JavaScript is available via downloaded from http://www.mapfish.org/downloads/. At the time of writing mapfish-client-1.2.tar.gz was the most recent version. The files can be unzipped using the open-source program 7-zip that handles both gzip and “tar ball” zip files. Once unzipped there are a number of samples that can be run and edited locally (look for the examples/map/index.html page). This alone is a huge step forward in creating a basic online mapping system that rivals proprietary offerings.
Further details on using the toolkit can be found at the Mapfish tutorial and this blog tutorial. I’ll also be writing some more technical posts, specifically around using Mapfish with Windows, as most of the current documentation assumes people are running Linux.