YashMK89 commited on
Commit
d3ceb3a
·
verified ·
1 Parent(s): a9d2246

update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -127,9 +127,10 @@ reducer_choice = st.selectbox(
127
 
128
  def convert_to_ee_geometry(geometry):
129
  # Handle shapely geometry
130
- if isinstance(geometry, base.BaseGeometry): # Corrected here
131
  if geometry.is_valid:
132
  geojson = geometry.__geo_interface__
 
133
  return ee.Geometry(geojson)
134
  else:
135
  raise ValueError("Invalid geometry: The polygon geometry is not valid.")
@@ -140,6 +141,7 @@ def convert_to_ee_geometry(geometry):
140
  if isinstance(geometry, str):
141
  geometry = json.loads(geometry)
142
  if 'type' in geometry and 'coordinates' in geometry:
 
143
  return ee.Geometry(geometry)
144
  else:
145
  raise ValueError("GeoJSON format is invalid.")
@@ -154,18 +156,16 @@ def convert_to_ee_geometry(geometry):
154
  kml_root = tree.getroot()
155
 
156
  # Extract coordinates from KML geometry (assuming it's a Polygon or MultiPolygon)
157
- # This approach is simplistic; it assumes KML has a <coordinates> tag
158
- # which may need customization based on KML structure.
159
  kml_namespace = {'kml': 'http://www.opengis.net/kml/2.2'}
160
  coordinates = kml_root.findall(".//kml:coordinates", kml_namespace)
161
  if coordinates:
162
- # Convert KML coordinates to GeoJSON-like structure
163
  coords = coordinates[0].text.strip().split()
164
  coords = [tuple(map(float, coord.split(','))) for coord in coords]
165
  geojson = {
166
- "type": "Polygon",
167
- "coordinates": [coords]
168
  }
 
169
  return ee.Geometry(geojson)
170
  else:
171
  raise ValueError("KML does not contain valid coordinates.")
 
127
 
128
  def convert_to_ee_geometry(geometry):
129
  # Handle shapely geometry
130
+ if isinstance(geometry, base.BaseGeometry):
131
  if geometry.is_valid:
132
  geojson = geometry.__geo_interface__
133
+ print("Shapely GeoJSON:", geojson) # Debugging: Inspect the GeoJSON structure
134
  return ee.Geometry(geojson)
135
  else:
136
  raise ValueError("Invalid geometry: The polygon geometry is not valid.")
 
141
  if isinstance(geometry, str):
142
  geometry = json.loads(geometry)
143
  if 'type' in geometry and 'coordinates' in geometry:
144
+ print("GeoJSON Geometry:", geometry) # Debugging: Inspect the GeoJSON structure
145
  return ee.Geometry(geometry)
146
  else:
147
  raise ValueError("GeoJSON format is invalid.")
 
156
  kml_root = tree.getroot()
157
 
158
  # Extract coordinates from KML geometry (assuming it's a Polygon or MultiPolygon)
 
 
159
  kml_namespace = {'kml': 'http://www.opengis.net/kml/2.2'}
160
  coordinates = kml_root.findall(".//kml:coordinates", kml_namespace)
161
  if coordinates:
 
162
  coords = coordinates[0].text.strip().split()
163
  coords = [tuple(map(float, coord.split(','))) for coord in coords]
164
  geojson = {
165
+ "type": "Polygon", # Ensure type is correct
166
+ "coordinates": [coords] # Ensure coordinates are structured as a list of coordinates
167
  }
168
+ print("KML GeoJSON:", geojson) # Debugging: Inspect the GeoJSON structure
169
  return ee.Geometry(geojson)
170
  else:
171
  raise ValueError("KML does not contain valid coordinates.")