Suchinthana commited on
Commit
85bb77d
·
1 Parent(s): 6aa54a4

apply only in polygon

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -180,9 +180,6 @@ def sort_coordinates_for_simple_polygon(geojson):
180
  # Update the GeoJSON with sorted coordinates
181
  geojson['features'][0]['geometry']['coordinates'][0] = sorted_coordinates
182
 
183
- #log geojson
184
- logger.info(f"Sorted GeoJSON: {geojson}")
185
-
186
  return geojson
187
 
188
  # Generate static map image
@@ -201,14 +198,7 @@ def generate_static_map(geojson_data, invisible=False):
201
  for coord in coords:
202
  m.add_marker(CircleMarker((coord[0], coord[1]), '#1C00ff00' if invisible else '#42445A85', 100))
203
  elif geom_type in ["Polygon", "MultiPolygon"]:
204
- # Sort coordinates for simple polygons
205
- if geom_type == "Polygon":
206
- oredered_geojson = sort_coordinates_for_simple_polygon(geojson_data)
207
- feature["geometry"]["coordinates"] = oredered_geojson["features"][0]["geometry"]["coordinates"]
208
- coords = feature["geometry"]["coordinates"]
209
- logger.info(f"coords: {coords}")
210
  for polygon in coords:
211
- logger.info(f"polygon: {polygon}")
212
  m.add_polygon(Polygon([(c[0], c[1]) for c in polygon], '#1C00ff00' if invisible else '#42445A85', 3))
213
 
214
  return m.render()
@@ -251,7 +241,11 @@ def handle_query(query):
251
  response = process_openai_response(query)
252
  geojson_data = generate_geojson(response)
253
 
254
- map_image = generate_static_map(geojson_data)
 
 
 
 
255
  empty_map_image = generate_static_map(geojson_data, invisible=True)
256
 
257
  difference = np.abs(np.array(map_image.convert("RGB")) - np.array(empty_map_image.convert("RGB")))
 
180
  # Update the GeoJSON with sorted coordinates
181
  geojson['features'][0]['geometry']['coordinates'][0] = sorted_coordinates
182
 
 
 
 
183
  return geojson
184
 
185
  # Generate static map image
 
198
  for coord in coords:
199
  m.add_marker(CircleMarker((coord[0], coord[1]), '#1C00ff00' if invisible else '#42445A85', 100))
200
  elif geom_type in ["Polygon", "MultiPolygon"]:
 
 
 
 
 
 
201
  for polygon in coords:
 
202
  m.add_polygon(Polygon([(c[0], c[1]) for c in polygon], '#1C00ff00' if invisible else '#42445A85', 3))
203
 
204
  return m.render()
 
241
  response = process_openai_response(query)
242
  geojson_data = generate_geojson(response)
243
 
244
+ if geojson_data["features"][0]["geometry"]["type"] == 'Polygon':
245
+ geojson_data_coords = sort_coordinates_for_simple_polygon(geojson_data)
246
+ map_image = generate_static_map(geojson_data_coords)
247
+ else:
248
+ map_image = generate_static_map(geojson_data)
249
  empty_map_image = generate_static_map(geojson_data, invisible=True)
250
 
251
  difference = np.abs(np.array(map_image.convert("RGB")) - np.array(empty_map_image.convert("RGB")))