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
/
SQL2GEOJSON_PUFFS.py
executable file
·78 lines (55 loc) · 2.53 KB
/
SQL2GEOJSON_PUFFS.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
#!/usr/bin/env python
"""
SQL2GEOJSON_PUFFS.py
export all ctd cast 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_PUFF_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='Cruise Database -> GEOJSON')
parser.add_argument('--geojson', action='store_true', help='create geojson file')
args = parser.parse_args()
#get information from local config file - a json formatted file
config_file = 'EcoFOCI_config/db_config/db_config_drifters.yaml'
EcoFOCI_db = EcoFOCI_PUFF_db_datastatus()
(db,cursor) = EcoFOCI_db.connect_to_DB(db_config_file=config_file,ftype='yaml')
data_puffs = EcoFOCI_db.read_floats(table='popupfloats_deployed')
if args.geojson:
### "Generating .geojson"
geojson_header = (
'{"type": "FeatureCollection","features": ['
)
geojson_point_coords = ''
for a_ind in sorted(data_puffs.keys()):
geojson_point_coords = geojson_point_coords + ('''
{{"type": "Feature","geometry":
{{"type": "Point","coordinates": [{1},{0}]}},
"properties": {{"ENG_SN":"{2}", "IMEI_SN":"{3}","GEN":"{4}", "DEPLOY_CRUISE":"{5}",
"SITE":"{6}", "DEPLOY_DEPTH_meters":"{7}", "DEPLOY_ DATETIMEUTC":"{8}", "UNIT_START_DATETIMEUTC":"{9}",
"RELEASE_DATETIMEUTC":"{10}", "DEPLOY_FISCAL_YEAR":"{11}"}}}}''').format(data_puffs[a_ind]['DEPLOY_LAT'],
data_puffs[a_ind]['DEPLOY_LON'],data_puffs[a_ind]['ENG_SN'],data_puffs[a_ind]['IMEI_SN'],
data_puffs[a_ind]['GEN'],data_puffs[a_ind]['DEPLOY_CRUISE'],data_puffs[a_ind]['SITE'],
data_puffs[a_ind]['DEPLOY_DEPTH_meters'],data_puffs[a_ind]['DEPLOY_ DATETIMEUTC'],data_puffs[a_ind]['UNIT_START_DATETIMEUTC'],
data_puffs[a_ind]['RELEASE_DATETIMEUTC'],data_puffs[a_ind]['DEPLOY_FISCAL_YEAR'])
if (a_ind != sorted(data_puffs.keys())[-1]):
geojson_point_coords = geojson_point_coords + ', '
geojson_tail = (
']\n'
'}\n'
)
print(geojson_header+geojson_point_coords+geojson_tail)