AO中用点选的方式选择点、线、面等(转)
AO中用点选的方式选择点、线、面等
void CWzjGISView:
ointSelect(double mapX, double mapY)//这个函数用于点选择
...{
IMapPtr ipMap;
ipMap=m_MapControl.GetMap();
//获取点图层
IFeatureLayerPtr ipFeatlyr;
ILayerPtr ipLayer;
ipMap->get_Layer(0,&ipLayer);
ipFeatlyr=ipLayer;
//获取鼠标点击点
IPointPtr ipPoint(CLSID_Point);
ipPoint->PutCoords(mapX,mapY);
IGeometryPtr ipGeometry;
ipGeometry=ipPoint;
IFeatureClassPtr ipFeatClass;
ipFeatlyr->get_FeatureClass(&ipFeatClass);
ITopologicalOperatorPtr ipTopo;
ipTopo=ipGeometry;
//设定缓冲区距离
double length;
length=ConvertPixelToMapUnits(ipMap,5);
//得到缓冲区多边形pBuffer:
IGeometryPtr ipBuffer;
ipTopo->Buffer(length,&ipBuffer);
//得到缓冲区的包络线
// ipBuffer->get_Envelope(&ipGeometry);
IEnvelopePtr ipGeoEnv;
ipBuffer->get_Envelope(&ipGeoEnv);
ipGeometry = ipGeoEnv;
// ipGeometry->
ISpatialFilterPtr ipSpatialFilter(CLSID_SpatialFilter);
ipSpatialFilter->putref_Geometry(ipGeometry);
esriGeometryType Type;
ipFeatClass->get_ShapeType(&Type);
switch(Type)
...{
case esriGeometryPoint:
ipSpatialFilter->put_SpatialRel(esriSpatialRelContains);
break;
case esriGeometryPolyline:
ipSpatialFilter->put_SpatialRel(esriSpatialRelCrosses);
break;
case esriGeometryPolygon:
ipSpatialFilter->put_SpatialRel(esriSpatialRelIntersects);
default:
break;
}
BSTR bstrshfName;
ipFeatClass->get_ShapeFieldName(&bstrshfName);
ipSpatialFilter->put_GeometryField(bstrshfName);
IFeatureCursorPtr ipCursor;
ipFeatClass->Search(ipSpatialFilter,false,&ipCursor);
/**//*
得到空间过滤运算的结果要素
*/
// IFeaturePtr m_ipFea;
ipCursor->NextFeature(&m_ipFea);
//下面把选择到的要素显示出来
IRgbColorPtr ipColor(CLSID_RgbColor);
ipColor->put_Blue(145);
ipColor->put_Red(110);
ipColor->put_Green(120);
ISimpleMarkerSymbolPtr ipMarkSym(CLSID_SimpleMarkerSymbol);
ipMarkSym->put_Style(esriSMSCircle);
ipMarkSym->put_OutlineSize(10);
ipMarkSym->put_OutlineColor(ipColor);
ISymbolPtr ipSymbol;
ipSymbol=ipMarkSym;
if (m_ipFea)
...{
m_ipFea->get_Shape(&shape);
ipMap->SelectFeature(ipFeatlyr,m_ipFea);
vSym = ipSymbol;
ipCursor->NextFeature(&m_ipFea);
}
IActiveViewPtr ipActView = m_MapControl.GetActiveView();
ipActView->Refresh();
}
void CWzjGISView:
![](http://bbs.esrichina-bj.cn/ESRI/images/smilies/default/tongue.gif)
...{
IMapPtr ipMap;
ipMap=m_MapControl.GetMap();
//获取点图层
IFeatureLayerPtr ipFeatlyr;
ILayerPtr ipLayer;
ipMap->get_Layer(0,&ipLayer);
ipFeatlyr=ipLayer;
//获取鼠标点击点
IPointPtr ipPoint(CLSID_Point);
ipPoint->PutCoords(mapX,mapY);
IGeometryPtr ipGeometry;
ipGeometry=ipPoint;
IFeatureClassPtr ipFeatClass;
ipFeatlyr->get_FeatureClass(&ipFeatClass);
ITopologicalOperatorPtr ipTopo;
ipTopo=ipGeometry;
//设定缓冲区距离
double length;
length=ConvertPixelToMapUnits(ipMap,5);
//得到缓冲区多边形pBuffer:
IGeometryPtr ipBuffer;
ipTopo->Buffer(length,&ipBuffer);
//得到缓冲区的包络线
// ipBuffer->get_Envelope(&ipGeometry);
IEnvelopePtr ipGeoEnv;
ipBuffer->get_Envelope(&ipGeoEnv);
ipGeometry = ipGeoEnv;
// ipGeometry->
ISpatialFilterPtr ipSpatialFilter(CLSID_SpatialFilter);
ipSpatialFilter->putref_Geometry(ipGeometry);
esriGeometryType Type;
ipFeatClass->get_ShapeType(&Type);
switch(Type)
...{
case esriGeometryPoint:
ipSpatialFilter->put_SpatialRel(esriSpatialRelContains);
break;
case esriGeometryPolyline:
ipSpatialFilter->put_SpatialRel(esriSpatialRelCrosses);
break;
case esriGeometryPolygon:
ipSpatialFilter->put_SpatialRel(esriSpatialRelIntersects);
default:
break;
}
BSTR bstrshfName;
ipFeatClass->get_ShapeFieldName(&bstrshfName);
ipSpatialFilter->put_GeometryField(bstrshfName);
IFeatureCursorPtr ipCursor;
ipFeatClass->Search(ipSpatialFilter,false,&ipCursor);
/**//*
得到空间过滤运算的结果要素
*/
// IFeaturePtr m_ipFea;
ipCursor->NextFeature(&m_ipFea);
//下面把选择到的要素显示出来
IRgbColorPtr ipColor(CLSID_RgbColor);
ipColor->put_Blue(145);
ipColor->put_Red(110);
ipColor->put_Green(120);
ISimpleMarkerSymbolPtr ipMarkSym(CLSID_SimpleMarkerSymbol);
ipMarkSym->put_Style(esriSMSCircle);
ipMarkSym->put_OutlineSize(10);
ipMarkSym->put_OutlineColor(ipColor);
ISymbolPtr ipSymbol;
ipSymbol=ipMarkSym;
if (m_ipFea)
...{
m_ipFea->get_Shape(&shape);
ipMap->SelectFeature(ipFeatlyr,m_ipFea);
vSym = ipSymbol;
ipCursor->NextFeature(&m_ipFea);
}
IActiveViewPtr ipActView = m_MapControl.GetActiveView();
ipActView->Refresh();
}