def test_long_attribute_names(self): line = Line( [(1.0, 5.0), (5.0, 5.0), (5.0, 1.0), (3.0, 3.0), (1.0, 1.0)], properties={ "geom_id": 27, "name": "test line", "description": "line for testing", "description_en": "Line for testing." }, crs=LonLatWGS84) with warnings.catch_warnings(): warnings.simplefilter("ignore") line.to_shapefile(os.path.join(TESTDIR, "data/line_truncated_attr")) for fnm in ("line_truncated_attr.shx", "line_truncated_attr.shx", "line_truncated_attr.dbf", "line_truncated_attr.prj"): self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm))) line2 = read_shapefile( os.path.join(TESTDIR, "data", "line_truncated_attr"))[0] self.assertTrue("DESCRIPTIO" in line2.properties) self.assertTrue("DESCRIPTI2" in line2.properties) self.assertTrue("GEOM_ID" in line2.properties) self.assertTrue("NAME" in line2.properties)
def test_read_polygon(self): polygon = read_shapefile(os.path.join(TESTDATA, "shp_input", "polygon"))[0] self.assertTrue("+proj=lonlat" in polygon.crs.get_proj4()) self.assertTrue("+a=6378137.0" in polygon.crs.get_proj4()) self.assertTrue("+f=0.00335281" in polygon.crs.get_proj4()) self.assertEqual(polygon.coordinates, ((1.0, 5.0, 5.0, 3.0, 1.0), (5.0, 5.0, 1.0, 3.0, 1.0))) return
def test_read_points_newp(self): # Read a multipoint with a projected cooridnate system newp = read_shapefile( os.path.join(TESTDATA, "shapefile", "newp_nsidc_north")) proj4 = ('+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 ' '+y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs') for part in proj4.split(): self.assertTrue(part[:8] in newp[0].crs.get_proj4()) coords = list(zip(*[pt.vertex[:2] for pt in newp])) self.assertEqual( coords, [(521236.8297444395, 521236.8297444395, 521236.8297444395, 547490.4452879033, 547490.4452879033, 547490.4452879033, 587584.1578033275, 587584.1578033275, 587584.1578033275, 571828.4918982167, 571828.4918982167), (-888853.1384770898, -888853.1384770898, -888853.1384770898, -902049.3617542256, -902049.3617542256, -902049.3617542256, -871214.0673764511, -871214.0673764511, -871214.0673764511, -850080.914674058, -850080.914674058)]) meterno = [pt.properties["meterno"] for pt in newp] self.assertEqual(meterno, [ 'IMS1/1', 'IMS2/1', '5952/2', 'IMS4/1', '5953/2', '1963/13', 'IMS5/1', '5213/A', '2121/13', 'IMS3/1', '3613/2' ]) depth = [pt.properties["depth_m"] for pt in newp] self.assertEqual(depth, [ '73', '143', '247', '86', '147', '250', '74', '142', '235', '150', '248' ])
def test_read_points_newp(self): # Read a multipoint with a projected cooridnate system newp = read_shapefile(os.path.join(TESTDATA, "shp_input", "newp_nsidc_north")) proj4 = ('+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 ' '+y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs') for part in proj4.split(): self.assertTrue(part[:8] in newp[0].crs.get_proj4()) coords = list(zip(*[pt.vertex[:2] for pt in newp])) self.assertEqual(coords, [(521236.8297444395, 521236.8297444395, 521236.8297444395, 547490.4452879033, 547490.4452879033, 547490.4452879033, 587584.1578033275, 587584.1578033275, 587584.1578033275, 571828.4918982167, 571828.4918982167), (-888853.1384770898, -888853.1384770898, -888853.1384770898, -902049.3617542256, -902049.3617542256, -902049.3617542256, -871214.0673764511, -871214.0673764511, -871214.0673764511, -850080.914674058, -850080.914674058)]) meterno = [pt.properties["meterno"] for pt in newp] self.assertEqual(meterno, ['IMS1/1', 'IMS2/1', '5952/2', 'IMS4/1', '5953/2', '1963/13', 'IMS5/1', '5213/A', '2121/13', 'IMS3/1', '3613/2']) depth = [pt.properties["depth_m"] for pt in newp] self.assertEqual(depth, ['73', '143', '247', '86', '147', '250', '74', '142', '235', '150', '248']) return
def test_long_attribute_names(self): line = Line([(1.0,5.0),(5.0,5.0),(5.0,1.0),(3.0,3.0),(1.0,1.0)], properties={ "geom_id": 27, "name": "test line", "description": "line for testing", "description_en": "Line for testing." }, crs=LonLatWGS84) with warnings.catch_warnings(): warnings.simplefilter("ignore") line.to_shapefile(os.path.join(TESTDIR, "data/line_truncated_attr")) for fnm in ("line_truncated_attr.shx", "line_truncated_attr.shx", "line_truncated_attr.dbf", "line_truncated_attr.prj"): self.assertTrue(os.path.isfile(os.path.join(TESTDIR, "data", fnm))) line2 = read_shapefile(os.path.join(TESTDIR, "data", "line_truncated_attr"))[0] self.assertTrue("DESCRIPTIO" in line2.properties) self.assertTrue("DESCRIPTI2" in line2.properties) self.assertTrue("GEOM_ID" in line2.properties) self.assertTrue("NAME" in line2.properties)
def test_read_polygon(self): polygon = read_shapefile(os.path.join(TESTDATA, "shapefile", "polygon"))[0] self.assertTrue("+proj=lonlat" in polygon.crs.get_proj4()) self.assertTrue("+a=6378137.0" in polygon.crs.get_proj4()) self.assertTrue("+f=0.00335281" in polygon.crs.get_proj4()) x, y = polygon.coords() self.assertTrue(np.all(x == np.array([1.0, 5.0, 5.0, 3.0, 1.0]))) self.assertTrue(np.all(y == np.array([5.0, 5.0, 1.0, 3.0, 1.0])))
def test_read_line(self): line = read_shapefile(os.path.join(TESTDATA, "shapefile", "line"))[0] self.assertTrue("+proj=lonlat" in line.crs.get_proj4()) self.assertTrue("+a=6378137.0" in line.crs.get_proj4()) self.assertTrue("+f=0.00335281" in line.crs.get_proj4()) x, y = line.coordinates self.assertTrue(np.all(x == np.array([1.0, 5.0, 5.0, 3.0, 1.0]))) self.assertTrue(np.all(y == np.array([5.0, 5.0, 1.0, 3.0, 1.0])))
def test_read_line(self): line = read_shapefile(os.path.join(TESTDATA, "shapefile", "line"))[0] self.assertTrue("+proj=lonlat" in line.crs.get_proj4()) self.assertTrue("+a=6378137.0" in line.crs.get_proj4()) self.assertTrue("+f=0.00335281" in line.crs.get_proj4()) x, y = line.coordinates self.assertTrue(np.all(x == np.array([1.0, 5.0, 5.0, 3.0, 1.0]))) self.assertTrue(np.all(y == np.array([5.0, 5.0, 1.0, 3.0, 1.0]))) return
def test_read_points(self): points = read_shapefile(os.path.join(TESTDATA, "shp_input", "points")) self.assertEqual(len(points), 4) pt = points[0] self.assertTrue("+proj=lonlat" in pt.crs.get_proj4()) self.assertTrue("+a=6378137.0" in pt.crs.get_proj4()) self.assertTrue("+f=0.00335281" in pt.crs.get_proj4()) mp = Multipoint(points) self.assertEqual(mp.d["species"], ['T. officianale', 'C. tectorum', 'M. alba', 'V. cracca']) self.assertEqual(mp.d["ID"], ['0', '1', '2', '3']) self.assertEqual(mp.coordinates, ((1.0, 3.0, 4.0, 2.0), (1.0, 1.0, 3.0, 2.0)))
def test_read_points(self): points = read_shapefile(os.path.join(TESTDATA, "shapefile", "points")) self.assertEqual(len(points), 4) pt = points[0] self.assertTrue("+proj=lonlat" in pt.crs.get_proj4()) self.assertTrue("+a=6378137.0" in pt.crs.get_proj4()) self.assertTrue("+f=0.00335281" in pt.crs.get_proj4()) mp = multipart_from_singleparts(points) self.assertEqual(mp.d["species"], ['T. officianale', 'C. tectorum', 'M. alba', 'V. cracca']) self.assertEqual(mp.d["ID"], ['0', '1', '2', '3']) x, y = mp.coordinates self.assertTrue(np.all(x == np.array((1.0, 3.0, 4.0, 2.0)))) self.assertTrue(np.all(y == np.array((1.0, 1.0, 3.0, 2.0))))
def test_read_points(self): shps = read_shapefile(os.path.join(TESTDATA, "newp")) mp = shps[0] self.assertEqual(mp.vertices, [(-14.612, 80.50906666666667), (-14.612, 80.50906666666667), (-14.612, 80.50906666666667), (-13.744733333333333, 80.28181666666667), (-13.744733333333333, 80.28181666666667), (-13.744733333333333, 80.28181666666667), (-11.002583333333334, 80.32173333333333), (-11.002583333333334, 80.32173333333333), (-11.002583333333334, 80.32173333333333), (-11.07225, 80.56316666666666), (-11.07225, 80.56316666666666)]) self.assertEqual(mp.data.getfield("meterno"), ['IMS1/1', 'IMS2/1', '5952/2', 'IMS4/1', '5953/2', '1963/13', 'IMS5/1', '5213/A', '2121/13', 'IMS3/1', '3613/2']) self.assertEqual(mp.data.getfield("depth_m"), [73, 143, 247, 86, 147, 250, 74, 142, 235, 150, 248]) return
def test_read_polygon(self): polygon = read_shapefile(os.path.join(TESTDATA, "shapefiles", "polygon"))[0] self.assertGeomEqual(polygon, self.polygon) return
def test_read_line(self): line = read_shapefile(os.path.join(TESTDATA, "shapefiles", "line"))[0] self.assertGeomEqual(line, self.line) return
def test_read_multipoint_attributes(self): mp = read_shapefile(os.path.join(TESTDATA, "shapefiles", "points")) self.assertEqual(mp[0].data.getfield("species"), self.multipoint.data.getfield("species")) return
def test_13(self): res = read_shapefile(os.path.join(self.dirname, "test13.shp")) self.assertEqual(type(res[0]), Multipolygon) self.assertEqual(len(res), 4)
def test_9(self): res = read_shapefile(os.path.join(self.dirname, "test9.shp")) self.assertEqual(type(res[0]), Line) self.assertEqual(len(res), 4)
def test_3(self): res = read_shapefile(os.path.join(self.dirname, "test3.shp")) self.assertEqual(type(res[0]), Point) self.assertEqual(len(res), 2)
def test_6(self): res = read_shapefile(os.path.join(self.dirname, "test6.shp")) self.assertEqual(type(res[0]), Multipoint) self.assertEqual(len(res), 3)
def test_13(self): res = read_shapefile(os.path.join(self.dirname, "test13.shp"))
def test_0(self): res = read_shapefile(os.path.join(self.dirname, "test0.shp"))