-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessing_base.py
More file actions
50 lines (34 loc) · 1.24 KB
/
Copy pathprocessing_base.py
File metadata and controls
50 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json
import rasterio
import numpy as np
import rasterio.features
from skimage import io
import matplotlib.pyplot as plt
from skimage import morphology
import png
box = []
shape_array = []
lista = io.imread('Amazonas2017.tif')
with rasterio.open('Amazonas2017.tif') as src:
box = src.transform
lista[np.where(lista < 0.9)] = 0
lista[np.where(lista >= 0.9)] = 1
first = morphology.remove_small_objects(lista.astype(bool), min_size=800, connectivity=4)
first_int = first.astype(np.int16)
# plt.imshow(lista)
# plt.imshow(golay)
# plt.show()
for shape, value in rasterio.features.shapes(first_int, transform=box, connectivity=8):
if value == 1:
shape_array.append(shape)
data = {"type": "FeatureCollection",
"crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}}}
feature_array = []
feature_ex = {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": []}}
for shape in shape_array:
feature_ex['geometry']['coordinates'] = shape['coordinates']
feature_array.append(feature_ex)
feature_ex = {"type": "Feature", "geometry": {"type": "Polygon", "coordinates": []}}
data['features'] = feature_array
with open('riverAmazonas2017.geojson', 'w') as fout:
json.dump(data, fout)