qt定位、导入shape

桌面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;
}

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值