Commit 2c88b351 authored by FLEURY Jules's avatar FLEURY Jules
Browse files

initial commit

parents
# -*- coding: utf-8 -*-
"""
Created on April 21th 2020
csv to leaflet
@author: Jules
"""
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import geopandas as gpd
import sys,os
import base64
import itertools
from shapely.geometry import Point, LineString
import folium
from folium import plugins
from folium import IFrame
from folium.plugins import HeatMap
from folium.plugins import MarkerCluster
from folium.plugins import MiniMap
from folium.plugins import MeasureControl
# ensure our graphs are displayed inline
# %matplotlib inline
print("************************************")
print(" STARTING ")
print("************************************")
#read inputs, CAUTION check path if Windows - Linux - Mac swapping
rep_images="C:\\Users\\sigeo\\Documents\\webmap_tp\\images_800px\\" # repertoire des images
rep="C:\\Users\\sigeo\\Documents\\webmap_tp\\" # repertoire du fichier csv
df = pd.read_csv(rep+"markers_website_input.csv", delimiter='\t',decimal=',')
# Create target Directory if don't exist
output_directory=rep+'OUTPUT\\'
try:
os.mkdir(output_directory)
except OSError as error:
print(error)
df.drop(labels="id", axis=1, inplace=True)
#nan_columns = df.columns[df.isna().any()].tolist()
geometry = [Point(xy) for xy in zip(df.longitude, df.latitude)]
crs = {'init': 'epsg:4326'}
geo_df = gpd.GeoDataFrame(df, crs=crs, geometry=geometry)
markers_map = folium.Map(location=[45, 5], tiles='Stamen Terrain',zoom_start=2)
clusters_map = MarkerCluster(name="Points of interest").add_to(markers_map)
folium.TileLayer(tiles='Stamen Watercolor',name="Stamen Watercolor").add_to(markers_map)
folium.TileLayer(tiles='OpenStreetMap',name="OpenStreetMap").add_to(markers_map)
folium.LayerControl().add_to(markers_map)
markers_map.add_child(folium.LatLngPopup())
minimap = MiniMap(toggle_display=True)
minimap.add_to(markers_map)
markers_map.add_child(MeasureControl())
for ix, row in geo_df.iterrows():
encoded = base64.b64encode(open(rep_images+str(row['img_name']), 'rb').read())
resolution, width, height = 75, 50, 25
imag='<img src="data:image/jpeg;base64,{}" style="height: 100%; width: 100%; object-fit: contain"/>'.format
# iframe_img = IFrame(imag(encoded.decode('UTF-8')), width=(width*resolution)+20, height=(height*resolution)+20)
html = f"""
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse;">
<tr> <td><h2>{str(row['title'])} </h2></td></tr>
<tr> <td>{str(row['comment'])} </td></tr>
<tr><td>{imag(encoded.decode('UTF-8'))}</td></tr>
<tr>
<td>
<a href="{str(row['url'])}" target="_blank"> {str(row['link_text'])} </a>
</td>
</tr>
</table>
"""
iframe = folium.IFrame(html=html, width=375, height=375)
popup = folium.Popup(iframe, max_width=375)
# Create a marker on the map
folium.Marker(location = [float(row['latitude']),float(row['longitude'])],popup=popup).add_to(clusters_map)
markers_map.save(output_directory + "markers_map.html")
markers_map
display(markers_map)
print("************************************")
print(" ENDING ")
print("************************************")
###########################
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 21 22:05:41 2020
Resize a folder of images to a set max width / height dimension, keeping proportions constrained
This script should be placed outside the images folder. By default this folder should be named images. The default max dimension size is 2560px, but it can be specified manually using the CLI e.g.
python photo-batch-resize-constrained.py --max-px-size 4000 --images-folder my_SLR_pictures
@author: agaleo91
from : https://gist.github.com/agalea91/12149be6d4f64ba61c7b1d222fce3174
"""
import click
import glob
import os
from PIL import Image
@click.command()
@click.option(
'--max-px-size',
default=2560,
help='The max height / width of image in pixels.'
)
@click.option(
'--images-folder',
default='images',
help='Name of folder containing images.'
)
def main(max_px_size, images_folder):
imgs = []
imgs += sorted(glob.glob(os.path.join(images_folder, '*.jpg')))
imgs += sorted(glob.glob(os.path.join(images_folder, '*.jpeg')))
print('Image files to resize:')
print('\n'.join(imgs))
output_folder = '{}/images_{}px'.format(images_folder, max_px_size)
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for img_path in imgs:
try:
resize(img_path, max_px_size, output_folder)
except Exception as e:
with open('error.txt', 'w') as f:
f.write(str(e))
def resize(img_path, max_px_size, output_folder):
with Image.open(img_path) as img:
width_0, height_0 = img.size
out_f_name = os.path.split(img_path)[-1]
out_f_path = os.path.join(output_folder, out_f_name)
if max((width_0, height_0)) <= max_px_size:
print('writing {} to disk (no change from original)'.format(out_f_path))
img.save(out_f_path)
return
if width_0 > height_0:
wpercent = max_px_size / float(width_0)
hsize = int(float(height_0) * float(wpercent))
img = img.resize((max_px_size, hsize), Image.ANTIALIAS)
print('writing {} to disk'.format(out_f_path))
img.save(out_f_path)
return
if width_0 < height_0:
hpercent = max_px_size / float(height_0)
wsize = int(float(width_0) * float(hpercent))
img = img.resize((wsize, max_px_size), Image.ANTIALIAS)
print('writing {} to disk'.format(out_f_path))
img.save(out_f_path)
return
if __name__ == '__main__':
main()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment