Debian Codegraph @

django/contrib/gis/db/backends/postgis/const.py

raw
1 """
2 PostGIS to GDAL conversion constant definitions
3 """
4
5 # Lookup to convert pixel type values from GDAL to PostGIS
6 GDAL_TO_POSTGIS = [None, 4, 6, 5, 8, 7, 10, 11, None, None, None, None]
7
8 # Lookup to convert pixel type values from PostGIS to GDAL
9 POSTGIS_TO_GDAL = [1, 1, 1, 3, 1, 3, 2, 5, 4, None, 6, 7, None, None]
10
11 # Struct pack structure for raster header, the raster header has the
12 # following structure:
13 #
14 # Endianness, PostGIS raster version, number of bands, scale, origin,
15 # skew, srid, width, and height.
16 #
17 # Scale, origin, and skew have x and y values. PostGIS currently uses
18 # a fixed endianness (1) and there is only one version (0).
19 POSTGIS_HEADER_STRUCTURE = "B H H d d d d d d i H H"
20
21 # Lookup values to convert GDAL pixel types to struct characters. This is
22 # used to pack and unpack the pixel values of PostGIS raster bands.
23 GDAL_TO_STRUCT = [
24 None,
25 "B",
26 "H",
27 "h",
28 "L",
29 "l",
30 "f",
31 "d",
32 None,
33 None,
34 None,
35 None,
36 ]
37
38 # Size of the packed value in bytes for different numerical types.
39 # This is needed to cut chunks of band data out of PostGIS raster strings
40 # when decomposing them into GDALRasters.
41 # See https://docs.python.org/library/struct.html#format-characters
42 STRUCT_SIZE = {
43 "b": 1, # Signed char
44 "B": 1, # Unsigned char
45 "?": 1, # _Bool
46 "h": 2, # Short
47 "H": 2, # Unsigned short
48 "i": 4, # Integer
49 "I": 4, # Unsigned Integer
50 "l": 4, # Long
51 "L": 4, # Unsigned Long
52 "f": 4, # Float
53 "d": 8, # Double
54 }
55
56 # Pixel type specifies type of pixel values in a band. Storage flag specifies
57 # whether the band data is stored as part of the datum or is to be found on the
58 # server's filesystem. There are currently 11 supported pixel value types, so 4
59 # bits are enough to account for all. Reserve the upper 4 bits for generic
60 # flags. See
61 # https://trac.osgeo.org/postgis/wiki/WKTRaster/RFC/RFC1_V0SerialFormat#Pixeltypeandstorageflag
62 BANDTYPE_PIXTYPE_MASK = 0x0F
63 BANDTYPE_FLAG_HASNODATA = 1 << 6