(* Creating geo files *.kml for each mushroom *)
maintainKML := (
Print["Creating KML files for each mushroom ..."];
gpstolerance = 60;
kmlhead = "
";
kmlfoot = "
";
textall = Table[
name = data[[1]];
datasql = data[[3]];
pics0 = Take[#, 3]&/@ datasql;
date = {2017,3,3}; (* for testing *)
getAttributes[name];
(* {date, pics0} = csubset; *)
sdate = DateString[date, {"MonthName", " ", "DayShort", ", ", "Year"}];
pics0 = Select[pics0, (roll = #[[2]]; fn = #[[3]];
t = shootingdata["datetime", roll, fn];
Head[t] === List) &];
pics0 = Select[pics0, (roll = #[[2]]; fn = #[[3]];
geolocat = shootingdata["gps position", roll, fn];
Head[geolocat] === List &&
ToExpression[shootingdata["gps delay", roll, fn]] < 60) &];
(*Selecting GPS tracks*)
times0 = Table[
{year, roll, fn} = pic;
tz1 = shootingdata["timezone1", roll, fn];
If[! NumberQ[tz1], tz1 = 0];
t = shootingdata["datetime", roll, fn];
Round[AbsoluteTime[t]] - 3600 tz1, {pic, pics0}];
tmin = Min[times0];
tmax = Max[times0];
gpstimes0 =
Select[gpstimes, (First[#] - gpstolerance <= tmax &&
tmin <= Last[#] + gpstolerance) &];
gpstimes0 =
Select[gpstimes0,
Or @@ Table[
First[#] - gpstolerance <= t <= Last[#] + gpstolerance, {t,
times0}] &];
mgps = Length[gpstimes0];
(*
pics0 = Select[pics0, (roll = #[[2]]; fn = #[[3]];
t = shootingdata["datetime", roll, fn];
Head[t] === List)&];
(* Selecting GPS tracks *)
nmid = Round[Length[pics0]/2 + 0.1];
{year, roll, fn} = pics0[[nmid]];
tz1 = shootingdata["timezone1", roll, fn];
If[!NumberQ[tz1], tz1 = 0];
times0 = shootingdata["datetime", #[[2]], #[[3]]] & /@ pics0;
times0 = Round /@ AbsoluteTime /@ times0 - 3600 tz1;
tmin = Min[times0];
tmax = Max[times0];
gpstimes0 = Select[gpstimes, (First[#] - gpstolerance <= tmax && tmin <= Last[#] + gpstolerance) &];
gpstimes0 = Select[gpstimes0, Or @@ Table[First[#] - gpstolerance <= t <= Last[#] + gpstolerance, {t, times0}] &];
mgps = Length[gpstimes0];
pics0 = Select[pics0, (roll = #[[2]]; fn = #[[3]];
geolocat = shootingdata["gps position", roll, fn];
Head[geolocat] === List && ToExpression[shootingdata["gps delay", roll, fn]] < 60)&];
*)
mpics0 = Length[pics0];
If[mpics0 != 0,
noPrint["Creating KML: Processing mushroom ", name];
dirkmz = ToFileName[{dir0, "loc"}];
checkdir1[dirkmz];
kmz = ToFileName[dirkmz, nameLUnd <> ".kmz"];
text = {
(* Adding line styles *)
If[mgps > 0,
SeedRandom[Plus @@ ToCharacterCode[name]];
coffset = RandomReal[];
Table[
hue = coffset + (ngps - 1)/mgps;
col = hex /@ (List @@ ColorConvert[Hue[hue], "RGB"]);
col = "CC" <> col[[3]] <> col[[2]] <> col[[1]];
"\[NewLine]", {ngps, mgps}], ""],
"" <> name <> "
Alexey Sergeev
" <>
(* urlroot <> "pictures/archives/" <> year <> "/" <> roll <> "/browser.htm\" /> *)
"1
Mushroom: " <> name <> " (" <> ToString[mpics0] <> " pictures)",
Table[
{year, roll, pic} = pic3;
capt = addsymb[ncaption[caption[roll, pic]]];
geolocat = shootingdata["gps position", roll, pic];
geolocat = StringTrim /@ (ToString /@ (NumberForm[#, {9, 6}, ExponentFunction -> (Null &)] & /@ geolocat));
geolocat = StringJoin[Riffle[Reverse[geolocat], ","]];
alt = shootingdata["gps altitude", roll, pic];
If[NumberQ[alt], geolocat = geolocat <> "," <> ToString[alt]];
plname = placename[roll, pic];
If[Head[plname] === String,
plname = "
" <> plname <> "",
plname = ""];
dat = shootingdata["datetime", roll, pic];
If[Head[dat] === List,
dat = "
" <>
DateString[dat, {"Year", ":", "Month", ":", "Day", " ", "Hour", ":", "Minute", ":", "Second"}] <>
"",
dat = ""];
{w, h} = ToString /@ whresizem[picsize[roll, pic]];
date0 = shootingdata["datetime", roll, pic];
diff0 = shootingdata["gps delay", roll, pic];
diff = Round[ToExpression[diff0]];
If[diff > 2,
df = ToString[diff];
If[diff > 9, df = "" <> df <> ""];
df = "
Showing position measured " <> df <> " minutes before the shot was taken.",
df = ""];
If[diff0 === "00",
df = "
Showing position interpolated from GPS tracks."];
styleid = roll <> "x" <> pic;
"
" <> roll <> "-" <> pic <> "
(* Removing bad symbols! *)
" <> StringReplace[capt, {"&" -> ""}] <> "
#map" <> styleid <> "
" <> geolocat <> "
", {pic3, pics0}],
(* Adding tracks *)
If[mgps > 0,
(* Print["Date ", date, " - adding tracks: ", mgps]; *)
Table[
{gpsts = gpstimes0[[ngps]];
{t1, t2} = {First[gpsts], Last[gpsts]} + 3600 tz1;
tmid = Round[(t1 + t2)/2];
sdate = DateString[tmid, {"MonthName", " ", "DayShort", ", ", "Year", " - ", "DayName"}];
t1 = DateString[t1, {"Hour", ":", "Minute", ":", "Second"}];
t1a = DateString[tmid, {"Year", "-", "Month", "-", "Day"}];
t2 = DateString[t2, {"Hour", ":", "Minute", ":", "Second"}];
desc = "(" <> t1 <> "-" <> t2 <> ") " <> t1a;
(* Print[ngps, ": ", desc]; *)
"
Tracks for " <> sdate <> "
" <> desc <> "
#line" <> ToString[ngps] <> "
",
Table[
{x, y} = printf /@ gpscoordinates[gpst];
"\[NewLine]" <> y <> "," <> x, {gpst, gpsts}],
"\[NewLine]
"}, {ngps, mgps}], ""]
};
textexp = StringJoin[Riffle[Flatten[{kmlhead, text, kmlfoot}], ""]];
(*Export[kml, textexp, "Text", CharacterEncoding -> "UTF8"];*)
Export[kmz, {textexp}, {"ZIP", {{"map.kml", "Text"}}}, CharacterEncoding -> "UTF8"];
]; (* If[mpics0 != 0, *)
If[mpics0 != 0, text, ""], {data, listsort}];
textall = Select[textall, (# =!= "")&];
textallexp = StringJoin[Riffle[Flatten[{kmlhead, textall, kmlfoot}], ""]];
kmzall = ToFileName[dir0, "indexf.kmz"];
Export[kmzall, {textallexp}, {"ZIP", {{"map.kml", "Text"}}}, CharacterEncoding -> "UTF8"];
Print["Creating KML files - completed"];
);