Skip to content

Commit af12f00

Browse files
committed
1.0: init
0 parents  commit af12f00

File tree

9 files changed

+400
-0
lines changed

9 files changed

+400
-0
lines changed

LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <https://unlicense.org>

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# QtProj
2+
3+
coordinate transformation tool by proj4 and Qt
4+
5+
## Depends
6+
7+
* [proj](https://proj.org/)
8+
9+
## Example
10+
11+
### SRC
12+
13+
```
14+
+proj=tmerc +lat_0=0 +lon_0=39 +k=1 +x_0=134156.988 +y_0=-6032524.376 +ellps=krass +towgs84=24.83,-130.97,-81.74,0,0,-0.13,-0.22 +units=m +no_defs
15+
190473.82
16+
229747.11
17+
0
18+
```
19+
20+
### DEST
21+
22+
```
23+
+proj=longlat
24+
25+
26+
27+
```
28+
29+
### Result
30+
31+
```
32+
+proj=longlat
33+
56.11910749
34+
40.53684436
35+
0.00000000
36+
```

image/play.png

1.41 KB
Loading

qtproj.pro

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
TEMPLATE = app
2+
QT += core gui
3+
4+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
5+
6+
TARGET = qtproj
7+
8+
INCLUDEPATH = src
9+
10+
SOURCES += \
11+
src/qtproj.cpp \
12+
src/main.cpp
13+
14+
HEADERS += src/qtproj.h
15+
16+
FORMS += src/qtproj.ui
17+
18+
RESOURCES += qtproj.qrc
19+
20+
LIBS += -lproj
21+
22+
# build dir
23+
UI_DIR = build
24+
MOC_DIR = build
25+
RCC_DIR = build
26+
OBJECTS_DIR = build
27+
mytarget.commands += $${QMAKE_MKDIR} build

qtproj.qrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<RCC>
2+
<qresource prefix="">
3+
<file>image/play.png</file>
4+
</qresource>
5+
</RCC>

src/main.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <QApplication>
2+
#include "qtproj.h"
3+
4+
int main(int argc, char *argv[])
5+
{
6+
QApplication a(argc, argv);
7+
QtProj w;
8+
w.show();
9+
return a.exec();
10+
}

src/qtproj.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#define ACCEPT_USE_OF_DEPRECATED_PROJ_API_H
2+
#include <proj_api.h>
3+
#include "qtproj.h"
4+
5+
QtProj::QtProj(QWidget *parent) : QMainWindow(parent)
6+
{
7+
ui.setupUi(this);
8+
connect(ui.actionTransfer,SIGNAL(triggered()),this,SLOT(slot_transfer()));
9+
}
10+
11+
QtProj::~QtProj()
12+
{
13+
14+
}
15+
16+
void QtProj::slot_transfer()
17+
{
18+
int flag, digits = 8;
19+
double lat, lon, height;
20+
QString qsSrc, qsDst;
21+
projPJ src, dst;
22+
23+
//TODO: need check
24+
lat = ui.le_srcLat->text().toDouble();
25+
lon = ui.le_srcLon->text().toDouble();
26+
height = ui.le_srcH->text().toDouble();
27+
//e.g.
28+
//double lat=41.44;
29+
//double lon=103.33;
30+
//double height=500;
31+
32+
qsSrc = ui.le_srcCS->text();
33+
qsDst = ui.le_dstCS->text();
34+
// e.g.
35+
// QString qsSrc = "+proj=longlat +datum=WGS84 +no_defs";
36+
// QString qsDst = "+proj=tmerc +lat_0=0 +lon_0=105 +k=1 +x_0=18500000 +y_0=0 +ellps=krass +units=m +no_defs +towgs84=0,0,0,0,0,0,0";
37+
38+
src = pj_init_plus(qsSrc.toStdString().c_str());
39+
dst = pj_init_plus(qsDst.toStdString().c_str());
40+
41+
if (src == NULL || dst == NULL)
42+
{
43+
ui.le_dstLat->setText(QString("Error"));
44+
if (src == NULL)
45+
ui.le_dstLon->setText(QString("Bad Src cs"));
46+
if (dst == NULL)
47+
ui.le_dstH->setText(QString("Bad Dst cs"));
48+
return;
49+
}
50+
51+
if ((qsSrc.contains("+proj=longlat", Qt::CaseInsensitive)) || (qsSrc.contains("+proj=latlong", Qt::CaseInsensitive)))
52+
{
53+
lon *= DEG_TO_RAD;
54+
lat *= DEG_TO_RAD;
55+
}
56+
57+
flag = pj_transform(src, dst, 1, 1, &lon, &lat, &height);
58+
59+
pj_free(src);
60+
pj_free(dst);
61+
62+
if (flag == 0)
63+
{
64+
if ((qsDst.contains("+proj=longlat", Qt::CaseInsensitive)) || (qsDst.contains("+proj=latlong", Qt::CaseInsensitive)))
65+
{
66+
lon /= DEG_TO_RAD;
67+
lat /= DEG_TO_RAD;
68+
}
69+
else
70+
{
71+
digits = 3;
72+
}
73+
74+
ui.le_dstLat->setText(QString::number(lat, 'f', digits));
75+
ui.le_dstLon->setText(QString::number(lon, 'f', digits));
76+
ui.le_dstH->setText(QString::number(height, 'f', digits));
77+
}
78+
else
79+
{
80+
ui.le_dstLat->setText(QString("Error"));
81+
ui.le_dstLon->setText(QString::number(flag, 'd', 2));
82+
ui.le_dstH->setText(QString("Error"));
83+
}
84+
}

src/qtproj.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef QTPROJ_H
2+
#define QTPROJ_H
3+
4+
#include <QMainWindow>
5+
#include "ui_qtproj.h"
6+
7+
class QtProj : public QMainWindow
8+
{
9+
Q_OBJECT
10+
11+
public:
12+
QtProj(QWidget *parent = 0);
13+
~QtProj();
14+
15+
private:
16+
Ui::QtProjClass ui;
17+
18+
private slots:
19+
void slot_transfer();
20+
};
21+
22+
#endif // QTPROJ_H

0 commit comments

Comments
 (0)