def _parse_area(cls, src_elem): """ :param src_elem: :class:`lxml.etree._Element` instance representing a source. :returns: Fully populated :class:`openquake.nrmllib.models.AreaSource` object. """ area = models.AreaSource() cls._set_common_attrs(area, src_elem) area_geom = models.AreaGeometry() area.geometry = area_geom [gml_pos_list] = _xpath(src_elem, './/gml:posList') coords = gml_pos_list.text.split() # Area source polygon geometries are always 2-dimensional and on the # Earth's surface (depth == 0.0). area_geom.wkt = utils.coords_to_poly_wkt(coords, 2) area_geom.upper_seismo_depth = float( _xpath(src_elem, './/nrml:upperSeismoDepth')[0].text) area_geom.lower_seismo_depth = float( _xpath(src_elem, './/nrml:lowerSeismoDepth')[0].text) area.mfd = cls._parse_mfd(src_elem) area.nodal_plane_dist = cls._parse_nodal_plane_dist(src_elem) area.hypo_depth_dist = cls._parse_hypo_depth_dist(src_elem) return area
def test_coords_to_poly_wkt_2d(self): expected = 'POLYGON((1.0 1.0, 2.0 2.0, 3.0 3.0, 1.0 1.0))' coords = [1.0, '1.0', '2.0', 2.0, 3.0, '3.0'] actual = utils.coords_to_poly_wkt(coords, 2) self.assertEqual(expected, actual)
def test_coords_to_poly_wkt_3d(self): expected = "POLYGON((1.0 1.0 0.1, 2.0 2.0 0.2, 3.0 3.0 0.3, 1.0 1.0 0.1))" coords = [1.0, "1.0", 0.1, "2.0", 2.0, "0.2", 3.0, "3.0", 0.3] actual = utils.coords_to_poly_wkt(coords, 3) self.assertEqual(expected, actual)
def test_coords_to_poly_wkt_2d(self): expected = "POLYGON((1.0 1.0, 2.0 2.0, 3.0 3.0, 1.0 1.0))" coords = [1.0, "1.0", "2.0", 2.0, 3.0, "3.0"] actual = utils.coords_to_poly_wkt(coords, 2) self.assertEqual(expected, actual)
def test_coords_to_poly_wkt_3d(self): expected = ( 'POLYGON((1.0 1.0 0.1, 2.0 2.0 0.2, 3.0 3.0 0.3, 1.0 1.0 0.1))') coords = [1.0, '1.0', 0.1, '2.0', 2.0, '0.2', 3.0, '3.0', 0.3] actual = utils.coords_to_poly_wkt(coords, 3) self.assertEqual(expected, actual)