You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

srs.py 3.5KB

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