程式設計語言:C++
Qgis版本:QGIS LTR 3.4
背景:
公司安排的開發任務,需要将WGS84坐标轉換為web墨卡托坐标,需要坐标系轉換.感覺qgis應該有此轉換方法,但是不清楚方法名.百度了一下,發現沒多少qgis的資訊,現在這個問題解決了,在此mark下,也友善下後來人吧!
- 需求簡單描述
- 将點的wgs84坐标轉換為web墨卡托坐标,以供後面計算使用
- 代碼樣例
-
#define WGS84_SRID (4326) #define WEBMERCATOR_SRID (3857) void transformPointsCoord(QList<QgsPoint> curPoints,QList<double>&PointsCoordX,QList<double>& PointsCoordY) { QgsCoordinateReferenceSystem dstCrs; dstCrs.createFromSrid(WEBMERCATOR_SRID); //web mercator QgsCoordinateReferenceSystem srcCrs; srcCrs.createFromSrid(WGS84_SRID); //wgs84 QgsCoordinateTransform crsTrans = QgsCoordinateTransform(srcCrs, dstCrs); for(size_t i = 0;i < curPoints.length(); i++) { QgsPointXY tmpPt = crsTrans.transform(curPoints[i]); PointsCoordX.push_back(tmpPt.x()); PointsCoordY.push_back(tmpPt.y()); } }
-
- 轉換效果