def test_polygon_with_simp(self): self.maxDiff = None class Collection(list): pass collection = Collection() # collection.crs = dict(proj="merc", lon_0=0, k=1, x_0=0, y_0=0, ellps="WGS84", datum="WGS84", units="m") collection.crs = None collection.schema = dict(geometry="Polygon") collection.extend([ OrderedDict([("type", "Feature"), ("geometry", OrderedDict([("type", "Polygon"), ("coordinates", [[(12.0, 53.0), (13.0, 54.0), (13.3, 55.1), (13.0, 56.0), (12.0, 53.0)]])])), ("properties", OrderedDict([("id", "1"), ("a", 3), ("b", True)]))]), OrderedDict([("type", "Feature"), ("geometry", OrderedDict([("type", "Polygon"), ("coordinates", [[(12.0, 73.0), (13.0, 74.0), (13.1, 75.4), (13.0, 76.0), (12.0, 73.0)]])])), ("properties", OrderedDict([("id", "2"), ("a", 9), ("b", False)]))]), ]) from io import StringIO string_io = StringIO() num_written = write_feature_collection(collection, string_io, conservation_ratio=0.5) # print(num_written, string_io.getvalue()) self.assertEqual(num_written, 2) self.assertEqual( string_io.getvalue(), '{"type": "FeatureCollection", "features": [\n' '{"type": "Feature", "geometry": {"type": "Polygon", ' '"coordinates": [[[12.0, 53.0], [13.0, 54.0], [13.0, 56.0], [12.0, 53.0]]]}, ' '"properties": {"id": "1", "a": 3, "b": true}, "_simp": 1, "_idx": 0, "id": 0},\n' '{"type": "Feature", "geometry": {"type": "Polygon", ' '"coordinates": [[[12.0, 73.0], [13.0, 74.0], [13.0, 76.0], [12.0, 73.0]]]}, ' '"properties": {"id": "2", "a": 9, "b": false}, "_simp": 1, "_idx": 1, "id": 1}\n' ']}\n')
def test_countries_with_simp(self): self.maxDiff = None class Collection(list): pass file = os.path.join(os.path.dirname(__file__), '..', '..', 'cate', 'ds', 'data', 'countries', 'countries.geojson') collection = fiona.open(file) from io import StringIO string_io = StringIO() num_written = write_feature_collection(collection, string_io, conservation_ratio=0) self.assertEqual(num_written, 179)
def test_countries_with_simp(self): self.maxDiff = None class Collection(list): pass file = os.path.join(os.path.dirname(__file__), '..', '..', 'cate', 'ds', 'data', 'countries', 'countries.geojson') collection = fiona.open(file) from io import StringIO string_io = StringIO() num_written = write_feature_collection(collection, string_io, conservation_ratio=0) self.assertEqual(num_written, 179)
def test_polygon_with_simp(self): self.maxDiff = None class Collection(list): pass collection = Collection() # collection.crs = dict(proj="merc", lon_0=0, k=1, x_0=0, y_0=0, ellps="WGS84", datum="WGS84", units="m") collection.crs = None collection.schema = dict(geometry="Polygon") collection.extend([ OrderedDict([("type", "Feature"), ("geometry", OrderedDict([("type", "Polygon"), ("coordinates", [[(12.0, 53.0), (13.0, 54.0), (13.3, 55.1), (13.0, 56.0), (12.0, 53.0)]])])), ("properties", OrderedDict([("id", "1"), ("a", 3), ("b", True)]))]), OrderedDict([("type", "Feature"), ("geometry", OrderedDict([("type", "Polygon"), ("coordinates", [[(12.0, 73.0), (13.0, 74.0), (13.1, 75.4), (13.0, 76.0), (12.0, 73.0)]])])), ("properties", OrderedDict([("id", "2"), ("a", 9), ("b", False)]))]), ]) from io import StringIO string_io = StringIO() num_written = write_feature_collection(collection, string_io, conservation_ratio=0.5) # print(num_written, string_io.getvalue()) self.assertEqual(num_written, 2) self.assertEqual(string_io.getvalue(), '{"type": "FeatureCollection", "features": [\n' '{"type": "Feature", "geometry": {"type": "Polygon", ' '"coordinates": [[[12.0, 53.0], [13.0, 54.0], [13.0, 56.0], [12.0, 53.0]]]}, ' '"properties": {"id": "1", "a": 3, "b": true}, "_simp": 1, "_idx": 0, "id": 0},\n' '{"type": "Feature", "geometry": {"type": "Polygon", ' '"coordinates": [[[12.0, 73.0], [13.0, 74.0], [13.0, 76.0], [12.0, 73.0]]]}, ' '"properties": {"id": "2", "a": 9, "b": false}, "_simp": 1, "_idx": 1, "id": 1}\n' ']}\n')