📄 湘源规划软件.htm
字号:
<TD width="10%" height=35>
<DIV align=right><IMG height=32
src="湘源规划软件.files/zhuye-20.jpg" width=30></DIV></TD>
<TD class=ht1 width=642>
<DIV align=center>MO基本代码(VC) </DIV></TD>
<TD class=16ff width="10%"> </TD></TR>
<TR>
<TD colSpan=3>
<HR width="100%" SIZE=1>
</TD></TR>
<TR>
<TD width="10%"> </TD>
<TD class=12g>
<DIV class=14 align=center></DIV></TD>
<TD class=12g width="10%"> </TD></TR>
<TR>
<TD> </TD>
<TD class=12g>作者:gis<BR>发表时间:2004-4-18
18:52:56<BR><BR>////**********属性浏览**********<BR>//<BR>///////////////////////////////////////////////////////////////<BR>//函数功能
: 选择地图要素<BR>//处理过程 :
先得到鼠标点击的要素的Recordset,将鼠标点击的要素加入到Track层<BR>//返 回 值 :
void<BR>//参数说明 : short Shift, //是否按下了Shift键<BR>// long
X, long
Y<BR>///////////////////////////////////////////////////////////////<BR>void
SelectFeatToSelection(CMap1& m_Map, short Shift,
long X, long Y)<BR>{<BR>if(Shift==0)
CLISTrackLayer::ClearTrack(m_Map);
//清除所有Track层数据<BR>long ShapeType;<BR>CMoRecordset
selSet;<BR>if(SelectFeatureOnMap(m_Map,X,Y,m_SelTolerance,selSet,ShapeType))<BR>//
SelectFeatureOnMap函数参考如下<BR>{<BR>CMoFields MoFields =
selSet.GetFields();<BR>CMoField
shapeField(MoFields.Item(COleVariant(TEXT("Shape"))));<BR>if(ShapeType==moShapeTypePolygon)<BR>{<BR>CMoPolygon
shape(shapeField.Getvalue().pdispVal);<BR>CLISTrackLayer::AddTrack(m_Map,shape,TRACK_SYMBOL_BLOCK0);
<BR>}<BR>if(ShapeType==moShapeTypeLine)<BR>{<BR>CMoLine
shape(shapeField.Getvalue().pdispVal);<BR>CLISTrackLayer::AddTrack(m_Map,shape,TRACK_SYMBOL_LINE0);<BR>}<BR>if(ShapeType==moShapeTypePoint)<BR>{<BR>CMoPoint
shape(shapeField.Getvalue().pdispVal);<BR>CLISTrackLayer::AddTrack(m_Map,shape,TRACK_SYMBOL_POINT0);<BR>}<BR>}<BR>}<BR>///////////////////////////////////////////////////////////////<BR>//函数功能
: 选择地图要素,自动判断该要素属于那一层,返回该要素的Recordset和<BR>//
要素所在图层的类型(点、线、面)<BR>//返 回 值 : BOOL<BR>//参数说明 :
CMap1& map,<BR>//long X, long Y,<BR>//double ptSize,
选择范围<BR>//CMoRecordset& set,
要素的Recordset(返回参数)<BR>//long& ShapeType
要素所在图层的类型(返回参数)<BR>///////////////////////////////////////////////////////////////<BR>BOOL
SelectFeatureOnMap(CMap1& map,long X,long Y,double
ptSize,CMoRecordset<BR>& set,long&
ShapeType)<BR>{<BR>double tolerance =
map.ToMapDistance((float)ptSize);<BR>CMoPointmapPt(map.ToMapPoint((float)X,
(float)Y));<BR>CMoLayers
layers(map.GetLayers());<BR>for(long
i=0;i<layers.GetCount();i++)<BR>{<BR>CMoMapLayer
Itemlayer(layers.Item(COleVariant(i)));<BR>if(!Itemlayer.GetVisible())
continue;<BR>ShapeType =
Itemlayer.GetShapeType();<BR>if(Itemlayer.GetShapeType()==moShapeTypePolygon)<BR>{<BR>set
= Itemlayer.SearchShape(mapPt,moPointInPolygon,
TEXT(""));<BR>if(!set.GetEof()) return
TRUE;<BR>}<BR>if(Itemlayer.GetShapeType()==moShapeTypePoint||Itemlayer.GetShapeType()==mo<BR>ShapeTypeLine)<BR>{<BR>set
= Itemlayer.SearchByDistance(mapPt,tolerance,
TEXT(""));<BR>if(!set.GetEof()) return
TRUE;<BR>}<BR>}<BR>return
FALSE;<BR>}<BR>///////////////////////////////////////////////////////////////<BR>//函数功能
: 取消选择<BR>//处理过程 : 清除所有Track层数据<BR>//返 回 值 :
void<BR>//参数说明 : CMap1&
map<BR>///////////////////////////////////////////////////////////////<BR>void
DelTrack(CMap1&
map)<BR>{<BR>CLISTrackLayer::ClearTrack(map);<BR>}<BR>///////////////////////////////////////////////////////////////<BR>//函数功能
: 输入线、矩形、多边形,选择与其有相交或包含关系的要素<BR>//处理过程 : <BR>//返 回 值 :
BOOL<BR>//参数说明 : BOOL fromTrackShp, ;是否直接从Track层取几何图形来选择
<BR>// int nID
;要输入几何图形的类型<BR>///////////////////////////////////////////////////////////////<BR>BOOL
ShowLayerFWAttrib(CMap1& m_Map, BOOL fromTrackShp,
int nID)<BR>{<BR>CMoPolygon poly;<BR>CMoLine
line;<BR>CMoRectangle rect;<BR>CMoEllipse
Ellipse;<BR>int shapeType =
0;<BR>if(fromTrackShp)<BR>{<BR>if(CLISTrackLayer::GetTrackCount(m_Map)!=1)<BR>{<BR>CLISTrackLayer::ClearTrack(m_Map);<BR>return
FALSE;<BR>}<BR>if(CLISTrackLayer::GetTrackShapeType(m_Map,0)==moShapeTypePolygon)
<BR>{<BR>CLISTrackLayer::GetTrackShape(m_Map,0,poly);
//获得Track层的第一个多边<BR>形<BR>if(!LPDISPATCH(poly)) return
FALSE;<BR>shapeType = moShapeTypePolygon;<BR>}<BR>else
if(CLISTrackLayer::GetTrackShapeType(m_Map,0)==moShapeTypeLine)
<BR>{<BR>CLISTrackLayer::GetTrackShape(m_Map,0,line);
//获得Track层的第一个线<BR>if(!LPDISPATCH(line)) return
FALSE;<BR>shapeType =
moShapeTypeLine;<BR>}<BR>else<BR>{<BR>CLISTrackLayer::ClearTrack(m_Map);<BR>return
FALSE;<BR>}<BR>}<BR>else<BR>{<BR>if(nID==ID_MAP_POLYFWATT)
//输入多边形<BR>{<BR>poly =
m_Map.TrackPolygon();<BR>if(!LPDISPATCH(poly)) return
FALSE;
<BR>CLISTrackLayer::AddTrack(m_Map,poly,TRACK_SYMBOL_BLOCK0);<BR>shapeType
= moShapeTypePolygon;<BR>}<BR>else
if(nID==ID_MAP_RECTFWATT) //输入矩形<BR>{<BR>rect =
m_Map.TrackRectangle();<BR>if(!LPDISPATCH(rect)) return
FALSE;<BR>CLISTrackLayer::AddTrack(m_Map,rect,TRACK_SYMBOL_BLOCK0);<BR>shapeType
= moShapeTypeRectangle;<BR>}<BR>else
if(nID==ID_MAP_CIRCLFWATT) //输入圆<BR>{<BR>Ellipse =
m_Map.TrackCircle();<BR>if(!LPDISPATCH(Ellipse)) return
FALSE;<BR>CLISTrackLayer::AddTrack(m_Map,Ellipse,TRACK_SYMBOL_BLOCK0);<BR>shapeType
= moShapeTypeEllipse;<BR>}<BR>else
if(nID==ID_MAP_LINEFWATT) //输入线<BR>{<BR>line =
m_Map.TrackLine();<BR>if(!LPDISPATCH(line)) return
FALSE;<BR>CLISTrackLayer::AddTrack(m_Map,line,TRACK_SYMBOL_LINE0);<BR>shapeType
=
moShapeTypeLine;<BR>}<BR>else<BR>{<BR><BR>}<BR>}<BR>CString
LayerCode =
FormatSDELayerCode(*m_LayerManger.m_curLayer);<BR>CMoLayers
layers(m_Map.GetLayers());<BR>CMoMapLayer
Itemlayer(layers.Item(COleVariant(LayerCode)));
<BR>if(!LPDISPATCH(Itemlayer))<BR>{<BR>AfxMessageBox("打
不 开 选 中 的 层 !");<BR>return TRUE;<BR>}<BR>long ShapeType
= Itemlayer.GetShapeType();<BR>CMoRecordset selSet;
<BR>if(shapeType == moShapeTypePolygon)<BR>selSet =
Itemlayer.SearchShape(poly,moAreaIntersect,
TEXT(""));<BR>else if(shapeType ==
moShapeTypeLine)<BR>selSet =
Itemlayer.SearchShape(line,moAreaIntersect,
TEXT(""));<BR>else if(shapeType ==
moShapeTypeRectangle)<BR>selSet =
Itemlayer.SearchShape(rect,moAreaIntersect,
TEXT(""));<BR>else if(shapeType ==
moShapeTypeEllipse)<BR>selSet =
Itemlayer.SearchShape(Ellipse,moAreaIntersect,
TEXT(""));<BR>else <BR>return TRUE;<BR>//
根据返回的Recordset对象在对话框中显示属性值,代码略<BR>return
TRUE;<BR>}<BR>///////////////////////////////////////////////////////////////<BR>//函数功能
: 根据表达式查询地图要素<BR>//处理过程 : <BR>//备 注 : <BR>//返 回 值 :
BOOL<BR>//参数说明 : CMap1& map,<BR>//CString layerCode,
//查询目标图层的名称<BR>//CString SQL,
//查询表达式,SQL形式<BR>//CMoRecordset& selSet,
//返回查询要素的Recordset<BR>//long& ShapeType
//返回查询目标图层的类型<BR>///////////////////////////////////////////////////////////////<BR>BOOL
SQLSearchFeature(CMap1& map,CString
layerCode,CString SQL,CMoRecordset& <BR>selSet,
long& ShapeType)<BR>{<BR>for(int
i=0;i<m_LayerManger.m_layers.GetSize();i++)<BR>{<BR>if(!m_LayerManger.m_layers.m_Visible)
continue;<BR>if(m_LayerManger.m_layers.m_LayerCode.CompareNoCase(layerCode)!=0)
con<BR>tinue;<BR>// 寻找目标图层<BR>CMoLayers layers =
map.GetLayers();<BR>CMoMapLayer
SearchLayer(layers.Item(COleVariant(FormatSDELayerCode(m_Lay<BR>erManger.m_layers))));<BR>if(!LPDISPATCH(SearchLayer))
return FALSE;<BR>VARIANT
va;<BR>VariantInit(&va);<BR>CMoRectangle
Rect,RectCell;<BR>Rect.CreateDispatch(TEXT("MapObjects2.Rectangle"));<BR>RectCell.CreateDispatch(TEXT("MapObjects2.Rectangle"));<BR>BOOL
Flag = TRUE;<BR>ShapeType =
SearchLayer.GetShapeType();<BR>selSet =
SearchLayer.SearchExpression(SQL);<BR>if(selSet.GetEof())
return
FALSE;<BR>while(!selSet.GetEof())<BR>{<BR>CMoFields
MoFields = selSet.GetFields();<BR>CMoField
shapeField(MoFields.Item(COleVariant(TEXT("Shape"))));<BR>if(ShapeType==moShapeTypePolygon)<BR>{<BR>CMoPolygon
shape(shapeField.Getvalue().pdispVal);<BR>CLISTrackLayer::AddTrack(map,shape,TRACK_SYMBOL_BLOCK1);<BR>RectCell
=
shape.GetExtent();<BR>}<BR>if(ShapeType==moShapeTypeLine)<BR>{<BR>CMoLine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -