1 from ctypes
import c_char_p
, c_double
, c_int
, c_void_p
, POINTER
2 from django
.contrib
.gis
.gdal
.envelope
import OGREnvelope
3 from django
.contrib
.gis
.gdal
.libgdal
import lgdal
, GEOJSON
4 from django
.contrib
.gis
.gdal
.prototypes
.errcheck
import check_bool
, check_envelope
5 from django
.contrib
.gis
.gdal
.prototypes
.generation
import (const_string_output
,
6 double_output
, geom_output
, int_output
, srs_output
, string_output
, void_output
)
8 ### Generation routines specific to this module ###
9 def env_func(f
, argtypes
):
10 "For getting OGREnvelopes."
13 f
.errcheck
= check_envelope
17 "For accessing point information."
18 return double_output(f
, [c_void_p
, c_int
])
21 f
.argtypes
= [c_void_p
, c_void_p
]
23 f
.errchck
= check_bool
26 ### OGR_G ctypes function prototypes ###
28 # GeoJSON routines, if supported.
30 from_json
= geom_output(lgdal
.OGR_G_CreateGeometryFromJson
, [c_char_p
])
31 to_json
= string_output(lgdal
.OGR_G_ExportToJson
, [c_void_p
], str_result
=True)
32 to_kml
= string_output(lgdal
.OGR_G_ExportToKML
, [c_void_p
, c_char_p
], str_result
=True)
38 # GetX, GetY, GetZ all return doubles.
39 getx
= pnt_func(lgdal
.OGR_G_GetX
)
40 gety
= pnt_func(lgdal
.OGR_G_GetY
)
41 getz
= pnt_func(lgdal
.OGR_G_GetZ
)
43 # Geometry creation routines.
44 from_wkb
= geom_output(lgdal
.OGR_G_CreateFromWkb
, [c_char_p
, c_void_p
, POINTER(c_void_p
), c_int
], offset
=-2)
45 from_wkt
= geom_output(lgdal
.OGR_G_CreateFromWkt
, [POINTER(c_char_p
), c_void_p
, POINTER(c_void_p
)], offset
=-1)
46 create_geom
= geom_output(lgdal
.OGR_G_CreateGeometry
, [c_int
])
47 clone_geom
= geom_output(lgdal
.OGR_G_Clone
, [c_void_p
])
48 get_geom_ref
= geom_output(lgdal
.OGR_G_GetGeometryRef
, [c_void_p
, c_int
])
49 get_boundary
= geom_output(lgdal
.OGR_G_GetBoundary
, [c_void_p
])
50 geom_convex_hull
= geom_output(lgdal
.OGR_G_ConvexHull
, [c_void_p
])
51 geom_diff
= geom_output(lgdal
.OGR_G_Difference
, [c_void_p
, c_void_p
])
52 geom_intersection
= geom_output(lgdal
.OGR_G_Intersection
, [c_void_p
, c_void_p
])
53 geom_sym_diff
= geom_output(lgdal
.OGR_G_SymmetricDifference
, [c_void_p
, c_void_p
])
54 geom_union
= geom_output(lgdal
.OGR_G_Union
, [c_void_p
, c_void_p
])
56 # Geometry modification routines.
57 add_geom
= void_output(lgdal
.OGR_G_AddGeometry
, [c_void_p
, c_void_p
])
58 import_wkt
= void_output(lgdal
.OGR_G_ImportFromWkt
, [c_void_p
, POINTER(c_char_p
)])
61 destroy_geom
= void_output(lgdal
.OGR_G_DestroyGeometry
, [c_void_p
], errcheck
=False)
63 # Geometry export routines.
64 to_wkb
= void_output(lgdal
.OGR_G_ExportToWkb
, None, errcheck
=True) # special handling for WKB.
65 to_wkt
= string_output(lgdal
.OGR_G_ExportToWkt
, [c_void_p
, POINTER(c_char_p
)])
66 to_gml
= string_output(lgdal
.OGR_G_ExportToGML
, [c_void_p
], str_result
=True)
67 get_wkbsize
= int_output(lgdal
.OGR_G_WkbSize
, [c_void_p
])
69 # Geometry spatial-reference related routines.
70 assign_srs
= void_output(lgdal
.OGR_G_AssignSpatialReference
, [c_void_p
, c_void_p
], errcheck
=False)
71 get_geom_srs
= srs_output(lgdal
.OGR_G_GetSpatialReference
, [c_void_p
])
74 get_area
= double_output(lgdal
.OGR_G_GetArea
, [c_void_p
])
75 get_centroid
= void_output(lgdal
.OGR_G_Centroid
, [c_void_p
, c_void_p
])
76 get_dims
= int_output(lgdal
.OGR_G_GetDimension
, [c_void_p
])
77 get_coord_dim
= int_output(lgdal
.OGR_G_GetCoordinateDimension
, [c_void_p
])
78 set_coord_dim
= void_output(lgdal
.OGR_G_SetCoordinateDimension
, [c_void_p
, c_int
], errcheck
=False)
80 get_geom_count
= int_output(lgdal
.OGR_G_GetGeometryCount
, [c_void_p
])
81 get_geom_name
= const_string_output(lgdal
.OGR_G_GetGeometryName
, [c_void_p
])
82 get_geom_type
= int_output(lgdal
.OGR_G_GetGeometryType
, [c_void_p
])
83 get_point_count
= int_output(lgdal
.OGR_G_GetPointCount
, [c_void_p
])
84 get_point
= void_output(lgdal
.OGR_G_GetPoint
, [c_void_p
, c_int
, POINTER(c_double
), POINTER(c_double
), POINTER(c_double
)], errcheck
=False)
85 geom_close_rings
= void_output(lgdal
.OGR_G_CloseRings
, [c_void_p
], errcheck
=False)
88 ogr_contains
= topology_func(lgdal
.OGR_G_Contains
)
89 ogr_crosses
= topology_func(lgdal
.OGR_G_Crosses
)
90 ogr_disjoint
= topology_func(lgdal
.OGR_G_Disjoint
)
91 ogr_equals
= topology_func(lgdal
.OGR_G_Equals
)
92 ogr_intersects
= topology_func(lgdal
.OGR_G_Intersects
)
93 ogr_overlaps
= topology_func(lgdal
.OGR_G_Overlaps
)
94 ogr_touches
= topology_func(lgdal
.OGR_G_Touches
)
95 ogr_within
= topology_func(lgdal
.OGR_G_Within
)
97 # Transformation routines.
98 geom_transform
= void_output(lgdal
.OGR_G_Transform
, [c_void_p
, c_void_p
])
99 geom_transform_to
= void_output(lgdal
.OGR_G_TransformTo
, [c_void_p
, c_void_p
])
101 # For retrieving the envelope of the geometry.
102 get_envelope
= env_func(lgdal
.OGR_G_GetEnvelope
, [c_void_p
, POINTER(OGREnvelope
)])