实现shape图层添加label

Posted ly570

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实现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);

  

 

以上是关于实现shape图层添加label的主要内容,如果未能解决你的问题,请参考以下文章

如何在arcgis中的shape图层里边导入excel表

Keras 2:在“合并”图层中使用lambda函数

ArcEngine GroupLayer监听图层改变

cesium添加shp图层实现显示或隐藏行政界线

ArcGIS server10.1如何动态添加栅格图层

Arcgis for js怎么实现柱状图?不是做在服务里面,而是我手动添加图层实现