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.

ds.py 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. """
  2. This module houses the ctypes function prototypes for OGR DataSource
  3. related data structures. OGR_Dr_*, OGR_DS_*, OGR_L_*, OGR_F_*,
  4. OGR_Fld_* routines are relevant here.
  5. """
  6. from ctypes import POINTER, c_char_p, c_double, c_int, c_long, c_void_p
  7. from django.contrib.gis.gdal.envelope import OGREnvelope
  8. from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
  9. from django.contrib.gis.gdal.prototypes.generation import (
  10. const_string_output, double_output, geom_output, int64_output, int_output,
  11. srs_output, void_output, voidptr_output,
  12. )
  13. c_int_p = POINTER(c_int) # shortcut type
  14. # Driver Routines
  15. register_all = void_output(lgdal.OGRRegisterAll, [], errcheck=False)
  16. cleanup_all = void_output(lgdal.OGRCleanupAll, [], errcheck=False)
  17. get_driver = voidptr_output(lgdal.OGRGetDriver, [c_int])
  18. get_driver_by_name = voidptr_output(lgdal.OGRGetDriverByName, [c_char_p], errcheck=False)
  19. get_driver_count = int_output(lgdal.OGRGetDriverCount, [])
  20. get_driver_name = const_string_output(lgdal.OGR_Dr_GetName, [c_void_p], decoding='ascii')
  21. # DataSource
  22. open_ds = voidptr_output(lgdal.OGROpen, [c_char_p, c_int, POINTER(c_void_p)])
  23. destroy_ds = void_output(lgdal.OGR_DS_Destroy, [c_void_p], errcheck=False)
  24. release_ds = void_output(lgdal.OGRReleaseDataSource, [c_void_p])
  25. get_ds_name = const_string_output(lgdal.OGR_DS_GetName, [c_void_p])
  26. get_layer = voidptr_output(lgdal.OGR_DS_GetLayer, [c_void_p, c_int])
  27. get_layer_by_name = voidptr_output(lgdal.OGR_DS_GetLayerByName, [c_void_p, c_char_p])
  28. get_layer_count = int_output(lgdal.OGR_DS_GetLayerCount, [c_void_p])
  29. # Layer Routines
  30. get_extent = void_output(lgdal.OGR_L_GetExtent, [c_void_p, POINTER(OGREnvelope), c_int])
  31. get_feature = voidptr_output(lgdal.OGR_L_GetFeature, [c_void_p, c_long])
  32. get_feature_count = int_output(lgdal.OGR_L_GetFeatureCount, [c_void_p, c_int])
  33. get_layer_defn = voidptr_output(lgdal.OGR_L_GetLayerDefn, [c_void_p])
  34. get_layer_srs = srs_output(lgdal.OGR_L_GetSpatialRef, [c_void_p])
  35. get_next_feature = voidptr_output(lgdal.OGR_L_GetNextFeature, [c_void_p])
  36. reset_reading = void_output(lgdal.OGR_L_ResetReading, [c_void_p], errcheck=False)
  37. test_capability = int_output(lgdal.OGR_L_TestCapability, [c_void_p, c_char_p])
  38. get_spatial_filter = geom_output(lgdal.OGR_L_GetSpatialFilter, [c_void_p])
  39. set_spatial_filter = void_output(lgdal.OGR_L_SetSpatialFilter, [c_void_p, c_void_p], errcheck=False)
  40. set_spatial_filter_rect = void_output(
  41. lgdal.OGR_L_SetSpatialFilterRect,
  42. [c_void_p, c_double, c_double, c_double, c_double], errcheck=False
  43. )
  44. # Feature Definition Routines
  45. get_fd_geom_type = int_output(lgdal.OGR_FD_GetGeomType, [c_void_p])
  46. get_fd_name = const_string_output(lgdal.OGR_FD_GetName, [c_void_p])
  47. get_feat_name = const_string_output(lgdal.OGR_FD_GetName, [c_void_p])
  48. get_field_count = int_output(lgdal.OGR_FD_GetFieldCount, [c_void_p])
  49. get_field_defn = voidptr_output(lgdal.OGR_FD_GetFieldDefn, [c_void_p, c_int])
  50. # Feature Routines
  51. clone_feature = voidptr_output(lgdal.OGR_F_Clone, [c_void_p])
  52. destroy_feature = void_output(lgdal.OGR_F_Destroy, [c_void_p], errcheck=False)
  53. feature_equal = int_output(lgdal.OGR_F_Equal, [c_void_p, c_void_p])
  54. get_feat_geom_ref = geom_output(lgdal.OGR_F_GetGeometryRef, [c_void_p])
  55. get_feat_field_count = int_output(lgdal.OGR_F_GetFieldCount, [c_void_p])
  56. get_feat_field_defn = voidptr_output(lgdal.OGR_F_GetFieldDefnRef, [c_void_p, c_int])
  57. get_fid = int_output(lgdal.OGR_F_GetFID, [c_void_p])
  58. get_field_as_datetime = int_output(
  59. lgdal.OGR_F_GetFieldAsDateTime,
  60. [c_void_p, c_int, c_int_p, c_int_p, c_int_p, c_int_p, c_int_p, c_int_p]
  61. )
  62. get_field_as_double = double_output(lgdal.OGR_F_GetFieldAsDouble, [c_void_p, c_int])
  63. get_field_as_integer = int_output(lgdal.OGR_F_GetFieldAsInteger, [c_void_p, c_int])
  64. if GDAL_VERSION >= (2, 0):
  65. get_field_as_integer64 = int64_output(lgdal.OGR_F_GetFieldAsInteger64, [c_void_p, c_int])
  66. get_field_as_string = const_string_output(lgdal.OGR_F_GetFieldAsString, [c_void_p, c_int])
  67. get_field_index = int_output(lgdal.OGR_F_GetFieldIndex, [c_void_p, c_char_p])
  68. # Field Routines
  69. get_field_name = const_string_output(lgdal.OGR_Fld_GetNameRef, [c_void_p])
  70. get_field_precision = int_output(lgdal.OGR_Fld_GetPrecision, [c_void_p])
  71. get_field_type = int_output(lgdal.OGR_Fld_GetType, [c_void_p])
  72. get_field_type_name = const_string_output(lgdal.OGR_GetFieldTypeName, [c_int])
  73. get_field_width = int_output(lgdal.OGR_Fld_GetWidth, [c_void_p])