UjjwalKGupta commited on
Commit
12eea75
1 Parent(s): cc028f1

Update CRS

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -155,11 +155,13 @@ def shape_3d_to_2d(shape):
155
 
156
  def preprocess_gdf(gdf):
157
  gdf["geometry"] = gdf["geometry"].apply(shape_3d_to_2d)
158
- epsg_code = find_best_epsg(gdf["geometry"])
159
- gdf = gdf.to_crs(epsg=int(epsg_code)) #Find best EPSG code
160
  gdf["geometry"] = gdf.buffer(0) # Fixes some invalid geometries
161
  return gdf
162
 
 
 
 
 
163
 
164
  def is_valid_polygon(geometry_gdf):
165
  geometry = geometry_gdf.geometry.item()
@@ -420,11 +422,10 @@ if isinstance(file_url, str):
420
 
421
  buffer = st.number_input("Buffer (m)", value=50, min_value=0, step=1)
422
 
423
-
424
  if len(input_gdf) > 1:
425
  st.warning(f"Only the first polygon in the KML will be processed; all other geometries will be ignored.")
426
 
427
- input_gdf = preprocess_gdf(gpd.read_file(file_url))
428
  # input_geometry_idx = st.selectbox("Select the geometry", input_gdf.index, format_func=format_fn)
429
 
430
  for i in range(len(input_gdf)):
@@ -435,6 +436,7 @@ else:
435
  st.error(f"No polygon found inside KML. Please check the KML file.")
436
  st.stop()
437
 
 
438
  outer_geometry_gdf = geometry_gdf.copy()
439
  outer_geometry_gdf["geometry"] = outer_geometry_gdf["geometry"].buffer(buffer)
440
  buffer_geometry_gdf = (
 
155
 
156
  def preprocess_gdf(gdf):
157
  gdf["geometry"] = gdf["geometry"].apply(shape_3d_to_2d)
 
 
158
  gdf["geometry"] = gdf.buffer(0) # Fixes some invalid geometries
159
  return gdf
160
 
161
+ def to_best_crs(gdf):
162
+ best_epsg_code = find_best_epsg(gdf["geometry"].iloc[0])
163
+ gdf = gdf.to_crs(epsg=best_epsg_code)
164
+ return gdf
165
 
166
  def is_valid_polygon(geometry_gdf):
167
  geometry = geometry_gdf.geometry.item()
 
422
 
423
  buffer = st.number_input("Buffer (m)", value=50, min_value=0, step=1)
424
 
425
+ input_gdf = preprocess_gdf(gpd.read_file(file_url))
426
  if len(input_gdf) > 1:
427
  st.warning(f"Only the first polygon in the KML will be processed; all other geometries will be ignored.")
428
 
 
429
  # input_geometry_idx = st.selectbox("Select the geometry", input_gdf.index, format_func=format_fn)
430
 
431
  for i in range(len(input_gdf)):
 
436
  st.error(f"No polygon found inside KML. Please check the KML file.")
437
  st.stop()
438
 
439
+ geometry_gdf = to_best_crs(geometry_gdf)
440
  outer_geometry_gdf = geometry_gdf.copy()
441
  outer_geometry_gdf["geometry"] = outer_geometry_gdf["geometry"].buffer(buffer)
442
  buffer_geometry_gdf = (