#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include <QFile>
#include <list>
#include <QPolygonF>
#include <QJsonDocument>
QJsonObject jsonFromQba(const QByteArray & qbaMessage);
std::list<QPolygonF> lstGetPolygon(const QJsonArray & jsonArr);
void vWriteMifFile(const std::list<QPolygonF> & lstPolygon);
std::list<QPolygonF> lstPolygonFromArray(const QJsonArray & jsonArr);
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QFile fp("SouthSea.json");
if(fp.open(QIODevice::ReadOnly))
{
QJsonObject jsonObj = jsonFromQba(fp.readAll());
fp.close();
QJsonArray jsonArr = jsonObj.value("features").toArray();
std::list<QPolygonF> lstIslands = lstGetPolygon(jsonArr);
vWriteMifFile(lstIslands);
}
}
MainWindow::~MainWindow()
{
delete ui;
}
QJsonObject jsonFromQba(const QByteArray & qbaMessage)
{
//QString 转Json
QJsonDocument jsonDocumen = QJsonDocument::fromJson(qbaMessage);
QJsonObject jsonObject = jsonDocumen.object();
return jsonObject;
}
std::list<QPolygonF> lstGetPolygon(const QJsonArray & jsonArr)
{
std::list<QPolygonF> lstRet;
for(const auto & jsonVal: jsonArr)
{
QJsonValue jsonGeom = jsonVal.toObject().value("geometry");
if (jsonGeom.isObject())
{
QJsonValue jsonValCood = jsonGeom.toObject().value("coordinates");
QJsonArray jsonArrCoord = jsonValCood.toArray();
std::list<QPolygonF> lstPloygon = lstPolygonFromArray(jsonArrCoord);
lstRet.splice(lstRet.end(), lstPloygon);
}
}
return lstRet;
}
void vWriteMifFile(const std::list<QPolygonF> & lstPolygon)
{
QFile fp("SouthSea.mif");
if(fp.open(QFile::WriteOnly))
{
QString qstrRegion = QString("Region %1\n").arg(lstPolygon.size());
fp.write(qstrRegion.toLatin1());
for(const auto & polygon: lstPolygon)
{
QString qstrPoints = QString(" %1\n").arg(polygon.size());
fp.write(qstrPoints.toLatin1());
for(const auto & pnt: polygon)
{
int iLong = pnt.x() * 1000000;
int iLat = pnt.y() * 1000000;
QString qstrPnt =
QString("%1.%2 %3.%4\n").
arg(iLong/1000000).arg(iLong%1000000, 6, 10, QChar('0')).
arg(iLat / 1000000).arg(iLat % 1000000, 6, 10, QChar('0'));
fp.write(qstrPnt.toLatin1());
}
}
fp.close();
}
}
//下面的函数将geoJson的coordinates的坐标解析出来
std::list<QPolygonF> lstPolygonFromArray(const QJsonArray & jsonArr)
{
std::list<QPolygonF> lstRet;
//jsonArr是多元数组元素,每一个元素是一个PolygonF
for(const auto & jsonVal: jsonArr)
{
auto jsonPolygon = jsonVal.toArray();
if(1 == jsonPolygon.size())
{
QPolygonF plgn;
auto jsonLine = jsonPolygon.at(0).toArray();
for(const auto & jsonVertex: jsonLine)
{
auto jsonLongLat = jsonVertex.toArray();
if(jsonLongLat.size() == 2)
plgn<<QPointF(jsonLongLat.at(0).toDouble(), jsonLongLat.at(1).toDouble());
}
lstRet.push_back(plgn);
}
}
return lstRet;
}
没有合适的资源?快使用搜索试试~ 我知道了~
Qt程序,将三沙市的GeoJson格式数据转化为mif文件
共68个文件
sample:11个
tlog:9个
cpp:3个
需积分: 10 1 下载量 98 浏览量
2022-11-02
15:35:50
上传
评论
收藏 30.6MB RAR 举报
温馨提示
Qt程序,将三沙市的GeoJson格式数据转化为mif文件
资源详情
资源评论
资源推荐
收起资源包目录
SouthSea.rar (68个子文件)
SouthSea
.vs
SouthSea
v16
Browse.VC.db 17.06MB
.suo 32KB
ipch
AutoPCH
41ce31960070ac22
MAIN.ipch 66.06MB
90ce75a81e4267d2
MAINWINDOW.ipch 71.69MB
SouthSea.vcxproj 14KB
SouthSea.mif 13KB
SouthSea.json 14KB
SouthSea.vcxproj.filters 3KB
.git
index 457B
hooks
fsmonitor-watchman.sample 3KB
pre-push.sample 1KB
prepare-commit-msg.sample 1KB
applypatch-msg.sample 478B
pre-commit.sample 2KB
pre-receive.sample 544B
pre-applypatch.sample 424B
commit-msg.sample 896B
pre-rebase.sample 5KB
update.sample 4KB
post-update.sample 189B
config 130B
description 73B
refs
tags
heads
master 41B
logs
refs
heads
master 335B
HEAD 335B
objects
60
50363fa71ed2da04105077f9fef06150d05ee2 304B
a3
948a91785f23b0d16b2459b21c04ee7f0a845e 194B
2d
454221473539790591e67febbccda445f70070 1KB
5c
32b986547cfceb4ae2606287aa10a09bcc3ac4 207B
27
c8768d0a59ea07ae62a67063d2e666c7e20299 173B
info
55
3c25d76df876b854bb54eff7e51c9bbbd87106 172B
3f
57321d5dbe648c7fd642c5009b5417ece0ad4d 222B
77
fa066943d458f2d5652c2f6d41b4baadb7820c 145B
pack
9b
30b51dbbebc9e0ccfe08c080066fad452695df 1KB
b4
8f94ec827033ef073fb3c7f060837e90b935ec 141B
info
exclude 240B
COMMIT_EDITMSG 50B
HEAD 23B
SouthSea.vcxproj.user 725B
SouthSea.sln 937B
x64
Debug
vc120.pdb 1.46MB
mainwindow.obj 490KB
moc_mainwindow.obj 173KB
main.obj 179KB
SouthSea.log 2KB
SouthSea.tlog
CL.write.1.tlog 1KB
CL.read.1.tlog 74KB
custombuild.read.1.tlog 348B
SouthSea.lastbuildstate 162B
cl.command.1.tlog 4KB
link.write.1.tlog 608B
link.command.1.tlog 2KB
link.read.1.tlog 3KB
custombuild.write.1.tlog 434B
custombuild.command.1.tlog 2KB
main.cpp 183B
mainwindow.ui 654B
GeneratedFiles
Release
ui_mainwindow.h 2KB
Debug
moc_mainwindow.cpp 3KB
SouthSea.v12.suo 20KB
debug
SouthSea.ilk 1.36MB
SouthSea.exe 112KB
SouthSea.pdb 2.36MB
mainwindow.cpp 3KB
mainwindow.h 313B
SouthSea.sdf 22.75MB
三沙市.geoJson 14KB
SouthSea.pro 381B
共 68 条
- 1
金色熊族
- 粉丝: 511
- 资源: 32
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0