From 7460fe5721352e7d7284aee891cb12cd57450d3d Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 11 Oct 2014 22:25:53 +0000 Subject: getmap (11oct14) git-svn-id: svn://tug.org/texlive/trunk@35355 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/latex/getmap/README | 19 +- Master/texmf-dist/doc/latex/getmap/getmap.dtx | 320 +++++++++++++++++++++++--- Master/texmf-dist/doc/latex/getmap/getmap.pdf | Bin 1938258 -> 2272309 bytes Master/texmf-dist/doc/latex/getmap/makefile | 5 +- Master/texmf-dist/scripts/getmap/getmapdl.lua | 157 ++++++++++++- Master/texmf-dist/tex/latex/getmap/getmap.sty | 2 +- 6 files changed, 443 insertions(+), 60 deletions(-) (limited to 'Master') diff --git a/Master/texmf-dist/doc/latex/getmap/README b/Master/texmf-dist/doc/latex/getmap/README index ef8f4e64f16..44ed3cfaa67 100644 --- a/Master/texmf-dist/doc/latex/getmap/README +++ b/Master/texmf-dist/doc/latex/getmap/README @@ -8,21 +8,16 @@ use this script also from the command line. License: LPPL -Changes in v1.7: +Changes in v1.8: -- added kml2epl and kml2gps modes to getmapdl.lua +- added support for long routes by the gps2gps mode (getmapdl.lua) - Google's *new* version of 'My Maps' allows the definition of - markers, routes and arbitrary lines on different layers and - export of all of these into kml files. + Long routes might be defined by several thousands of way points. + Encoding these into a encoded polyline would hugely exceed the + URL length limit of 2048 bytes. The gps2gps mode allows you to + reduce the number of gps coordinates based on a given bound. - getmapdl -m kml2epl -K file.kml - - will parse the file and output the geographical coordinates of - defined places and the routes and lines as encoded polylines - -- added multi track support for gpx2epl and gpx2gps modes; - revised gps2epl mode +- added multi route support for gps2epl mode - updated documentation diff --git a/Master/texmf-dist/doc/latex/getmap/getmap.dtx b/Master/texmf-dist/doc/latex/getmap/getmap.dtx index 29d6404f5fd..45b7bb14a2f 100644 --- a/Master/texmf-dist/doc/latex/getmap/getmap.dtx +++ b/Master/texmf-dist/doc/latex/getmap/getmap.dtx @@ -14,21 +14,16 @@ use this script also from the command line. License: LPPL -Changes in v1.7: +Changes in v1.8: -- added kml2epl and kml2gps modes to getmapdl.lua +- added support for long routes by the gps2gps mode (getmapdl.lua) - Google's *new* version of 'My Maps' allows the definition of - markers, routes and arbitrary lines on different layers and - export of all of these into kml files. - - getmapdl -m kml2epl -K file.kml - - will parse the file and output the geographical coordinates of - defined places and the routes and lines as encoded polylines + Long routes might be defined by several thousands of way points. + Encoding these into a encoded polyline would hugely exceed the + URL length limit of 2048 bytes. The gps2gps mode allows you to + reduce the number of gps coordinates based on a given bound. -- added multi track support for gpx2epl and gpx2gps modes; - revised gps2epl mode +- added multi route support for gps2epl mode - updated documentation @@ -146,6 +141,13 @@ download getmap.dtx and makefile (Linux) or install.bat (Windows) year = {2014}, } +@misc{bib:mucberkml, + author = {Kleber, Josef}, + note = {\href{https://bitbucket.org/kleberj/getmap/downloads/MucBer.kml}{https://bitbucket.org/kleberj/getmap/downloads/MucBer.kml}}, + title = {{MucBer: München Stachus -> Berlin Brandenburger Tor}}, + year = {2014}, + } + % %<*luafile> #!/usr/bin/env texlua @@ -188,9 +190,10 @@ local PITCH = "" local LANGUAGE = "" local GPFILE = "" local KMLFILE = "" +local BOUND = 0.1 local OFILE = "getmap" local QUIET = "false" -local VERSION = "v1.4 (18/09/2014)" +local VERSION = "v1.5 (07/10/2014)" function pversion() print("getmapdl.lua " .. VERSION) @@ -280,6 +283,10 @@ getmapdl.lua [options] -K specify the kml file + gps2gps mode only: + + -B specify the bound for reducing way points (default: 0.1) + ]]) pversion() end @@ -335,6 +342,23 @@ function printepl(epltable) print(stingwithoutcontrolcharacters) end +function isnotnumber(number) + if tonumber(number) == nil then + return true + else + return false + end +end + +function dbtbound(Onum, num, bound) + local absdiff = math.abs(tonumber(Onum) - tonumber(num)) + if absdiff >= tonumber(bound) then + return true + else + return false + end +end + do local newarg = {} local i, limit = 1, #arg @@ -408,6 +432,9 @@ do elseif arg[i] == "-K" then KMLFILE = arg[i+1] i = i + 1 + elseif arg[i] == "-B" then + BOUND = arg[i+1] + i = i + 1 elseif arg[i] == "-o" then OFILE = arg[i+1] i = i + 1 @@ -518,6 +545,8 @@ if MODE == "gpx2gps" then if string.match(line, "") then @@ -527,26 +556,128 @@ if MODE == "gpx2gps" then os.exit(0) end +if MODE == "gps2gps" then + local file = GPFILE + local bound = BOUND + local incount = 0 + local outcount = 0 + local routecount = 1 + local latitude + local longitude + local Olatitude + local Olongitude + local Llatitude + local Llongitude + local ignorenextline = false + local firstroute = true + + for line in io.lines(file) + do + latitude, longitude = line:match("([^,]+),([^,]+)") + if ignorenextline == true then + line = "" + ignorenextline = false + end + -- if line contains "Point:" then gps coordinates + -- in the next line must be ignored! + if line:match("Point:") then + ignorenextline = true + end + if line:match("Route:") then + if firstroute == true then + firstroute = false + routecount = 0 + else + -- print last pair of coordinates + print(Llatitude .. "," .. Llongitude) + outcount = outcount + 1 + io.stderr:write("\nRoute " .. routecount .. ": reduced gps coordinates (Bound = " .. bound .. "): " .. incount .. " -> " .. outcount) + end + incount = 0 + outcount = 0 + routecount = routecount + 1 + print("\n" .. line .. "\n") + line = "" + end + if line == "" or isnotnumber(latitude) or isnotnumber(longitude) + then + -- empty line or no gps coordinates -> do nothing + else + latitude = round(latitude,5) + longitude = round(longitude,5) + Llatitude = latitude + Llongitude = longitude + incount = incount + 1 + if incount == 1 then + Olatitude = latitude + Olongitude = longitude + print(Olatitude .. "," .. Olongitude) + outcount = outcount + 1 + else + if dbtbound(Olatitude,latitude,bound) or dbtbound(Olongitude,longitude,bound) then + print(latitude .. "," .. longitude) + outcount = outcount + 1 + Olatitude = latitude + Olongitude = longitude + end + end + end + end + -- print last pair of coordinates + print(Llatitude .. "," .. Llongitude) + outcount = outcount + 1 + io.stderr:write("\nRoute " .. routecount .. ": reduced gps coordinates (Bound = " .. bound .. "): " .. incount .. " -> " .. outcount) + os.exit(0) +end + if MODE == "gps2epl" then local file = GPFILE local Olatitude = 0 local Olongitude = 0 local epl = {} + local firstroute = true for line in io.lines(file) do local latitude local longitude local encnum + latitude, longitude = line:match("([^,]+),([^,]+)") - latitude = round(latitude,5)*100000 - longitude = round(longitude,5)*100000 - encnum = encodeNumber(latitude - Olatitude) - table.insert(epl,encnum) - encnum = encodeNumber(longitude - Olongitude) - table.insert(epl,encnum) - Olatitude = latitude - Olongitude = longitude + if ignorenextline == true then + line = "" + ignorenextline = false + end + -- if line contains "Point:" then gps coordinates + -- in the next line must be ignored! + if line:match("Point:") then + ignorenextline = true + end + if line:match("Route:") then + if firstroute == true then + firstroute = false + else + printepl(epl) + Olatitude = 0 + Olongitude = 0 + epl = {} + end + print("\n" .. line .. "\n") + line = "" + end + if line == "" or isnotnumber(latitude) or isnotnumber(longitude) + then + -- empty line or no gps coordinates -> do nothing + else + latitude = round(latitude,5)*100000 + longitude = round(longitude,5)*100000 + encnum = encodeNumber(latitude - Olatitude) + table.insert(epl,encnum) + encnum = encodeNumber(longitude - Olongitude) + table.insert(epl,encnum) + Olatitude = latitude + Olongitude = longitude + end end printepl(epl) os.exit(0) @@ -560,13 +691,13 @@ if MODE == "kml2gps" or MODE == "kml2epl" then local Olatitude = 0 local Olongitude = 0 local epl = {} - + for line in io.lines(file) do local latitude local longitide local elevation - + -- reset for new route if string.match(line, "") then Olatitude = 0 @@ -602,11 +733,13 @@ if MODE == "kml2gps" or MODE == "kml2epl" then end for cocsv in string.gmatch(colist, "%S+") do longitude, latitude, altitude = cocsv:match("([^,]+),([^,]+),([^,]+)") + latitude = round(latitude,5) + longitude = round(longitude,5) if MODE == "kml2epl" then local encnum if cotype == "route" then - latitude = round(latitude,5)*100000 - longitude = round(longitude,5)*100000 + latitude = latitude*100000 + longitude = longitude*100000 encnum = encodeNumber(latitude - Olatitude) table.insert(epl,encnum) encnum = encodeNumber(longitude - Olongitude) @@ -867,7 +1000,11 @@ if not ofile then end print("\n\ngetmapdl.lua:") print("url = " .. IMGURL) +print("url length = " .. string.len(IMGURL) .. " bytes") print("output = " .. UOFILE) +if string.len(IMGURL) > 2048 then + getmap_error(23, "URL exceeds length limit of 2048 bytes!") +end ret, msg = http.request{ url = IMGURL, sink = ltn12.sink.file(ofile) @@ -1615,12 +1752,13 @@ path={&path=weight:5|color:orange|Bode Museum, Berlin|% % \item[osm] downloads a static map image based on OpenStreetMap data % \item[gm] downloads a static map image based on Google Maps data % \item[gsv] downloads an image based on Google Street View data -% \item[gpx2epl] parses a \texttt{gpx} file and outputs encoded polylines (\texttt{epl}) to \texttt{STDOUT} -% \item[gps2epl] parses a \texttt{gps} file and outputs \texttt{epl} -% \item[gpx2gps] parses a \texttt{gpx} file and outputs a list of geographic coordinate pairs (\texttt{gps}) % \item[kml2epl] parses a \texttt{kml} file and outputs geographical coordinates of places and -% encoded polylines for routes and lines +% encoded polylines (\texttt{epl}) for routes and lines to \texttt{STDOUT} % \item[kml2gps] parses a \texttt{kml} file and outputs geographical coordinates +% \item[gpx2epl] parses a \texttt{gpx} file and outputs encoded polylines +% \item[gpx2gps] parses a \texttt{gpx} file and outputs a list of geographic coordinate pairs (\texttt{gps}) +% \item[gps2epl] parses a \texttt{gps} file and outputs \texttt{epl} +% \item[gps2gps] parses a \texttt{gps} file and outputs -- based on a given bound -- a reduced list of \texttt{gps} coordinates % \end{description} % The first three modes are used by \cmd\getmap. You may use the script also from the command line! % \texttt{getmapdl -h} will give you a list of available commad line options. @@ -1844,25 +1982,137 @@ pathfile={berlin2.epl}]{}% % % \fi % +% \subsubsection{Long routes} +% +% Long routes are defined by a huge number of way points, but the URL length +% is limited to 2048 bytes. The following \href{https://bitbucket.org/kleberj/getmap/downloads/MucBer.kml}{example}\footnote{https://bitbucket.org/kleberj/getmap/downloads/MucBer.kml} +% (Stachus, Munich $\rightarrow$ Brandenburg Gate, Berlin) consists of more +% than 6000 way points. A created polyline would hugely exceed the URL length limit! +% +% After transfering the \texttt{kml} file into a \texttt{gps} file, you can use +% the \texttt{gps2gps} mode of \texttt{getmapdl} to reduce the number of +% way points by a given bound. It takes a new pair of \texttt{gps} coordinates +% only if the difference of latitude or longitude is larger than the given bound! +% Finally, you can use the new \texttt{gps} file to create an encoded polyline. +% +% \iffalse +%<*example> +% \fi +\begin{filecontents*}{mucber.epl} +&path=weight:5|color:orange|enc:}cydHw{qeAc|CmbCcoCq{CswDk`Be~C_oAqcDe_@wdD~eAs_Dt~AsbDn{A{aEhk@maD`i@kcDhAk}CoHcnD|Hg}CvVk{Cmx@i|Cpe@c|Cp|@kaClxDk~CzxCqnDzkAk`DftAc}CrrAonDtqBu|C~m@e~CoGc}Csd@wnD{EyjDr@s}C`@}iDoBskCn|CgbCp_D_pB~aD_cB~aDc}CgOssBr}Ci`Cj{CwzAl_Dc|Cnp@w{C~dAagDnk@o{Cnu@o{ChcCclEhdBalDni@u{CpUagFfRa}CfLq|CxQu{Cr\m{C{sBwqC}|Cm}CucDuhD}jDa}GiuD{|CkuBm~CeqCkoAwdDkyAkmDc`CkiDmaEm`Ck|CeCakBwfD}_D{gBo|CbUw}C~yAw|Cqc@{}C}`BumC_|Cqr@kvDmSk}Cu{CiaAkbDbGi_DoGw_DyLk`DxH{_Dmb@q}Cyr@{cAkaDcs@{_DarAy{C_|By_Dy~Ck`Ci}CeMm|CqiCi|CmzAmgDkUm`D_wBg}CiVu~C|aBg|Cva@i{Cc\}zBv~Cw`DyyBq_D_gB{|CoEu{ChLacDfSy|CeBk{CjsC}~Ca~@_}Cil@w|Coz@e_DidCecDivBe|Cqc@{{CemAa_DcyBq|C}|A_|CtuAsfE|dDwzDrz@e~CvXo~C|c@s{CicCirB}jDkq@q}C{dDiuBkcDsnAm}CsnAk}DuI{|CkMmvFmsEy|CmuBc~Cw{C_`Do~CqhEujHekBc|CkvCmaDufDqgC_}Csh@e|Cnq@kuDemAm}CczA{bEgg@cvDlyAiaDbUi{Cjw@i}CsLy}F}I_cDc{@gjDi_@o_Ds]{|D_c@o|Cy}A}qBubDo}CowCoyBe|Cy_Du_CotAg}C}}@obD{sCu{CkrB_jDqoFcmCsmBq_D_l@w}Caz@mdD}eBa`DmuBonE_nA_|Cw`BaaDalDqfCu_CwyDenBqwDqzA{~C}mDkgEcdAmcDsi@{`DabBq{Ccx@s{CsfDwsDueDvR_hD_WcuAu_Dsj@g~DkF{kFf_@waDcOa`DkDc|C}_DceCiu@{aDu|Ckv@m{CcpAiz@k|CmeD}eBeaEedCg`CeaDe`Cy{CwdBipEgJ_gDwOy{Fq@at@ +\end{filecontents*} +\getmap[file=mucber, mode=gm, language=de, xsize=400, ysize=600, scale=2,% + markers={&markers=size:mid|label:M|color:green|48.139030000000005,11.56556% + &markers=label:B|color:blue|52.51591,13.37732},% + pathfile={mucber.epl}]{}% +\begin{center} +\includegraphics[height=11cm]{mucber}% +\end{center} +% \iffalse +% +% \fi +% +% \iffalse +%<*example> +% \fi +\begin{lstlisting} +$ getmapdl -m kml2gps -K MucBer.kml >MucBer.gps + +$ cat MucBer.gps +Route: Route von Stachus, München nach Brandenburger Tor, Pariser + Platz, Berlin +48.13903,11.56556 +48.1392,11.56562 +[ ... many, many way points ...] +52.5159,13.37735 +52.51591,13.37732 + + +Point: Stachus, München [Karlsplatz 10, 80335 München, Deutschla +nd] +48.13903,11.56556 + + +Point: Brandenburger Tor, Pariser Platz, Berlin [Ebertstraße 21, + 10117 Berlin, Deutschland] +52.51591,13.37732 + +$ getmapdl -m gps2gps -G MucBer.gps -B 0.025 >MucBerR.gps + +Route 1: reduced gps coordinates (Bound = 0.025): 6119 -> 193 + +$ getmapdl -m gps2epl -G MucBerR.gps + +Route: Route von Stachus, München nach Brandenburger Tor, Pariser + Platz, Berlin + +}cydHw{qeAc|CmbCcoCq{CswDk`Be~C_oAqcDe_@wdD~eAs_Dt~AsbDn{A{aEhk@m +aD`i@kcDhAk}CoHcnD|Hg}CvVk{Cmx@i|Cpe@c|Cp|@kaClxDk~CzxCqnDzkAk`Df +tAc}CrrAonDtqBu|C~m@e~CoGc}Csd@wnD{EyjDr@s}C`@}iDoBskCn|CgbCp_D_p +B~aD_cB~aDc}CgOssBr}Ci`Cj{CwzAl_Dc|Cnp@w{C~dAagDnk@o{Cnu@o{ChcCcl +EhdBalDni@u{CpUagFfRa}CfLq|CxQu{Cr\m{C{sBwqC}|Cm}CucDuhD}jDa}GiuD +{|CkuBm~CeqCkoAwdDkyAkmDc`CkiDmaEm`Ck|CeCakBwfD}_D{gBo|CbUw}C~yAw +|Cqc@{}C}`BumC_|Cqr@kvDmSk}Cu{CiaAkbDbGi_DoGw_DyLk`DxH{_Dmb@q}Cyr +@{cAkaDcs@{_DarAy{C_|By_Dy~Ck`Ci}CeMm|CqiCi|CmzAmgDkUm`D_wBg}CiVu +~C|aBg|Cva@i{Cc\}zBv~Cw`DyyBq_D_gB{|CoEu{ChLacDfSy|CeBk{CjsC}~Ca~ +@_}Cil@w|Coz@e_DidCecDivBe|Cqc@{{CemAa_DcyBq|C}|A_|CtuAsfE|dDwzDr +z@e~CvXo~C|c@s{CicCirB}jDkq@q}C{dDiuBkcDsnAm}CsnAk}DuI{|CkMmvFmsE +y|CmuBc~Cw{C_`Do~CqhEujHekBc|CkvCmaDufDqgC_}Csh@e|Cnq@kuDemAm}Ccz +A{bEgg@cvDlyAiaDbUi{Cjw@i}CsLy}F}I_cDc{@gjDi_@o_Ds]{|D_c@o|Cy}A}q +BubDo}CowCoyBe|Cy_Du_CotAg}C}}@obD{sCu{CkrB_jDqoFcmCsmBq_D_l@w}Ca +z@mdD}eBa`DmuBonE_nA_|Cw`BaaDalDqfCu_CwyDenBqwDqzA{~C}mDkgEcdAmcD +si@{`DabBq{Ccx@s{CsfDwsDueDvR_hD_WcuAu_Dsj@g~DkF{kFf_@waDcOa`DkDc +|C}_DceCiu@{aDu|Ckv@m{CcpAiz@k|CmeD}eBeaEedCg`CeaDe`Cy{CwdBipEgJ_ +gDwOy{Fq@at@ +\end{lstlisting} +% \iffalse +% +% \fi +% +% Taking a look into the log file, we find: +% +% \iffalse +%<*example> +% \fi +\begin{lstlisting} +getmapdl.lua: +url = http://maps.googleapis.com/maps/api/staticmap? ... +url length = 1866 bytes +output = mucber.png +\end{lstlisting} +% \iffalse +% +% \fi +% +% With 193 way points we almost reached the URL length limit +% of 2048 bytes. The accuracy of the encoded polyline is obviously +% good enough. So, about 200 way points seem to be a good choice. But +% the length of an encoded pair of \texttt{gps} coordinates depends on the +% space between two points and may vary between 2 and 8 bytes! +% % \section{Implementation} % \changes{v1.0}{2014/05/25}{CTAN upload} % \changes{v1.2}{2014/07/11}{added support for Google Maps} % \changes{v1.2}{2014/07/11}{renamed osmimage.lua to getmapdl.lua} % \changes{v1.3}{2014/07/19}{added support for Google Street View} -% \changes{v1.4}{2014/07/25}{added options language, markers, visible, path and pathfile in gm mode} +% \changes{v1.4}{2014/07/25}{\texttt{getmapdl.lua}: added options language, markers, visible, path and pathfile in gm mode} % \changes{v1.5}{2014/08/12}{added \texttt{gpx2gps} \texttt{bash} script} % \changes{v1.6}{2014/08/16}{removed \texttt{gpx2gps} \texttt{bash} script} -% \changes{v1.6}{2014/08/16}{added \texttt{gpx2epl}, \texttt{gps2epl} and \texttt{gpx2gps} modes to \texttt{getmapdl.lua}} -% \changes{v1.7}{2014/09/18}{added \texttt{kml2gps} and \texttt{kml2epl} modes to \texttt{getmapdl.lua}} -% \changes{v1.7}{2014/09/18}{added multi track support for \texttt{gpx2gps} and \texttt{gpx2epl} mode} -% \changes{v1.7}{2014/09/18}{revised \texttt{gps2epl} mode} +% \changes{v1.6}{2014/08/16}{\texttt{getmapdl.lua}: added \texttt{gpx2epl}, \texttt{gps2epl} and \texttt{gpx2gps} modes} +% \changes{v1.7}{2014/09/18}{\texttt{getmapdl.lua}: added \texttt{kml2gps} and \texttt{kml2epl} modes} +% \changes{v1.7}{2014/09/18}{\texttt{getmapdl.lua}: added multi track support for \texttt{gpx2gps} and \texttt{gpx2epl} mode} +% \changes{v1.7}{2014/09/18}{\texttt{getmapdl.lua}: revised \texttt{gps2epl} mode} +% \changes{v1.8}{2014/10/06}{\texttt{getmapdl.lua}: added check of URL length and output to log} +% \changes{v1.8}{2014/10/07}{\texttt{getmapdl.lua}: added \texttt{gps2gps} mode to reduce way points with a given bound (default: 0.1)} +% \changes{v1.8}{2014/10/07}{\texttt{getmapdl.lua}: added multi route support for \texttt{gps2epl} mode} +% \changes{v1.8}{2014/10/07}{\texttt{getmapdl.lua}: added rounding of gps coordinates to \texttt{kml2gps} and \texttt{gpx2gps} modes} % \begin{macrocode} %<*package> % \end{macrocode} % First, we provide the \LaTeX\ package \package{getmap}. % \begin{macrocode} \NeedsTeXFormat{LaTeX2e}% -\ProvidesPackage{getmap}[2014/09/18 v1.7 getmap.sty - Josef Kleber (C) 2014]% +\ProvidesPackage{getmap}[2014/10/07 v1.8 getmap.sty - Josef Kleber (C) 2014]% % \end{macrocode} % We need a few packages! % \begin{macrocode} diff --git a/Master/texmf-dist/doc/latex/getmap/getmap.pdf b/Master/texmf-dist/doc/latex/getmap/getmap.pdf index fc1e7d94797..4f59356e9bd 100644 Binary files a/Master/texmf-dist/doc/latex/getmap/getmap.pdf and b/Master/texmf-dist/doc/latex/getmap/getmap.pdf differ diff --git a/Master/texmf-dist/doc/latex/getmap/makefile b/Master/texmf-dist/doc/latex/getmap/makefile index 322429c3e0d..f5ed1fe3e88 100644 --- a/Master/texmf-dist/doc/latex/getmap/makefile +++ b/Master/texmf-dist/doc/latex/getmap/makefile @@ -5,7 +5,7 @@ PKGNAME = getmap all: doc -doc: $(PKGNAME).pdf package +doc: package $(PKGNAME).pdf $(PKGNAME).pdf: pdflatex -shell-escape $(PKGNAME).dtx @@ -17,6 +17,9 @@ $(PKGNAME).pdf: makeindex -s gind.ist $(PKGNAME) makeindex -s gglo.ist $(PKGNAME).glo -o $(PKGNAME).gls pdflatex $(PKGNAME).dtx + makeindex -s gind.ist $(PKGNAME) + makeindex -s gglo.ist $(PKGNAME).glo -o $(PKGNAME).gls + pdflatex $(PKGNAME).dtx package: pdftex $(PKGNAME).dtx diff --git a/Master/texmf-dist/scripts/getmap/getmapdl.lua b/Master/texmf-dist/scripts/getmap/getmapdl.lua index 0ca4ac6bbb3..841574e91d7 100755 --- a/Master/texmf-dist/scripts/getmap/getmapdl.lua +++ b/Master/texmf-dist/scripts/getmap/getmapdl.lua @@ -38,9 +38,10 @@ local PITCH = "" local LANGUAGE = "" local GPFILE = "" local KMLFILE = "" +local BOUND = 0.1 local OFILE = "getmap" local QUIET = "false" -local VERSION = "v1.4 (18/09/2014)" +local VERSION = "v1.5 (07/10/2014)" function pversion() print("getmapdl.lua " .. VERSION) @@ -130,6 +131,10 @@ getmapdl.lua [options] -K specify the kml file + gps2gps mode only: + + -B specify the bound for reducing way points (default: 0.1) + ]]) pversion() end @@ -185,6 +190,23 @@ function printepl(epltable) print(stingwithoutcontrolcharacters) end +function isnotnumber(number) + if tonumber(number) == nil then + return true + else + return false + end +end + +function dbtbound(Onum, num, bound) + local absdiff = math.abs(tonumber(Onum) - tonumber(num)) + if absdiff >= tonumber(bound) then + return true + else + return false + end +end + do local newarg = {} local i, limit = 1, #arg @@ -258,6 +280,9 @@ do elseif arg[i] == "-K" then KMLFILE = arg[i+1] i = i + 1 + elseif arg[i] == "-B" then + BOUND = arg[i+1] + i = i + 1 elseif arg[i] == "-o" then OFILE = arg[i+1] i = i + 1 @@ -368,6 +393,8 @@ if MODE == "gpx2gps" then if string.match(line, "") then @@ -377,26 +404,128 @@ if MODE == "gpx2gps" then os.exit(0) end +if MODE == "gps2gps" then + local file = GPFILE + local bound = BOUND + local incount = 0 + local outcount = 0 + local routecount = 1 + local latitude + local longitude + local Olatitude + local Olongitude + local Llatitude + local Llongitude + local ignorenextline = false + local firstroute = true + + for line in io.lines(file) + do + latitude, longitude = line:match("([^,]+),([^,]+)") + if ignorenextline == true then + line = "" + ignorenextline = false + end + -- if line contains "Point:" then gps coordinates + -- in the next line must be ignored! + if line:match("Point:") then + ignorenextline = true + end + if line:match("Route:") then + if firstroute == true then + firstroute = false + routecount = 0 + else + -- print last pair of coordinates + print(Llatitude .. "," .. Llongitude) + outcount = outcount + 1 + io.stderr:write("\nRoute " .. routecount .. ": reduced gps coordinates (Bound = " .. bound .. "): " .. incount .. " -> " .. outcount) + end + incount = 0 + outcount = 0 + routecount = routecount + 1 + print("\n" .. line .. "\n") + line = "" + end + if line == "" or isnotnumber(latitude) or isnotnumber(longitude) + then + -- empty line or no gps coordinates -> do nothing + else + latitude = round(latitude,5) + longitude = round(longitude,5) + Llatitude = latitude + Llongitude = longitude + incount = incount + 1 + if incount == 1 then + Olatitude = latitude + Olongitude = longitude + print(Olatitude .. "," .. Olongitude) + outcount = outcount + 1 + else + if dbtbound(Olatitude,latitude,bound) or dbtbound(Olongitude,longitude,bound) then + print(latitude .. "," .. longitude) + outcount = outcount + 1 + Olatitude = latitude + Olongitude = longitude + end + end + end + end + -- print last pair of coordinates + print(Llatitude .. "," .. Llongitude) + outcount = outcount + 1 + io.stderr:write("\nRoute " .. routecount .. ": reduced gps coordinates (Bound = " .. bound .. "): " .. incount .. " -> " .. outcount) + os.exit(0) +end + if MODE == "gps2epl" then local file = GPFILE local Olatitude = 0 local Olongitude = 0 local epl = {} + local firstroute = true for line in io.lines(file) do local latitude local longitude local encnum + latitude, longitude = line:match("([^,]+),([^,]+)") - latitude = round(latitude,5)*100000 - longitude = round(longitude,5)*100000 - encnum = encodeNumber(latitude - Olatitude) - table.insert(epl,encnum) - encnum = encodeNumber(longitude - Olongitude) - table.insert(epl,encnum) - Olatitude = latitude - Olongitude = longitude + if ignorenextline == true then + line = "" + ignorenextline = false + end + -- if line contains "Point:" then gps coordinates + -- in the next line must be ignored! + if line:match("Point:") then + ignorenextline = true + end + if line:match("Route:") then + if firstroute == true then + firstroute = false + else + printepl(epl) + Olatitude = 0 + Olongitude = 0 + epl = {} + end + print("\n" .. line .. "\n") + line = "" + end + if line == "" or isnotnumber(latitude) or isnotnumber(longitude) + then + -- empty line or no gps coordinates -> do nothing + else + latitude = round(latitude,5)*100000 + longitude = round(longitude,5)*100000 + encnum = encodeNumber(latitude - Olatitude) + table.insert(epl,encnum) + encnum = encodeNumber(longitude - Olongitude) + table.insert(epl,encnum) + Olatitude = latitude + Olongitude = longitude + end end printepl(epl) os.exit(0) @@ -452,11 +581,13 @@ if MODE == "kml2gps" or MODE == "kml2epl" then end for cocsv in string.gmatch(colist, "%S+") do longitude, latitude, altitude = cocsv:match("([^,]+),([^,]+),([^,]+)") + latitude = round(latitude,5) + longitude = round(longitude,5) if MODE == "kml2epl" then local encnum if cotype == "route" then - latitude = round(latitude,5)*100000 - longitude = round(longitude,5)*100000 + latitude = latitude*100000 + longitude = longitude*100000 encnum = encodeNumber(latitude - Olatitude) table.insert(epl,encnum) encnum = encodeNumber(longitude - Olongitude) @@ -717,7 +848,11 @@ if not ofile then end print("\n\ngetmapdl.lua:") print("url = " .. IMGURL) +print("url length = " .. string.len(IMGURL) .. " bytes") print("output = " .. UOFILE) +if string.len(IMGURL) > 2048 then + getmap_error(23, "URL exceeds length limit of 2048 bytes!") +end ret, msg = http.request{ url = IMGURL, sink = ltn12.sink.file(ofile) diff --git a/Master/texmf-dist/tex/latex/getmap/getmap.sty b/Master/texmf-dist/tex/latex/getmap/getmap.sty index 041ffca259b..3a44b6a0e29 100644 --- a/Master/texmf-dist/tex/latex/getmap/getmap.sty +++ b/Master/texmf-dist/tex/latex/getmap/getmap.sty @@ -27,7 +27,7 @@ %% This work consists of all files listed in manifest.txt. %% \NeedsTeXFormat{LaTeX2e}% -\ProvidesPackage{getmap}[2014/09/18 v1.7 getmap.sty - Josef Kleber (C) 2014]% +\ProvidesPackage{getmap}[2014/10/07 v1.8 getmap.sty - Josef Kleber (C) 2014]% \RequirePackage{xkeyval}% \RequirePackage{stringenc}% \RequirePackage{ifthen}% -- cgit v1.2.3