def test_write_2(self): if not _rave.isXmlSupported(): return import _projectionregistry registry = _projectionregistry.load(self.FIXTURE) newproj = _projection.new("testid", "something", "+proj=latlong +ellps=WGS84 +datum=WGS84") registry.add(newproj) registry.write(self.TEMPORARY_FILE) nreg = _projectionregistry.load(self.TEMPORARY_FILE) self.assertEqual(6, nreg.size()) self.assertEqual("testid", nreg.get(5).id) self.assertEqual("something", nreg.get(5).description) self.assertEqual("+proj=latlong +ellps=WGS84 +datum=WGS84", nreg.get(5).definition)
def test_add(self): if not _rave.isXmlSupported(): return import _projectionregistry registry = _projectionregistry.load(self.FIXTURE) newproj = _projection.new("testid", "something", "+proj=latlong +ellps=WGS84 +datum=WGS84") registry.add(newproj) self.assertEqual(6, registry.size()) self.assertEqual("testid", registry.getByName("testid").id) self.assertEqual("something", registry.getByName("testid").description)
def _loadarea(self, areaid): if not _rave.isXmlSupported(): return import _arearegistry, _projectionregistry projreg = _projectionregistry.load(self._projregistryconfig) areareg = _arearegistry.load(self._arearegistryconfig, projreg) try: foundarea = areareg.getByName(areaid) self._registry[foundarea.id] = foundarea except IndexError: pass
def reload(self): self._registry = {} if not _rave.isXmlSupported(): return import _arearegistry, _projectionregistry projreg = _projectionregistry.load(self._projregistryconfig) areareg = _arearegistry.load(self._arearegistryconfig, projreg) len = areareg.size() for i in range(len): a = areareg.get(i) self._registry[a.id] = a
def test_remove(self): if not _rave.isXmlSupported(): return import _projectionregistry registry = _projectionregistry.load(self.FIXTURE) registry.remove(2) self.assertEqual(4, registry.size()) try: registry.getByName("ps14e60n") self.fail("Expected IndexError") except IndexError: pass
def test_getByName(self): if not _rave.isXmlSupported(): return import _projectionregistry registry = _projectionregistry.load(self.FIXTURE) self.assertTrue(registry != None) self.assertEqual("llwgs84", registry.getByName("llwgs84").id) self.assertEqual("rack", registry.getByName("rack").id) self.assertEqual("ps14e60n", registry.getByName("ps14e60n").id) self.assertEqual("laea20e60n", registry.getByName("laea20e60n").id) self.assertEqual("rot10w30s", registry.getByName("rot10w30s").id)
def test_load(self): if not _rave.isXmlSupported(): return import _projectionregistry registry = _projectionregistry.load(self.FIXTURE) self.assertTrue(registry != None) self.assertEqual(5, registry.size()) self.assertEqual("llwgs84", registry.get(0).id) self.assertEqual("rack", registry.get(1).id) self.assertEqual("ps14e60n", registry.get(2).id) self.assertEqual("laea20e60n", registry.get(3).id) self.assertEqual("rot10w30s", registry.get(4).id)
def test_write(self): if not _rave.isXmlSupported(): return import _projectionregistry registry = _projectionregistry.load(self.FIXTURE) newproj = _projection.new("testid", "something", "+proj=latlong +ellps=WGS84 +datum=WGS84") registry.add(newproj) registry.write(self.TEMPORARY_FILE) tree = ElementTree.parse(self.TEMPORARY_FILE) projs = tree.findall("projection") self.assertEqual(6, len(projs)) self.assertEqual("testid", projs[5].get('id')) self.assertEqual("something", projs[5].find("description").text.strip()) self.assertEqual("+proj=latlong +ellps=WGS84 +datum=WGS84", projs[5].find("projdef").text.strip())
def test_load_laea_withprojregistry(self): if not _rave.isXmlSupported(): return import _arearegistry import _projectionregistry projregistry = _projectionregistry.load(self.PROJ_FIXTURE) registry = _arearegistry.load(self.AREA_FIXTURE, projregistry) self.assertTrue(registry != None) area = registry.get(1) self.assertEqual("laea20e60n", area.pcsid) self.assertTrue(area.projection != None) self.assertEqual("Nordic, all radars, 2 km, laea", area.description) self.assertEqual(987, area.xsize) self.assertEqual(543, area.ysize) self.assertAlmostEqual(2000.0, area.xscale, 4) self.assertAlmostEqual(1000.0, area.yscale, 4) self.assertAlmostEqual(-738816.513333, area.extent[0], 4) self.assertAlmostEqual(-3995515.596160, area.extent[1], 4) self.assertAlmostEqual(955183.48666699999, area.extent[2], 4) self.assertAlmostEqual(-1787515.59616, area.extent[3], 4)
def remove(id, filename=PROJECTION_REGISTRY): reg = _projectionregistry.load(filename) reg.removeByName(id) reg.write(filename)
def add(id, description, definition, filename=PROJECTION_REGISTRY): reg = _projectionregistry.load(filename) reg.removeByName(id) # Is silent if entry doesn't exist reg.add(_projection.new(id, description, definition)) reg.write(filename)