|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
#include "GISManager.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GISManager* GISManager::m_gisMananger = NULL;
|
|
|
|
|
int GISManager::m_iCounter = 0;
|
|
|
|
|
|
|
|
|
|
GISManager::GISManager()
|
|
|
|
|
{
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GISManager::~GISManager()
|
|
|
|
|
{
|
|
|
|
|
//DestroyObject();
|
|
|
|
|
m_gisMananger = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GISManager* GISManager::getInstance()
|
|
|
|
|
{
|
|
|
|
|
if(m_gisMananger == NULL)
|
|
|
|
|
{
|
|
|
|
|
m_gisMananger = new GISManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_iCounter++;
|
|
|
|
|
|
|
|
|
|
return m_gisMananger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::DestroyObject()
|
|
|
|
|
{
|
|
|
|
|
m_iCounter--;
|
|
|
|
|
if((m_iCounter ==0)&&(m_gisMananger!=NULL)) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>㣬<EFBFBD>Ҿ<EFBFBD>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>ʱ
|
|
|
|
|
{
|
|
|
|
|
delete m_gisMananger;
|
|
|
|
|
//m_gisMananger = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::init()
|
|
|
|
|
{
|
|
|
|
|
m_map = NULL;
|
|
|
|
|
m_bHaveAddMap = false;
|
|
|
|
|
m_pMapCwnd = NULL;
|
|
|
|
|
m_etcFenceManager = NULL;
|
|
|
|
|
m_editAttributes = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::setMap(CMap1* pMap)
|
|
|
|
|
{
|
|
|
|
|
if(pMap !=NULL)
|
|
|
|
|
m_map = pMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::Openlocalfile(CString file)
|
|
|
|
|
{
|
|
|
|
|
if(!m_map->GetSafeHwnd())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int error=0;
|
|
|
|
|
CString filetype=GetFileType(file);
|
|
|
|
|
CString filename=GetFileName(file);
|
|
|
|
|
filetype.MakeLower();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(filetype.Compare(_T("shp"))==0)
|
|
|
|
|
{
|
|
|
|
|
mapWindow::IShapefilePtr shape;
|
|
|
|
|
shape.CreateInstance("MapWinGIS.Shapefile");
|
|
|
|
|
if( !shape->Open((_bstr_t)file,NULL))
|
|
|
|
|
{
|
|
|
|
|
error=1;
|
|
|
|
|
}
|
|
|
|
|
_bstr_t pro=shape->GetProjection();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>õ<EFBFBD>ͼ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ɫΪ<C9AB><CEAA>ɫ
|
|
|
|
|
m_map->SetBackColor(RGB(255,255,255));
|
|
|
|
|
|
|
|
|
|
int shpLayerPose = m_map->AddLayer(shape,true);
|
|
|
|
|
|
|
|
|
|
//<2F>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
m_map->MoveLayerBottom(shpLayerPose);
|
|
|
|
|
|
|
|
|
|
//m_LayerManager.AddLayerInfo(filename,1);
|
|
|
|
|
|
|
|
|
|
//<2F>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>ͼ
|
|
|
|
|
m_bHaveAddMap = true;
|
|
|
|
|
}
|
|
|
|
|
else if(filetype.Compare(_T("img"))==0)
|
|
|
|
|
{
|
|
|
|
|
mapWindow::IImagePtr image;
|
|
|
|
|
image.CreateInstance("MapWinGIS.Image");
|
|
|
|
|
if( !image->Open((_bstr_t)file,mapWindow::IMG_FILE,true,NULL))
|
|
|
|
|
{
|
|
|
|
|
error=1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>õ<EFBFBD>ͼ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ɫΪ<C9AB>Ұ<EFBFBD>ɫ
|
|
|
|
|
m_map->SetBackColor(RGB(255,255,255));
|
|
|
|
|
|
|
|
|
|
m_map->AddLayer(image,true);
|
|
|
|
|
//m_LayerManager.AddLayerInfo(filename,2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>ͼ
|
|
|
|
|
m_bHaveAddMap = true;
|
|
|
|
|
}
|
|
|
|
|
else if(filetype.Compare(_T("tif"))==0)
|
|
|
|
|
{
|
|
|
|
|
mapWindow::IImagePtr image;
|
|
|
|
|
image.CreateInstance("MapWinGIS.Image");
|
|
|
|
|
if( !image->Open((_bstr_t)file,mapWindow::TIFF_FILE,true,NULL))
|
|
|
|
|
{
|
|
|
|
|
error=1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>õ<EFBFBD>ͼ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ɫΪ<C9AB>Ұ<EFBFBD>ɫ
|
|
|
|
|
m_map->SetBackColor(RGB(255,255,255));
|
|
|
|
|
|
|
|
|
|
int tiffLayerID = m_map->AddLayer(image,true);
|
|
|
|
|
|
|
|
|
|
//m_LayerManager.AddLayerInfo(filename,2);
|
|
|
|
|
|
|
|
|
|
//<2F>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>ͼ
|
|
|
|
|
m_bHaveAddMap = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if(filetype.Compare(_T("asc"))==0)
|
|
|
|
|
{
|
|
|
|
|
mapWindow::IImagePtr image;
|
|
|
|
|
image.CreateInstance("MapWinGIS.Image");
|
|
|
|
|
if( !image->Open((_bstr_t)file,mapWindow::ASC_FILE,true,NULL))
|
|
|
|
|
{
|
|
|
|
|
error=1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>õ<EFBFBD>ͼ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ɫΪ<C9AB>Ұ<EFBFBD>ɫ
|
|
|
|
|
m_map->SetBackColor(RGB(255,255,255));
|
|
|
|
|
|
|
|
|
|
m_map->AddLayer(image,true);
|
|
|
|
|
//m_LayerManager.AddLayerInfo(filename,2);
|
|
|
|
|
|
|
|
|
|
//<2F>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>ͼ
|
|
|
|
|
m_bHaveAddMap = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(error==1)
|
|
|
|
|
{
|
|
|
|
|
CString msg = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + file;
|
|
|
|
|
AfxMessageBox(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CString GISManager::GetFileType(CString file)
|
|
|
|
|
{
|
|
|
|
|
CString type;
|
|
|
|
|
long len=file.GetLength();
|
|
|
|
|
int pos=file.ReverseFind('.');
|
|
|
|
|
type=file.Right(len-pos-1);
|
|
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CString GISManager::GetFileName(CString file)
|
|
|
|
|
{
|
|
|
|
|
CString name;
|
|
|
|
|
long len=file.GetLength();
|
|
|
|
|
int pos=file.ReverseFind('\\');
|
|
|
|
|
name=file.Right(len-pos-1);
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::Redraw()
|
|
|
|
|
{
|
|
|
|
|
if(m_map->GetSafeHwnd())
|
|
|
|
|
{
|
|
|
|
|
m_map->Redraw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::RemoveAllLayers()
|
|
|
|
|
{
|
|
|
|
|
if(m_map->GetSafeHwnd())
|
|
|
|
|
{
|
|
|
|
|
m_map->RemoveAllLayers();
|
|
|
|
|
m_map->Redraw();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>õ<EFBFBD>ͼ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>ɫΪ<C9AB><CEAA>ɫ
|
|
|
|
|
m_map->SetBackColor(RGB(0,0,0));
|
|
|
|
|
|
|
|
|
|
//<2F>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>ͼ
|
|
|
|
|
m_bHaveAddMap = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
brief<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ijһͼ<EFBFBD><EFBFBD>
|
|
|
|
|
param: shapeIDͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
return<EFBFBD><EFBFBD>void
|
|
|
|
|
*/
|
|
|
|
|
void GISManager::EraseShape(long& shapeID)
|
|
|
|
|
{
|
|
|
|
|
if(shapeID != -1)
|
|
|
|
|
{
|
|
|
|
|
if(m_map->GetSafeHwnd())
|
|
|
|
|
{
|
|
|
|
|
m_map->RemoveLayer(shapeID);
|
|
|
|
|
shapeID = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::CreateEmptyPointShapefile(long &shpLayerID,mapWindow::tkDefaultPointSymbol ptStyle /*= mapWindow::tkPointType::ptSquare*/,
|
|
|
|
|
const unsigned long drawColor /*= RGB(255,0,0)*/, int ptSize /*= 20*/)
|
|
|
|
|
{
|
|
|
|
|
if(!m_map->GetSafeHwnd())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SHPͼ<50><CDBC>
|
|
|
|
|
mapWindow::IShapefilePtr targetPtShape;
|
|
|
|
|
targetPtShape.CreateInstance("MapWinGIS.Shapefile");
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>յĵ<D5B5>ͼ<EFBFBD><CDBC>
|
|
|
|
|
targetPtShape->CreateNewWithShapeID(_T(""), mapWindow::SHP_POINT);
|
|
|
|
|
|
|
|
|
|
//Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
|
|
|
|
shpLayerID = m_map->AddLayer(targetPtShape, true);
|
|
|
|
|
|
|
|
|
|
mapWindow::IShapeDrawingOptionsPtr pShapeDrawingOption;
|
|
|
|
|
pShapeDrawingOption.CreateInstance("MapWinGIS.ShapeDrawingOptions");
|
|
|
|
|
|
|
|
|
|
pShapeDrawingOption->FillColor = drawColor;
|
|
|
|
|
pShapeDrawingOption->PointSize = ptSize;
|
|
|
|
|
pShapeDrawingOption->SetDefaultPointSymbol(ptStyle);
|
|
|
|
|
//pShapeDrawingOption->PointType = ptStyle;
|
|
|
|
|
//pShapeDrawingOption->PointSidesCount = 4;
|
|
|
|
|
|
|
|
|
|
(m_map->GetShapefile(shpLayerID)).SetDefaultDrawingOptions(pShapeDrawingOption);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::CreateEmptyAreaShapfile(long& layerHandle, const unsigned long drawColor, const unsigned long& fillColor /* = RGB */,
|
|
|
|
|
const float& fillTransparency /*= 60.0*/)
|
|
|
|
|
{
|
|
|
|
|
if(!m_map->GetSafeHwnd())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SHPͼ<50><CDBC>
|
|
|
|
|
mapWindow::IShapefilePtr targetPtShape;
|
|
|
|
|
targetPtShape.CreateInstance("MapWinGIS.Shapefile");
|
|
|
|
|
|
|
|
|
|
targetPtShape->CreateNewWithShapeID(_T(""), mapWindow::SHP_POLYGON);
|
|
|
|
|
|
|
|
|
|
//Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
|
|
|
|
layerHandle = m_map->AddLayer(targetPtShape, TRUE);
|
|
|
|
|
|
|
|
|
|
mapWindow::IShapeDrawingOptionsPtr pShapeDrawingOption;
|
|
|
|
|
pShapeDrawingOption.CreateInstance("MapWinGIS.ShapeDrawingOptions");
|
|
|
|
|
|
|
|
|
|
pShapeDrawingOption->FillColor = fillColor;
|
|
|
|
|
pShapeDrawingOption->FillTransparency = fillTransparency;
|
|
|
|
|
pShapeDrawingOption->FillHatchStyle = mapWindow::tkGDIPlusHatchStyle::hsCross;
|
|
|
|
|
pShapeDrawingOption->LineColor = drawColor;
|
|
|
|
|
//pShapeDrawingOption->LineStipple = mapWindow::tkLineStipple::lsDotted;
|
|
|
|
|
//pShapeDrawingOption->LineWidth = 2;
|
|
|
|
|
|
|
|
|
|
(m_map->GetShapefile(layerHandle)).SetDefaultDrawingOptions(pShapeDrawingOption);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::CreateEmptyLineShapfile(long &shpLayerID, const unsigned long lineColor, float lineWidth /* = 1 */,
|
|
|
|
|
mapWindow::tkDashStyle lineStyle /*= mapWindow::tkLineStipple::lsNone*/)
|
|
|
|
|
{
|
|
|
|
|
if(!m_map->GetSafeHwnd())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SHPͼ<50><CDBC>
|
|
|
|
|
mapWindow::IShapefilePtr targetPtShape;
|
|
|
|
|
targetPtShape.CreateInstance("MapWinGIS.Shapefile");
|
|
|
|
|
|
|
|
|
|
targetPtShape->CreateNewWithShapeID(_T(""), mapWindow::ShpfileType::SHP_POLYLINE);
|
|
|
|
|
|
|
|
|
|
//Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
|
|
|
|
shpLayerID = m_map->AddLayer(targetPtShape, true);
|
|
|
|
|
|
|
|
|
|
mapWindow::IShapeDrawingOptionsPtr pShapeDrawingOption;
|
|
|
|
|
pShapeDrawingOption.CreateInstance("MapWinGIS.ShapeDrawingOptions");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pShapeDrawingOption->LineColor = lineColor;
|
|
|
|
|
pShapeDrawingOption->LineWidth = lineWidth;
|
|
|
|
|
pShapeDrawingOption->LineStipple = lineStyle;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(m_map->GetShapefile(shpLayerID)).SetDefaultDrawingOptions(pShapeDrawingOption);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>shpfileͼ<65><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD>룺ʸ<EBA3BA><CAB8>ͼ<EFBFBD><CDBC>ID<49><44>shpLayerID<49><44>shp<68><70><EFBFBD><EFBFBD>shpType
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD>ȡ<EFBFBD>lon; γ<>ȡ<EFBFBD>lat
|
|
|
|
|
void GISManager::AddOnePoint2Shapfile(const long shpLayerID, const int shpType, const double lon, const double lat)
|
|
|
|
|
{
|
|
|
|
|
if(!m_map->GetSafeHwnd())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mapWindow::IPointPtr pintPtr;
|
|
|
|
|
pintPtr.CreateInstance("MapWinGIS.Point");
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
pintPtr->x = lon;
|
|
|
|
|
|
|
|
|
|
//γ<><CEB3>
|
|
|
|
|
pintPtr->y = lat;
|
|
|
|
|
|
|
|
|
|
//shpfile<6C>ļ<EFBFBD><C4BC>е<EFBFBD>shpͼ<70><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
long shpNum = (m_map->GetShapefile(shpLayerID)).GetNumShapes();
|
|
|
|
|
|
|
|
|
|
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ڸ<EFBFBD>shpͼ<70>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>shpͼ<70><CDBC>
|
|
|
|
|
if (shpNum == 0)
|
|
|
|
|
{
|
|
|
|
|
mapWindow::IShapePtr shapePtr;
|
|
|
|
|
shapePtr.CreateInstance("MapWinGIS.Shape");
|
|
|
|
|
|
|
|
|
|
if (shpType == 0) //<2F><>ͼ<EFBFBD><CDBC>
|
|
|
|
|
{
|
|
|
|
|
shapePtr->Create(mapWindow::SHP_POINT);
|
|
|
|
|
}
|
|
|
|
|
else if (shpType == 1) //<2F><>ͼ<EFBFBD><CDBC>
|
|
|
|
|
{
|
|
|
|
|
shapePtr->Create(mapWindow::SHP_POLYLINE);
|
|
|
|
|
}
|
|
|
|
|
else if (shpType == 2) //<2F><>ͼ<EFBFBD><CDBC>
|
|
|
|
|
{
|
|
|
|
|
shapePtr->Create(mapWindow::SHP_POLYGON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ǰshp<68>в<EFBFBD><D0B2><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
shapePtr->InsertPoint(pintPtr, &shpNum);
|
|
|
|
|
|
|
|
|
|
//<2F><>shpfile<6C>ļ<EFBFBD><C4BC>в<EFBFBD><D0B2><EFBFBD>shp<68>ļ<EFBFBD>
|
|
|
|
|
(m_map->GetShapefile(shpLayerID)).EditInsertShape(shapePtr, &shpNum);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD>õ<EFBFBD>ǰ<EFBFBD><C7B0>shp
|
|
|
|
|
CShape shape = (m_map->GetShapefile(shpLayerID)).GetShape(shpNum-1);
|
|
|
|
|
|
|
|
|
|
//<2F><>ǰ<EFBFBD>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
long curLinePts = shape.GetNumPoints();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ǰshp<68>в<EFBFBD><D0B2><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
shape.InsertPoint(pintPtr, &curLinePts);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD>ڵ<EFBFBD>ʸ<EFBFBD><CAB8>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>
|
|
|
|
|
//<2F><><EFBFBD>룺<EFBFBD><EBA3BA>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>drawLayerID
|
|
|
|
|
// <09><><EFBFBD><EFBFBD><EFBFBD>꣬<EFBFBD><EAA3AC><EFBFBD><EFBFBD>lon, γ<><CEB3>lat
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>strPtName
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫstrColor
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB>ֵfontColor
|
|
|
|
|
void GISManager::DrawPointShapeLayer(long &drawLayerID, const double lon, const double lat, CString strPtName, const CString strColor, unsigned long fontColor)
|
|
|
|
|
{
|
|
|
|
|
if(!m_map->GetSafeHwnd())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//<2F>жϵ<D0B6>ʸ<EFBFBD><CAB8>ͼ<EFBFBD><CDBC><EFBFBD>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE>
|
|
|
|
|
if (drawLayerID != -1)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ʸ<EFBFBD><CAB8>ͼ<EFBFBD><CDBC>
|
|
|
|
|
//ClearPointShape(drawLayerID);
|
|
|
|
|
EraseShape(drawLayerID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////<2F>½<EFBFBD><C2BD><EFBFBD>ʸ<EFBFBD><CAB8>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>///////////////////////////////////
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
|
|
|
|
CreateEmptyPointShapefile(drawLayerID, mapWindow::tkDefaultPointSymbol::dpsDiamond, RGB(0,255,0),16);
|
|
|
|
|
|
|
|
|
|
SetLabelCategory(drawLayerID,12,strColor,fontColor,0.0,-8);
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD>뺽<EFBFBD><EBBABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
AddOnePoint2Shapfile(drawLayerID, 0, lon, lat);
|
|
|
|
|
|
|
|
|
|
/////////////////////<2F><>SHPͼ<50><CDBC><EFBFBD>м<EFBFBD><D0BC><EFBFBD>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>Ϣ///////////////////////////////
|
|
|
|
|
USES_CONVERSION;
|
|
|
|
|
|
|
|
|
|
std::string name(strPtName);
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Labels
|
|
|
|
|
drawLabel(false, drawLayerID, strPtName, lon, lat);
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>»<EFBFBD><C2BB><EFBFBD>
|
|
|
|
|
Redraw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::setPointRotation(const long& shapeLayerID, double rotation)
|
|
|
|
|
{
|
|
|
|
|
if(!m_map->GetSafeHwnd())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CShapeDrawingOptions pShapeDrawingOption;
|
|
|
|
|
pShapeDrawingOption = m_map->GetShapefile(shapeLayerID).GetDefaultDrawingOptions();
|
|
|
|
|
pShapeDrawingOption.SetPointRotation(rotation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::SetLabelCategory(const long& shapeID, int fontSize /*= 12*/, CString colorName /*= _T("<22><>ɫ")*/, unsigned long fontColor /*= RGB(255,0,0)*/, double XOffset/* = 0*/, double YOffset /*= 0*/)
|
|
|
|
|
{
|
|
|
|
|
if(shapeID == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CLabels labesPtr;
|
|
|
|
|
labesPtr = (m_map->GetShapefile(shapeID)).GetLabels();
|
|
|
|
|
|
|
|
|
|
CLabelCategory labelCategory = labesPtr.AddCategory((LPCTSTR)colorName);
|
|
|
|
|
labelCategory.SetFontColor(fontColor);
|
|
|
|
|
labelCategory.SetAlignment(1);
|
|
|
|
|
labelCategory.SetOffsetX(XOffset);
|
|
|
|
|
labelCategory.SetOffsetY(YOffset);
|
|
|
|
|
labelCategory.SetFontBold(TRUE);
|
|
|
|
|
labelCategory.SetFontName(LPCTSTR("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
labelCategory.SetFontSize(fontSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::SetLabelCategory2(const long& shapeID, int fontSize /*= 12*/, unsigned long fontColor /*= RGB(255,0,0)*/, unsigned long frameBackColor /*= RGB(0,0,0)*/,
|
|
|
|
|
double XOffset/* = 0*/, double YOffset /*= 0*/)
|
|
|
|
|
{
|
|
|
|
|
if(shapeID == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CLabels labesPtr;
|
|
|
|
|
labesPtr = (m_map->GetShapefile(shapeID)).GetLabels();
|
|
|
|
|
|
|
|
|
|
CLabelCategory labelCategory = labesPtr.AddCategory(_T(""));
|
|
|
|
|
labelCategory.SetFontColor(fontColor);
|
|
|
|
|
labelCategory.SetAlignment(1);
|
|
|
|
|
labelCategory.SetOffsetX(XOffset);
|
|
|
|
|
labelCategory.SetOffsetY(YOffset);
|
|
|
|
|
labelCategory.SetFontBold(TRUE);
|
|
|
|
|
labelCategory.SetFontName(LPCTSTR("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
labelCategory.SetFontSize(fontSize);
|
|
|
|
|
labelCategory.SetFrameType(1);
|
|
|
|
|
labelCategory.SetFrameBackColor(frameBackColor);
|
|
|
|
|
labelCategory.SetFrameVisible(TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::SetInnerLabelCategory(const long& layerHandle,int fontSize /* = 12 */, unsigned long fontColor /*= RGB(255,0,0)*/,
|
|
|
|
|
double XOffset/* = 0*/, double YOffset /*= 0*/)
|
|
|
|
|
{
|
|
|
|
|
if(layerHandle == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CShapefile sf;
|
|
|
|
|
sf = m_map->GetShapefile(layerHandle);
|
|
|
|
|
|
|
|
|
|
CLabelCategory LBCPtr;
|
|
|
|
|
LBCPtr.CreateDispatch(_T("MapWinGIS.LabelCategory"));
|
|
|
|
|
|
|
|
|
|
LBCPtr.SetName(_T("labelcategoty"));
|
|
|
|
|
LBCPtr.SetFontColor(fontColor);
|
|
|
|
|
LBCPtr.SetAlignment(1);
|
|
|
|
|
LBCPtr.SetOffsetX(XOffset);
|
|
|
|
|
LBCPtr.SetOffsetY(YOffset);
|
|
|
|
|
LBCPtr.SetFontBold(TRUE);
|
|
|
|
|
LBCPtr.SetFrameVisible(FALSE);
|
|
|
|
|
LBCPtr.SetFontName(_T("song"));
|
|
|
|
|
LBCPtr.SetFontSize((long)fontSize);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf.GetLabels().SetOptions(LBCPtr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::drawLabel(bool isAdd, const long& shapefileID, const CString& labelName, const double& lon, const double& lat,
|
|
|
|
|
const double& rotation /*= 0*/, const long& labalCatIndex/* = 0*/)
|
|
|
|
|
{
|
|
|
|
|
if(!m_map->GetSafeHwnd())
|
|
|
|
|
return;
|
|
|
|
|
if(shapefileID == -1)
|
|
|
|
|
return;
|
|
|
|
|
CLabels labesPtr;
|
|
|
|
|
labesPtr = (m_map->GetShapefile(shapefileID)).GetLabels();
|
|
|
|
|
if(!isAdd)
|
|
|
|
|
labesPtr.Clear();
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Labels
|
|
|
|
|
labesPtr.AddLabel(LPCTSTR(labelName), lon, lat, rotation, labalCatIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD><EFBFBD>ݾ<EFBFBD>γ<EFBFBD>ȡ<EFBFBD><C8A1>Ƕȼ<C7B6><C8BC><EFBFBD>ij<EFBFBD><C4B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void GISManager::CalculatePolygonCoordinate(const double lon, const double lat, const double yaw, double (*pArrayData)[2], const std::vector<PtPixel>& pvec)
|
|
|
|
|
{
|
|
|
|
|
if(!m_map->GetSafeHwnd())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
double pixelX = 0;
|
|
|
|
|
double pixelY = 0;
|
|
|
|
|
m_map->ProjToPixel(lon, lat, &pixelX, &pixelY);
|
|
|
|
|
|
|
|
|
|
const double DEG2RAD = 0.017453292519943295769236907684886127134428718885417;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>ôź<C3B4><C5BA><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
double sinang = sin(yaw * DEG2RAD);
|
|
|
|
|
double cosang = cos(yaw * DEG2RAD);
|
|
|
|
|
|
|
|
|
|
//<2F><>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
double rotatePixelX = 0;
|
|
|
|
|
double rotatePixelY = 0;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD>㾭<EFBFBD><E3BEAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>ƽ<EFBFBD>ƺ<EFBFBD><C6BA>Ķ<EFBFBD><C4B6><EFBFBD><EFBFBD>ε<EFBFBD><CEB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
for(int k=0; k<pvec.size(); k++)
|
|
|
|
|
{
|
|
|
|
|
rotatePixelX = pixelX + (pvec[k]._ptX * cosang - pvec[k]._ptY * sinang); //X<><58><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
rotatePixelY = pixelY + (pvec[k]._ptX * sinang + pvec[k]._ptY * cosang); //Y<><59><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>γ<EFBFBD><CEB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
m_map->PixelToProj(rotatePixelX, rotatePixelY, &pArrayData[k][0], &pArrayData[k][1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::clearShapefileShape(const long& shapeLayerID)
|
|
|
|
|
{
|
|
|
|
|
if(!m_map->GetSafeHwnd())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(shapeLayerID != -1)
|
|
|
|
|
m_map->GetShapefile(shapeLayerID).EditClear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long GISManager::getLayerShapeIndex(const long& layerHandle, const int& elementID, const int& sel /* = 0 */)
|
|
|
|
|
{
|
|
|
|
|
long shapeIndex = -1;
|
|
|
|
|
|
|
|
|
|
if(layerHandle== -1 || elementID<1)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
CShapefile sf = m_map->GetShapefile(layerHandle);
|
|
|
|
|
|
|
|
|
|
long fieldIndex = -1;
|
|
|
|
|
if(sel == 0)
|
|
|
|
|
fieldIndex = sf.GetTable().GetFieldIndexByName(_T("ID"));
|
|
|
|
|
else
|
|
|
|
|
fieldIndex = sf.GetTable().GetFieldIndexByName(_T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
|
|
|
|
|
if(fieldIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
long numShapes = sf.GetNumShapes();
|
|
|
|
|
for(long i = 0; i < numShapes; i++)
|
|
|
|
|
{
|
|
|
|
|
CString pfindValueId;
|
|
|
|
|
pfindValueId.Format(_T("%d"), elementID);
|
|
|
|
|
CString pRelValueId = (CString)sf.GetCellValue(fieldIndex, i);
|
|
|
|
|
if(pRelValueId == pfindValueId)
|
|
|
|
|
{
|
|
|
|
|
shapeIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return shapeIndex;
|
|
|
|
|
|
|
|
|
|
return shapeIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int GISManager::getLayerShapeEleID(const long& layerHandle, const long& shapeIndex, const int& sel /* = 0 */)
|
|
|
|
|
{
|
|
|
|
|
int id = 0;
|
|
|
|
|
|
|
|
|
|
if(layerHandle== -1 || shapeIndex == -1)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
CShapefile sf = m_map->GetShapefile(layerHandle);
|
|
|
|
|
|
|
|
|
|
long fieldIndex = -1;
|
|
|
|
|
if(sel == 0)
|
|
|
|
|
fieldIndex = sf.GetTable().GetFieldIndexByName(_T("ID"));
|
|
|
|
|
else
|
|
|
|
|
fieldIndex = sf.GetTable().GetFieldIndexByName(_T("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
|
|
|
|
|
if(fieldIndex != -1)
|
|
|
|
|
{
|
|
|
|
|
CString pValue = (CString)sf.GetCellValue(fieldIndex, shapeIndex);
|
|
|
|
|
|
|
|
|
|
id = atoi(pValue);
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool GISManager::deleteShape(const long& layerHandle, const long& shapeIndex)
|
|
|
|
|
{
|
|
|
|
|
if(layerHandle==-1 || shapeIndex== -1)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
CShapefile sf;
|
|
|
|
|
sf = m_map->GetShapefile(layerHandle);
|
|
|
|
|
|
|
|
|
|
sf.EditDeleteShape(shapeIndex);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::changeLayerShapeLineStyle(const long& layerHandle, const long& shapeIndex, const CString& styleName, unsigned long lineColor,float lineWidth /*= 1*/,
|
|
|
|
|
mapWindow::tkLineStipple lineStyle /*= mapWindow::tkLineStipple::lsDashed*/)
|
|
|
|
|
{
|
|
|
|
|
if(layerHandle==-1 || shapeIndex==-1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CShapefile sf = m_map->GetShapefile(layerHandle);
|
|
|
|
|
|
|
|
|
|
CShapefileCategory sc;
|
|
|
|
|
long categoryIndex = -1;
|
|
|
|
|
CString sfcName = styleName;
|
|
|
|
|
long sfcNum = sf.GetCategories().GetCount();
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Categories<65><73><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ں<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>ShapefileCategory
|
|
|
|
|
for(long i=0; i<sfcNum; i++)
|
|
|
|
|
{
|
|
|
|
|
sc = sf.GetCategories().GetItem(i);
|
|
|
|
|
if(sc.GetName() == sfcName)
|
|
|
|
|
{
|
|
|
|
|
categoryIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(categoryIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
sc = sf.GetCategories().Add(sfcName);
|
|
|
|
|
|
|
|
|
|
sc.GetDrawingOptions().SetLineColor(lineColor);
|
|
|
|
|
sc.GetDrawingOptions().SetLineWidth(lineWidth);
|
|
|
|
|
sc.GetDrawingOptions().SetLineStipple(lineStyle);
|
|
|
|
|
|
|
|
|
|
categoryIndex = sf.GetCategories().GetCount() - 1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sc = sf.GetCategories().GetItem(categoryIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sf.SetShapeCategory(shapeIndex, categoryIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::changeAreaLayerShapeStyle(const long& layerHandle, const long& shapeIndex, const CString& styleName, const unsigned long drawColor,
|
|
|
|
|
const unsigned long& fillColor, const float& fillTransparency)
|
|
|
|
|
{
|
|
|
|
|
if(layerHandle==-1 || shapeIndex==-1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CShapefile sf = m_map->GetShapefile(layerHandle);
|
|
|
|
|
|
|
|
|
|
CShapefileCategory sc;
|
|
|
|
|
long categoryIndex = -1;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Categories<65><73><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ں<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>ShapefileCategory
|
|
|
|
|
long sfCategoriesNum = sf.GetCategories().GetCount();
|
|
|
|
|
for(long i=0; i<sfCategoriesNum; i++)
|
|
|
|
|
{
|
|
|
|
|
sc = sf.GetCategories().GetItem(i);
|
|
|
|
|
if(sc.GetName() == styleName)
|
|
|
|
|
{
|
|
|
|
|
categoryIndex = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(categoryIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
sc = sf.GetCategories().Add(styleName);
|
|
|
|
|
|
|
|
|
|
sc.GetDrawingOptions().SetFillColor(fillColor);
|
|
|
|
|
sc.GetDrawingOptions().SetFillTransparency(fillTransparency);
|
|
|
|
|
sc.GetDrawingOptions().SetFillType(0);
|
|
|
|
|
sc.GetDrawingOptions().SetFillHatchStyle(0);
|
|
|
|
|
sc.GetDrawingOptions().SetLineColor(drawColor);
|
|
|
|
|
|
|
|
|
|
categoryIndex = sf.GetCategories().GetCount() - 1;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sc = sf.GetCategories().GetItem(categoryIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sf.SetShapeCategory(shapeIndex, categoryIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::editAttributeValue(const long& layerHandler, const long& shapeIndex, const CString& fieldName, const CString& value)
|
|
|
|
|
{
|
|
|
|
|
CShapefile sf;
|
|
|
|
|
sf = m_map->GetShapefile(layerHandler);
|
|
|
|
|
|
|
|
|
|
long fieldIndex = sf.GetTable().GetFieldIndexByName((_bstr_t)fieldName);
|
|
|
|
|
_variant_t pValue(value);
|
|
|
|
|
sf.EditCellValue(fieldIndex, shapeIndex, (VARIANT)pValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long GISManager::selectShape(const long& layerHandle, long x, long y, long x2 /* = -1 */, long y2 /* = -1 */,bool isPt /*= false*/,
|
|
|
|
|
mapWindow::SelectMode selectMode /*= mapWindow::SelectMode::INCLUSION*/)
|
|
|
|
|
{
|
|
|
|
|
if(layerHandle == -1)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
CShapefile sf;
|
|
|
|
|
sf = m_map->GetShapefile(layerHandle);
|
|
|
|
|
|
|
|
|
|
if(sf != NULL)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>shape
|
|
|
|
|
sf.SelectNone();
|
|
|
|
|
Redraw();
|
|
|
|
|
|
|
|
|
|
double projX1 = 0.0;
|
|
|
|
|
double projY1 = 0.0;
|
|
|
|
|
double projX2 = 0.0;
|
|
|
|
|
double projY2 = 0.0;
|
|
|
|
|
|
|
|
|
|
if(x2==-1 && y2== -1)
|
|
|
|
|
{
|
|
|
|
|
if(isPt)
|
|
|
|
|
{
|
|
|
|
|
m_map->PixelToProj(x,y,&projX1,&projY1);
|
|
|
|
|
m_map->PixelToProj(x,y,&projX2,&projY2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_map->PixelToProj(x-15,y-15,&projX1,&projY1);
|
|
|
|
|
m_map->PixelToProj(x+15,y+15,&projX2,&projY2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_map->PixelToProj(x,y,&projX1,&projY1);
|
|
|
|
|
m_map->PixelToProj(x2,y2,&projX2,&projY2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VARIANT result;
|
|
|
|
|
|
|
|
|
|
mapWindow::IExtentsPtr ext;
|
|
|
|
|
ext.CreateInstance("MapWinGIS.Extents");
|
|
|
|
|
|
|
|
|
|
ext->SetBounds(projX1, projY1, 0.0, projX2, projY2, 0.0);
|
|
|
|
|
|
|
|
|
|
bool isSelect = sf.SelectShapes(ext,0.0, selectMode, &result);
|
|
|
|
|
if(isSelect)
|
|
|
|
|
{
|
|
|
|
|
int count = (int)result.parray->rgsabound->cElements;
|
|
|
|
|
long *index = (long*)(result.parray->pvData);
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ѡ<EFBFBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD>õ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ϊѡ<CEAA><D1A1>
|
|
|
|
|
sf.SetShapeSelected(index[0],VARIANT_TRUE);
|
|
|
|
|
Redraw();
|
|
|
|
|
return index[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::selectShapes(const long& layerHandle, long x1, long y1, long x2, long y2, std::vector<long>& selectedIndexVec)
|
|
|
|
|
{
|
|
|
|
|
if(layerHandle == -1)
|
|
|
|
|
return ;
|
|
|
|
|
|
|
|
|
|
CShapefile sf;
|
|
|
|
|
sf = m_map->GetShapefile(layerHandle);
|
|
|
|
|
|
|
|
|
|
if(sf == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>shape
|
|
|
|
|
sf.SelectNone();
|
|
|
|
|
|
|
|
|
|
double projX1 = 0.0;
|
|
|
|
|
double projY1 = 0.0;
|
|
|
|
|
m_map->PixelToProj(x1, y1, &projX1, &projY1);
|
|
|
|
|
|
|
|
|
|
double projX2 = 0.0;
|
|
|
|
|
double projY2 = 0.0;
|
|
|
|
|
m_map->PixelToProj(x2, y2, &projX2, &projY2);
|
|
|
|
|
|
|
|
|
|
VARIANT result;
|
|
|
|
|
|
|
|
|
|
mapWindow::IExtentsPtr ext;
|
|
|
|
|
ext.CreateInstance("MapWinGIS.Extents");
|
|
|
|
|
ext->SetBounds(projX1, projY1, 0.0, projX2, projY2, 0.0);
|
|
|
|
|
|
|
|
|
|
bool isSelect = sf.SelectShapes(ext,0.0, mapWindow::SelectMode::INCLUSION, &result);
|
|
|
|
|
if(isSelect)
|
|
|
|
|
{
|
|
|
|
|
int count = (int)result.parray->rgsabound->cElements;
|
|
|
|
|
long *index = (long*)(result.parray->pvData);
|
|
|
|
|
|
|
|
|
|
if(count>=1)
|
|
|
|
|
{
|
|
|
|
|
for(int j=0; j < count; j++)
|
|
|
|
|
{
|
|
|
|
|
//s = s +
|
|
|
|
|
TRACE("%d\n", index[j]);
|
|
|
|
|
|
|
|
|
|
sf.SetShapeSelected(index[j],VARIANT_TRUE);
|
|
|
|
|
|
|
|
|
|
//<2F><>ѡ<EFBFBD>е<EFBFBD>ͼԪ<CDBC><D4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뵽<EFBFBD><EBB5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
selectedIndexVec.push_back(index[j]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Redraw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long GISManager::selectAreaShape(const long& layerHandle, long x, long y)
|
|
|
|
|
{
|
|
|
|
|
if(layerHandle == -1)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
CShapefile sf;
|
|
|
|
|
sf = m_map->GetShapefile(layerHandle);
|
|
|
|
|
|
|
|
|
|
if(sf != NULL)
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>shape
|
|
|
|
|
sf.SelectNone();
|
|
|
|
|
Redraw();
|
|
|
|
|
|
|
|
|
|
double projX1 = 0.0;
|
|
|
|
|
double projY1 = 0.0;
|
|
|
|
|
|
|
|
|
|
m_map->PixelToProj(x,y,&projX1,&projY1);
|
|
|
|
|
|
|
|
|
|
VARIANT result;
|
|
|
|
|
|
|
|
|
|
mapWindow::IExtentsPtr ext;
|
|
|
|
|
ext.CreateInstance("MapWinGIS.Extents");
|
|
|
|
|
|
|
|
|
|
ext->SetBounds(projX1, projY1, 0.0, projX1, projY1, 0.0);
|
|
|
|
|
|
|
|
|
|
bool isSelect = sf.SelectShapes(ext,0.0, mapWindow::SelectMode::INCLUSION, &result);
|
|
|
|
|
if(isSelect)
|
|
|
|
|
{
|
|
|
|
|
int count = (int)result.parray->rgsabound->cElements;
|
|
|
|
|
long *index = (long*)(result.parray->pvData);
|
|
|
|
|
|
|
|
|
|
CShape shapePtr = sf.GetShape(index[0]);
|
|
|
|
|
double minArea = shapePtr.GetArea(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>СֵΪѡ<CEAA>еĵ<D0B5>һ<EFBFBD><D2BB>
|
|
|
|
|
long returnIndex = index[0]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>ʼΪ<CABC><CEAA>һ<EFBFBD><D2BB>
|
|
|
|
|
for(int i=1; i < count; i++)
|
|
|
|
|
{
|
|
|
|
|
shapePtr = sf.GetShape(index[i]);
|
|
|
|
|
if(minArea > shapePtr.GetArea())
|
|
|
|
|
{
|
|
|
|
|
returnIndex = index[i];
|
|
|
|
|
minArea = shapePtr.GetArea();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf.SetShapeSelected(returnIndex,VARIANT_TRUE);
|
|
|
|
|
Redraw();
|
|
|
|
|
|
|
|
|
|
return returnIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GISManager::releaseSelected(const long& layerHandle)
|
|
|
|
|
{
|
|
|
|
|
if(layerHandle == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CShapefile sf;
|
|
|
|
|
sf = m_map->GetShapefile(layerHandle);
|
|
|
|
|
if(sf!=NULL)
|
|
|
|
|
{
|
|
|
|
|
sf.SelectNone();
|
|
|
|
|
Redraw();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GISManager::calculateExtents(const double& x, const double& y, double lenOfSide, mapWindow::IExtentsPtr extents)
|
|
|
|
|
{
|
|
|
|
|
double lon1 = 0.0;
|
|
|
|
|
double lat1 = 0.0;
|
|
|
|
|
double lon2 = 0.0;
|
|
|
|
|
double lat2 = 0.0;
|
|
|
|
|
|
|
|
|
|
double distance = lenOfSide/sqrtf(2);
|
|
|
|
|
|
|
|
|
|
CalculatePtCoordinate(lon1, lat1, x, y, 225, distance, 3);
|
|
|
|
|
CalculatePtCoordinate(lon2, lat2, x, y, 45, distance, 3);
|
|
|
|
|
|
|
|
|
|
extents->SetBounds(lon1, lat1, 0.0, lon2, lat2, 0.0);
|
|
|
|
|
}
|