我想用 TikZ 繪製一張地圖,作為初學者,這張地圖應該在蘭伯特等角圓錐投影。不過為了方便起見,我想包括一些測地線計算,讓使用者可以輕鬆透明地了解他在做什麼,而無需使用外部工具進行轉換和計算。我過去曾這樣做過,效果很好,但我想將其提升到一個新的水平並尋求您的意見。
註釋中帶有解釋的可能輸入代碼可能如下所示:
\begin{tikz}
\begin{projection}[type=Lambert conformal conic,stdlat1=2,stdlat2=-2,lon0=0,k=1]
\coordinate(point1) at (1.0,0.5); %1 degree North, 0.5 degree East
\coordinate(point2) at (-1.0,-0.5); %1 degree South, 0.5 degree West
\draw (point1) -- ++ (relative cs:100m,50m); %draw line from point1 to a coordinate 100 meters (in reality) to the east and 50 meters (in reality) to the north relative of point1
\draw (point1) -- (point2); %draw line from point1 to point2 (can be straight, does not have to be a geodesic)
\draw ($(point2) + (relative cs: 45:2nm)$) -- (point1); %draw a line from a point on a 45 degree bearing with a distance of 2 nautical miles from point1 to point2
\draw (point1) arc (relative cs: 60:90:3nm); %draw a circle segment from point1 with starting heading of 060 and end heading of 090 with a 3 nautical mile radius
\end{projection}
\end{tikz}
輸入參數的命名法取自測地線庫。
任何想法,甚至起點都受到高度讚賞,因為我什至找不到與此接近的東西。歡迎使用 LuaTeX 或類似的可能實作!
答案1
感謝@Schrödinger's cat 在評論中提供的寶貴意見。透過應用它們,我能夠想出一個滿足我需求的基本結構。您可以看到我如何將其應用到一個工作範例中,該範例繪製了美國的 4 個城市、亞利桑那州和一個網格: 其程式碼(沒有亞利桑那州的邊界,因為這會使文件變得很大),如下所示:
\documentclass{article}
\usepackage[a4paper, landscape, margin=0cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
Arizona in Lambert Conical projection and the airports PHX, AUS, DTW and JFK
\directlua{lambert = require("lambert")}
\newcommand\addLUADEDplot[8]{%
\directlua{lambert.LambertConicalForward(#1,#2,#3,#4,#5,#6,#7,#8)}%
}
\newenvironment{ellipsoid}[1][a=6378137,f=0.0033528106647475]{
\setkeys{ellipsoid}{#1}}
\newenvironment{lambertconical}[1][stdlat1=33,stdlat2=45,lon0=-112,k=1]{\setkeys{lambertconicalkeys}{#1}}
\makeatletter
\define@key{latlonkeys}{lat}{\def\mylat{#1}}
\define@key{latlonkeys}{lon}{\def\mylon{#1}}
\define@key{ellipsoid}{a}{\def\ellipsoidA{#1}}
\define@key{ellipsoid}{f}{\def\ellipsoidF{#1}}
\define@key{lambertconicalkeys}{stdlat1}{\def\lambertconicalStdLatONE{#1}}
\define@key{lambertconicalkeys}{stdlat2}{\def\lambertconicalStdLatTWO{#1}}
\define@key{lambertconicalkeys}{lon0}{\def\lambertconicalLonZERO{#1}}
\define@key{lambertconicalkeys}{k}{\def\lambertconicalK{#1}}
\makeatother
\tikzdeclarecoordinatesystem{latlon}%
{%
\setkeys{latlonkeys}{#1}%
\addLUADEDplot{\ellipsoidA}{\ellipsoidF}{\lambertconicalStdLatONE}{\lambertconicalStdLatTWO}{\lambertconicalK}{\lambertconicalLonZERO}{\mylat}{\mylon}%
}
\begin{tikzpicture}[scale=0.45]
\begin{ellipsoid}[a=6378137,f=0.0033528106647475]
\begin{lambertconical}[stdlat1=33,stdlat2=45,lon0=-112,k=0.00001]
%\draw [->] (0,0,0) -- (0,0,350);
\node at (latlon cs:lat=33.434167,lon=-112.011667){PHX};
\node at (latlon cs:lat=30.194444,lon=-97.67){AUS};
\node at (latlon cs:lat=42.2125,lon=-83.353333){DTW};
\node at (latlon cs:lat=40.639722,lon=-73.778889){JFK};
\foreach \lon in {-124,-123, ..., -66}
{
\foreach \lat in {25,26, ..., 49}
{
\draw (latlon cs:lat=\lat,lon=\lon) -- (latlon cs:lat=\lat,lon={\lon+1});
\draw (latlon cs:lat=\lat,lon=\lon) -- (latlon cs:lat={\lat+1},lon=\lon);
}
}
\end{lambertconical}
\end{ellipsoid}
\end{tikzpicture}
\end{document}
蘭伯特等角圓錐曲線的 Lua 實現(僅對於球體,會出現複雜情況),如下所示:
local function print_LambertConformalConicForward(a,f,stdlat1,stdlat2,k1,lon0,lat,lon)
lat0 = 40;
n = math.log(math.cos(math.rad(stdlat1))/math.cos(math.rad(stdlat2))) / math.log( math.tan((math.pi/4)+math.rad(stdlat2/2)) / math.tan((math.pi/4)+math.rad(stdlat1/2)))
F = (math.cos(math.rad(stdlat1)) * math.pow(math.tan((math.pi/4)+math.rad(stdlat1/2)), n)) / n
rho = (a * F) / math.pow(math.tan((math.pi/4)+(math.rad(lat)/2)), n)
rho_0 = (a * F) / math.pow(math.tan((math.pi/4)+(math.rad(lat0)/2)), n)
theta = n * (math.rad(lon-lon0))
x = (rho * math.sin(theta)) * k1
y = (rho_0 - (rho * math.cos(theta))) * k1
tex.sprint("\\pgfpointxyz{"..x.."}{"..y.."}{0}%")
end
return { LambertConicalForward = print_LambertConformalConicForward }
2021 年 12 月 10 日編輯:我正在製作另一張地圖,看來我並不是唯一一個尋找使用 TikZ 繪製地圖的人。現在有一個基於地圖圖塊的用於此目的的包,但它也可以在沒有基本地圖的情況下使用:mercatormap
可以在以下位置找到https://ctan.org/pkg/mercatormap