-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool.php
192 lines (134 loc) · 5.27 KB
/
tool.php
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/************************************************************************************
t. schneider | tes at mit.edu | 6.3.09
laboratory for autonomous marine sensing systems
tool.php - various kml tools
************************************************************************************/
/************************************************************************************
connections
************************************************************************************/
require_once('connections/mysql.php');
/************************************************************************************
includes
************************************************************************************/
require_once('includes/geov_html_writer.php');
require_once('includes/kml_writer.php');
$html = new geov_html_writer();
include "includes/geov_header.php";
/************************************************************************************
handle url variables (POST/GET)
************************************************************************************/
$post_actions = array('em3000');
$do = "nothing";
foreach($post_actions as $action)
$do = (isset($_POST[$action])) ? $action : $do;
/************************************************************************************
do stuff
************************************************************************************/
$message = "";
switch($do)
{
default:
break;
case 'em3000':
if (is_uploaded_file($_FILES['contour']['tmp_name'])) {
$message .= "file ". $_FILES['contour']['name'] ." uploaded successfully.\n";
$fid = fopen($_FILES['contour']['tmp_name'], 'r');
header('Content-disposition: attachment; filename='.basename( $_FILES['contour']['name'] ).'.kml');
$kml = new kml_writer();
create_em3000_kml($fid, $kml);
$kml->echo_kml();
die();
}
break;
}
/************************************************************************************
start html output (no header() past here)
************************************************************************************/
$html->h2("kml tools");
$html->hr();
$html->navbar("tools");
$html->hr();
if($message != "")
{
$html->pre($message);
$html->hr();
}
$html->push("form", array("method"=>"post", "name"=>"tool_form", "action"=>"tool.php", "enctype"=>"multipart/form-data"));
$html->h3("EM3000 contour.daf to kml file:");
$html->p("choose a contour.daf file to upload:");
$html->input_upload("contour", 10000000);
$html->button("make kml file", array("name"=>"em3000", "type"=>"submit"));
$html->pop(); //</form>
$html->hr();
include "includes/geov_footer.php";
// closes all tags
$html->echo_html();
/************************************************************************************
functions
************************************************************************************/
function create_em3000_kml($fid, $kml)
{
$kml->push("Document");
$kml->push_folder("Bathymetry map", "", false, "click isobath on map to see depth");
$state = "none";
$curdepth = 0;
$depths = array();
$min_lat = 90;
$i=0;
while ($line = fgets($fid))
{
++$i;
switch($state)
{
case "none":
if (!substr_compare("START", $line, 0, 5, true))
{
$out = sscanf($line, "START %d, %d=%d;%d=%d");
$curdepth = $out[2];
$depths[] = $curdepth;
$kml->push("Placemark");
$kml->element("name", "depth=".$curdepth);
$kml->push("LineString");
$kml->element("tessellate", "1");
$kml->element("altitudeMode", "clampToSeaFloor");
$kml->push("coordinates");
$state = "reading";
}
break;
case "reading":
if (!substr_compare("STOP", $line, 0, 4, true))
{
$kml->pop();
$kml->pop();
$kml->element("styleUrl", "#".$curdepth);
$kml->pop();
$state = "none";
}
else
{
if(!($i % 10))
{
$line_pieces = explode(" ", $line);
$kml->insert($line_pieces[0].",".$line_pieces[1]);
if ($line_pieces[1] < $min_lat)
$min_lat = $line_pieces[1];
}
}
break;
}
}
$max = max($depths);
$min = min($depths);
$spread = $max - $min;
$kml->pop();
foreach($depths as $depth)
{
// AABBGGRR
$r = max(0, 255*(1-($depth-$min)/($spread)));
$g = 0;
$b = min(255, 255*($depth-$min)/($spread));
$kml->line_style($depth, sprintf("AA%02X%02X%02X", $b, $g, $r), 1);
}
}
?>