ssb-sgis 1.0.1__py3-none-any.whl → 1.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sgis/__init__.py +97 -115
- sgis/exceptions.py +3 -1
- sgis/geopandas_tools/__init__.py +1 -0
- sgis/geopandas_tools/bounds.py +75 -38
- sgis/geopandas_tools/buffer_dissolve_explode.py +38 -34
- sgis/geopandas_tools/centerlines.py +53 -44
- sgis/geopandas_tools/cleaning.py +87 -104
- sgis/geopandas_tools/conversion.py +149 -101
- sgis/geopandas_tools/duplicates.py +31 -17
- sgis/geopandas_tools/general.py +76 -48
- sgis/geopandas_tools/geometry_types.py +21 -7
- sgis/geopandas_tools/neighbors.py +20 -8
- sgis/geopandas_tools/overlay.py +136 -53
- sgis/geopandas_tools/point_operations.py +9 -8
- sgis/geopandas_tools/polygon_operations.py +48 -56
- sgis/geopandas_tools/polygons_as_rings.py +121 -78
- sgis/geopandas_tools/sfilter.py +14 -14
- sgis/helpers.py +114 -56
- sgis/io/dapla_functions.py +32 -23
- sgis/io/opener.py +13 -6
- sgis/io/read_parquet.py +1 -1
- sgis/maps/examine.py +39 -26
- sgis/maps/explore.py +112 -66
- sgis/maps/httpserver.py +12 -12
- sgis/maps/legend.py +124 -65
- sgis/maps/map.py +66 -41
- sgis/maps/maps.py +31 -29
- sgis/maps/thematicmap.py +46 -33
- sgis/maps/tilesources.py +3 -8
- sgis/networkanalysis/_get_route.py +5 -4
- sgis/networkanalysis/_od_cost_matrix.py +44 -1
- sgis/networkanalysis/_points.py +10 -4
- sgis/networkanalysis/_service_area.py +5 -2
- sgis/networkanalysis/closing_network_holes.py +20 -62
- sgis/networkanalysis/cutting_lines.py +55 -43
- sgis/networkanalysis/directednetwork.py +15 -7
- sgis/networkanalysis/finding_isolated_networks.py +4 -3
- sgis/networkanalysis/network.py +15 -13
- sgis/networkanalysis/networkanalysis.py +72 -54
- sgis/networkanalysis/networkanalysisrules.py +20 -16
- sgis/networkanalysis/nodes.py +2 -3
- sgis/networkanalysis/traveling_salesman.py +5 -2
- sgis/parallel/parallel.py +337 -127
- sgis/raster/__init__.py +6 -0
- sgis/raster/base.py +9 -3
- sgis/raster/cube.py +280 -208
- sgis/raster/cubebase.py +15 -29
- sgis/raster/indices.py +3 -7
- sgis/raster/methods_as_functions.py +0 -124
- sgis/raster/raster.py +313 -127
- sgis/raster/torchgeo.py +58 -37
- sgis/raster/zonal.py +38 -13
- {ssb_sgis-1.0.1.dist-info → ssb_sgis-1.0.2.dist-info}/LICENSE +1 -1
- {ssb_sgis-1.0.1.dist-info → ssb_sgis-1.0.2.dist-info}/METADATA +87 -16
- ssb_sgis-1.0.2.dist-info/RECORD +61 -0
- {ssb_sgis-1.0.1.dist-info → ssb_sgis-1.0.2.dist-info}/WHEEL +1 -1
- sgis/raster/bands.py +0 -48
- sgis/raster/gradient.py +0 -78
- ssb_sgis-1.0.1.dist-info/RECORD +0 -63
sgis/raster/cubebase.py
CHANGED
|
@@ -1,39 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def _raster_from_path(path, raster_type, res, **kwargs):
|
|
6
|
-
return raster_type.from_path(path, res=res, **kwargs)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def _from_gdf_func(gdf, raster_type, **kwargs):
|
|
10
|
-
return raster_type.from_gdf(gdf, **kwargs)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def _write_func(raster, path, **kwargs):
|
|
14
|
-
raster.write(path, **kwargs)
|
|
15
|
-
return raster
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def _add(raster, scalar):
|
|
19
|
-
return raster + scalar
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from pathlib import Path
|
|
20
3
|
|
|
4
|
+
from geopandas import GeoDataFrame
|
|
21
5
|
|
|
22
|
-
|
|
23
|
-
return raster * scalar
|
|
6
|
+
from .raster import Raster
|
|
24
7
|
|
|
25
8
|
|
|
26
|
-
def
|
|
27
|
-
return
|
|
9
|
+
def _from_gdf_func(gdf: GeoDataFrame, **kwargs) -> Raster:
|
|
10
|
+
return Raster.from_gdf(gdf, **kwargs)
|
|
28
11
|
|
|
29
12
|
|
|
30
|
-
def
|
|
31
|
-
return
|
|
13
|
+
def _raster_from_path(path: str, **kwargs) -> Raster:
|
|
14
|
+
return Raster.from_path(path, **kwargs)
|
|
32
15
|
|
|
33
16
|
|
|
34
|
-
def
|
|
35
|
-
return
|
|
17
|
+
def _method_as_func(self: Raster, method: str, **kwargs) -> Callable:
|
|
18
|
+
return getattr(self, method)(**kwargs)
|
|
36
19
|
|
|
37
20
|
|
|
38
|
-
def
|
|
39
|
-
|
|
21
|
+
def _write_func(raster: Raster, folder: str, **kwargs):
|
|
22
|
+
path = str(Path(folder) / Path(raster.name).stem) + ".tif"
|
|
23
|
+
raster.write(path, **kwargs)
|
|
24
|
+
raster.path = path
|
|
25
|
+
return raster
|
sgis/raster/indices.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from
|
|
1
|
+
from collections.abc import Callable
|
|
2
2
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
import pandas as pd
|
|
@@ -18,10 +18,6 @@ def water(green: np.ndarray, nir: np.ndarray) -> np.ndarray:
|
|
|
18
18
|
return np.where((green + nir) == 0, 0, (green - nir) / (green + nir))
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def water(swir: np.ndarray, nir: np.ndarray) -> np.ndarray:
|
|
22
|
-
return np.where((swir + nir) == 0, 0, (nir - swir) / (nir + swir))
|
|
23
|
-
|
|
24
|
-
|
|
25
21
|
def builtup(swir: np.ndarray, nir: np.ndarray) -> np.ndarray:
|
|
26
22
|
return np.where((swir + nir) == 0, 0, (swir - nir) / (swir + nir))
|
|
27
23
|
|
|
@@ -34,13 +30,13 @@ def get_raster_pairs(
|
|
|
34
30
|
cube,
|
|
35
31
|
band_name1: str,
|
|
36
32
|
band_name2: str,
|
|
37
|
-
):
|
|
33
|
+
) -> list[tuple[Raster, Raster]]:
|
|
38
34
|
unique = pd.DataFrame({"tile": cube.tile, "date": cube.date}).drop_duplicates(
|
|
39
35
|
["tile", "date"]
|
|
40
36
|
)
|
|
41
37
|
|
|
42
38
|
raster_pairs = []
|
|
43
|
-
for tile, date in zip(unique["tile"], unique["date"]):
|
|
39
|
+
for tile, date in zip(unique["tile"], unique["date"], strict=False):
|
|
44
40
|
query = (cube.tile == tile) & (cube.date == date)
|
|
45
41
|
band1 = cube.copy()[query & (cube.band == band_name1)]
|
|
46
42
|
band2 = cube.copy()[query & (cube.band == band_name2)]
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"""Method-to-function to use as mapping function."""
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def _cube_merge(cubebounds, **kwargs):
|
|
6
|
-
assert isinstance(cubebounds, dict)
|
|
7
|
-
return cube_merge(cube=cubebounds["cube"], bounds=cubebounds["bounds"], **kwargs)
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def _method_as_func(self, method, **kwargs):
|
|
11
|
-
return getattr(self, method)(**kwargs)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def _astype_raster(raster, raster_type):
|
|
15
|
-
"""Returns raster as another raster type."""
|
|
16
|
-
return raster_type(raster)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def _raster_from_path(path, raster_type, band_index, **kwargs):
|
|
20
|
-
return raster_type.from_path(path, band_index=band_index, **kwargs)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def _from_gdf_func(gdf, raster_type, **kwargs):
|
|
24
|
-
return raster_type.from_gdf(gdf, **kwargs)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def _to_gdf_func(raster, **kwargs):
|
|
28
|
-
return raster.to_gdf(**kwargs)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def _write_func(raster, folder, **kwargs):
|
|
32
|
-
path = str(Path(folder) / Path(raster.name).stem) + ".tif"
|
|
33
|
-
raster.write(path, **kwargs)
|
|
34
|
-
raster.path = path
|
|
35
|
-
return raster
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
def _clip_func(raster, mask, **kwargs):
|
|
39
|
-
return raster.clip(mask, **kwargs)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def _clip_func(raster, mask, **kwargs):
|
|
43
|
-
return raster.clip(mask, **kwargs)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def _load_func(raster, **kwargs):
|
|
47
|
-
return raster.load(**kwargs)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def _zonal_func(raster, **kwargs):
|
|
51
|
-
return raster.zonal(**kwargs)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def _to_crs_func(raster, **kwargs):
|
|
55
|
-
return raster.to_crs(**kwargs)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def _set_crs_func(raster, **kwargs):
|
|
59
|
-
return raster.set_crs(**kwargs)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def _array_astype_func(array, dtype):
|
|
63
|
-
return array.astype(dtype)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def _add(raster, scalar):
|
|
67
|
-
return raster + scalar
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def _mul(raster, scalar):
|
|
71
|
-
return raster * scalar
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def _sub(raster, scalar):
|
|
75
|
-
return raster - scalar
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def _truediv(raster, scalar):
|
|
79
|
-
return raster / scalar
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def _floordiv(raster, scalar):
|
|
83
|
-
return raster // scalar
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def _pow(raster, scalar):
|
|
87
|
-
return raster**scalar
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def _clip_base(cube, mask):
|
|
91
|
-
if (
|
|
92
|
-
hasattr(mask, "crs")
|
|
93
|
-
and mask.crs
|
|
94
|
-
and not pyproj.CRS(cube.crs).equals(pyproj.CRS(mask.crs))
|
|
95
|
-
):
|
|
96
|
-
raise ValueError("crs mismatch.")
|
|
97
|
-
|
|
98
|
-
# first remove rows not within mask
|
|
99
|
-
cube._df = cube._df.loc[cube.boxes.intersects(to_shapely(mask))]
|
|
100
|
-
|
|
101
|
-
return cube
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
def _write_base(cube, subfolder_col, root):
|
|
105
|
-
if cube.df["name"].isna().any():
|
|
106
|
-
raise ValueError("Cannot have missing values in 'name' column when writing.")
|
|
107
|
-
|
|
108
|
-
if cube.df["name"].duplicated().any():
|
|
109
|
-
raise ValueError("Cannot have duplicate names when writing files.")
|
|
110
|
-
|
|
111
|
-
cube.validate_cube_df(cube.df)
|
|
112
|
-
|
|
113
|
-
if subfolder_col:
|
|
114
|
-
folders = [
|
|
115
|
-
Path(root) / subfolder if subfolder else Path(root)
|
|
116
|
-
for subfolder in cube.df[subfolder_col]
|
|
117
|
-
]
|
|
118
|
-
else:
|
|
119
|
-
folders = [Path(root) for _ in cube]
|
|
120
|
-
|
|
121
|
-
rasters = list(cube)
|
|
122
|
-
args = [item for item in zip(rasters, folders)]
|
|
123
|
-
|
|
124
|
-
return cube, args
|