def test_parse(self): keywords = dict(geom_uid=[None, 'ID'], geom=[None, get_geometry_dictionaries(), get_geometry_dictionaries(uid='ID')]) for k in self.iter_product_keywords(keywords): g = Geom(k.geom, geom_uid=k.geom_uid) ret = g.parse(k.geom) if k.geom is None: self.assertIsNone(ret) else: if k.geom_uid is None: actual = constants.OCGIS_UNIQUE_GEOMETRY_IDENTIFIER else: actual = k.geom_uid for element in ret: self.assertEqual(element.geom.ugid.name, actual)
def test_parse(self): keywords = dict(geom_uid=[None, 'ID'], geom=[ None, get_geometry_dictionaries(), get_geometry_dictionaries(uid='ID') ]) for k in self.iter_product_keywords(keywords): g = Geom(k.geom, geom_uid=k.geom_uid) ret = g.parse(k.geom) if k.geom is None: self.assertIsNone(ret) else: if k.geom_uid is None: actual = constants.OCGIS_UNIQUE_GEOMETRY_IDENTIFIER else: actual = k.geom_uid for element in ret: self.assertEqual(element.geom.ugid.name, actual)
def test_get_spatial_subset_circular_geometries(self): """Test circular geometries. They were causing wrapping errors.""" geoms = get_geometry_dictionaries() rd = self.test_data.get_rd('cancm4_tas') buffered = [element['geom'].buffer(rd.get().grid.resolution * 2) for element in geoms] for buff in buffered: ss = SpatialSubsetOperation(rd.get(), wrap=False) gvar = GeometryVariable(value=buff, name='geom', dimensions='dim', crs=WGS84()) ret = ss.get_spatial_subset('intersects', gvar) self.assertTrue(np.all(ret.grid.x.get_value() >= 0))
def test_system_geometry_dictionary(self): """Test geometry dictionaries come out properly as collections.""" subset = self.get_subset_operation() conv = NumpyConverter(subset) coll = conv.write() geom = get_geometry_dictionaries() container = coll.children[2] self.assertEqual(container['COUNTRY'].get_value()[0], 'Germany') self.assertEqual(container.geom.get_value()[0], geom[1]['geom']) self.assertEqual(len(coll.children), 3)
def test_geometry_dictionaries(self): """Test geometry dictionaries as input.""" for crs in [None, WGS84(), CoordinateReferenceSystem(epsg=2136)]: geom = get_geometry_dictionaries() if crs is not None: for g in geom: g['crs'] = crs g = Geom(geom) self.assertEqual(len(g.value), 3) for gdict, field in zip(geom, g.value): self.assertEqual(field.geom.geom_type, 'Point') if crs is None: self.assertIsInstance(field.crs, env.DEFAULT_COORDSYS.__class__) else: self.assertIsInstance(field.crs, crs.__class__) self.assertEqual(set([v.name for v in field.data_variables]), set(['UGID', 'COUNTRY'])) self.assertEqual(field.geom.ugid.shape[0], 1) self.assertEqual(field['UGID'].get_value()[0], gdict['properties']['UGID']) self.assertEqual(field['COUNTRY'].get_value()[0], gdict['properties']['COUNTRY'])
def test_geometry_dictionaries(self): """Test geometry dictionaries as input.""" for crs in [None, WGS84(), CoordinateReferenceSystem(epsg=2136)]: geom = get_geometry_dictionaries() if crs is not None: for g in geom: g['crs'] = crs g = Geom(geom) self.assertEqual(len(g.value), 3) for gdict, field in zip(geom, g.value): self.assertEqual(field.geom.geom_type, 'Point') if crs is None: self.assertIsInstance(field.crs, env.DEFAULT_COORDSYS.__class__) else: self.assertIsInstance(field.crs, crs.__class__) self.assertEqual(set([v.name for v in field.data_variables]), set(['UGID', 'COUNTRY'])) self.assertEqual(field.geom.ugid.shape[0], 1) self.assertEqual(field['UGID'].get_value()[0], gdict['properties']['UGID']) self.assertEqual(field['COUNTRY'].get_value()[0], gdict['properties']['COUNTRY'])
def get_subset_operation(self): geom = get_geometry_dictionaries() rd = self.test_data.get_rd('cancm4_tas') ops = ocgis.OcgOperations(dataset=rd, geom=geom, select_nearest=True) subset = OperationsEngine(ops) return subset