Skip to content
Browse files

gis: gdal: Now supports the official GDAL 1.5 binaries for Windows, g…

…reatly simplifying installation for that platform; implemented STDCALL aliases for OSR routines that have inconsistent calling convention via the `std_call` function; removed unused prototypes module code.

git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@6993 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent b11172e commit 1d5e689af2fa541cab83ed7f777f247b32623b6d @jbronn jbronn committed Jan 4, 2008
View
20 django/contrib/gis/gdal/libgdal.py
@@ -14,7 +14,7 @@
pass
elif os.name == 'nt':
# Windows NT shared library
- lib_name = 'libgdal-1.dll'
+ lib_name = 'gdal15.dll'
elif os.name == 'posix':
platform = os.uname()[0]
if platform == 'Darwin':
@@ -29,6 +29,24 @@
# This loads the GDAL/OGR C library
lgdal = CDLL(lib_name)
+# On Windows, the GDAL binaries have some OSR routines exported with
+# STDCALL, while others are not. Thus, the library will also need to
+# be loaded up as WinDLL for said OSR functions that require the
+# different calling convention.
+if os.name == 'nt':
+ from ctypes import WinDLL
+ lwingdal = WinDLL(lib_name)
+
+def std_call(func):
+ """
+ Returns the correct STDCALL function for certain OSR routines on Win32
+ platforms.
+ """
+ if os.name == 'nt':
+ return lwingdal[func]
+ else:
+ return lgdal[func]
+
#### Version-information functions. ####
def _version_info(key):
"Returns GDAL library version information with the given key."
View
16 django/contrib/gis/gdal/prototypes/__init__.py
@@ -1,16 +0,0 @@
-"""
- This routine provides shortuct functions to generate ctypes prototypes
- for the GDAL routines.
-"""
-# OGR Geometry prototypes.
-from django.contrib.gis.gdal.prototypes.geom import \
- assign_srs, clone_geom, create_geom, destroy_geom, from_wkb, from_wkt, \
- get_area, get_coord_dims, get_dims, get_envelope, get_geom_count, get_geom_name, get_geom_srs, get_geom_type, get_point_count, get_wkbsize, \
- getx, get_geom_ref, gety, getz, to_gml, to_wkt
-
-# Spatial Reference prototypes.
-from django.contrib.gis.gdal.prototypes.srs import \
- clone_srs
-
-# TEMPORARY
-from generation import double_output, string_output, void_output
View
24 django/contrib/gis/gdal/prototypes/srs.py
@@ -1,5 +1,5 @@
from ctypes import c_char_p, c_int, c_void_p, POINTER
-from django.contrib.gis.gdal.libgdal import lgdal
+from django.contrib.gis.gdal.libgdal import lgdal, std_call
from django.contrib.gis.gdal.prototypes.generation import \
const_string_output, double_output, int_output, \
srs_output, string_output, void_output
@@ -20,10 +20,10 @@ def units_func(f):
return double_output(f, [c_void_p, POINTER(c_char_p)], strarg=True)
# Creation & destruction.
-clone_srs = srs_output(lgdal.OSRClone, [c_void_p])
-new_srs = srs_output(lgdal.OSRNewSpatialReference, [c_char_p])
+clone_srs = srs_output(std_call('OSRClone'), [c_void_p])
+new_srs = srs_output(std_call('OSRNewSpatialReference'), [c_char_p])
release_srs = void_output(lgdal.OSRRelease, [c_void_p], errcheck=False)
-destroy_srs = void_output(lgdal.OSRDestroySpatialReference, [c_void_p], errcheck=False)
+destroy_srs = void_output(std_call('OSRDestroySpatialReference'), [c_void_p], errcheck=False)
srs_validate = void_output(lgdal.OSRValidate, [c_void_p])
# Getting the semi_major, semi_minor, and flattening functions.
@@ -34,7 +34,7 @@ def units_func(f):
# WKT, PROJ, EPSG, XML importation routines.
from_wkt = void_output(lgdal.OSRImportFromWkt, [c_void_p, POINTER(c_char_p)])
from_proj = void_output(lgdal.OSRImportFromProj4, [c_void_p, c_char_p])
-from_epsg = void_output(lgdal.OSRImportFromEPSG, [c_void_p, c_int])
+from_epsg = void_output(std_call('OSRImportFromEPSG'), [c_void_p, c_int])
from_xml = void_output(lgdal.OSRImportFromXML, [c_void_p, c_char_p])
# Morphing to/from ESRI WKT.
@@ -49,15 +49,15 @@ def units_func(f):
angular_units = units_func(lgdal.OSRGetAngularUnits)
# For exporting to WKT, PROJ.4, "Pretty" WKT, and XML.
-to_wkt = string_output(lgdal.OSRExportToWkt, [c_void_p, POINTER(c_char_p)])
-to_proj = string_output(lgdal.OSRExportToProj4, [c_void_p, POINTER(c_char_p)])
-to_pretty_wkt = string_output(lgdal.OSRExportToPrettyWkt, [c_void_p, POINTER(c_char_p), c_int], offset=-2)
+to_wkt = string_output(std_call('OSRExportToWkt'), [c_void_p, POINTER(c_char_p)])
+to_proj = string_output(std_call('OSRExportToProj4'), [c_void_p, POINTER(c_char_p)])
+to_pretty_wkt = string_output(std_call('OSRExportToPrettyWkt'), [c_void_p, POINTER(c_char_p), c_int], offset=-2)
-# FIXME: This leaks memory, still don't know why.
+# Memory leak fixed in GDAL 1.5; still exists in 1.4.
to_xml = string_output(lgdal.OSRExportToXML, [c_void_p, POINTER(c_char_p), c_char_p], offset=-2)
# String attribute retrival routines.
-get_attr_value = const_string_output(lgdal.OSRGetAttrValue, [c_void_p, c_char_p, c_int])
+get_attr_value = const_string_output(std_call('OSRGetAttrValue'), [c_void_p, c_char_p, c_int])
get_auth_name = const_string_output(lgdal.OSRGetAuthorityName, [c_void_p, c_char_p])
get_auth_code = const_string_output(lgdal.OSRGetAuthorityCode, [c_void_p, c_char_p])
@@ -67,5 +67,5 @@ def units_func(f):
isprojected = int_output(lgdal.OSRIsProjected, [c_void_p])
# Coordinate transformation
-new_ct= srs_output(lgdal.OCTNewCoordinateTransformation, [c_void_p, c_void_p])
-destroy_ct = void_output(lgdal.OCTDestroyCoordinateTransformation, [c_void_p], errcheck=False)
+new_ct= srs_output(std_call('OCTNewCoordinateTransformation'), [c_void_p, c_void_p])
+destroy_ct = void_output(std_call('OCTDestroyCoordinateTransformation'), [c_void_p], errcheck=False)

0 comments on commit 1d5e689

Please sign in to comment.
Something went wrong with that request. Please try again.