如何计算每10公里2个点之间的所有点(纬度和经度)?
how to calculate all points (latitude and longitude) between 2 points every 10 km?
我在地图上有 2 个点(经纬度):
第 1 点:(40.437,-3.7325)
称之为 Madrid
第 2 点:(48.853,2.351074)
称之为 Paris
。
假设我在两点之间画一条线(Mardid --> Paris)我希望得到两点之间所有 lat/lon 的列表。
我正在使用 Haversine 公式计算 2 点之间的距离,但无法弄清楚如何在 point2 的方向上增加 10km?
在 Python 中寻找解决方案。
为什么要重新发明轮子?有免费的图书馆可以做到这一点:
C++ The original Charles Karney's GeographicLib
C#The C# port Flitesys.GeographicLib
您首先测量从马德里到巴黎的航班的初始航向(调用 Geodesic.Inverse(..)),然后沿该方向行驶 10 公里、20 公里、30 公里等(通过调用 Geodesic.Direct(..)).
import pyproj
madrid = (40.437,-3.7325) # lat, lon
paris = (48.853, 2.351074)
# look, we're using proper geometry, not a sphere approximtion!
g = pyproj.Geod(ellps="WGS84")
fwd_azimuth, back_azimuth, distance = g.inv(paris[1], paris[0], madrid[1], madrid[0])
# distance is 1051578.506043991
spacing = 10000 # it's in meters
npth = distance // spacing
points = g.fwd_intermediate(paris[1], paris[0], fwd_azimuth, npth, spacing)
list(points)
的结果是:
[105,
10000.0,
1060000.0,
array('d', [2.2841147476974495, 2.2173634769260593, 2.150819074399177, 2.0844804335061093, 2.018346454270266, 1.9524160433074975, 1.886688113784584, 1.8211615853779506, 1.755835384232539, 1.6907084429209114, 1.6257797004025019, 1.5610481019831033, 1.4965125992745119, 1.432172150154378, 1.3680257187263005, 1.3040722752800191, 1.2403107962518984, 1.1767402641855804, 1.113359667692788, 1.050168001414417, 0.9871642659817574, 0.9243474679779276, 0.8617166198995521, 0.7992707401185934, 0.7370088528443952, 0.6749299880859474, 0.6130331816143366, 0.5513174749254073, 0.48978191520261016, 0.4284255552800733, 0.36724745360588695, 0.30624667420553875, 0.24542228664561305, 0.18477336599765692, 0.12429899280225021, 0.06399825303331674, 0.0038702380625750266, -0.05608595537575356, -0.11587122522005133, -0.17548646411623947, -0.23493255945243385, -0.29421039339350097, -0.3533208429153225, -0.4122647798389152, -0.4710430708643054, -0.5296565776042774, -0.5881061566178034, -0.6463926594434017, -0.7045169326321932, -0.762479817780831, -0.8202821515641912, -0.8779247657678653, -0.935408487320482, -0.9927341383258104, -1.049902536094676, -1.1069144931766535, -1.163770817391641, -1.2204723118611298, -1.2770197750393688, -1.3334140007442956, -1.389655778188284, -1.4457458920087038, -1.501685122298269, -1.5574742446352121, -1.6131140301133118, -1.6686052453715994, -1.7239486526240326, -1.7791450096888881, -1.8341950700179903, -1.8890995827257604, -1.943859292618073, -1.9984749402208979, -2.0529472618088387, -2.1072769894334136, -2.161464850951148, -2.2155115700515773, -2.2694178662849596, -2.32318445508986, -2.3768120478205614, -2.4303013517742893, -2.4836530702182533, -2.5368679024164877, -2.589946543656604, -2.642889685276232, -2.695698014689428, -2.7483722154128123, -2.8009129670915507, -2.8533209455252124, -2.905596822693419, -2.957741266781308, -3.0097549422048506, -3.0616385096360426, -3.113392626027825, -3.165017944638929, -3.216515115058533, -3.267884783230732, -3.319127591478851, -3.3702441785296267, -3.421235179537185, -3.4721012261068913, -3.5228429463190163, -3.573460964752241, -3.6239559025070514, -3.674328377228901, -3.724579003131279]),
array('d', [48.77470199636237, 48.69636414316576, 48.61798666503888, 48.539569785051285, 48.46111372472616, 48.38261870405296, 48.304084941500015, 48.225512654026964, 48.14690205709707, 48.06825336468954, 47.98956678931156, 47.91084254201041, 47.83208083238533, 47.753281868599345, 47.67444585739103, 47.59557300408608, 47.51666351260883, 47.43771758549373, 47.35873542389656, 47.27971722760575, 47.20066319505346, 47.12157352332656, 47.04244840817768, 46.96328804403592, 46.88409262401768, 46.80486233993726, 46.72559738231744, 46.64629794039994, 46.566964202155795, 46.48759635429563, 46.4081945822799, 46.328759070328914, 46.24929000143294, 46.1697875573621, 46.0902519186762, 46.01068326473454, 45.931081773705536, 45.85144762257637, 45.77178098716245, 45.69208204211687, 45.612350960939736, 45.53258791598748, 45.45279307848195, 45.37296661851962, 45.29310870508056, 45.2132195060374, 45.13329918816417, 45.05334791714519, 44.97336585758367, 44.893353173010425, 44.813310025892434, 44.7332365776413, 44.65313298862177, 44.572999418159945, 44.49283602455168, 44.412642965070695, 44.33242039597678, 44.25216847252387, 44.17188734896792, 44.091577178574994, 44.01123811362902, 43.930870305439605, 43.85047390434976, 43.770049059743606, 43.68959592005384, 43.60911463276944, 43.52860534444292, 43.448068200697946, 43.3675033462365, 43.28691092484621, 43.20629107940761, 43.1256439519012, 43.04496968341459, 42.964268414149515, 42.88354028342878, 42.80278542970319, 42.72200399055841, 42.64119610272169, 42.56036190206868, 42.47950152363003, 42.39861510159805, 42.317702769333245, 42.23676465937086, 42.15580090342729, 42.07481163240646, 41.993796976406195, 41.91275706472454, 41.83169202586589, 41.75060198754728, 41.669487076704414, 41.58834741949782, 41.50718314131885, 41.42599436679559, 41.3447812197989, 41.26354382344815, 41.18228230011717, 41.10099677143994, 41.01968735831632, 40.93835418091777, 40.856997358692944, 40.77561701037325, 40.69421325397846, 40.6127862068221, 40.53133598551695, 40.44986270598043]),
None]
此过程在典型的地理软件包中称为线致密化。这个问题的一个很好的答案可以在下面的 GIS 堆栈交换中找到(在 python):
我在地图上有 2 个点(经纬度):
第 1 点:(40.437,-3.7325)
称之为 Madrid
第 2 点:(48.853,2.351074)
称之为 Paris
。
假设我在两点之间画一条线(Mardid --> Paris)我希望得到两点之间所有 lat/lon 的列表。
我正在使用 Haversine 公式计算 2 点之间的距离,但无法弄清楚如何在 point2 的方向上增加 10km?
在 Python 中寻找解决方案。
为什么要重新发明轮子?有免费的图书馆可以做到这一点:
C++ The original Charles Karney's GeographicLib
C#The C# port Flitesys.GeographicLib
您首先测量从马德里到巴黎的航班的初始航向(调用 Geodesic.Inverse(..)),然后沿该方向行驶 10 公里、20 公里、30 公里等(通过调用 Geodesic.Direct(..)).
import pyproj
madrid = (40.437,-3.7325) # lat, lon
paris = (48.853, 2.351074)
# look, we're using proper geometry, not a sphere approximtion!
g = pyproj.Geod(ellps="WGS84")
fwd_azimuth, back_azimuth, distance = g.inv(paris[1], paris[0], madrid[1], madrid[0])
# distance is 1051578.506043991
spacing = 10000 # it's in meters
npth = distance // spacing
points = g.fwd_intermediate(paris[1], paris[0], fwd_azimuth, npth, spacing)
list(points)
的结果是:
[105,
10000.0,
1060000.0,
array('d', [2.2841147476974495, 2.2173634769260593, 2.150819074399177, 2.0844804335061093, 2.018346454270266, 1.9524160433074975, 1.886688113784584, 1.8211615853779506, 1.755835384232539, 1.6907084429209114, 1.6257797004025019, 1.5610481019831033, 1.4965125992745119, 1.432172150154378, 1.3680257187263005, 1.3040722752800191, 1.2403107962518984, 1.1767402641855804, 1.113359667692788, 1.050168001414417, 0.9871642659817574, 0.9243474679779276, 0.8617166198995521, 0.7992707401185934, 0.7370088528443952, 0.6749299880859474, 0.6130331816143366, 0.5513174749254073, 0.48978191520261016, 0.4284255552800733, 0.36724745360588695, 0.30624667420553875, 0.24542228664561305, 0.18477336599765692, 0.12429899280225021, 0.06399825303331674, 0.0038702380625750266, -0.05608595537575356, -0.11587122522005133, -0.17548646411623947, -0.23493255945243385, -0.29421039339350097, -0.3533208429153225, -0.4122647798389152, -0.4710430708643054, -0.5296565776042774, -0.5881061566178034, -0.6463926594434017, -0.7045169326321932, -0.762479817780831, -0.8202821515641912, -0.8779247657678653, -0.935408487320482, -0.9927341383258104, -1.049902536094676, -1.1069144931766535, -1.163770817391641, -1.2204723118611298, -1.2770197750393688, -1.3334140007442956, -1.389655778188284, -1.4457458920087038, -1.501685122298269, -1.5574742446352121, -1.6131140301133118, -1.6686052453715994, -1.7239486526240326, -1.7791450096888881, -1.8341950700179903, -1.8890995827257604, -1.943859292618073, -1.9984749402208979, -2.0529472618088387, -2.1072769894334136, -2.161464850951148, -2.2155115700515773, -2.2694178662849596, -2.32318445508986, -2.3768120478205614, -2.4303013517742893, -2.4836530702182533, -2.5368679024164877, -2.589946543656604, -2.642889685276232, -2.695698014689428, -2.7483722154128123, -2.8009129670915507, -2.8533209455252124, -2.905596822693419, -2.957741266781308, -3.0097549422048506, -3.0616385096360426, -3.113392626027825, -3.165017944638929, -3.216515115058533, -3.267884783230732, -3.319127591478851, -3.3702441785296267, -3.421235179537185, -3.4721012261068913, -3.5228429463190163, -3.573460964752241, -3.6239559025070514, -3.674328377228901, -3.724579003131279]),
array('d', [48.77470199636237, 48.69636414316576, 48.61798666503888, 48.539569785051285, 48.46111372472616, 48.38261870405296, 48.304084941500015, 48.225512654026964, 48.14690205709707, 48.06825336468954, 47.98956678931156, 47.91084254201041, 47.83208083238533, 47.753281868599345, 47.67444585739103, 47.59557300408608, 47.51666351260883, 47.43771758549373, 47.35873542389656, 47.27971722760575, 47.20066319505346, 47.12157352332656, 47.04244840817768, 46.96328804403592, 46.88409262401768, 46.80486233993726, 46.72559738231744, 46.64629794039994, 46.566964202155795, 46.48759635429563, 46.4081945822799, 46.328759070328914, 46.24929000143294, 46.1697875573621, 46.0902519186762, 46.01068326473454, 45.931081773705536, 45.85144762257637, 45.77178098716245, 45.69208204211687, 45.612350960939736, 45.53258791598748, 45.45279307848195, 45.37296661851962, 45.29310870508056, 45.2132195060374, 45.13329918816417, 45.05334791714519, 44.97336585758367, 44.893353173010425, 44.813310025892434, 44.7332365776413, 44.65313298862177, 44.572999418159945, 44.49283602455168, 44.412642965070695, 44.33242039597678, 44.25216847252387, 44.17188734896792, 44.091577178574994, 44.01123811362902, 43.930870305439605, 43.85047390434976, 43.770049059743606, 43.68959592005384, 43.60911463276944, 43.52860534444292, 43.448068200697946, 43.3675033462365, 43.28691092484621, 43.20629107940761, 43.1256439519012, 43.04496968341459, 42.964268414149515, 42.88354028342878, 42.80278542970319, 42.72200399055841, 42.64119610272169, 42.56036190206868, 42.47950152363003, 42.39861510159805, 42.317702769333245, 42.23676465937086, 42.15580090342729, 42.07481163240646, 41.993796976406195, 41.91275706472454, 41.83169202586589, 41.75060198754728, 41.669487076704414, 41.58834741949782, 41.50718314131885, 41.42599436679559, 41.3447812197989, 41.26354382344815, 41.18228230011717, 41.10099677143994, 41.01968735831632, 40.93835418091777, 40.856997358692944, 40.77561701037325, 40.69421325397846, 40.6127862068221, 40.53133598551695, 40.44986270598043]),
None]
此过程在典型的地理软件包中称为线致密化。这个问题的一个很好的答案可以在下面的 GIS 堆栈交换中找到(在 python):