Skip to content
Snippets Groups Projects
Commit b30bff8c authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

fix: map return json structure, maybe

parent 80be3b43
No related branches found
No related tags found
1 merge request!7Clhp map
No preview for this file type
import geopandas as gpd
from shapely.geometry import Polygon, LineString, MultiLineString
from shapely.ops import linemerge, unary_union, polygonize
import matplotlib.pyplot as plt
import random
import json
import os
......@@ -30,31 +32,47 @@ def get_relation(self, body_of_water: str): # NB: implement body_of_water
divided_map.extend(combine_grid_with_poly(polygon, lines))
####################### PLOTTIND ############################
tiles = [gpd.GeoDataFrame(geometry=[tile]) for tile in divided_map]
sub_div_id = 0
for tile in tiles:
tile['sub_div_id'] = sub_div_id
tile['sub_div_center'] = tile['geometry'].centroid.apply(lambda x: [x.x, x.y])
sub_div_id += 1
print("Plotting... This may take some time...")
# NB test plot
fig, ax = plt.subplots()
ax.set_aspect(1.5)
tiles_json = {'type': 'FeatureCollection', 'features': []}
# Plot each tile
for tile in tiles:
feature = {
random_color = "#{:06x}".format(random.randint(0, 0xFFFFFF))
gpd.GeoSeries(tile.geometry).plot(ax=ax, facecolor=random_color, edgecolor='none')
plt.show()
##################### PLOTTIND END ###########################
features = []
sub_div_id = 0
for tile in divided_map:
tile_feature = {
'type': 'Feature',
'geometry': tile.geometry.__geo_interface__,
'geometry': tile.__geo_interface__,
'properties': {
'sub_div_id': int(tile['sub_div_id'].iloc[0]),
'sub_div_center': tile['sub_div_center'].tolist()
'sub_div_id': sub_div_id,
'sub_div_center': tile.centroid.coords[0]
}
}
tiles_json['features'].append(feature)
features.append(tile_feature)
sub_div_id += 1
feature_collection = {
'type': 'FeatureCollection',
'features': features
}
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
self.wfile.write(json.dumps(tiles_json).encode('utf-8'))
self.wfile.write(json.dumps(feature_collection).encode('utf-8'))
def create_grid(poly: Polygon, cell_size):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment