Yet Another Python Projection Package

The new PCL 0.9.1 source release contains a cartography.referencing module that can be built, installed, and used independently of the rest of the library. It requires only that PROJ.4 is installed on your system, and that you have a C compiler to compile the extension module. I've been itching for something that fits in the gap between Thuban's Projection (too limited) and OGR's spatial referencing (too intricate), and this is my swipe at that itch.

Cartography.referencing uses PROJ.4's pj_transform(), and is a bit like using the cs2cs utility program. Here's a usage example from the how-to:

from cartography.referencing.srs import SpatialReference
from cartography.referencing.transform.proj4 import ProjTransform
utm13 = SpatialReference(epsg=26913)
wgs84 = SpatialReference(epsg=4326)
t = ProjTransform(utm13, wgs84)
transformed_coords = t.transform([(-105, 39), (-106, 40)])

# transformed_coords is
# [(499999.99999999889, 4316776.5830979366),
#  (414639.53815663763, 4428236.0645195534)]

There are unit tests and coverage measures:

[sean@lenny referencing]$ ./runcoverage
running coverage tests ...
...............
----------------------------------------------------------------------
Ran 15 tests in 0.068s

OK
Name    Stmts   Exec  Cover
---------------------------
srs        19     18    94%
proj4       7      7   100%
---------------------------
TOTAL      26     25    96%

and the tests run leak-free under valgrind:

[sean@lenny referencing]$ ./rungrind
==18242== Memcheck, a memory error detector for x86-linux.
==18242== Copyright (C) 2002-2004, and GNU GPL'd, by Julian Seward et al.
==18242== Using valgrind-2.2.0, a program supervision framework for x86-linux.
==18242== Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward et al.
==18242== For more details, rerun with: -v
==18242==
...............
----------------------------------------------------------------------
Ran 15 tests in 3.586s

OK
==18242==
==18242== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1208 from 7)
==18242== malloc/free: in use at exit: 681366 bytes in 119 blocks.
==18242== malloc/free: 2822 allocs, 2703 frees, 1599734 bytes allocated.
==18242== For counts of detected errors, rerun with: -v
==18242== searching for pointers to 119 not-freed blocks.
==18242== checked 4106828 bytes.
==18242==
==18242== LEAK SUMMARY:
==18242==    definitely lost: 0 bytes in 0 blocks.
==18242==    possibly lost:   0 bytes in 0 blocks.
==18242==    still reachable: 681166 bytes in 118 blocks.
==18242==         suppressed: 200 bytes in 1 blocks.
==18242== Reachable blocks (those to which a pointer was found) are not shown.
==18242== To see them, rerun with: --show-reachable=yes

The code we use in PrimaGIS and ZCO to transform between spatial and image coordinates might well be moved to cartography.referencing.transform in the future.

Comments

Re: Yet Another Python Projection Package

Author: Mateusz Łoskot

Hi, I tried to build YAPPP on my Windows box using VC+ 7.1 but I got a message saying that I have to use VC++ 6.0 because Python was build with this compiler. I have no VC++ 6.0 :-( Do you know any trick how to get around this problem? Cheers

Re: Yet Another Python Projection Package

Author: Sean Gillies

Windows binaries for Python 2.3.x, whether they are from python.org or ActiveState, were compiled with VC6, and so must be extension modules for them. The only way around this is to re-compile Python 2.3 from source using VC7. Instead of doing that, how about giving my new binary package a try? http://gispython.org/downloads/gispy/PCL-Referencing-0.10.0-rc1-win32.zip There is an announcement about this package archived at http://lists.gispython.org/pipermail/community/2005-December/000059.html