def add(id, description, projection_id, extent, xsize, ysize, xscale, yscale, filename=AREA_REGISTRY): reg = _arearegistry.load(filename) reg.removeByName(id) # Is silent if entry doesn't exist a = _area.new() a.id, a.description, a.pcsid = id, description, projection_id a.extent = extent a.xsize, a.ysize = xsize, ysize a.xscale, a.yscale = xscale, yscale p = rave_projection.pcs(a.pcsid) pid = p.id pname = p.name if isinstance(pid, bytes): pid = pid.decode() if isinstance(pname, bytes): pname = pname.decode() a.projection = _projection.new(pid, pname, " ".join(p.definition)) reg.add(a) reg.write(filename)
def test_write(self): if not _rave.isXmlSupported(): return import _arearegistry registry = _arearegistry.load(self.AREA_FIXTURE) a = _area.new() a.id = "nisse" a.description = "nisses test" a.xsize = 111 a.ysize = 222 a.xscale = 1000.0 a.yscale = 2000.0 a.extent = (-738816.513333, -3995515.596160, 955183.48666699999, -1787515.59616) a.pcsid = "laea20e60n" registry.add(a) registry.write(self.TEMPORARY_FILE) tree = ElementTree.parse(self.TEMPORARY_FILE) areas = tree.findall("area") self.assertEqual(3, len(areas)) self.assertEqual("nisse", areas[2].get('id')) args = areas[2].findall("areadef/arg") self.assertEqual("laea20e60n", self.findArgElements(args, "id", "pcs").text.strip()) self.assertEqual(None, self.findArgElements(args, "id", "pcs").get("type")) self.assertEqual( "111", self.findArgElements(args, "id", "xsize").text.strip()) self.assertEqual("int", self.findArgElements(args, "id", "xsize").get("type")) self.assertEqual( "222", self.findArgElements(args, "id", "ysize").text.strip()) self.assertEqual("int", self.findArgElements(args, "id", "ysize").get("type")) self.assertEqual( "1000.0", self.findArgElements(args, "id", "xscale").text.strip()[:6]) self.assertEqual( "float", self.findArgElements(args, "id", "xscale").get("type")) self.assertEqual( "2000.0", self.findArgElements(args, "id", "yscale").text.strip()[:6]) self.assertEqual( "float", self.findArgElements(args, "id", "yscale").get("type")) extent = self.findArgElements(args, "id", "extent").text.strip().split(",") self.assertEqual("-738816.5", extent[0].strip()[:9]) self.assertEqual("-3995515.5", extent[1].strip()[:10]) self.assertEqual("955183.4", extent[2].strip()[:8]) self.assertEqual("-1787515.5", extent[3].strip()[:10]) self.assertEqual( "sequence", self.findArgElements(args, "id", "extent").get("type"))
def test_removeByName(self): if not _rave.isXmlSupported(): return import _arearegistry registry = _arearegistry.load(self.AREA_FIXTURE) registry.removeByName("nrd2km_laea20e60n") self.assertEqual(1, registry.size()) self.assertEqual("nrd2km", registry.get(0).id)
def test_load(self): if not _rave.isXmlSupported(): return import _arearegistry registry = _arearegistry.load(self.AREA_FIXTURE) self.assertTrue(registry != None) self.assertEqual(2, registry.size()) self.assertEqual("nrd2km", registry.get(0).id) self.assertEqual("nrd2km_laea20e60n", registry.get(1).id)
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_write_2(self): if not _rave.isXmlSupported(): return import _arearegistry registry = _arearegistry.load(self.AREA_FIXTURE) a = _area.new() a.id = "nisse" a.description = "nisses test" a.xsize = 111 a.ysize = 222 a.xscale = 1000.0 a.yscale = 2000.0 a.extent = (-738816.513333, -3995515.596160, 955183.48666699999, -1787515.59616) a.pcsid = "laea20e60n" registry.add(a) registry.write(self.TEMPORARY_FILE) newreg = _arearegistry.load(self.TEMPORARY_FILE) self.assertEqual(3, newreg.size()) self.assertEqual("nrd2km", newreg.get(0).id) self.assertEqual("nrd2km_laea20e60n", newreg.get(1).id) self.assertEqual("nisse", newreg.get(2).id)
def test_add(self): if not _rave.isXmlSupported(): return import _arearegistry registry = _arearegistry.load(self.AREA_FIXTURE) a = _area.new() a.id = "nisse" a.xsize = 111 a.ysize = 222 a.xscale = 1000.0 a.yscale = 2000.0 a.extent = (-738816.513333, -3995515.596160, 955183.48666699999, -1787515.59616) a.pcsid = "laea20e60n" registry.add(a) self.assertEqual(3, registry.size()) self.assertEqual("nisse", registry.getByName("nisse").id)
def test_load_laea(self): if not _rave.isXmlSupported(): return import _arearegistry registry = _arearegistry.load(self.AREA_FIXTURE) self.assertTrue(registry != None) area = registry.get(1) self.assertEqual("laea20e60n", area.pcsid) self.assertEqual(None, area.projection) 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 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=AREA_REGISTRY): reg = _arearegistry.load(filename) reg.removeByName(id) reg.write(filename)