Skip to content
Snippets Groups Projects
Commit 0cf03cb4 authored by benjamin.jakimow@geo.hu-berlin.de's avatar benjamin.jakimow@geo.hu-berlin.de
Browse files

made SpatialPoint and SpatialExtent hashable

parent 07ca22e4
No related branches found
No related tags found
No related merge requests found
......@@ -31,7 +31,8 @@ class testclassUtilityTests(unittest.TestCase):
pass
def test_spatialObjection(self):
def test_spatialObjects(self):
"""Test we can click OK."""
import example
pathRE = file_search(os.path.dirname(example.__file__), 're*', recursive=True)[0]
......@@ -45,6 +46,14 @@ class testclassUtilityTests(unittest.TestCase):
self.assertIsInstance(pt1, SpatialPoint)
d = {}
for t in [pt1, se]:
try:
d[t] = '{}'.format(t)
except:
self.fail('Unable to use {} as dictionary key.'.format(type(t)))
if __name__ == "__main__":
unittest.main()
......
......@@ -99,7 +99,7 @@ def scaledUnitString(num, infix=' ', suffix='B', div=1000):
return "{:.1f}{}{}{}".format(num, infix, unit, suffix)
class SpatialPoint(QgsPoint):
class SpatialPoint(QgsPointXY):
"""
Object to keep QgsPoint and QgsCoordinateReferenceSystem together
"""
......@@ -123,6 +123,9 @@ class SpatialPoint(QgsPoint):
super(SpatialPoint, self).__init__(*args)
self.mCrs = crs
def __hash__(self):
return hash(str(self))
def setCrs(self, crs):
assert isinstance(crs, QgsCoordinateReferenceSystem)
self.mCrs = crs
......@@ -155,7 +158,7 @@ class SpatialPoint(QgsPoint):
def toCrs(self, crs):
assert isinstance(crs, QgsCoordinateReferenceSystem)
pt = QgsPoint(self)
pt = QgsPointXY(self)
if self.mCrs != crs:
pt = saveTransform(pt, self.mCrs, crs)
......@@ -291,7 +294,7 @@ def px2geo(px, gt):
#see http://www.gdal.org/gdal_datamodel.html
gx = gt[0] + px.x()*gt[1]+px.y()*gt[2]
gy = gt[3] + px.x()*gt[4]+px.y()*gt[5]
return QgsPoint(gx,gy)
return QgsPointXY(gx,gy)
class SpatialExtent(QgsRectangle):
......@@ -400,16 +403,16 @@ class SpatialExtent(QgsRectangle):
s = ""
def upperRightPt(self):
return QgsPoint(*self.upperRight())
return QgsPointXY(*self.upperRight())
def upperLeftPt(self):
return QgsPoint(*self.upperLeft())
return QgsPointXY(*self.upperLeft())
def lowerRightPt(self):
return QgsPoint(*self.lowerRight())
return QgsPointXY(*self.lowerRight())
def lowerLeftPt(self):
return QgsPoint(*self.lowerLeft())
return QgsPointXY(*self.lowerLeft())
def upperRight(self):
......@@ -442,6 +445,11 @@ class SpatialExtent(QgsRectangle):
self.xMinimum(), self.yMinimum(),
self.xMaximum(), self.yMaximum()
), {}
def __hash__(self):
return hash(str(self))
def __str__(self):
return self.__repr__()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment