2

VBS2用のプラグインを作成しています。プログラムでは、LAT LONG、UTM、または MGRS のいずれかでグリッドを出力できます。BNGに変換できる必要があります。Proj.4 を使用して動作する TKinter アプリケーションを Python で作成できましたが、C++ で DLL として作成する必要があります。

(51.20650N 1.81906W) を使用する LatLong im は既知のポイントであり、BNG 変換は約 SU 127 452 です。

#include <proj_api.h>




double x = 51.20650; //atof(GetStrArgument(input, 0)); 
double y = 1.81906;  //atof(GetStrArgument(input, 1));  

char *pj_latlongc = "+proj=longlat +datum=WGS84";
char *pj_UTMc = "+proj=utm +zone=29 +ellps=WGS84";
char *osc = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs";

projPJ pj_OS = pj_init_plus(osc);
projPJ pj_UTM = pj_init_plus(pj_UTMc);
projPJ pj_latlong = pj_init_plus(pj_latlongc);

x *= DEG_TO_RAD;
y *= DEG_TO_RAD;

int p = pj_transform(pj_latlong, pj_OS, 1, 1, &x, &y, NULL);

残念ながら、結果は完全に間違っており、意味がありません.誰かがこれについて助けてくれますか?

4

1 に答える 1

2

x を y に切り替え、x の符号を反転すると、より良い結果が得られるようです。コンソールでこれらの数値を実行すると、出力は指定したポイント (51.20650N 1.81906W)projによりよく一致するようです。

echo -1.81906 51.20650 | proj -V +proj=tmerc
Longitude: 1d49'8.616"W [ -1.81906 ]
Latitude:  51d12'23.4"N [ 51.2065 ]

同様に、cs2cs一見理にかなった出力を返します。

echo -1.81906 51.20650 | cs2cs -v +proj=longlat +datum=WGS84   +to   +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs
# ---- From Coordinate System ----
#Lat/long (Geodetic alias)
#
# +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
# ---- To Coordinate System ----
#Transverse Mercator
# Cyl, Sph&Ell
# +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000
# +ellps=airy +datum=OSGB36 +units=m +no_defs
# +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894
#--- following specified but NOT used
# +ellps=airy
412736.92  145270.05 -47.95

これは、C++ プログラムの出力と同じです。

double x = -1.81906;
double y = 51.20650;
412736.924409  145270.054358

比較のために、British Geological Survey の BNG コンバーターで数値を実行しましたが、これも一致しているようです。

Easting: 412737
Northing: 145270

これらの数値をOrdnance Survey National Gridリファレンスの形式で記述するには、100km の整数倍を差し引くだけで、このJavaScript 用ソース コード に示されている対応する文字が得られます。最終結果はSU 127 452、必要に応じて次のようになります。

#include <proj_api.h>
#include <iostream>

int main() {
  double x = -1.81906;
  double y = 51.20650;

  const char* pj_latlongc = "+proj=longlat +datum=WGS84";
  const char* osc = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs";

  projPJ pj_latlong = pj_init_plus(pj_latlongc);
  projPJ pj_OS = pj_init_plus(osc);

  x *= DEG_TO_RAD;
  y *= DEG_TO_RAD;

  int p = pj_transform(pj_latlong, pj_OS, 1, 1, &x, &y, NULL);

  std::cout.setf(std::ios::fixed, std::ios::floatfield);
  std::cout.setf(std::ios::showpoint);
  std::cout << x << "  " << y << std::endl;;
  // prints 412736.924409  145270.054358


  // now convert to UK Grid Ref
  int e1 = floor(x/100000);
  int n1 = floor(y/100000);
  int e2 = (int)x % 100000 / 100;
  int n2 = (int)y % 100000 / 100;
  char l1 = (19 - n1) - (19-n1) % 5 + ((e1 + 10)/5);
  char l2 = (19 - n1) * 5 % 25 + e1 % 5;
  if (l1 > 7) l1++;
  if (l2 > 7) l2++;
  l1 = 'A' + l1;
  l2 = 'A' + l2;

  std::cout << l1 << l2 << ' ' << e2 << ' ' << n2 << std::endl;
  // prints SU 127 452
}
于 2015-07-19T15:42:18.913 に答える