forked from vv01f/ccc-map
modify for veb it
This commit is contained in:
parent
fc0951e63d
commit
8162ca0d37
|
@ -1,11 +1,12 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
echo "this takes some time depending on the amount of addresses in your lists …"
|
echo "this takes some time depending on the amount of addresses in your lists …"
|
||||||
for file in *-csv ; do
|
for file in *.csv ; do
|
||||||
out=$(echo "${file}"|cut -d- -f1)".geojson"
|
out=$(echo "${file}"|cut -d"." -f1)".geojson"
|
||||||
if test -e "${out}" ; do
|
if test -e "${out}" ; then
|
||||||
echo "file exists: ${out}, skipping."
|
echo "file exists: ${out}, skipping."
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
echo ./lookup.py "${file}"
|
echo ./lookup.py "${file}"
|
||||||
./lookup.py "${file}" 2>/dev/null > "${out}"
|
./lookup.py "${file}" > "${out}"
|
||||||
|
#~ ./lookup.py "${file}" 2>/dev/null > "${out}"
|
||||||
done
|
done
|
||||||
|
|
29
lookup.py
29
lookup.py
|
@ -5,13 +5,19 @@ from geopy import Nominatim
|
||||||
# ~ import json
|
# ~ import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import sys
|
#disable ssl verification
|
||||||
|
import ssl
|
||||||
|
import geopy.geocoders
|
||||||
|
ctx = ssl.create_default_context()
|
||||||
|
ctx.check_hostname = False
|
||||||
|
ctx.verify_mode = ssl.CERT_NONE
|
||||||
|
geopy.geocoders.options.default_ssl_context = ctx
|
||||||
|
#/
|
||||||
|
|
||||||
# debug print to stderr, https://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python
|
# debug print to stderr, https://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python
|
||||||
def eprint(*args, **kwargs):
|
def eprint(*args, **kwargs):
|
||||||
print(*args, file=sys.stderr, **kwargs)
|
print(*args, file=sys.stderr, **kwargs)
|
||||||
|
|
||||||
# ~ fn="ct-csv"
|
|
||||||
if len(sys.argv) == 2:
|
if len(sys.argv) == 2:
|
||||||
fn = sys.argv[1]
|
fn = sys.argv[1]
|
||||||
else:
|
else:
|
||||||
|
@ -21,9 +27,9 @@ else:
|
||||||
sys.exit(1) # exit with error
|
sys.exit(1) # exit with error
|
||||||
|
|
||||||
# for retreiving geo coordinates from addresses
|
# for retreiving geo coordinates from addresses
|
||||||
geolocator = Nominatim(user_agent="my-mapper")
|
geolocator = Nominatim(user_agent="vebit-mapper")
|
||||||
# lat: 0=111,1km,1=11km,2=1km… lng: 0=70km,1=7km,2=.7km…
|
# lat: 0=111,1km; 1=11km; 2=1km… lng: 0=70km; 1=7km; 2=0,7km…
|
||||||
precision = 2
|
precision = 1
|
||||||
|
|
||||||
# convert csv to geojson
|
# convert csv to geojson
|
||||||
|
|
||||||
|
@ -31,18 +37,23 @@ firstline = True
|
||||||
# start json list
|
# start json list
|
||||||
print ( '{"type":"FeatureCollection","features":[' )
|
print ( '{"type":"FeatureCollection","features":[' )
|
||||||
# get data from file
|
# get data from file
|
||||||
|
eprint( "opening: "+fn )
|
||||||
with open( fn, 'r' ) as fp:
|
with open( fn, 'r' ) as fp:
|
||||||
for place in fp:
|
for place in fp:
|
||||||
#error handling: expect
|
#error handling: expect
|
||||||
arrAddress = place.split(",")
|
arrAddress = place.split(";")
|
||||||
strAddress = ",".join(arrAddress[2:6])
|
strAddress1 = str(" ".join(arrAddress[1:2]))
|
||||||
|
eprint( "… "+strAddress1 )
|
||||||
|
strAddress2 = ",".join(arrAddress[3:5])
|
||||||
|
eprint( "… "+strAddress2 )
|
||||||
|
strAddress = strAddress1+","+strAddress2
|
||||||
eprint( "looking up: "+strAddress )
|
eprint( "looking up: "+strAddress )
|
||||||
location = geolocator.geocode( strAddress )
|
location = geolocator.geocode( strAddress )
|
||||||
if location is not None: # its a class
|
if location is not None: # its a class
|
||||||
# todo: ceil coords to hide true location in format string
|
# todo: ceil coords to hide true location in format string
|
||||||
# ~ strCoordPlace = '{:s},{:.6f},{:.6f}'.format( arrAddress[3], location.latitude, location.longitude )
|
# ~ strCoordPlace = '{:s},{:.6f},{:.6f}'.format( arrAddress[3], location.latitude, location.longitude )
|
||||||
geojson = '{{"type":"Feature","geometry":{{"type":"Point","coordinates":[{:.'+str(precision)+'f},{:.'+str(precision)+'f}]}},"properties":{{"name":"{:s}","marker":"{:s}"}}}}';
|
geojson = '{{"type":"Feature","geometry":{{"type":"Point","coordinates":[{:.'+str(precision)+'f},{:.'+str(precision)+'f}]}},"properties":{{"name":"{:s}","title":"{:s}","marker":"{:s}"}}}}';
|
||||||
strCoordPlace = geojson.format( location.longitude, location.latitude, arrAddress[1], fn.split("-")[0] )
|
strCoordPlace = geojson.format( location.longitude, location.latitude, arrAddress[1], arrAddress[1], fn.split("-")[0] )
|
||||||
if firstline == False :
|
if firstline == False :
|
||||||
print (",")
|
print (",")
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue