• 实现shape图层添加label


    void CmapwingisTest2View::OnToolsAdd32780()

    {

             TCHAR szFilters[]= _T("SHP Files (*.shp)|*.shp||");  

             CFileDialog fileDlg (TRUE,_T("shp"),_T("*.shp"),  

                       OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);  

             if( fileDlg.DoModal ()!=IDOK )   return;

             CString m_strFilePath = fileDlg.GetPathName();  

             if (_T("")!=m_strFilePath)  

             {  

                       // 先删除所有图层  

                       //m_map.RemoveAllLayers();  

                       // 获取后缀名判断文件是tif图像还是shp文件  

                       CString strExt = m_strFilePath.Right(3);  

                        

                       if (_T("shp")==strExt)  

                       {  

                                mapWindow::IShapefilePtr pshapefilebound;

                                pshapefilebound.CreateInstance(__uuidof(mapWindow::Shapefile));

                                pshapefilebound->Open(_bstr_t(m_strFilePath),false );

                                m_map.AddLayer( pshapefilebound,TRUE) ;

                                mapWindow::ILabelsPtr labels=pshapefilebound->GetLabels( );//?

                                labels->PutFontSize(12);

                                labels->PutFontBold(true);

                                labels->PutFontOutlineVisible(true);

                                labels->PutFontOutlineWidth(4);

                                mapWindow::ILabelCategoryPtr cat;

                                labels->AddCategory("Red");

                                long fieldIndex = 1;//默认首个列

                                CString str;

                                IFieldPtr Fields;

                                //pshapefilebound->GetField(0);

                                _variant_t var;

                                for (long i = 0; i < pshapefilebound->GetNumShapes() ; i++)

                                {

                                         IShapePtr shp =  pshapefilebound->GetShape(i);

                                         IPointPtr pt= shp->GetCenter(   );

                                         var = pshapefilebound->GetCellValue(fieldIndex, i);

                                         str = var.bstrVal; //需要判断本列是否为文本,待解决

                                         labels->AddLabel( _bstr_t(str ),pt->Getx(),pt->Gety(),0,laCenter);

                                }

                                labels->put_Synchronized(true);

      

  • 相关阅读:
    Centos下使用Docker部署MySql
    用C#编写游戏脚本
    VS2013使用自带的数据库 Microsoft SQL Server 2012 Express LocalDB
    WIN11下访问Gitee(WIN11下GITEE 拉取PULL和推送PUSH失败的解决办法)
    前端MVC Vue2学习总结(二)——Vue的实例、生命周期与Vue脚手架(vue-cli)
    前端MVC Vue2学习总结(一)——MVC与vue2概要、模板、数据绑定与综合示例
    JavaScript学习总结(五)——jQuery插件开发与发布
    JavaScript学习总结(四)——this、原型链、javascript面向对象
    JavaScript学习总结(三)——闭包、IIFE、apply、函数与对象
    JavaScript学习总结(二)——延迟对象、跨域、模板引擎、弹出层、AJAX示例
  • 原文地址:https://www.cnblogs.com/ly570/p/11491437.html
Copyright © 2020-2023  润新知