geofileops 0.10.1.dev0__tar.gz → 0.10.1.dev1__tar.gz

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 (42) hide show
  1. {geofileops-0.10.1.dev0/geofileops.egg-info → geofileops-0.10.1.dev1}/PKG-INFO +1 -1
  2. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/geoops.py +2 -4
  3. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_geoops_gpd.py +15 -11
  4. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_geoops_sql.py +70 -91
  5. geofileops-0.10.1.dev1/geofileops/version.txt +1 -0
  6. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1/geofileops.egg-info}/PKG-INFO +1 -1
  7. geofileops-0.10.1.dev0/geofileops/version.txt +0 -1
  8. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/LICENSE.txt +0 -0
  9. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/MANIFEST.in +0 -0
  10. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/README.md +0 -0
  11. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/__init__.py +0 -0
  12. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/_compat.py +0 -0
  13. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/fileops.py +0 -0
  14. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/helpers/__init__.py +0 -0
  15. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/helpers/_configoptions_helper.py +0 -0
  16. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/helpers/_general_helper.py +0 -0
  17. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/helpers/_parameter_helper.py +0 -0
  18. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/helpers/layerstyles.py +0 -0
  19. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/py.typed +0 -0
  20. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/__init__.py +0 -0
  21. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_general_util.py +0 -0
  22. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_geofileinfo.py +0 -0
  23. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_geometry_util.py +0 -0
  24. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_geoops_ogr.py +0 -0
  25. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_geopath_util.py +0 -0
  26. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_geoseries_util.py +0 -0
  27. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_io_util.py +0 -0
  28. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_ogr_sql_util.py +0 -0
  29. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_ogr_util.py +0 -0
  30. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_processing_util.py +0 -0
  31. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_sqlite_userdefined.py +0 -0
  32. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/_sqlite_util.py +0 -0
  33. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/geodataframe_util.py +0 -0
  34. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/geofiletypes.csv +0 -0
  35. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops/util/test.gpkg +0 -0
  36. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops.egg-info/SOURCES.txt +0 -0
  37. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops.egg-info/dependency_links.txt +0 -0
  38. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops.egg-info/requires.txt +0 -0
  39. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/geofileops.egg-info/top_level.txt +0 -0
  40. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/pyproject.toml +0 -0
  41. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/setup.cfg +0 -0
  42. {geofileops-0.10.1.dev0 → geofileops-0.10.1.dev1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: geofileops
3
- Version: 0.10.1.dev0
3
+ Version: 0.10.1.dev1
4
4
  Summary: Python toolbox to process large vector files faster.
5
5
  Home-page: https://github.com/geofileops/geofileops
6
6
  Author: Pieter Roggemans
@@ -97,16 +97,14 @@ def dissolve_within_distance(
97
97
  """
98
98
  input_path = Path(input_path)
99
99
  output_path = Path(output_path)
100
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
101
+ return
100
102
 
101
103
  start_time = datetime.now()
102
104
  operation_name = "dissolve_within_distance"
103
105
  logger = logging.getLogger(f"geofileops.{operation_name}")
104
106
  nb_steps = 9
105
107
 
106
- # Already check here if it is useful to continue
107
- if _io_util.output_exists(path=output_path, remove_if_exists=force):
108
- return
109
-
110
108
  tempdir = _io_util.create_tempdir(f"geofileops/{operation_name}")
111
109
  try:
112
110
  # First dissolve the input.
@@ -564,6 +564,9 @@ def makevalid(
564
564
  batchsize: int = -1,
565
565
  force: bool = False,
566
566
  ):
567
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
568
+ return
569
+
567
570
  # Determine if collapsed parts need to be kept after makevalid or not
568
571
  keep_collapsed = True
569
572
  if force_output_geometrytype is None:
@@ -745,12 +748,14 @@ def _apply_geooperation_to_layer(
745
748
  logger = logging.getLogger(f"geofileops.{operation_name}")
746
749
 
747
750
  # Check input parameters...
748
- if not input_path.exists():
749
- raise FileNotFoundError(f"{operation_name}: input_path not found: {input_path}")
750
- if input_path == output_path:
751
- raise ValueError(f"{operation_name}: output_path must not equal input_path")
752
751
  if _io_util.output_exists(path=output_path, remove_if_exists=force):
753
752
  return
753
+
754
+ if input_path == output_path:
755
+ raise ValueError(f"{operation_name}: output_path must not equal input_path")
756
+ if not input_path.exists():
757
+ raise FileNotFoundError(f"{operation_name}: input_path not found: {input_path}")
758
+
754
759
  if not isinstance(input_layer, LayerInfo):
755
760
  input_layer = gfo.get_layerinfo(input_path, input_layer)
756
761
  if output_layer is None:
@@ -1121,13 +1126,16 @@ def dissolve(
1121
1126
  operation_name = f"{operation_prefix}dissolve"
1122
1127
  logger = logging.getLogger(f"geofileops.{operation_name}")
1123
1128
 
1124
- # Check input parameters
1129
+ # Check if we need to calculate anyway
1130
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
1131
+ return
1132
+
1125
1133
  if groupby_columns is not None and len(list(groupby_columns)) == 0:
1126
1134
  raise ValueError("groupby_columns=[] is not supported. Use None.")
1127
- if not input_path.exists():
1128
- raise FileNotFoundError(f"input_path not found: {input_path}")
1129
1135
  if input_path == output_path:
1130
1136
  raise ValueError("output_path must not equal input_path")
1137
+ if not input_path.exists():
1138
+ raise FileNotFoundError(f"input_path not found: {input_path}")
1131
1139
 
1132
1140
  if not isinstance(input_layer, LayerInfo):
1133
1141
  input_layer = gfo.get_layerinfo(input_path, input_layer)
@@ -1185,10 +1193,6 @@ def dissolve(
1185
1193
  agg_column["column"], columns_available
1186
1194
  )
1187
1195
 
1188
- # Now input parameters are checked, check if we need to calculate anyway
1189
- if _io_util.output_exists(path=output_path, remove_if_exists=force):
1190
- return
1191
-
1192
1196
  # Check what we need to do in an error occurs
1193
1197
  on_data_error = ConfigOptions.on_data_error
1194
1198
 
@@ -87,7 +87,6 @@ def buffer(
87
87
  force_output_geometrytype = GeometryType.MULTIPOLYGON
88
88
 
89
89
  # Go!
90
- # ---
91
90
  return _single_layer_vector_operation(
92
91
  input_path=input_path,
93
92
  output_path=output_path,
@@ -124,9 +123,6 @@ def convexhull(
124
123
  force: bool = False,
125
124
  ):
126
125
  # Init + prepare sql template for this operation
127
- # ----------------------------------------------
128
- if not isinstance(input_layer, LayerInfo):
129
- input_layer = gfo.get_layerinfo(input_path, input_layer)
130
126
  sql_template = """
131
127
  SELECT ST_ConvexHull({geometrycolumn}) AS {geometrycolumn}
132
128
  {columns_to_select_str}
@@ -135,9 +131,7 @@ def convexhull(
135
131
  {batch_filter}
136
132
  """
137
133
 
138
- # Go!
139
- # ---
140
- # Output geometry type same as input geometry type
134
+ # TODO: output type is now always the same as input, but that's not correct.
141
135
  return _single_layer_vector_operation(
142
136
  input_path=input_path,
143
137
  output_path=output_path,
@@ -148,7 +142,7 @@ def convexhull(
148
142
  output_layer=output_layer,
149
143
  columns=columns,
150
144
  explodecollections=explodecollections,
151
- force_output_geometrytype=input_layer.geometrytype,
145
+ force_output_geometrytype="KEEP_INPUT",
152
146
  gridsize=gridsize,
153
147
  keep_empty_geoms=keep_empty_geoms,
154
148
  where_post=where_post,
@@ -204,9 +198,6 @@ def delete_duplicate_geometries(
204
198
  """
205
199
 
206
200
  # Go!
207
- if not isinstance(input_layer, LayerInfo):
208
- input_layer = gfo.get_layerinfo(input_path, input_layer)
209
-
210
201
  return _single_layer_vector_operation(
211
202
  input_path=input_path,
212
203
  output_path=output_path,
@@ -217,7 +208,7 @@ def delete_duplicate_geometries(
217
208
  output_layer=output_layer,
218
209
  columns=columns,
219
210
  explodecollections=explodecollections,
220
- force_output_geometrytype=input_layer.geometrytype,
211
+ force_output_geometrytype="KEEP_INPUT",
221
212
  gridsize=0.0,
222
213
  keep_empty_geoms=keep_empty_geoms,
223
214
  where_post=where_post,
@@ -317,11 +308,7 @@ def makevalid(
317
308
  batchsize: int = -1,
318
309
  force: bool = False,
319
310
  ):
320
- # If output file already exists, either clean up or return...
321
- operation_name = "makevalid"
322
- logger = logging.getLogger(f"geofileops.{operation_name}")
323
- if not force and output_path.exists():
324
- logger.info(f"Stop, output already exists {output_path}")
311
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
325
312
  return
326
313
 
327
314
  # Determine output_geometrytype + make it multitype if it wasn't specified.
@@ -377,7 +364,7 @@ def makevalid(
377
364
  output_path=output_path,
378
365
  sql_template=sql_template,
379
366
  geom_selected=True,
380
- operation_name=operation_name,
367
+ operation_name="makevalid",
381
368
  input_layer=input_layer,
382
369
  output_layer=output_layer,
383
370
  columns=columns,
@@ -410,10 +397,10 @@ def select(
410
397
  force: bool = False,
411
398
  operation_prefix: str = "",
412
399
  ):
413
- # Check if output already exists here, to avoid to much logging to be written
414
- logger = logging.getLogger(f"geofileops.{operation_prefix}select")
415
400
  if _io_util.output_exists(path=output_path, remove_if_exists=force):
416
401
  return
402
+
403
+ logger = logging.getLogger(f"geofileops.{operation_prefix}select")
417
404
  logger.debug(f" -> select to execute:\n{sql_stmt}")
418
405
 
419
406
  # If no output geometrytype is specified, use the geometrytype of the input layer
@@ -479,10 +466,6 @@ def simplify(
479
466
  {{batch_filter}}
480
467
  """
481
468
 
482
- # Output geometry type same as input geometry type
483
- if not isinstance(input_layer, LayerInfo):
484
- input_layer = gfo.get_layerinfo(input_path, input_layer)
485
-
486
469
  return _single_layer_vector_operation(
487
470
  input_path=input_path,
488
471
  output_path=output_path,
@@ -493,7 +476,7 @@ def simplify(
493
476
  output_layer=output_layer,
494
477
  columns=columns,
495
478
  explodecollections=explodecollections,
496
- force_output_geometrytype=input_layer.geometrytype,
479
+ force_output_geometrytype="KEEP_INPUT",
497
480
  gridsize=gridsize,
498
481
  keep_empty_geoms=keep_empty_geoms,
499
482
  where_post=where_post,
@@ -514,7 +497,7 @@ def _single_layer_vector_operation(
514
497
  output_layer: str | None,
515
498
  columns: list[str] | None,
516
499
  explodecollections: bool,
517
- force_output_geometrytype: GeometryType | None,
500
+ force_output_geometrytype: GeometryType | str | None,
518
501
  gridsize: float,
519
502
  keep_empty_geoms: bool,
520
503
  where_post: str | None,
@@ -556,11 +539,15 @@ def _single_layer_vector_operation(
556
539
  start_time = datetime.now()
557
540
  logger = logging.getLogger(f"geofileops.{operation_name}")
558
541
 
542
+ # If output file already exists, either clean up or return...
543
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
544
+ return
545
+
559
546
  # Check/clean input parameters...
560
- if not input_path.exists():
561
- raise FileNotFoundError(f"{operation_name}: input_path not found: {input_path}")
562
547
  if input_path == output_path:
563
548
  raise ValueError(f"{operation_name}: output_path must not equal input_path")
549
+ if not input_path.exists():
550
+ raise FileNotFoundError(f"{operation_name}: input_path not found: {input_path}")
564
551
  if where_post is not None and where_post == "":
565
552
  where_post = None
566
553
  if isinstance(columns, str):
@@ -573,9 +560,11 @@ def _single_layer_vector_operation(
573
560
  if output_layer is None:
574
561
  output_layer = gfo.get_default_layer(output_path)
575
562
 
576
- # If output file already exists, either clean up or return...
577
- if _io_util.output_exists(path=output_path, remove_if_exists=force):
578
- return
563
+ if isinstance(force_output_geometrytype, str):
564
+ if force_output_geometrytype == "KEEP_INPUT":
565
+ force_output_geometrytype = input_layer.geometrytype
566
+ else:
567
+ raise ValueError(f"unsupported {force_output_geometrytype=}")
579
568
 
580
569
  # Determine if fid can be preserved
581
570
  preserve_fid = False
@@ -909,7 +898,9 @@ def clip(
909
898
  input_columns_prefix: str = "",
910
899
  output_with_spatial_index: bool | None = None,
911
900
  ):
912
- # Init
901
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
902
+ return
903
+
913
904
  # In the query, important to only extract the geometry types that are expected
914
905
  if not isinstance(input_layer, LayerInfo):
915
906
  input_layer = gfo.get_layerinfo(input_path, input_layer)
@@ -1050,6 +1041,9 @@ def difference( # noqa: D417
1050
1041
  operation_name = f"{operation_prefix}difference"
1051
1042
  logger = logging.getLogger(f"geofileops.{operation_name}")
1052
1043
 
1044
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
1045
+ return
1046
+
1053
1047
  input1_layer, input2_layer, output_layer = _validate_params(
1054
1048
  input1_path=input1_path,
1055
1049
  input2_path=input2_path,
@@ -1059,8 +1053,6 @@ def difference( # noqa: D417
1059
1053
  output_layer=output_layer,
1060
1054
  operation_name=operation_name,
1061
1055
  )
1062
- if _io_util.output_exists(path=output_path, remove_if_exists=force):
1063
- return
1064
1056
 
1065
1057
  # Determine output_geometrytype
1066
1058
  primitivetypeid = input1_layer.geometrytype.to_primitivetype.value
@@ -1449,12 +1441,9 @@ def export_by_location(
1449
1441
 
1450
1442
  operation_name = "export_by_location"
1451
1443
  logger = logging.getLogger(f"geofileops.{operation_name}")
1452
- if output_path.exists():
1453
- if not force:
1454
- logger.info(f"Stop, output already exists {output_path}")
1455
- return
1456
- else:
1457
- gfo.remove(output_path)
1444
+
1445
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
1446
+ return
1458
1447
 
1459
1448
  start_time = datetime.now()
1460
1449
 
@@ -1588,10 +1577,6 @@ def export_by_location(
1588
1577
  WHERE sub_area.{area_inters_column_name} >= {min_area_intersect}
1589
1578
  """
1590
1579
 
1591
- if not isinstance(input_layer, LayerInfo):
1592
- input_layer = gfo.get_layerinfo(input_path, input_layer)
1593
-
1594
- # Go!
1595
1580
  _two_layer_vector_operation(
1596
1581
  input1_path=input_path,
1597
1582
  input2_path=input_to_compare_with_path,
@@ -1606,7 +1591,7 @@ def export_by_location(
1606
1591
  input2_columns_prefix="",
1607
1592
  output_layer=output_layer,
1608
1593
  explodecollections=False,
1609
- force_output_geometrytype=input_layer.geometrytype,
1594
+ force_output_geometrytype="KEEP_INPUT",
1610
1595
  gridsize=gridsize,
1611
1596
  where_post=where_post,
1612
1597
  nb_parallel=nb_parallel,
@@ -1659,10 +1644,6 @@ def export_by_distance(
1659
1644
  layer2.{{input2_geometrycolumn}}) <= {max_distance})
1660
1645
  """
1661
1646
 
1662
- if not isinstance(input1_layer, LayerInfo):
1663
- input1_layer = gfo.get_layerinfo(input_to_select_from_path, input1_layer)
1664
-
1665
- # Go!
1666
1647
  return _two_layer_vector_operation(
1667
1648
  input1_path=input_to_select_from_path,
1668
1649
  input2_path=input_to_compare_with_path,
@@ -1677,7 +1658,7 @@ def export_by_distance(
1677
1658
  input2_columns_prefix="",
1678
1659
  output_layer=output_layer,
1679
1660
  explodecollections=False,
1680
- force_output_geometrytype=input1_layer.geometrytype,
1661
+ force_output_geometrytype="KEEP_INPUT",
1681
1662
  gridsize=gridsize,
1682
1663
  where_post=where_post,
1683
1664
  nb_parallel=nb_parallel,
@@ -1740,6 +1721,9 @@ def intersection( # noqa: D417
1740
1721
  operation_name = f"{operation_prefix}intersection"
1741
1722
  logger = logging.getLogger(f"geofileops.{operation_name}")
1742
1723
 
1724
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
1725
+ return
1726
+
1743
1727
  input1_layer, input2_layer, output_layer = _validate_params(
1744
1728
  input1_path=input1_path,
1745
1729
  input2_path=input2_path,
@@ -1749,8 +1733,6 @@ def intersection( # noqa: D417
1749
1733
  output_layer=output_layer,
1750
1734
  operation_name=operation_name,
1751
1735
  )
1752
- if _io_util.output_exists(path=output_path, remove_if_exists=force):
1753
- return
1754
1736
 
1755
1737
  # In the query, important to only extract the geometry types that are expected
1756
1738
  primitivetype_to_extract = PrimitiveType(
@@ -2091,10 +2073,6 @@ def join_by_location(
2091
2073
  SELECT l1_fid FROM layer1_relations_filtered)
2092
2074
  """
2093
2075
 
2094
- if not isinstance(input1_layer, LayerInfo):
2095
- input1_layer = gfo.get_layerinfo(input1_path, input1_layer)
2096
-
2097
- # Go!
2098
2076
  return _two_layer_vector_operation(
2099
2077
  input1_path=input1_path,
2100
2078
  input2_path=input2_path,
@@ -2109,7 +2087,7 @@ def join_by_location(
2109
2087
  input2_columns_prefix=input2_columns_prefix,
2110
2088
  output_layer=output_layer,
2111
2089
  explodecollections=explodecollections,
2112
- force_output_geometrytype=input1_layer.geometrytype,
2090
+ force_output_geometrytype="KEEP_INPUT",
2113
2091
  gridsize=gridsize,
2114
2092
  where_post=where_post,
2115
2093
  nb_parallel=nb_parallel,
@@ -2168,10 +2146,6 @@ def _prepare_filter_by_location_params(
2168
2146
  layer2_groupby = "GROUP BY layer2.fid_1" if subdivided else ""
2169
2147
  geom2 = f"ST_union({geom2})" if subdivided else f"{geom2}"
2170
2148
 
2171
- # When "contains" is used, geomA and geomB need to be swapped
2172
- geomA = geom2 if "contains" in query.lower() else geom1
2173
- geomB = geom1 if "contains" in query.lower() else geom2
2174
-
2175
2149
  spatial_relations_filter: str = ""
2176
2150
  relation_should_be_found = True
2177
2151
 
@@ -2206,7 +2180,7 @@ def _prepare_filter_by_location_params(
2206
2180
  relation_is_true = not relation_is_true
2207
2181
 
2208
2182
  spatial_relations_column = (
2209
- f',ST_{spatial_relation}({geomA}, {geomB}) AS "GFO_$TEMP$_SPATIAL_RELATION"'
2183
+ f',ST_{spatial_relation}({geom1}, {geom2}) AS "GFO_$TEMP$_SPATIAL_RELATION"'
2210
2184
  )
2211
2185
  spatial_relations_filter = (
2212
2186
  f'{subquery_alias}."GFO_$TEMP$_SPATIAL_RELATION" = {int(relation_is_true)}'
@@ -2243,7 +2217,7 @@ def _prepare_filter_by_location_params(
2243
2217
 
2244
2218
  # Prepare the spatial relation column
2245
2219
  spatial_relations_column = spatial_relations_column.format(
2246
- input1=geomA, input2=geomB
2220
+ input1=geom1, input2=geom2
2247
2221
  )
2248
2222
 
2249
2223
  if true_for_disjoint and avoid_disjoint:
@@ -2382,10 +2356,9 @@ def join_nearest(
2382
2356
  # Init some things...
2383
2357
  # Because there is preprocessing done in this function, check output path
2384
2358
  # here already
2385
- logger = logging.getLogger("geofileops.join_nearest")
2386
- if output_path.exists() and force is False:
2387
- logger.info(f"Stop, output already exists {output_path}")
2359
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
2388
2360
  return
2361
+
2389
2362
  if input1_layer is None:
2390
2363
  input1_layer = gfo.get_only_layer(input1_path)
2391
2364
  if input2_layer is None:
@@ -2474,9 +2447,6 @@ def join_nearest(
2474
2447
  {{batch_filter}}
2475
2448
  """
2476
2449
 
2477
- input1_layer_info = gfo.get_layerinfo(input1_path, input1_layer)
2478
-
2479
- # Go!
2480
2450
  return _two_layer_vector_operation(
2481
2451
  input1_path=input1_tmp_path,
2482
2452
  input2_path=input2_tmp_path,
@@ -2490,7 +2460,7 @@ def join_nearest(
2490
2460
  input2_columns=input2_columns,
2491
2461
  input2_columns_prefix=input2_columns_prefix,
2492
2462
  output_layer=output_layer,
2493
- force_output_geometrytype=input1_layer_info.geometrytype,
2463
+ force_output_geometrytype="KEEP_INPUT",
2494
2464
  explodecollections=explodecollections,
2495
2465
  gridsize=0.0,
2496
2466
  where_post=None,
@@ -2579,6 +2549,9 @@ def identity(
2579
2549
 
2580
2550
  logger = logging.getLogger("geofileops.identity")
2581
2551
 
2552
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
2553
+ return
2554
+
2582
2555
  input1_layer, input2_layer, output_layer = _validate_params(
2583
2556
  input1_path=input1_path,
2584
2557
  input2_path=input2_path,
@@ -2588,8 +2561,6 @@ def identity(
2588
2561
  output_layer=output_layer,
2589
2562
  operation_name="identity",
2590
2563
  )
2591
- if _io_util.output_exists(path=output_path, remove_if_exists=force):
2592
- return
2593
2564
 
2594
2565
  tempdir = _io_util.create_tempdir("geofileops/identity")
2595
2566
  try:
@@ -2744,6 +2715,9 @@ def symmetric_difference(
2744
2715
  f"input2: {input2_path}, output: {output_path}"
2745
2716
  )
2746
2717
 
2718
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
2719
+ return
2720
+
2747
2721
  input1_layer, input2_layer, output_layer = _validate_params(
2748
2722
  input1_path=input1_path,
2749
2723
  input2_path=input2_path,
@@ -2753,8 +2727,6 @@ def symmetric_difference(
2753
2727
  output_layer=output_layer,
2754
2728
  operation_name="symmetric_difference",
2755
2729
  )
2756
- if _io_util.output_exists(path=output_path, remove_if_exists=force):
2757
- return
2758
2730
 
2759
2731
  tempdir = _io_util.create_tempdir("geofileops/symmdiff")
2760
2732
  try:
@@ -2915,6 +2887,9 @@ def union(
2915
2887
  operation_name = "union"
2916
2888
  logger = logging.getLogger(f"geofileops.{operation_name}")
2917
2889
 
2890
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
2891
+ return
2892
+
2918
2893
  input1_layer, input2_layer, output_layer = _validate_params(
2919
2894
  input1_path=input1_path,
2920
2895
  input2_path=input2_path,
@@ -2924,8 +2899,6 @@ def union(
2924
2899
  output_layer=output_layer,
2925
2900
  operation_name=operation_name,
2926
2901
  )
2927
- if _io_util.output_exists(path=output_path, remove_if_exists=force):
2928
- return
2929
2902
 
2930
2903
  start_time = datetime.now()
2931
2904
  tempdir = _io_util.create_tempdir("geofileops/union")
@@ -3094,7 +3067,7 @@ def _two_layer_vector_operation(
3094
3067
  input2_columns_prefix: str,
3095
3068
  output_layer: str | None,
3096
3069
  explodecollections: bool,
3097
- force_output_geometrytype: GeometryType | None,
3070
+ force_output_geometrytype: GeometryType | str | None,
3098
3071
  gridsize: float,
3099
3072
  where_post: str | None,
3100
3073
  nb_parallel: int,
@@ -3131,7 +3104,8 @@ def _two_layer_vector_operation(
3131
3104
  output_layer (str): [description]. Defaults to None.
3132
3105
  explodecollections (bool, optional): Explode collecions in output.
3133
3106
  Defaults to False.
3134
- force_output_geometrytype (GeometryType, optional): Defaults to None.
3107
+ force_output_geometrytype (GeometryType or str, optional): Defaults to None.
3108
+ If "KEEP_INPUT", the geometry type of the input1_layer is used.
3135
3109
  gridsize (float, optional): the size of the grid the coordinates of the ouput
3136
3110
  will be rounded to. Eg. 0.001 to keep 3 decimals. Value 0.0 doesn't change
3137
3111
  the precision. Defaults to 0.0.
@@ -3167,6 +3141,9 @@ def _two_layer_vector_operation(
3167
3141
  # Init
3168
3142
  logger = logging.getLogger(f"geofileops.{operation_name}")
3169
3143
 
3144
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
3145
+ return
3146
+
3170
3147
  # Validate the input and output layer parameter
3171
3148
  input1_layer, input2_layer, output_layer = _validate_params(
3172
3149
  input1_path=input1_path,
@@ -3182,9 +3159,11 @@ def _two_layer_vector_operation(
3182
3159
  f"{operation_name}: if use_ogr True, input1_path should equal input2_path!"
3183
3160
  )
3184
3161
 
3185
- # Only check this after _validate_params to avoid files getting accidentely removed.
3186
- if _io_util.output_exists(path=output_path, remove_if_exists=force):
3187
- return
3162
+ if isinstance(force_output_geometrytype, str):
3163
+ if force_output_geometrytype == "KEEP_INPUT":
3164
+ force_output_geometrytype = input1_layer.geometrytype
3165
+ else:
3166
+ raise ValueError(f"unsupported {force_output_geometrytype=}")
3188
3167
 
3189
3168
  # For columns params, if a string is passed, convert to list
3190
3169
  if isinstance(input1_columns, str):
@@ -3496,6 +3475,7 @@ def _two_layer_vector_operation(
3496
3475
  # convert geometrytype to multitype to avoid ogr warnings
3497
3476
  output_geometrytype_now = force_output_geometrytype.to_multitype
3498
3477
  if "geom" in column_datatypes:
3478
+ assert output_geometrytype_now is not None
3499
3479
  column_datatypes["geom"] = output_geometrytype_now.name
3500
3480
 
3501
3481
  # Remark: this temp file doesn't need spatial index
@@ -3647,6 +3627,10 @@ def _validate_params(
3647
3627
  a tuple with the layers:
3648
3628
  input1_layer (LayerInfo), input2_layer (LayerInfo), output_layer (str)
3649
3629
  """
3630
+ if output_path in (input1_path, input2_path):
3631
+ raise ValueError(
3632
+ f"{operation_name}: output_path must not equal one of input paths"
3633
+ )
3650
3634
  if not input1_path.exists():
3651
3635
  raise FileNotFoundError(
3652
3636
  f"{operation_name}: input1_path not found: {input1_path}"
@@ -3655,10 +3639,6 @@ def _validate_params(
3655
3639
  raise FileNotFoundError(
3656
3640
  f"{operation_name}: input2_path not found: {input2_path}"
3657
3641
  )
3658
- if output_path in (input1_path, input2_path):
3659
- raise ValueError(
3660
- f"{operation_name}: output_path must not equal one of input paths"
3661
- )
3662
3642
 
3663
3643
  # Get layer info
3664
3644
  if not isinstance(input1_layer, LayerInfo):
@@ -4129,15 +4109,18 @@ def dissolve_singlethread(
4129
4109
  force: bool = False,
4130
4110
  ):
4131
4111
  """Remark: this is not a parallelized version!!!"""
4112
+ if _io_util.output_exists(path=output_path, remove_if_exists=force):
4113
+ return
4114
+
4132
4115
  # Init
4133
4116
  logger = logging.getLogger("geofileops.dissolve")
4134
4117
  start_time = datetime.now()
4135
4118
 
4136
4119
  # Check input params
4137
- if not input_path.exists():
4138
- raise FileNotFoundError(f"input_path not found: {input_path}")
4139
4120
  if input_path == output_path:
4140
4121
  raise ValueError("output_path must not equal input_path")
4122
+ if not input_path.exists():
4123
+ raise FileNotFoundError(f"input_path not found: {input_path}")
4141
4124
  if where_post is not None and where_post == "":
4142
4125
  where_post = None
4143
4126
 
@@ -4258,10 +4241,6 @@ def dissolve_singlethread(
4258
4241
  f'AS "{agg_column["as"]}"'
4259
4242
  )
4260
4243
 
4261
- # Check output path
4262
- if _io_util.output_exists(path=output_path, remove_if_exists=force):
4263
- return
4264
-
4265
4244
  # Now prepare the sql statement
4266
4245
  # Remark: calculating the area in the enclosing selects halves the processing time
4267
4246
 
@@ -0,0 +1 @@
1
+ 0.10.1.dev1
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: geofileops
3
- Version: 0.10.1.dev0
3
+ Version: 0.10.1.dev1
4
4
  Summary: Python toolbox to process large vector files faster.
5
5
  Home-page: https://github.com/geofileops/geofileops
6
6
  Author: Pieter Roggemans
@@ -1 +0,0 @@
1
- 0.10.1.dev0