12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import geopandas as gpd
- import matplotlib.pyplot as plt
- from shapely.wkt import loads
- from PIL import Image
- def resizeImage(filePath):
-
- original_image = Image.open(filePath)
-
- resized_image = original_image.resize((256, 256))
- filePath = filePath.replace('tb', 'tb_256')
-
- resized_image.save(filePath)
- def savePng(fileName, ewkt):
-
- geometry = loads(ewkt.split(';')[1])
- gdf = gpd.GeoDataFrame(geometry=[geometry])
-
- fig, ax = plt.subplots(figsize=(10, 10))
-
- if geometry.geom_type == 'Polygon':
- ax.fill(*geometry.exterior.xy, color='black')
- for interior in geometry.interiors:
- ax.fill(*interior.xy, color='white')
-
- elif geometry.geom_type == 'MultiPolygon':
- for poly in geometry.geoms:
- ax.fill(*poly.exterior.xy, color='black')
- for interior in poly.interiors:
- ax.fill(*interior.xy, color='white')
-
- ax.set_xlim(gdf.total_bounds[[0, 2]])
- ax.set_ylim(gdf.total_bounds[[1, 3]])
-
- ax.axis('off')
-
- filePath = 'img/tb/' + fileName + '.png'
- plt.savefig(filePath, dpi=300, bbox_inches='tight', pad_inches=0)
- plt.close()
-
- resizeImage(filePath)
|