This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQL2GEOJSON_Moorings.py
executable file
·94 lines (68 loc) · 3.34 KB
/
SQL2GEOJSON_Moorings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
"""
SQL2GEOJSON_Moorings.py
export all mooring locations to geojson format for plotting
"""
#System Stack
import datetime
import argparse
import mysql.connector
import sys
#Science Stack
import numpy as np
#User Stack
import io_utils.ConfigParserLocal as ConfigParserLocal
from io_utils.EcoFOCI_db_io import EcoFOCI_db_datastatus
__author__ = 'Shaun Bell'
__email__ = '[email protected]'
__created__ = datetime.datetime(2015, 5, 28)
__modified__ = datetime.datetime(2015, 5, 28)
__version__ = "0.1.0"
__status__ = "Development"
__keywords__ = 'moorings','csv','google maps', 'heatmap', 'geojson'
"""------------------------------- MAIN ----------------------------------------"""
parser = argparse.ArgumentParser(description='Mooring Database -> GEOJSON For currently deployed')
parser.add_argument('--geojson', action='store_true', help='create geojson file')
parser.add_argument('--google_earth', action='store_true', help='create google earth file')
parser.add_argument('--all', action='store_true', help='create files for all moorings')
args = parser.parse_args()
#get information from local config file - a json formatted file
config_file = 'EcoFOCI_config/db_config/db_config_mooring.yaml'
EcoFOCI_db = EcoFOCI_db_datastatus()
(db,cursor) = EcoFOCI_db.connect_to_DB(db_config_file=config_file,ftype='yaml')
if args.all:
data_mooring = EcoFOCI_db.read_mooring_summary(table='mooringdeploymentlogs')
else:
data_mooring = EcoFOCI_db.read_mooring_summary(table='mooringdeploymentlogs',deployed=True,verbose=False)
#find missing or undeployed data and skip
for a_ind in data_mooring.keys():
if (data_mooring[a_ind]['Latitude'] == '') or (data_mooring[a_ind]['Latitude'] == 'NOT DEPLOYED') or not(data_mooring[a_ind]['Latitude']):
data_mooring[a_ind]['Latitude'] = '00 0.00 N'
data_mooring[a_ind]['Longitude'] = '00 0.00 W'
mooring_lat = np.array([float(data_mooring[a_ind]['Latitude'].split()[0]) + float(data_mooring[a_ind]['Latitude'].split()[1])/60.0 for a_ind in data_mooring.keys()])
mooring_lon = np.array([-1.0*(float(data_mooring[a_ind]['Longitude'].split()[0]) + float(data_mooring[a_ind]['Longitude'].split()[1])/60.0) for a_ind in data_mooring.keys()])
mooringid = data_mooring.keys()
if args.geojson:
### "Generating .geojson"
geojson_header = (
'{"type": "FeatureCollection","features": ['
)
geojson_point_coords = ''
for k, value in enumerate(mooring_lat):
if (mooring_lat[k] != 0.0) and (mooring_lon[k] != 0.0):
geojson_point_coords = geojson_point_coords + ('{{"type": "Feature","geometry": {{"type": "Point","coordinates": [{1},{0}]}}, "properties": {{"MooringID":"{2}" }}}}').format(mooring_lat[k],mooring_lon[k],mooringid[k])
if (k+1 != len(mooring_lat)):
geojson_point_coords = geojson_point_coords + ', '
geojson_tail = (
']\n'
'}\n'
)
print geojson_header + geojson_point_coords + geojson_tail
if args.google_earth:
point_coords = ''
for k, value in enumerate(mooring_lat):
if (mooring_lat[k] != 0.0) and (mooring_lon[k] != 0.0):
point_coords = point_coords + ('new google.maps.LatLng({0},{1})').format(mooring_lat[k],mooring_lon[k])
if (k+1 != len(mooring_lat)):
point_coords = point_coords + ',\n'
print point_coords