PageRenderTime 38ms CodeModel.GetById 12ms app.highlight 20ms RepoModel.GetById 2ms app.codeStats 0ms

/django/contrib/gis/gdal/prototypes/srs.py

https://code.google.com/p/mango-py/
Python | 72 lines | 39 code | 13 blank | 20 comment | 0 complexity | e0fc013559d010d31774dc9e435d0a49 MD5 | raw file
 1from ctypes import c_char_p, c_int, c_void_p, POINTER
 2from django.contrib.gis.gdal.libgdal import lgdal, std_call
 3from django.contrib.gis.gdal.prototypes.generation import \
 4    const_string_output, double_output, int_output, \
 5    srs_output, string_output, void_output
 6
 7## Shortcut generation for routines with known parameters.
 8def srs_double(f):
 9    """
10    Creates a function prototype for the OSR routines that take
11    the OSRSpatialReference object and
12    """
13    return double_output(f, [c_void_p, POINTER(c_int)], errcheck=True)
14
15def units_func(f):
16    """
17    Creates a ctypes function prototype for OSR units functions, e.g.,
18    OSRGetAngularUnits, OSRGetLinearUnits.
19    """
20    return double_output(f, [c_void_p, POINTER(c_char_p)], strarg=True)
21
22# Creation & destruction.
23clone_srs = srs_output(std_call('OSRClone'), [c_void_p])
24new_srs = srs_output(std_call('OSRNewSpatialReference'), [c_char_p])
25release_srs = void_output(lgdal.OSRRelease, [c_void_p], errcheck=False)
26destroy_srs = void_output(std_call('OSRDestroySpatialReference'), [c_void_p], errcheck=False)
27srs_validate = void_output(lgdal.OSRValidate, [c_void_p])
28
29# Getting the semi_major, semi_minor, and flattening functions.
30semi_major = srs_double(lgdal.OSRGetSemiMajor)
31semi_minor = srs_double(lgdal.OSRGetSemiMinor)
32invflattening = srs_double(lgdal.OSRGetInvFlattening)
33
34# WKT, PROJ, EPSG, XML importation routines.
35from_wkt = void_output(lgdal.OSRImportFromWkt, [c_void_p, POINTER(c_char_p)])
36from_proj = void_output(lgdal.OSRImportFromProj4, [c_void_p, c_char_p])
37from_epsg = void_output(std_call('OSRImportFromEPSG'), [c_void_p, c_int])
38from_xml = void_output(lgdal.OSRImportFromXML, [c_void_p, c_char_p])
39from_user_input = void_output(std_call('OSRSetFromUserInput'), [c_void_p, c_char_p])
40
41# Morphing to/from ESRI WKT.
42morph_to_esri = void_output(lgdal.OSRMorphToESRI, [c_void_p])
43morph_from_esri = void_output(lgdal.OSRMorphFromESRI, [c_void_p])
44
45# Identifying the EPSG
46identify_epsg = void_output(lgdal.OSRAutoIdentifyEPSG, [c_void_p])
47
48# Getting the angular_units, linear_units functions
49linear_units = units_func(lgdal.OSRGetLinearUnits)
50angular_units = units_func(lgdal.OSRGetAngularUnits)
51
52# For exporting to WKT, PROJ.4, "Pretty" WKT, and XML.
53to_wkt = string_output(std_call('OSRExportToWkt'), [c_void_p, POINTER(c_char_p)])
54to_proj = string_output(std_call('OSRExportToProj4'), [c_void_p, POINTER(c_char_p)])
55to_pretty_wkt = string_output(std_call('OSRExportToPrettyWkt'), [c_void_p, POINTER(c_char_p), c_int], offset=-2)
56
57# Memory leak fixed in GDAL 1.5; still exists in 1.4.
58to_xml = string_output(lgdal.OSRExportToXML, [c_void_p, POINTER(c_char_p), c_char_p], offset=-2)
59
60# String attribute retrival routines.
61get_attr_value = const_string_output(std_call('OSRGetAttrValue'), [c_void_p, c_char_p, c_int])
62get_auth_name = const_string_output(lgdal.OSRGetAuthorityName, [c_void_p, c_char_p])
63get_auth_code = const_string_output(lgdal.OSRGetAuthorityCode, [c_void_p, c_char_p])
64
65# SRS Properties
66isgeographic = int_output(lgdal.OSRIsGeographic, [c_void_p])
67islocal = int_output(lgdal.OSRIsLocal, [c_void_p])
68isprojected = int_output(lgdal.OSRIsProjected, [c_void_p])
69
70# Coordinate transformation
71new_ct= srs_output(std_call('OCTNewCoordinateTransformation'), [c_void_p, c_void_p])
72destroy_ct = void_output(std_call('OCTDestroyCoordinateTransformation'), [c_void_p], errcheck=False)