34 lines
1.4 KiB
Python
Executable File
34 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from geopy import Nominatim
|
|
# ~ import json
|
|
|
|
geolocator = Nominatim(user_agent="my-mapper")
|
|
|
|
# first test to retreive geo coordinates
|
|
|
|
fn="ct-csv"
|
|
with open( fn, 'r' ) as fp:
|
|
for place in fp:
|
|
#error handling: expect
|
|
arrAddress = place.split(",")
|
|
strAddress = ",".join(arrAddress[1:4])
|
|
# ~ print( strAddress )
|
|
location = geolocator.geocode( strAddress )
|
|
if location is not None: # its a class
|
|
# todo: ceil coords to hide true location in format string
|
|
# ~ strCoordPlace = '{:s},{:.6f},{:.6f}'.format( arrAddress[3], location.latitude, location.longitude )
|
|
geojson = '{{"type":"Feature","geometry": {{"type": "Point","coordinates":[{:.6f}, {:.6f}]}},"properties":{{"name":"{:s}","marker":"ct"}}}}';
|
|
strCoordPlace = geojson.format( location.latitude, location.longitude, arrAddress[3] )
|
|
# ~ {"type": "Feature","geometry": {"type": "Point","coordinates":[125.6, 10.1]},"properties":{"name":"Dinagat Islands"}}
|
|
print ( strCoordPlace )
|
|
|
|
# ~ m = folium.Map( # etc..)
|
|
# ~ m.save("filename.png")
|
|
|
|
# ~ https://github.com/python-visualization/folium/issues/35#issuecomment-164784086
|
|
# ~ https://github.com/wbkd/leaflet-mapshot
|
|
# ~ https://stackoverflow.com/questions/44800396/python-ipyleaflet-export-map-as-png-or-jpg-or-svg
|
|
|
|
# ~ m = folium.Map(location=[51, 13], zoom_start=5, tiles='Stamen Toner') # Mapbox Bright , CartoDB Positron
|