1 |
1549
|
aaronmk
|
<html><body style="background-color:yellow;">
|
2 |
|
|
<h1 style="text-align:center;"> CTFS to VegX conversion </h1>
|
3 |
|
|
|
4 |
|
|
<?php
|
5 |
|
|
$dbhost = 'localhost';
|
6 |
|
|
$dbuser = 's_sramteke';
|
7 |
|
|
$dbpass = 'S6a52mxX';
|
8 |
|
|
echo date("m/d/y :H:i:s",time());
|
9 |
|
|
$conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error');
|
10 |
|
|
|
11 |
|
|
$dbname = 's_sramteke';
|
12 |
|
|
mysql_select_db($dbname);
|
13 |
|
|
|
14 |
|
|
//$sql = "SELECT * FROM `DFtemp`";
|
15 |
|
|
//$result = mysql_query($sql);
|
16 |
|
|
|
17 |
|
|
$xmlHandle = fopen("new_Xml_CTFS_row.xml","w");
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
$writer = new XMLWriter();
|
21 |
|
|
$writer->openMemory();
|
22 |
|
|
$writer->setIndent(true);
|
23 |
|
|
$writer->setIndentString(" ");
|
24 |
|
|
$writer->startDocument('1.0', 'UTF-8');
|
25 |
|
|
|
26 |
|
|
$writer->startElement('vegX');
|
27 |
|
|
$writer->writeAttribute("xsi:noNamespaceSchemaLocation", "C:/Development/Utilities/LCR.Utilities.DataImport/LCR.Utilities.MappingTool/Resources/VEGX15~1.2/veg.xsd");
|
28 |
|
|
$writer->writeAttribute("xmlns:acc", "eml://ecoinformatics.org/access-2.0.1");
|
29 |
|
|
$writer->writeAttribute("xmlns:cov", "eml://ecoinformatics.org/coverage-2.0.1");
|
30 |
|
|
$writer->writeAttribute("xmlns:doc", "eml://ecoinformatics.org/documentation-2.0.1");
|
31 |
|
|
$writer->writeAttribute("xmlns:lit", "eml://ecoinformatics.org/literature-2.0.1");
|
32 |
|
|
$writer->writeAttribute("xmlns:party","eml://ecoinformatics.org/party-2.0.1");
|
33 |
|
|
$writer->writeAttribute("xmlns:proj","eml://ecoinformatics.org/project-2.0.1");
|
34 |
|
|
$writer->writeAttribute("xmlns:res","eml://ecoinformatics.org/resource-2.0.1");
|
35 |
|
|
$writer->writeAttribute("xmlns:txt","eml://ecoinformatics.org/text-2.0.1");
|
36 |
|
|
$writer->writeAttribute("xmlns:dwe","http://rs.tdwg.org/dwc/dwelement/");
|
37 |
|
|
$writer->writeAttribute("xmlns:dwg","http://rs.tdwg.org/dwc/geospatial/");
|
38 |
|
|
$writer->writeAttribute("xmlns:misc","http://www.bfn.de/misc-1.0.1");
|
39 |
|
|
$writer->writeAttribute("xmlns:org","http://www.bfn.de/organismobservation-1.0.1");
|
40 |
|
|
$writer->writeAttribute("xmlns:plot","http://www.bfn.de/plot-1.0.1");
|
41 |
|
|
$writer->writeAttribute("xmlns:obs","http://www.bfn.de/plotobservation-1.0.1");
|
42 |
|
|
$writer->writeAttribute("xmlns:tcs","http://www.tdwg.org/schemas/tcs/1.01");
|
43 |
|
|
$writer->writeAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
|
44 |
|
|
$filename = "new_Xml_CTFS_row.xml";
|
45 |
|
|
|
46 |
|
|
$file = $writer->outputMemory();
|
47 |
|
|
|
48 |
|
|
file_put_contents($filename,$file);
|
49 |
|
|
|
50 |
|
|
$i=0;
|
51 |
|
|
|
52 |
|
|
/*while($row = mysql_fetch_row($result))
|
53 |
|
|
{
|
54 |
|
|
$writer->startElement('projects');
|
55 |
|
|
|
56 |
|
|
$writer->startElement('project');
|
57 |
|
|
$writer->writeElement('title','Project 1');
|
58 |
|
|
$writer->endElement();
|
59 |
|
|
$writer->endElement();
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
}*/
|
63 |
|
|
|
64 |
|
|
$sql = "SELECT distinct `PlotID`, `Plot`, `QuadratID`, `QuadratName`, `gx`, `gy` FROM `DFtemp` WHERE plot = 'bci'";
|
65 |
|
|
|
66 |
|
|
$result = mysql_query($sql);
|
67 |
|
|
$writer->startElement('plots');
|
68 |
|
|
|
69 |
|
|
while($row = mysql_fetch_row($result))
|
70 |
|
|
{
|
71 |
|
|
|
72 |
|
|
$writer->startElement('plot');
|
73 |
|
|
$writer->writeElement('plotUniqueIdentifier',$row[0]);
|
74 |
|
|
$writer->writeElement('plotName',$row[1]);
|
75 |
|
|
|
76 |
|
|
$writer->startElement('geospatial');
|
77 |
|
|
$writer->writeElement('dwg:VerbatimLatitude',$row[4]);
|
78 |
|
|
$writer->writeElement('dwg:VerbatimLongitude',$row[5]);
|
79 |
|
|
$writer->endElement();
|
80 |
|
|
|
81 |
|
|
$writer->endElement();
|
82 |
|
|
|
83 |
|
|
$writer->startElement('plot');
|
84 |
|
|
$writer->writeElement('plotUniqueIdentifier',$row[2]);
|
85 |
|
|
$writer->writeElement('plotName',$row[3]);
|
86 |
|
|
|
87 |
|
|
$writer->startElement('relatedPlot');
|
88 |
|
|
$writer->startElement('relatedPlot');
|
89 |
|
|
$writer->writeElement('relatedPlotID',$row[0]);
|
90 |
|
|
$writer->writeElement('plotRelationship',"Quadrant");
|
91 |
|
|
$writer->endElement();
|
92 |
|
|
$writer->endElement();
|
93 |
|
|
$writer->endElement();
|
94 |
|
|
$i++;
|
95 |
|
|
|
96 |
|
|
if($i == 1000)
|
97 |
|
|
{
|
98 |
|
|
file_put_contents('new_Xml_CTFS_row.xml', $writer->flush(true), FILE_APPEND);
|
99 |
|
|
$i = 0;
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
$writer->endElement();
|
103 |
|
|
|
104 |
|
|
file_put_contents($filename, $writer->flush(true), FILE_APPEND);
|
105 |
|
|
|
106 |
|
|
$i=0;
|
107 |
|
|
|
108 |
|
|
$sql = "select MeasureID,CensusID,QuadratID, PlotCensusNumber, ExactDate,PLotID FROM `DFtemp` WHERE plot = 'bci'";
|
109 |
|
|
$result = mysql_query($sql);
|
110 |
|
|
|
111 |
|
|
$writer->startElement('plotObservations');
|
112 |
|
|
while($row = mysql_fetch_row($result))
|
113 |
|
|
{
|
114 |
|
|
$writer->startElement('plotObservation');
|
115 |
|
|
$writer->writeAttribute("id",$row[0]);
|
116 |
|
|
$writer->writeElement('plotUniqueIdentifierID',$row[5]);
|
117 |
|
|
$writer->writeElement('obsStartDate',$row[4]);
|
118 |
|
|
$writer->startElement('simpleUserdefined');
|
119 |
|
|
$writer->writeElement('name',"CensusID");
|
120 |
|
|
$writer->writeElement('value',$row[1]);
|
121 |
|
|
$writer->writeElement('methodID',"CensusID");
|
122 |
|
|
$writer->endElement();
|
123 |
|
|
$writer->endElement();
|
124 |
|
|
|
125 |
|
|
$writer->startElement('plotObservation');
|
126 |
|
|
$writer->writeAttribute("id",$row[2]);
|
127 |
|
|
$writer->writeElement('plotUniqueIdentifierID',$row[2]);
|
128 |
|
|
$writer->writeElement('obsStartDate',$row[4]);
|
129 |
|
|
$writer->startElement('simpleUserdefined');
|
130 |
|
|
$writer->writeElement('name',"CensusID");
|
131 |
|
|
$writer->writeElement('value',$row[1]);
|
132 |
|
|
$writer->writeElement('methodID',"CensusID");
|
133 |
|
|
$writer->endElement();
|
134 |
|
|
$writer->endElement();
|
135 |
|
|
|
136 |
|
|
$i++;
|
137 |
|
|
|
138 |
|
|
if($i == 1000)
|
139 |
|
|
{
|
140 |
|
|
file_put_contents('new_Xml_CTFS_row.xml', $writer->flush(true), FILE_APPEND);
|
141 |
|
|
$i = 0;
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
}
|
145 |
|
|
$writer->endElement();
|
146 |
|
|
|
147 |
|
|
file_put_contents($filename, $writer->flush(true), FILE_APPEND);
|
148 |
|
|
|
149 |
|
|
$i=0;
|
150 |
|
|
|
151 |
|
|
$sql = " select Genus,Family,SpeciesName,GenusSpecies,SpeciesID,Mnemonic FROM `DFtemp` WHERE plot = 'bci'";
|
152 |
|
|
|
153 |
|
|
$result = mysql_query($sql);
|
154 |
|
|
$writer->startElement('taxonConcepts');
|
155 |
|
|
while($row = mysql_fetch_row($result))
|
156 |
|
|
{
|
157 |
|
|
$writer->startElement('taxonConcept');
|
158 |
|
|
$writer->writeAttribute("id",$row[0]);
|
159 |
|
|
$writer->writeElement('tcs:Name',$row[0]);
|
160 |
|
|
$writer->writeAttribute("scientific","false");
|
161 |
|
|
//$writer->endElement();
|
162 |
|
|
$writer->writeElement('tcs:Rank',"Genus");
|
163 |
|
|
$writer->endElement();
|
164 |
|
|
|
165 |
|
|
$writer->startElement('taxonConcept');
|
166 |
|
|
$writer->writeAttribute("id",$row[1]);
|
167 |
|
|
$writer->writeElement('tcs:Name',$row[1]);
|
168 |
|
|
$writer->writeAttribute("scientific","false");
|
169 |
|
|
//$writer->endElement();
|
170 |
|
|
$writer->writeElement('tcs:Rank',"Family");
|
171 |
|
|
|
172 |
|
|
$writer->startElement('tcs:TaxonRelationships');
|
173 |
|
|
$writer->startElement('tcs:TaxonRelationship');
|
174 |
|
|
$writer->writeAttribute("type","is child taxon of");
|
175 |
|
|
$writer->writeElement('tcs:ToTaxonConcept',$row[0]);
|
176 |
|
|
$writer->endElement();
|
177 |
|
|
$writer->endElement();
|
178 |
|
|
$writer->endElement();
|
179 |
|
|
|
180 |
|
|
$writer->startElement('taxonConcept');
|
181 |
|
|
$writer->writeAttribute("id",$row[2]);
|
182 |
|
|
$writer->startElement('tcs:Name');
|
183 |
|
|
$writer->startAttribute("scientific");
|
184 |
|
|
$writer->text("false");
|
185 |
|
|
$writer->endAttribute();
|
186 |
|
|
$writer->text($row[2]);
|
187 |
|
|
$writer->endElement();
|
188 |
|
|
$writer->writeElement('tcs:Rank',"Species");
|
189 |
|
|
|
190 |
|
|
$writer->startElement('tcs:TaxonRelationships');
|
191 |
|
|
$writer->startElement('tcs:TaxonRelationship');
|
192 |
|
|
$writer->writeAttribute("type","is child taxon of");
|
193 |
|
|
$writer->writeElement('tcs:ToTaxonConcept',$row[0]);
|
194 |
|
|
$writer->endElement();
|
195 |
|
|
$writer->startElement('tcs:TaxonRelationship');
|
196 |
|
|
$writer->writeAttribute("type","is child taxon of");
|
197 |
|
|
$writer->writeElement('tcs:ToTaxonConcept',$row[1]);
|
198 |
|
|
$writer->endElement();
|
199 |
|
|
$writer->endElement();
|
200 |
|
|
$writer->endElement();
|
201 |
|
|
|
202 |
|
|
$i++;
|
203 |
|
|
|
204 |
|
|
if($i == 1000)
|
205 |
|
|
{
|
206 |
|
|
file_put_contents('new_Xml_CTFS_row.xml', $writer->flush(true), FILE_APPEND);
|
207 |
|
|
$i = 0;
|
208 |
|
|
}
|
209 |
|
|
|
210 |
|
|
}
|
211 |
|
|
$writer->endElement();
|
212 |
|
|
|
213 |
|
|
$i=0;
|
214 |
|
|
|
215 |
|
|
file_put_contents('new_Xml_CTFS_row.xml', $writer->flush(true), FILE_APPEND);
|
216 |
|
|
|
217 |
|
|
$sql = "select SpeciesID,Mnemonic FROM `DFtemp` WHERE plot = 'bci'";
|
218 |
|
|
|
219 |
|
|
$result = mysql_query($sql);
|
220 |
|
|
$writer->startElement('taxonNameUsageConcepts');
|
221 |
|
|
while($row = mysql_fetch_row($result))
|
222 |
|
|
{
|
223 |
|
|
$writer->startElement('taxonNameUsageConcept');
|
224 |
|
|
$writer->writeAttribute("id",$row[0]);
|
225 |
|
|
$writer->writeElement('authorName');
|
226 |
|
|
$writer->writeElement('authorCode',$row[1]);
|
227 |
|
|
$writer->endElement();
|
228 |
|
|
|
229 |
|
|
$i++;
|
230 |
|
|
|
231 |
|
|
if($i == 1000)
|
232 |
|
|
{
|
233 |
|
|
file_put_contents('new_Xml_CTFS_row.xml', $writer->flush(true), FILE_APPEND);
|
234 |
|
|
$i = 0;
|
235 |
|
|
}
|
236 |
|
|
|
237 |
|
|
}
|
238 |
|
|
$writer->endElement();
|
239 |
|
|
|
240 |
|
|
$i=0;
|
241 |
|
|
|
242 |
|
|
file_put_contents('new_Xml_CTFS_row.xml', $writer->flush(true), FILE_APPEND);
|
243 |
|
|
|
244 |
|
|
$sql = "select MeasureID,PlotID,x,y,TreeID,Tag,StemId,StemTag,DBH,HOM,ListOfTSM,status FROM `DFtemp` WHERE plot = 'bci'";
|
245 |
|
|
|
246 |
|
|
$result = mysql_query($sql);
|
247 |
|
|
$writer->startElement('individualOrganismObservations');
|
248 |
|
|
while($row = mysql_fetch_row($result))
|
249 |
|
|
{
|
250 |
|
|
$writer->startElement('individualOrganismObservation');
|
251 |
|
|
$writer->writeAttribute("id",$row[0]);
|
252 |
|
|
$writer->writeElement('plotObservationID',$row[0]);
|
253 |
|
|
$writer->writeElement('individualOrganismID',$row[4]);
|
254 |
|
|
$writer->startElement('diameterBaseDistance');
|
255 |
|
|
$writer->startElement('diameter');
|
256 |
|
|
$writer->writeElement('value',$row[8]);
|
257 |
|
|
$writer->writeElement('attributeID',"DBH");
|
258 |
|
|
$writer->endElement();
|
259 |
|
|
$writer->startElement('baseDistance');
|
260 |
|
|
$writer->writeElement('value',$row[9]);
|
261 |
|
|
$writer->writeElement('attributeID',"HOM");
|
262 |
|
|
$writer->endElement();
|
263 |
|
|
$writer->endElement();
|
264 |
|
|
|
265 |
|
|
$writer->startElement("relatedIndividual");
|
266 |
|
|
$writer->startElement("relatedItem");
|
267 |
|
|
$writer->writeElement('relatedItemID',$row[6]);
|
268 |
|
|
$writer->writeElement('itemRelationship',"Stem");
|
269 |
|
|
$writer->endElement();
|
270 |
|
|
$writer->endElement();
|
271 |
|
|
|
272 |
|
|
$writer->startElement('relativePlotPosition');
|
273 |
|
|
$writer->writeElement('relativeX',$row[2]);
|
274 |
|
|
$writer->writeElement('relativeY',$row[3]);
|
275 |
|
|
$writer->endElement();
|
276 |
|
|
|
277 |
|
|
$str = $row[10];
|
278 |
|
|
while($str != "")
|
279 |
|
|
{
|
280 |
|
|
$pos = strpos($str,',');
|
281 |
|
|
if($pos === false)
|
282 |
|
|
{
|
283 |
|
|
$TSMcode = $str;
|
284 |
|
|
$str = "";
|
285 |
|
|
}
|
286 |
|
|
else
|
287 |
|
|
{
|
288 |
|
|
$TSMcode=substr($str,0,$pos);
|
289 |
|
|
$str = substr($str,$pos+1);
|
290 |
|
|
}
|
291 |
|
|
//echo $TSMcode;
|
292 |
|
|
$sqlt = "select status from attributes where attr = '" . $TSMcode . "'";
|
293 |
|
|
//echo $sqlt;
|
294 |
|
|
$resultt = mysql_query($sqlt);
|
295 |
|
|
$rowt = mysql_fetch_row($resultt);
|
296 |
|
|
//echo $rowt[0];
|
297 |
|
|
|
298 |
|
|
$writer->startElement('simpleUserdefined');
|
299 |
|
|
$writer->writeElement('name',$rowt[0]);
|
300 |
|
|
$writer->writeElement('value',$TSMcode);
|
301 |
|
|
$writer->writeElement('methodID',$TSMcode);
|
302 |
|
|
$writer->endElement();
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
$writer->writeElement('individualOrganismHealth',$row[11]);
|
306 |
|
|
|
307 |
|
|
$writer->endElement();
|
308 |
|
|
|
309 |
|
|
$i++;
|
310 |
|
|
|
311 |
|
|
if($i == 1000)
|
312 |
|
|
{
|
313 |
|
|
file_put_contents('new_Xml_CTFS_row.xml', $writer->flush(true), FILE_APPEND);
|
314 |
|
|
$i = 0;
|
315 |
|
|
}
|
316 |
|
|
}
|
317 |
|
|
$writer->endElement();
|
318 |
|
|
file_put_contents('new_Xml_CTFS_row.xml', $writer->flush(true), FILE_APPEND);
|
319 |
|
|
|
320 |
|
|
$sql = "select SpeciesID,TreeID,Tag,StemId,StemTag FROM `DFtemp` WHERE plot = 'bci'";
|
321 |
|
|
|
322 |
|
|
$i = 0;
|
323 |
|
|
|
324 |
|
|
$result = mysql_query($sql);
|
325 |
|
|
$writer->startElement('individualOrganisms');
|
326 |
|
|
while($row = mysql_fetch_row($result))
|
327 |
|
|
{
|
328 |
|
|
$writer->startElement('individualOrganism');
|
329 |
|
|
$writer->writeAttribute("id",$row[1]);
|
330 |
|
|
$writer->writeElement('taxonNameUsageConceptID',$row[0]);
|
331 |
|
|
$writer->writeElement('identificationLabel',$row[2]);
|
332 |
|
|
$writer->endElement();
|
333 |
|
|
|
334 |
|
|
$writer->startElement('individualOrganism');
|
335 |
|
|
$writer->writeAttribute("id",$row[3]);
|
336 |
|
|
$writer->writeElement('taxonNameUsageConceptID',$row[0]);
|
337 |
|
|
$writer->writeElement('identificationLabel',$row[4]);
|
338 |
|
|
$writer->endElement();
|
339 |
|
|
$i++;
|
340 |
|
|
|
341 |
|
|
if($i == 1000)
|
342 |
|
|
{
|
343 |
|
|
file_put_contents('new_Xml_CTFS_row.xml', $writer->flush(true), FILE_APPEND);
|
344 |
|
|
$i = 0;
|
345 |
|
|
}
|
346 |
|
|
}
|
347 |
|
|
$writer->endElement();
|
348 |
|
|
file_put_contents('new_Xml_CTFS_row.xml', $writer->flush(true), FILE_APPEND);
|
349 |
|
|
|
350 |
|
|
$writer->startElement('attributes');
|
351 |
|
|
$writer->startElement('attribute');
|
352 |
|
|
$writer->writeAttribute("id","DBH");
|
353 |
|
|
$writer->startElement('quantitative');
|
354 |
|
|
$writer->writeElement('methodID');
|
355 |
|
|
$writer->writeElement('unit','m');
|
356 |
|
|
$writer->writeElement('precision','.01');
|
357 |
|
|
$writer->writeElement('upperBound',"10000");
|
358 |
|
|
$writer->writeElement('lowerBound',"0");
|
359 |
|
|
$writer->endElement();
|
360 |
|
|
$writer->endElement();
|
361 |
|
|
$writer->startElement('attribute');
|
362 |
|
|
$writer->writeAttribute("id","HOM");
|
363 |
|
|
$writer->startElement('quantitative');
|
364 |
|
|
$writer->writeElement('methodID');
|
365 |
|
|
$writer->writeElement('unit','m');
|
366 |
|
|
$writer->writeElement('precision','.01');
|
367 |
|
|
$writer->writeElement('upperBound',"10000");
|
368 |
|
|
$writer->writeElement('lowerBound',"0");
|
369 |
|
|
$writer->endElement();
|
370 |
|
|
$writer->endElement();
|
371 |
|
|
$writer->endElement();
|
372 |
|
|
|
373 |
|
|
|
374 |
|
|
|
375 |
|
|
$sql = "select attr,status from attributes";
|
376 |
|
|
$result = mysql_query($sql);
|
377 |
|
|
$writer->startElement('methods');
|
378 |
|
|
$writer->startElement('method');
|
379 |
|
|
$writer->writeAttribute("id","CensusID");
|
380 |
|
|
$writer->writeElement('description',"Census information");
|
381 |
|
|
$writer->writeElement('name',"CensusID");
|
382 |
|
|
$writer->endElement();
|
383 |
|
|
while($row = mysql_fetch_row($result))
|
384 |
|
|
{
|
385 |
|
|
$writer->startElement('method');
|
386 |
|
|
$writer->writeAttribute("id",$row[0]);
|
387 |
|
|
$writer->writeElement('description',$row[1]);
|
388 |
|
|
$writer->writeElement('name',$row[0]);
|
389 |
|
|
$writer->endElement();
|
390 |
|
|
}
|
391 |
|
|
$writer->endElement();
|
392 |
|
|
|
393 |
|
|
$writer->endElement();
|
394 |
|
|
|
395 |
|
|
$writer->endDocument();
|
396 |
|
|
|
397 |
|
|
//header('Content-type: text/xml');
|
398 |
|
|
|
399 |
|
|
//echo $writer->outputMemory();
|
400 |
|
|
|
401 |
|
|
$filename = "new_Xml_CTFS_row.xml";
|
402 |
|
|
|
403 |
|
|
//$file = $writer->outputMemory();
|
404 |
|
|
file_put_contents($filename, $writer->flush(true), FILE_APPEND);
|
405 |
|
|
//file_put_contents($filename,$file);
|
406 |
|
|
|
407 |
|
|
echo "and Veg-X file for the uploaded csv file was created";
|
408 |
|
|
echo date("m/d/y :H:i:s",time());
|
409 |
|
|
?>
|
410 |
|
|
<FORM METHOD="LINK" ACTION="new_Xml_CTFS_row.xml">
|
411 |
|
|
<br/>
|
412 |
|
|
<br/>
|
413 |
|
|
<br/>
|
414 |
|
|
<INPUT TYPE="submit" VALUE="Click to See the VegX file">
|
415 |
|
|
</FORM>
|
416 |
|
|
</body></html>
|
417 |
|
|
|
418 |
|
|
|
419 |
|
|
|
420 |
|
|
|
421 |
|
|
|
422 |
|
|
|
423 |
|
|
|
424 |
|
|
|
425 |
|
|
|
426 |
|
|
|