VC+MO2.0连接ArcSDE并且读出SDE中的空间数据(三)

 现在查询上基本完成了,不过仅仅是一些简单的查询而已。首先我还是贴一下放大、缩小、漫游一些简单的代码:
CMoRectangle Rect;

CMoPoint Point;
if(this->m_CursorStat == "zoomin")

{

   Rect = this->m_MapObject.TrackRectangle();

   this->m_MapObject.SetExtent(Rect);

}

else if(this->m_CursorStat=="zoomout")

{

   double Width,Height;

   Point = this->m_MapObject.ToMapPoint((float)X,(float)Y);

   Rect = this->m_MapObject.GetExtent();

   Width = Rect.GetWidth();

   Height = Rect.GetHeight();

   Rect.SetRight(Point.GetX()+Width);

   Rect.SetLeft(Point.GetX()-Width);

   Rect.SetBottom(Point.GetY()-Height);

   Rect.SetTop(Point.GetY()+Height);

   this->m_MapObject.SetExtent(Rect);

}

else if(this->m_CursorStat=="pan")

{

   this->m_MapObject.Pan();

}
这些都比较easy,就略去介绍了。下面开始讲查询:我这里的查询用的是Expression语句,其实还有其他的方法,如SearchShape,这里先介绍前者的用法。它其实就是一个约束条件,你把它扔给一个图层处理,然后图层就会根据你的语句得到结果,返回一个CMoRecordset类型。如:

CMoRecordset recs(this->m_CurrentLayer.SearchExpression(expression));

recs就是当前图层,执行语句expression之后得到的结果集合。这里我用的只是Like的SQL语法(其他的还没有得知如何用),所以结果返回就是一条记录,或者说就是表中的一行。下面以点图层搜索为例:

CMoFields fields(recs.GetFields());//得到字段集合

CMoField shapeField(fields.Item(COleVariant(TEXT("Shape"))));

//用字段shape初始化shapeField,必须用shape

if(lyrType=="MultiPoints")

{

//这里这个shape文件是一个点对象

CMoPoint shape(shapeField.GetValue().pdispVal);

this->m_MapObject.FlashShape(shape, 3);//将这个点闪动三次

}

其中,lyrType是图层的类型,通过GetSplitString函数得到。这样,只要执行Select * from CurrentLayer where CITY_NAME Like Denver类似的语句就可得到结果。

下一次如果有续的话,应该是了解返回多个查询结果的情形。

原文地址:https://www.cnblogs.com/googlegis/p/2979099.html