ssb-sgis 1.0.2__py3-none-any.whl → 1.0.4__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 (50) hide show
  1. sgis/__init__.py +20 -9
  2. sgis/debug_config.py +24 -0
  3. sgis/exceptions.py +2 -2
  4. sgis/geopandas_tools/bounds.py +33 -36
  5. sgis/geopandas_tools/buffer_dissolve_explode.py +136 -35
  6. sgis/geopandas_tools/centerlines.py +4 -91
  7. sgis/geopandas_tools/cleaning.py +1576 -583
  8. sgis/geopandas_tools/conversion.py +38 -19
  9. sgis/geopandas_tools/duplicates.py +29 -8
  10. sgis/geopandas_tools/general.py +263 -100
  11. sgis/geopandas_tools/geometry_types.py +4 -4
  12. sgis/geopandas_tools/neighbors.py +19 -15
  13. sgis/geopandas_tools/overlay.py +2 -2
  14. sgis/geopandas_tools/point_operations.py +5 -5
  15. sgis/geopandas_tools/polygon_operations.py +510 -105
  16. sgis/geopandas_tools/polygons_as_rings.py +40 -8
  17. sgis/geopandas_tools/sfilter.py +29 -12
  18. sgis/helpers.py +3 -3
  19. sgis/io/dapla_functions.py +238 -19
  20. sgis/io/read_parquet.py +1 -1
  21. sgis/maps/examine.py +27 -12
  22. sgis/maps/explore.py +450 -65
  23. sgis/maps/legend.py +177 -76
  24. sgis/maps/map.py +206 -103
  25. sgis/maps/maps.py +178 -105
  26. sgis/maps/thematicmap.py +243 -83
  27. sgis/networkanalysis/_service_area.py +6 -1
  28. sgis/networkanalysis/closing_network_holes.py +2 -2
  29. sgis/networkanalysis/cutting_lines.py +15 -8
  30. sgis/networkanalysis/directednetwork.py +1 -1
  31. sgis/networkanalysis/finding_isolated_networks.py +15 -8
  32. sgis/networkanalysis/networkanalysis.py +17 -19
  33. sgis/networkanalysis/networkanalysisrules.py +1 -1
  34. sgis/networkanalysis/traveling_salesman.py +1 -1
  35. sgis/parallel/parallel.py +64 -27
  36. sgis/raster/__init__.py +0 -6
  37. sgis/raster/base.py +208 -0
  38. sgis/raster/cube.py +54 -8
  39. sgis/raster/image_collection.py +3257 -0
  40. sgis/raster/indices.py +17 -5
  41. sgis/raster/raster.py +138 -243
  42. sgis/raster/sentinel_config.py +120 -0
  43. sgis/raster/zonal.py +0 -1
  44. {ssb_sgis-1.0.2.dist-info → ssb_sgis-1.0.4.dist-info}/METADATA +6 -7
  45. ssb_sgis-1.0.4.dist-info/RECORD +62 -0
  46. sgis/raster/methods_as_functions.py +0 -0
  47. sgis/raster/torchgeo.py +0 -171
  48. ssb_sgis-1.0.2.dist-info/RECORD +0 -61
  49. {ssb_sgis-1.0.2.dist-info → ssb_sgis-1.0.4.dist-info}/LICENSE +0 -0
  50. {ssb_sgis-1.0.2.dist-info → ssb_sgis-1.0.4.dist-info}/WHEEL +0 -0
@@ -64,7 +64,7 @@ def to_single_geom_type(
64
64
  ValueError: If 'geom_type' is neither 'polygon', 'line' or 'point'.
65
65
 
66
66
  Examples:
67
- --------
67
+ ---------
68
68
  First create a GeoDataFrame of mixed geometries.
69
69
 
70
70
  >>> from sgis import to_gdf, to_single_geom_type
@@ -138,7 +138,7 @@ def to_single_geom_type(
138
138
 
139
139
  def _shapely_to_single_geom_type(geom: Geometry, geom_type: str) -> Geometry:
140
140
  parts = shapely.get_parts(geom)
141
- return shapely.unary_union(
141
+ return shapely.union_all(
142
142
  [part for part in parts if geom_type.lower() in part.geom_type.lower()]
143
143
  )
144
144
 
@@ -156,7 +156,7 @@ def get_geom_type(gdf: GeoDataFrame | GeoSeries) -> str:
156
156
  TypeError: If 'gdf' is not of type GeoDataFrame or GeoSeries.
157
157
 
158
158
  Examples:
159
- --------
159
+ ---------
160
160
  >>> from sgis import to_gdf, get_geom_type
161
161
  >>> gdf = to_gdf([0, 0])
162
162
  >>> gdf
@@ -204,7 +204,7 @@ def is_single_geom_type(gdf: GeoDataFrame | GeoSeries) -> bool:
204
204
  TypeError: If 'gdf' is not of type GeoDataFrame or GeoSeries.
205
205
 
206
206
  Examples:
207
- --------
207
+ ---------
208
208
  >>> from sgis import to_gdf, get_geom_type
209
209
  >>> gdf = to_gdf([0, 0])
210
210
  >>> gdf
@@ -13,6 +13,7 @@ import shapely
13
13
  from geopandas import GeoDataFrame
14
14
  from geopandas import GeoSeries
15
15
  from pandas import DataFrame
16
+ from pandas import MultiIndex
16
17
  from pandas import Series
17
18
  from sklearn.neighbors import NearestNeighbors
18
19
 
@@ -50,7 +51,7 @@ def get_neighbor_indices(
50
51
  system.
51
52
 
52
53
  Examples:
53
- --------
54
+ ---------
54
55
  >>> from sgis import get_neighbor_indices, to_gdf
55
56
  >>> points = to_gdf([(0, 0), (0.5, 0.5)])
56
57
  >>> points
@@ -97,29 +98,32 @@ def get_neighbor_indices(
97
98
  ['a' 'a' 'b' 'b']
98
99
 
99
100
  """
101
+ if isinstance(gdf.index, MultiIndex) or isinstance(neighbors.index, MultiIndex):
102
+ raise ValueError("get_neighbor_indices not implemented for pandas.MultiIndex")
100
103
  if gdf.crs != neighbors.crs:
101
104
  raise ValueError(f"'crs' mismatch. Got {gdf.crs} and {neighbors.crs}")
102
105
 
103
106
  if isinstance(neighbors, GeoSeries):
104
107
  neighbors = neighbors.to_frame()
108
+ else:
109
+ neighbors = neighbors[[neighbors._geometry_column_name]]
105
110
 
106
111
  # buffer and keep only geometry column
107
112
  if max_distance and predicate != "nearest":
108
- gdf = gdf.buffer(max_distance).to_frame()
113
+ gdf = gdf.buffer(max_distance).to_frame("geometry")
109
114
  else:
110
- gdf = gdf.geometry.to_frame()
115
+ gdf = gdf.geometry.to_frame("geometry")
116
+
117
+ neighbors.index.name = None
118
+ gdf.index.name = None
111
119
 
112
120
  if predicate == "nearest":
113
121
  max_distance = None if max_distance == 0 else max_distance
114
- joined = gdf.sjoin_nearest(
115
- neighbors, how="inner", max_distance=max_distance
116
- ).rename(columns={"index_right": "neighbor_index"}, errors="raise")
122
+ joined = gdf.sjoin_nearest(neighbors, how="inner", max_distance=max_distance)
117
123
  else:
118
- joined = gdf.sjoin(neighbors, how="inner", predicate=predicate).rename(
119
- columns={"index_right": "neighbor_index"}, errors="raise"
120
- )
124
+ joined = gdf.sjoin(neighbors, how="inner", predicate=predicate)
121
125
 
122
- return joined["neighbor_index"]
126
+ return joined.rename(columns={"index_right": "neighbor_index"})["neighbor_index"]
123
127
 
124
128
 
125
129
  def get_neighbor_dfs(
@@ -153,7 +157,7 @@ def get_all_distances(
153
157
  not the same.
154
158
 
155
159
  Examples:
156
- --------
160
+ ---------
157
161
  >>> from sgis import get_all_distances, random_points
158
162
  >>> points = random_points(100)
159
163
  >>> neighbors = random_points(100)
@@ -297,7 +301,7 @@ def get_k_nearest_neighbors(
297
301
  not the same.
298
302
 
299
303
  Examples:
300
- --------
304
+ ---------
301
305
  Make some random points.
302
306
 
303
307
  >>> from sgis import get_k_nearest_neighbors, random_points
@@ -469,6 +473,6 @@ def _get_edges(
469
473
  Returns:
470
474
  A 2d numpy array of edges (from-to indices).
471
475
  """
472
- return np.array(
473
- [[(i, neighbor) for neighbor in indices[i]] for i in range(len(gdf))]
474
- )
476
+ row_indices = np.arange(len(indices)).reshape(-1, 1)
477
+
478
+ return np.stack((np.broadcast_to(row_indices, indices.shape), indices), axis=-1)
@@ -238,8 +238,8 @@ def _shapely_pd_overlay(
238
238
  left, right = tree.query(df1.geometry.values, predicate=predicate)
239
239
 
240
240
  pairs = _get_intersects_pairs(df1, df2, left, right, rsuffix)
241
- assert pairs.geometry.notna().all()
242
- assert pairs.geom_right.notna().all()
241
+ assert pairs.geometry.notna().all(), pairs.geometry
242
+ assert pairs.geom_right.notna().all(), pairs.geom_right
243
243
 
244
244
  if how == "intersection":
245
245
  overlayed = [
@@ -5,7 +5,7 @@ import pandas as pd
5
5
  from geopandas import GeoDataFrame
6
6
  from geopandas import GeoSeries
7
7
  from shapely import distance
8
- from shapely import unary_union
8
+ from shapely import union_all
9
9
  from shapely.ops import nearest_points
10
10
 
11
11
  from ..geopandas_tools.geometry_types import get_geom_type
@@ -48,7 +48,7 @@ def snap_within_distance(
48
48
  vertices.
49
49
 
50
50
  Examples:
51
- --------
51
+ ---------
52
52
  Create som points.
53
53
 
54
54
  >>> from sgis import snap_within_distance, to_gdf
@@ -136,7 +136,7 @@ def snap_all(
136
136
  vertices.
137
137
 
138
138
  Examples:
139
- --------
139
+ ---------
140
140
  Create som points.
141
141
 
142
142
  >>> from sgis import snap_all, to_gdf
@@ -201,9 +201,9 @@ def _shapely_snap(
201
201
  max_distance: int | float | None = None,
202
202
  ) -> GeoSeries:
203
203
  try:
204
- unioned = to.unary_union
204
+ unioned = union_all(to.geometry.values)
205
205
  except AttributeError:
206
- unioned = unary_union(to)
206
+ unioned = union_all(to)
207
207
 
208
208
  nearest = nearest_points(points, unioned)[1]
209
209