提个简单的问题:怎样在vc+mapx中用FeatureFactory创建多边形图元,为什么我这段代码不对?

cloudrain 2005-03-23 05:08:44
大虾们:我需要建立一个矩形图元,用了以下的代码:
CMapXRectangle feRect;//其中m_map是MapX控件,lyr是已经存在的图层,dbX,dbY是矩形的左下角坐
//标,dbSize是矩形大小
VARIANT vVal;
CMapXFeatureFactory feFac;
try
{
feRect.CreateDispatch(feRect.GetClsid());
feFac=m_map.GetFeatureFactory();
feRect.Set(dbX,dbY,dbX+dbSize,dbY+dbSize);
vVal.vt=VT_VARIANT;
vVal.pdispVal=feRect.m_lpDispatch;
vVal.pdispVal->AddRef();
lyr.AddFeature(feFac.CreateRegion(vVal));
}
catch(COleDispatchException *e)
{
e->ReportError();
e->Delete();
}
catch(COleException *e)
{
e->ReportError();
e->Delete();
}
这段代码运行后报出异常:(Invalid points object)该如何解决啊??
...全文
159 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
charryli 2005-03-28
  • 打赏
  • 举报
回复
哦,忘了,是MapX
BOOL CMapEditorView::DrawRectFill(double X1, double Y1, double X2, double Y2)
{
if(m_MapX.GetLayers().GetInsertionLayer()==NULL)
return FALSE;
if(m_MapX.Distance(X1,Y1,X2,Y2)==0)
return FALSE;
try
{
VARIANT fx,fy;
m_MapX.ConvertCoordV(&fx,&fy,COleVariant(X1),COleVariant(Y1),miMapToScreen);
VARIANT sx,sy;
m_MapX.ConvertCoordV(&sx,&sy,COleVariant(X2),COleVariant(Y2),miMapToScreen);
VARIANT mapx1,mapy1,mapx2,mapy2;
m_MapX.ConvertCoordV(&fx,&sy,&mapx1,&mapy1,miScreenToMap);
m_MapX.ConvertCoordV(&sx,&fy,&mapx2,&mapy2,miScreenToMap);
double x2,y2,x4,y4;
x2 = mapx1.dblVal;
y2 = mapy1.dblVal;
x4 = mapx2.dblVal;
y4 = mapy2.dblVal;
CMapXFeature pFea;
CMapXPoints points;
points.CreateDispatch(points.GetClsid());
CMapXFeatureFactory pFactory;
pFactory=m_MapX.GetFeatureFactory();
points.AddXY(X1,Y1);
points.AddXY(x2,y2);
points.AddXY(X2,Y2);
points.AddXY(x4,y4);
COleVariant vtPoints;
vtPoints.vt = VT_DISPATCH;
vtPoints.pdispVal = points.m_lpDispatch;
vtPoints.pdispVal->AddRef();
pFea=pFactory.CreateRegion(vtPoints);
pFea.SetStyle(m_MapX.GetDefaultStyle());
pFea=m_MapX.GetLayers().GetInsertionLayer().AddFeature(pFea);
m_MapX.GetLayers().GetInsertionLayer().GetSelection().Replace(pFea);
// m_MapX.GetLayers().GetInsertionLayer().Refresh();
return TRUE;
}
catch (COleDispatchException *e)
{
e->ReportError();
e->Delete();
}
catch (COleException *e)
{
e->ReportError();
e->Delete();
}
return FALSE;
}
charryli 2005-03-28
  • 打赏
  • 举报
回复
CMoLine polygon;
polygon.CreateDispatch(TEXT("MapObjects2.Polygon"));
CMoParts parts=polygon.GetParts();

CMoPoints points;
points.CreateDispatch(TEXT("MapObjects2.Points"));

CMoPoint point;
point.CreateDispatch(TEXT("MapObjects2.Point"));
point.SetX(m_trace_rectangle.GetLeft());
point.SetY(m_trace_rectangle.GetBottom());
points.Add(point);
point.SetX(m_trace_rectangle.GetRight());
point.SetY(m_trace_rectangle.GetBottom());
points.Add(point);
point.SetX(m_trace_rectangle.GetRight());
point.SetY(m_trace_rectangle.GetTop());
points.Add(point);
point.SetX(m_trace_rectangle.GetLeft());
point.SetY(m_trace_rectangle.GetTop());
points.Add(point);
parts.Add(points);

CMainFrame * pFrame;
pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
int index=pFrame->GetCurLayer();

CMoLayers layers = m_map.GetLayers();
CMoMapLayer layer(layers.Item(COleVariant(long(index))));
if(layer.GetLayerType()!=0)
return;
CMoRecordset recs(layer.GetRecords());

if(!recs.m_lpDispatch) return;
CMoFields fields(recs.GetFields());
try {
if(recs.GetSupportsTransactions())
recs.StartTransaction();
recs.AddNew();
SetValue(fields,"Shape",polygon.m_lpDispatch);
// SetValue(fields, "OBJECTID", (double)GetLayerMaxObjID(index));
// SetValue(fields, DEV_TYPE, (long)GetDevTypeID(layer.GetName()));
recs.Update();
if(recs.GetSupportsTransactions())
recs.CommitTransaction();
}
catch(CException *e) {
e->ReportError();
e->Delete();
recs.CancelUpdate();
recs.StopEditing();
return;
}
cloudrain 2005-03-23
  • 打赏
  • 举报
回复
补充一下:我用CMapXPoints对象先加入四个坐标点也出现Invalid points object错误提示

2,141

社区成员

发帖
与我相关
我的任务
社区描述
它是一种特定的十分重要的空间信息系统。它是在计算机硬、软件系统支持下,对整个或部分地球表层(包括大气层)空间中的有关地理分布数据进行采集、储存、管理、运算、分析、显示和描述的技术系统。
社区管理员
  • 地理信息系统
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧