Django

Code

Changeset 6993

Show
Ignore:
Timestamp:
01/04/08 00:41:13 (6 months ago)
Author:
jbronn
Message:

gis: gdal: Now supports the official GDAL 1.5 binaries for Windows, greatly 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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/gdal/libgdal.py

    r6914 r6993  
    1515elif os.name == 'nt': 
    1616    # Windows NT shared library 
    17     lib_name = 'libgdal-1.dll' 
     17    lib_name = 'gdal15.dll' 
    1818elif os.name == 'posix': 
    1919    platform = os.uname()[0] 
     
    2929# This loads the GDAL/OGR C library 
    3030lgdal = CDLL(lib_name) 
     31 
     32# On Windows, the GDAL binaries have some OSR routines exported with  
     33# STDCALL, while others are not.  Thus, the library will also need to  
     34# be loaded up as WinDLL for said OSR functions that require the  
     35# different calling convention. 
     36if os.name == 'nt': 
     37    from ctypes import WinDLL 
     38    lwingdal = WinDLL(lib_name) 
     39 
     40def std_call(func): 
     41    """ 
     42    Returns the correct STDCALL function for certain OSR routines on Win32 
     43    platforms. 
     44    """ 
     45    if os.name == 'nt': 
     46        return lwingdal[func] 
     47    else: 
     48        return lgdal[func] 
    3149 
    3250#### Version-information functions. #### 
  • django/branches/gis/django/contrib/gis/gdal/prototypes/__init__.py

    r6686 r6993  
    1 """ 
    2  This routine provides shortuct functions to generate ctypes prototypes 
    3  for the GDAL routines. 
    4 """ 
    5 # OGR Geometry prototypes. 
    6 from django.contrib.gis.gdal.prototypes.geom import \ 
    7     assign_srs, clone_geom, create_geom, destroy_geom, from_wkb, from_wkt, \ 
    8     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, \ 
    9     getx, get_geom_ref, gety, getz, to_gml, to_wkt 
    10  
    11 # Spatial Reference prototypes. 
    12 from django.contrib.gis.gdal.prototypes.srs import \ 
    13     clone_srs 
    14  
    15 # TEMPORARY 
    16 from generation import double_output, string_output, void_output 
  • django/branches/gis/django/contrib/gis/gdal/prototypes/srs.py

    r6914 r6993  
    11from ctypes import c_char_p, c_int, c_void_p, POINTER 
    2 from django.contrib.gis.gdal.libgdal import lgdal 
     2from django.contrib.gis.gdal.libgdal import lgdal, std_call 
    33from django.contrib.gis.gdal.prototypes.generation import \ 
    44    const_string_output, double_output, int_output, \ 
     
    2121 
    2222# Creation & destruction. 
    23 clone_srs = srs_output(lgdal.OSRClone, [c_void_p]) 
    24 new_srs = srs_output(lgdal.OSRNewSpatialReference, [c_char_p]) 
     23clone_srs = srs_output(std_call('OSRClone'), [c_void_p]) 
     24new_srs = srs_output(std_call('OSRNewSpatialReference'), [c_char_p]) 
    2525release_srs = void_output(lgdal.OSRRelease, [c_void_p], errcheck=False) 
    26 destroy_srs = void_output(lgdal.OSRDestroySpatialReference, [c_void_p], errcheck=False) 
     26destroy_srs = void_output(std_call('OSRDestroySpatialReference'), [c_void_p], errcheck=False) 
    2727srs_validate = void_output(lgdal.OSRValidate, [c_void_p]) 
    2828 
     
    3535from_wkt = void_output(lgdal.OSRImportFromWkt, [c_void_p, POINTER(c_char_p)]) 
    3636from_proj = void_output(lgdal.OSRImportFromProj4, [c_void_p, c_char_p]) 
    37 from_epsg = void_output(lgdal.OSRImportFromEPSG, [c_void_p, c_int]) 
     37from_epsg = void_output(std_call('OSRImportFromEPSG'), [c_void_p, c_int]) 
    3838from_xml = void_output(lgdal.OSRImportFromXML, [c_void_p, c_char_p]) 
    3939 
     
    5050 
    5151# For exporting to WKT, PROJ.4, "Pretty" WKT, and XML. 
    52 to_wkt = string_output(lgdal.OSRExportToWkt, [c_void_p, POINTER(c_char_p)]) 
    53 to_proj = string_output(lgdal.OSRExportToProj4, [c_void_p, POINTER(c_char_p)]) 
    54 to_pretty_wkt = string_output(lgdal.OSRExportToPrettyWkt, [c_void_p, POINTER(c_char_p), c_int], offset=-2) 
     52to_wkt = string_output(std_call('OSRExportToWkt'), [c_void_p, POINTER(c_char_p)]) 
     53to_proj = string_output(std_call('OSRExportToProj4'), [c_void_p, POINTER(c_char_p)]) 
     54to_pretty_wkt = string_output(std_call('OSRExportToPrettyWkt'), [c_void_p, POINTER(c_char_p), c_int], offset=-2) 
    5555 
    56 # FIXME: This leaks memory, still don't know why
     56# Memory leak fixed in GDAL 1.5; still exists in 1.4
    5757to_xml = string_output(lgdal.OSRExportToXML, [c_void_p, POINTER(c_char_p), c_char_p], offset=-2) 
    5858 
    5959# String attribute retrival routines. 
    60 get_attr_value = const_string_output(lgdal.OSRGetAttrValue, [c_void_p, c_char_p, c_int]) 
     60get_attr_value = const_string_output(std_call('OSRGetAttrValue'), [c_void_p, c_char_p, c_int]) 
    6161get_auth_name = const_string_output(lgdal.OSRGetAuthorityName, [c_void_p, c_char_p]) 
    6262get_auth_code = const_string_output(lgdal.OSRGetAuthorityCode, [c_void_p, c_char_p]) 
     
    6868 
    6969# Coordinate transformation 
    70 new_ct= srs_output(lgdal.OCTNewCoordinateTransformation, [c_void_p, c_void_p]) 
    71 destroy_ct = void_output(lgdal.OCTDestroyCoordinateTransformation, [c_void_p], errcheck=False) 
     70new_ct= srs_output(std_call('OCTNewCoordinateTransformation'), [c_void_p, c_void_p]) 
     71destroy_ct = void_output(std_call('OCTDestroyCoordinateTransformation'), [c_void_p], errcheck=False)