diff --git a/lookup.py b/lookup.py index 5dae718..7c94016 100755 --- a/lookup.py +++ b/lookup.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from geopy import Nominatim +# ~ import json geolocator = Nominatim(user_agent="my-mapper") @@ -8,10 +9,25 @@ geolocator = Nominatim(user_agent="my-mapper") fn="ct-csv" with open( fn, 'r' ) as fp: - for line in fp: - location = geolocator.geocode(line) - # ~ print (location.latitude, location.longitude) + 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 - # ~ print (location) - print ( location.latitude, location.longitude) -fp.close() + # 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 diff --git a/prepare.sh b/prepare.sh index 09a67c7..38845ad 100755 --- a/prepare.sh +++ b/prepare.sh @@ -11,10 +11,11 @@ test -e ct-csv && echo "file already exists." || curl -o ct-csv "https://"${auth test -e erfa-csv && echo "file already exists." || curl -o erfa-csv "https://"${auth}"doku.ccc.de/Spezial:Semantische_Suche/-5B-5BKategorie:Chaostreffs-5D-5D-20-5B-5BChaostreff-2DIs-2DErfa::wahr-5D-5D-20-5B-5BChaostreff-2DActive::wahr-5D-5D/-3FChaostreff-2DPhysical-2DAddress%3DAdresse/-3FChaostreff-2DPhysical-2DPostcode%3DPLZ/-3FChaostreff-2DPhysical-2DCity%3DStadt/-3FChaostreff-2DCountry%3DLand/mainlabel%3D/limit%3D100/order%3DASC/sort%3DErfa-2DCity/offset%3D0/format%3Dcsv/headers%3Dshow/searchlabel%3DCSV/sep%3D,/filename%3Derfa-2Dbesuchsadressen.csv" # preprocess csv data for file in $(echo 'ct-csv\nerfa-csv'); do - sed -e 's/"//g' -e 's/\([0-9]\{4,5\}\),/\1 /g' ${file} > tmpfile && mv tmpfile ${file} + sed -e 's/"//g' ${file} > tmpfile && mv tmpfile ${file} + #~ sed -e 's/\([0-9]\{4,5\}\),/\1 /g' ${file} > tmpfile && mv tmpfile ${file} sed '1d' ${file} > tmpfile && mv tmpfile ${file} done # dependencies -pip3 install geopy # looking up addresses/coordinates -pip3 install folium # leaflet.js with python +#~ pip3 install geopy # looking up addresses/coordinates +#~ pip3 install folium # leaflet.js with python