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