ssb-sgis 1.0.1__py3-none-any.whl → 1.0.3__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.
Files changed (60) hide show
  1. sgis/__init__.py +107 -121
  2. sgis/exceptions.py +5 -3
  3. sgis/geopandas_tools/__init__.py +1 -0
  4. sgis/geopandas_tools/bounds.py +86 -47
  5. sgis/geopandas_tools/buffer_dissolve_explode.py +62 -39
  6. sgis/geopandas_tools/centerlines.py +53 -44
  7. sgis/geopandas_tools/cleaning.py +87 -104
  8. sgis/geopandas_tools/conversion.py +164 -107
  9. sgis/geopandas_tools/duplicates.py +33 -19
  10. sgis/geopandas_tools/general.py +84 -52
  11. sgis/geopandas_tools/geometry_types.py +24 -10
  12. sgis/geopandas_tools/neighbors.py +23 -11
  13. sgis/geopandas_tools/overlay.py +136 -53
  14. sgis/geopandas_tools/point_operations.py +11 -10
  15. sgis/geopandas_tools/polygon_operations.py +53 -61
  16. sgis/geopandas_tools/polygons_as_rings.py +121 -78
  17. sgis/geopandas_tools/sfilter.py +17 -17
  18. sgis/helpers.py +116 -58
  19. sgis/io/dapla_functions.py +32 -23
  20. sgis/io/opener.py +13 -6
  21. sgis/io/read_parquet.py +2 -2
  22. sgis/maps/examine.py +55 -28
  23. sgis/maps/explore.py +471 -112
  24. sgis/maps/httpserver.py +12 -12
  25. sgis/maps/legend.py +285 -134
  26. sgis/maps/map.py +248 -129
  27. sgis/maps/maps.py +123 -119
  28. sgis/maps/thematicmap.py +260 -94
  29. sgis/maps/tilesources.py +3 -8
  30. sgis/networkanalysis/_get_route.py +5 -4
  31. sgis/networkanalysis/_od_cost_matrix.py +44 -1
  32. sgis/networkanalysis/_points.py +10 -4
  33. sgis/networkanalysis/_service_area.py +5 -2
  34. sgis/networkanalysis/closing_network_holes.py +22 -64
  35. sgis/networkanalysis/cutting_lines.py +58 -46
  36. sgis/networkanalysis/directednetwork.py +16 -8
  37. sgis/networkanalysis/finding_isolated_networks.py +6 -5
  38. sgis/networkanalysis/network.py +15 -13
  39. sgis/networkanalysis/networkanalysis.py +79 -61
  40. sgis/networkanalysis/networkanalysisrules.py +21 -17
  41. sgis/networkanalysis/nodes.py +2 -3
  42. sgis/networkanalysis/traveling_salesman.py +6 -3
  43. sgis/parallel/parallel.py +372 -142
  44. sgis/raster/base.py +9 -3
  45. sgis/raster/cube.py +331 -213
  46. sgis/raster/cubebase.py +15 -29
  47. sgis/raster/image_collection.py +2560 -0
  48. sgis/raster/indices.py +17 -12
  49. sgis/raster/raster.py +356 -275
  50. sgis/raster/sentinel_config.py +104 -0
  51. sgis/raster/zonal.py +38 -14
  52. {ssb_sgis-1.0.1.dist-info → ssb_sgis-1.0.3.dist-info}/LICENSE +1 -1
  53. {ssb_sgis-1.0.1.dist-info → ssb_sgis-1.0.3.dist-info}/METADATA +87 -16
  54. ssb_sgis-1.0.3.dist-info/RECORD +61 -0
  55. {ssb_sgis-1.0.1.dist-info → ssb_sgis-1.0.3.dist-info}/WHEEL +1 -1
  56. sgis/raster/bands.py +0 -48
  57. sgis/raster/gradient.py +0 -78
  58. sgis/raster/methods_as_functions.py +0 -124
  59. sgis/raster/torchgeo.py +0 -150
  60. ssb_sgis-1.0.1.dist-info/RECORD +0 -63
@@ -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
sgis/raster/torchgeo.py DELETED
@@ -1,150 +0,0 @@
1
- import glob
2
- import os
3
- import warnings
4
- from typing import Iterable
5
-
6
- import rasterio
7
- import rasterio.merge
8
- from rasterio.io import DatasetReader
9
- from rasterio.vrt import WarpedVRT
10
- from torchgeo.datasets.geo import RasterDataset
11
- from torchgeo.datasets.sentinel import Sentinel2 as TorchgeoSentinel2
12
-
13
-
14
- try:
15
- import dapla as dp
16
- except ImportError:
17
- pass
18
-
19
- try:
20
- from gcsfs.core import GCSFile
21
- except ImportError:
22
-
23
- class GCSFile:
24
- pass
25
-
26
-
27
- from ..io._is_dapla import is_dapla
28
- from ..io.opener import opener
29
- from .bands import SENTINEL2_FILENAME_REGEX
30
-
31
-
32
- class GCSRasterDataset(RasterDataset):
33
- """Wrapper around torchgeo's RasterDataset that works in and outside of Dapla (stat norway)."""
34
-
35
- def __init__(self, *args, **kwargs):
36
- super().__init__(*args, **kwargs)
37
- if is_dapla():
38
- [file.close() for file in self.files]
39
-
40
- @property
41
- def files(self) -> set[GCSFile] | set[str]:
42
- """A list of all files in the dataset.
43
-
44
- Returns:
45
- All files in the dataset.
46
-
47
- .. versionadded:: 0.5
48
- """
49
- if isinstance(self.paths, str):
50
- paths: list[str] = [self.paths]
51
- else:
52
- paths = self.paths
53
-
54
- if is_dapla():
55
- fs = dp.FileClient.get_gcs_file_system()
56
- files: set[GCSFile] = {
57
- fs.open(x)
58
- for x in _get_gcs_paths(
59
- paths, filename_glob=self.filename_glob, file_system=fs
60
- )
61
- }
62
- return files
63
-
64
- # Using set to remove any duplicates if directories are overlapping
65
- files: set[str] = set()
66
- for path in paths:
67
- if os.path.isdir(path):
68
- pathname = os.path.join(path, "**", self.filename_glob)
69
- files |= {
70
- x for x in glob.iglob(pathname, recursive=True) if os.path.isfile(x)
71
- }
72
- elif os.path.isfile(path):
73
- files.add(path)
74
- else:
75
- warnings.warn(
76
- f"Could not find any relevant files for provided path '{path}'. "
77
- f"Path was ignored.",
78
- UserWarning,
79
- )
80
-
81
- return files
82
-
83
- def _load_warp_file(self, filepath: str) -> DatasetReader:
84
- """Load and warp a file to the correct CRS and resolution.
85
-
86
- Args:
87
- filepath: file to load and warp
88
-
89
- Returns:
90
- file handle of warped VRT
91
- """
92
- with opener(filepath) as f:
93
- src = rasterio.open(f)
94
-
95
- # Only warp if necessary
96
- if src.crs != self.crs:
97
- vrt = WarpedVRT(src, crs=self.crs)
98
- src.close()
99
- return vrt
100
- else:
101
- return src
102
-
103
-
104
- def _get_gcs_paths(
105
- paths: str | Iterable[str], filename_glob: str, file_system=None
106
- ) -> set[str]:
107
- if file_system is None:
108
- file_system = dp.FileClient.get_gcs_file_system()
109
-
110
- # Using set to remove any duplicates if directories are overlapping
111
- out_paths: set[str] = set()
112
- for path in paths:
113
- pathname = os.path.join(path, "**", filename_glob)
114
- if is_dapla():
115
- out_paths |= {
116
- x for x in file_system.glob(pathname, recursive=True) if "." in x
117
- }
118
- return out_paths
119
-
120
-
121
- class Sentinel2(GCSRasterDataset):
122
- """Works like torchgeo's Sentinel2, with custom regexes."""
123
-
124
- date_format: str = "%Y%m%d"
125
- filename_glob = "SENTINEL2X_*_*.*"
126
-
127
- filename_regex = SENTINEL2_FILENAME_REGEX
128
-
129
- all_bands = [
130
- # "B1",
131
- "B2",
132
- "B3",
133
- "B4",
134
- "B5",
135
- "B6",
136
- "B7",
137
- "B8",
138
- "B8A",
139
- # "B9",
140
- # "B10",
141
- "B11",
142
- "B12",
143
- ]
144
- rgb_bands = ["B4", "B3", "B2"]
145
-
146
- separate_files = True
147
-
148
- cmap: dict[int, tuple[int, int, int, int]] = {}
149
-
150
- plot = TorchgeoSentinel2.plot
@@ -1,63 +0,0 @@
1
- sgis/__init__.py,sha256=GB1iSexFAzc3SeAXpd9BqSEmEJsekLo_RJ5SPVzqjdM,4018
2
- sgis/exceptions.py,sha256=ztMp4sB9xxPvwj2IEsO5kOaB4FmHuU_7-M2pZ7qaxTs,576
3
- sgis/geopandas_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- sgis/geopandas_tools/bounds.py,sha256=junTbokVTfiMc-PtsCmP3SfwfOjl2U_QBmsxkbAdXlA,22565
5
- sgis/geopandas_tools/buffer_dissolve_explode.py,sha256=ECctpuYI5fcg3LUJMpzfZR64KT6-k7z8QsncJu6HnvM,17930
6
- sgis/geopandas_tools/centerlines.py,sha256=96jZpORHm-As4MoT8ImHPCoq2UDyBhKKw98a84Qes-A,14142
7
- sgis/geopandas_tools/cleaning.py,sha256=tzCV7kLNFqAgfExTO0FL9nDNiCyxZLxAP-OfTC-m9Gc,23889
8
- sgis/geopandas_tools/conversion.py,sha256=LIrcXVCrta7Zdqwdxi121NJpKxX5t_TGMQHP6nJz7Uw,21903
9
- sgis/geopandas_tools/duplicates.py,sha256=VesYwQKHI7p0DPF7IopPKUFF3xLHtZ-bExINIwbudFk,13124
10
- sgis/geopandas_tools/general.py,sha256=p8y0Nc8VdrmL4Mecpoh426fGGBYk4LTs-OptC4wlQgE,24999
11
- sgis/geopandas_tools/geocoding.py,sha256=n47aFQMm4yX1MsPnTM4dFjwegCA1ZmGUDj1uyu7OJV4,691
12
- sgis/geopandas_tools/geometry_types.py,sha256=0uouqIV0fegz-45XZgXX8cNJo1EOMwofmTSGt1N55CU,7167
13
- sgis/geopandas_tools/neighbors.py,sha256=-OS2LCU9iWga8d6JkdQWD_OaQNO4hbf_WcfT0bGzWGY,15895
14
- sgis/geopandas_tools/overlay.py,sha256=OCEA3IxUi2SnZoi4ZPpIgbC1Sb_zeJbZPmX2zCBMKfk,23426
15
- sgis/geopandas_tools/point_operations.py,sha256=Cpa02sf_W8nI6FvzJGO9jNM_ZOwIz8nDhKxNdQTqom4,6897
16
- sgis/geopandas_tools/polygon_operations.py,sha256=DWLsoQoTTeQ9OZdz2H3RlCsaZLGOvBSCSULn8WJuNjw,36718
17
- sgis/geopandas_tools/polygons_as_rings.py,sha256=bDpQQZLHCvSUqT9LiVwAJy8EWQw8SX1ciFz_MNhdayA,11184
18
- sgis/geopandas_tools/sfilter.py,sha256=i6_iUlKnrfPvlFveW6GR6QcqdENw9ytFApVJ2kMUaRo,8531
19
- sgis/helpers.py,sha256=nDx1XRttZ563r2JAdWHuc7s2LZcmD7wxyFaUUk3-S3k,6190
20
- sgis/io/_is_dapla.py,sha256=o_qFD5GOi3dsSGOKmW6R8wZU0htVwFgRbGX7ppJCqT4,431
21
- sgis/io/dapla_functions.py,sha256=kVY3TuC6bbyZ5bDSqTbvfpcc5BCgmF_6Qc9ozpg-I2k,7987
22
- sgis/io/opener.py,sha256=W5rzVZx8dFHuRlTmhaS7-nU5Y8my-AWblf0vMqSR40U,610
23
- sgis/io/read_parquet.py,sha256=GSW2NDy4-XosbamPEzB1xhWxFAPHuGEJZglfQ-V6DzY,3774
24
- sgis/maps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- sgis/maps/examine.py,sha256=mZ-XLunAznCz9S0IT0ZAdd38ZKHuH4da3x01lWLh5gs,8110
26
- sgis/maps/explore.py,sha256=v0CjW9hnHo_zik8G2yncQDYEaErk-wL7rTq-N8gd4h0,30785
27
- sgis/maps/httpserver.py,sha256=z9D66SizO9GIZKaSLIqpFWnwOZZh-kiuVPjFt3WZr8o,1902
28
- sgis/maps/legend.py,sha256=buHo_UwzPYHIs7kS6H_xETekIR8m9R4PACXfTTMYQWE,20680
29
- sgis/maps/map.py,sha256=cerSlus8DNCBbqYdjCugL6r6cp0ZaQOuWE030mFxRl0,23688
30
- sgis/maps/maps.py,sha256=V48GvecyYAFOc932a7abnBe_ZfziYZCZ5-1BubP8VzM,20331
31
- sgis/maps/thematicmap.py,sha256=6aVPciftW1YjxjRVQDipxayl3aI3tHpYiZ3HfpnSavc,14132
32
- sgis/maps/tilesources.py,sha256=gGqNJ4d0PkIP72lZe2c5OMJsxJHz2DVsczw7QSjn96M,2733
33
- sgis/networkanalysis/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
- sgis/networkanalysis/_get_route.py,sha256=qWnMabeyIdCKOlnFYNYQUrnl_iBdSSequtsbWAbPIM4,6308
35
- sgis/networkanalysis/_od_cost_matrix.py,sha256=6plN-cpGib8RL7_LhMxo09RJOMR2mjj7M02T4NgLnCA,2151
36
- sgis/networkanalysis/_points.py,sha256=aQzn_E_-N-hbtoWMxOzm3PFiwO3O0_AUk9-EOoay_24,4206
37
- sgis/networkanalysis/_service_area.py,sha256=7bOf1I6yzDJMQxYFCtjQw9lpW7YNStVbX8z-QS8Nyec,5336
38
- sgis/networkanalysis/closing_network_holes.py,sha256=L7g5Z7qr9oH8JaJ8oqDNrkg2bwAcgh0tuXZCB_1MfGg,13329
39
- sgis/networkanalysis/cutting_lines.py,sha256=SiEJXIBMJvBBsHgT_FwV5h97i0Z2TFNwSh1dMS93KQQ,14267
40
- sgis/networkanalysis/directednetwork.py,sha256=2l_qBH7wyEd3HMBfMG_0i_xyHUFKbyB1vTDRYI3olnA,11217
41
- sgis/networkanalysis/finding_isolated_networks.py,sha256=IZWWotvnvxSgK5lXtByiynL13aWJRPl1HhNpyf0ddSU,3370
42
- sgis/networkanalysis/network.py,sha256=UvPPIEfZCjoLBIyHFuSsWXYarku2l3CHrkhX3iiGkl4,7686
43
- sgis/networkanalysis/networkanalysis.py,sha256=raz5T5Va5xvnLJC7tNkPx57ZUIdm1aEeqMMpOZPGDqQ,67276
44
- sgis/networkanalysis/networkanalysisrules.py,sha256=UMSo5-a8OF-0yzDgjxNcU0TpMjOpVrqrejgHikMRsXU,12607
45
- sgis/networkanalysis/nodes.py,sha256=p87X0JRrxL7XGEDWe4K6meWqKqZMD2f_jM6zptuBRRQ,6844
46
- sgis/networkanalysis/traveling_salesman.py,sha256=UBa4ZPwcAgUeqgYt-Uvr_2g3BKsOvNfTfvKMGjoRuTY,5558
47
- sgis/parallel/parallel.py,sha256=ZeRjIyUis0oOJ6mZMDNP4vWOcI73tzYnn8U4tsRhiE0,26997
48
- sgis/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
- sgis/raster/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
- sgis/raster/bands.py,sha256=3InIIsJNhLl9ZXBKueJwb1mu44bUq18amKZ43MOMNpc,1015
51
- sgis/raster/base.py,sha256=FczvhVomdNnZSkhOtVo0uPqDe4svkH9h3_7cWuT8AmQ,942
52
- sgis/raster/cube.py,sha256=RaZifh-5ulyhkgWj8lANotYz34eNR3yQU2V6BqVX1pk,34854
53
- sgis/raster/cubebase.py,sha256=Y_bqlLzdb_kCcZX5TH052VZH_GpA9fSKcfqhlTGHF1M,735
54
- sgis/raster/gradient.py,sha256=92uRXPkVSt75W_yYA-D2Kk2BfzbHt5524kEvent7-QQ,2352
55
- sgis/raster/indices.py,sha256=MfHeWAtHqjqYkgpOXdOcvL_VV1CUYWTcBYTcHEJuJLw,2782
56
- sgis/raster/methods_as_functions.py,sha256=7gfeQ4BCJUvfqLr3W1ZT3ozt_Yo5aumSxtNmEV1YFTw,2789
57
- sgis/raster/raster.py,sha256=WLBdwiH3OVLJBzxIYgzISGsJKUY6QO8e4vtJ1E3LMtE,45375
58
- sgis/raster/torchgeo.py,sha256=RdpRQQb41eYIHQqQDoBjXUUKK-9TPE5pqw4UalbmVOI,3898
59
- sgis/raster/zonal.py,sha256=9xStg2AT3vCzlcWQlCSwFGESHdEY-xMJnLbXlpkwopI,3259
60
- ssb_sgis-1.0.1.dist-info/LICENSE,sha256=lL2h0dNKGTKAE0CjTy62SDbRennVD1xPgM5LzGqhKeo,1074
61
- ssb_sgis-1.0.1.dist-info/METADATA,sha256=bCjOKQ5Uk-2NcE2pOUHGlf7LRgtZQB5UGG8tltypwUw,9068
62
- ssb_sgis-1.0.1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
63
- ssb_sgis-1.0.1.dist-info/RECORD,,