桌面ArcGIS需要esri为Qt开发的一个SDK,链接https://developers.arcgis.com/qt/latest/
需要注意的是Qt5.12(包含)版本之后支持这个SDK,早期版本并不支持,当然Qt可以下载多个版本,在一台电脑都可以运行。
默认安装即可,SDK会自动集成在Qt中,新建Qt项目可以找到ArcGIS模板, 选择你喜欢的方式:WIdgets、C++、QML
官方给出的例子都是基于QML和C++,我用的是Widgets,使用过程发现某些功能在Widgets不行,建议用C++或QML。
可以看到我设置了几种定位方式,具体差别可以查看官网说明。
效果:
在安装位置为我们提供了例子,可以直接运行:
当你需要发布的时候从这个bin文件中把需要的文件考出来就可以运行自己的程序了。
在Qt运行程序我发现无法加载底图,不要慌,在上图的bin文件下面运行发布的程序功能一切正常。
导入shape效果(批量):
点线面分别渲染,滑动条可以设置所有图层透明度:
定位的代码:
m_mapView = new MapGraphicsView(this);
m_map = new Map(Basemap::topographic(this), this);
m_mapView->setMap(m_map);
m_mapView->setAttributionTextVisible(false);//去logo
void MyArcgis::onClick(){
m_mapView->locationDisplay()->stop();
m_mapView->locationDisplay()->setAutoPanMode(LocationDisplayAutoPanMode::Off);
}
void MyArcgis::onClick2(){
m_mapView->locationDisplay()->start();
m_mapView->locationDisplay()->setAutoPanMode(LocationDisplayAutoPanMode::Recenter);
}
void MyArcgis::onClick3(){
m_mapView->locationDisplay()->start();
m_mapView->locationDisplay()->setAutoPanMode(LocationDisplayAutoPanMode::Navigation);
}
加载shape代码:
void MyArcgis::onClick5(){
QStringList filelist = QFileDialog::getOpenFileNames(this,"Open","","*.shp;;*.*");
if(filelist.size() == 0)
return;
for(int i=0;i<filelist.size();i++)
{
ShapefileFeatureTable *mfeatureTable = new ShapefileFeatureTable(filelist[i], this);
FeatureLayer* layer = new FeatureLayer(mfeatureTable, this);
connect(layer, &FeatureLayer::doneLoading, this, [this, layer, mfeatureTable](Error loadError)
{
if (!loadError.isEmpty())
return;
GeometryType geoType = mfeatureTable->geometryType();
if (geoType == GeometryType::Point) {
// 点渲染
SimpleMarkerSymbol* pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle::Diamond, QColor("red"), 10, this);
SimpleRenderer *renderer = new SimpleRenderer(pointSymbol,this);
layer->setRenderer(renderer);
}
if (geoType == GeometryType::Polyline) {
// 线渲染
SimpleLineSymbol* sls = new SimpleLineSymbol(SimpleLineSymbolStyle::Solid, QColor("yellow"), 5, this);
SimpleRenderer *renderer = new SimpleRenderer(sls,this);
layer->setRenderer(renderer);
}
if (geoType == GeometryType::Polygon) {
// 面渲染
SimpleFillSymbol* sfs = new SimpleFillSymbol(SimpleFillSymbolStyle::Solid, QColor(0, 0, 255, 80), this);
SimpleRenderer *renderer = new SimpleRenderer(sfs,this);
layer->setRenderer(renderer);
}
if(mboolFirstLoad){
mboolFirstLoad = false;//将图层自动缩放至第一个shape所在位置
m_mapView->setViewpointCenter(layer->fullExtent().center(), 80000);
}
});
m_map->operationalLayers()->append(layer);
}
mboolFirstLoad = true;
}