MCPcopy
hub / github.com/django/django / SpatialReference

Class SpatialReference

django/contrib/gis/gdal/srs.py:45–349  ·  view source on GitHub ↗

A wrapper for the OGRSpatialReference object. According to the GDAL web site, the SpatialReference object "provide[s] services to represent coordinate systems (projections and datums) and to transform between them."

Source from the content-addressed store, hash-verified

43
44
45class SpatialReference(GDALBase):
46 """
47 A wrapper for the OGRSpatialReference object. According to the GDAL web
48 site, the SpatialReference object "provide[s] services to represent
49 coordinate systems (projections and datums) and to transform between them."
50 """
51
52 destructor = capi.release_srs
53
54 def __init__(self, srs_input="", srs_type="user", axis_order=None):
55 """
56 Create a GDAL OSR Spatial Reference object from the given input.
57 The input may be string of OGC Well Known Text (WKT), an integer
58 EPSG code, a PROJ string, and/or a projection "well known" shorthand
59 string (one of 'WGS84', 'WGS72', 'NAD27', 'NAD83').
60 """
61 if not isinstance(axis_order, (NoneType, AxisOrder)):
62 raise ValueError(
63 "SpatialReference.axis_order must be an AxisOrder instance."
64 )
65 self.axis_order = axis_order or AxisOrder.TRADITIONAL
66 if srs_type == "wkt":
67 self.ptr = capi.new_srs(c_char_p(b""))
68 self.import_wkt(srs_input)
69 if self.axis_order == AxisOrder.TRADITIONAL:
70 capi.set_axis_strategy(self.ptr, self.axis_order)
71 return
72 elif isinstance(srs_input, str):
73 try:
74 # If SRID is a string, e.g., '4326', then make acceptable
75 # as user input.
76 srid = int(srs_input)
77 srs_input = "EPSG:%d" % srid
78 except ValueError:
79 pass
80 elif isinstance(srs_input, int):
81 # EPSG integer code was input.
82 srs_type = "epsg"
83 elif isinstance(srs_input, self.ptr_type):
84 srs = srs_input
85 srs_type = "ogr"
86 else:
87 raise TypeError('Invalid SRS type "%s"' % srs_type)
88
89 if srs_type == "ogr":
90 # Input is already an SRS pointer.
91 srs = srs_input
92 else:
93 # Creating a new SRS pointer, using the string buffer.
94 buf = c_char_p(b"")
95 srs = capi.new_srs(buf)
96
97 # If the pointer is NULL, throw an exception.
98 if not srs:
99 raise SRSException(
100 "Could not create spatial reference from: %s" % srs_input
101 )
102 else:

Callers 15

add_srs_entryFunction · 0.90
check_srsMethod · 0.90
srsMethod · 0.90
_get_srsMethod · 0.90
_set_srsMethod · 0.90
transformMethod · 0.90
srsMethod · 0.90
transformMethod · 0.90
get_dump_objectMethod · 0.90
test_srsMethod · 0.90
test_srs_transformMethod · 0.90
test_raster_transformMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_srsMethod · 0.72
test_srs_transformMethod · 0.72
test_raster_transformMethod · 0.72
test01_wktMethod · 0.72
test02_bad_wktMethod · 0.72
test03_get_wktMethod · 0.72
test04_projMethod · 0.72
test05_epsgMethod · 0.72
test07_boolean_propsMethod · 0.72
test08_angular_linearMethod · 0.72
test09_authorityMethod · 0.72
test10_attributesMethod · 0.72