袁绍伦
路人甲
路人甲
  • 注册日期2003-08-08
  • 发帖数654
  • QQ164646905
  • 铜币1336枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:4553回复:11

VC+MO to Create Buffer

楼主#
更多 发布于:2004-10-10 16:34
<P><FONT color=#ff0000>My work. </FONT></P>
<P><FONT color=#ff0000>Hope that it can help you.</FONT></P>
<P><FONT color=#ff0000>The Function is as follows:</FONT></P>
<P>vector<CMoPolygon> CreateBuffer(CMoRecordset; BufferRecords, double; BufferTolerance, int; BufferLayerStyle, string; BufferUnits)
{
vector<CMoPolygon> TempVectorPoly;
CComVariant Extent(m_map.GetFullExtent().m_lpDispatch);
if (BufferUnits == "千米")
  BufferTolerance = 1000 * BufferTolerance;
  
switch (BufferLayerStyle)
{
case 0://点图层
  {
   BufferRecords.MoveFirst();
   while (!BufferRecords.GetEof())
   {
    CMoPoint point(BufferRecords.GetFields().Item(CComVariant("Shape")).GetValue().pdispVal);
    CMoPolygon PolygonBuffer(point.Buffer(BufferTolerance,Extent));
    TempVectorPoly.push_back(PolygonBuffer);
    BufferRecords.MoveNext();
   }
   break;
  }
case 1://线图层
  {
   BufferRecords.MoveFirst();
   while (!BufferRecords.GetEof())
   {
    CMoLine line(BufferRecords.GetFields().Item(CComVariant("Shape")).GetValue().pdispVal);
    CMoPolygon PolygonBuffer(line.Buffer(BufferTolerance,Extent));
    TempVectorPoly.push_back(PolygonBuffer);
    BufferRecords.MoveNext();  
   }
   break;
  }
case 2://面图层
  {
   BufferRecords.MoveFirst();
   while (!BufferRecords.GetEof())
   {
    CMoPolygon Polygon(BufferRecords.GetFields().Item(CComVariant("Shape")).GetValue().pdispVal);
    CMoPolygon PolygonBuffer(Polygon.Buffer(BufferTolerance,Extent));
    TempVectorPoly.push_back(PolygonBuffer);
    BufferRecords.MoveNext();  
   }
   break;
  }
}
return TempVectorPoly;
}</P>
[此贴子已经被作者于2004-10-10 16:35:29编辑过]
喜欢0 评分0
愿意和大家交朋友! QQ:47559983 MSN:shaolun_yuan@hotmail.com eMail:shaolun-yuan@163.com
mao__mao_
路人甲
路人甲
  • 注册日期2004-09-19
  • 发帖数41
  • QQ
  • 铜币219枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2004-10-10 17:29
<P>不用CComVariant用COleVariant不行吗?</P><P>我用CComVariant为什么说未定义?</P><P>俺还是个初学者,请多指教!先行谢过</P>
举报 回复(0) 喜欢(0)     评分
mao__mao_
路人甲
路人甲
  • 注册日期2004-09-19
  • 发帖数41
  • QQ
  • 铜币219枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2004-10-11 09:49
<P>我的代码是这样写的</P>
<P>CMoLine l;
CMoLine g_searchLine;
l=m_Map.TrackLine();
if(LPDISPATCH(l))
 g_searchLine = l;</P>
<P>CMoPolygon shpBuffer;
VARIANT va;
VariantInit(;va);
va.vt=VT_DISPATCH;
va.pdispVal=g_searchLine.GetExtent().m_lpDispatch;
shpBuffer=g_searchLine.Buffer(100,va);</P>
<P>为什么执行到最后一句shpBuffer=g_searchLine.Buffer(100,va);总是出错?还请多多指教</P>
举报 回复(0) 喜欢(0)     评分
lixaokui
路人甲
路人甲
  • 注册日期2003-12-25
  • 发帖数768
  • QQ28796446
  • 铜币27枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2004-10-11 11:37
<img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" /><img src="images/post/smile/dvbbs/em01.gif" />
西门吹血,有了鼓风机,就不用吹啦!
举报 回复(0) 喜欢(0)     评分
袁绍伦
路人甲
路人甲
  • 注册日期2003-08-08
  • 发帖数654
  • QQ164646905
  • 铜币1336枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2004-10-11 14:42
<DIV class=quote><B>以下是引用<I>mao__mao_</I>在2004-10-10 17:29:24的发言:</B>

<P>不用CComVariant用COleVariant不行吗?</P>
<P>我用CComVariant为什么说未定义?</P>
<P>俺还是个初学者,请多指教!先行谢过</P></DIV>
<P>
<P>#include <atlcomcli.h></P>
<P>then you can use CComVariant </P>
<P>you can see MSDN , to search CComVairant ,<FONT color=#ff0000>then you will find:</FONT></P>
<DIV>
<H1>CComVariant Class</H1></DIV>
<DIV>
<H4>See Also</H4>
<P><a href="ms-help://MS.MSDNQTR.2003FEB.2052/vclib/html/_atl_ccomvariant_class_members.htm" target="_blank" >Class Members</A> | <a href="ms-help://MS.MSDNQTR.2003FEB.2052/vclib/html/_atl_atl_class_overview.htm" target="_blank" >ATL Class Overview</A></P><!--Footer Start--></DIV>
<DIV>
<H4>Requirements</H4>
<P><B>Header: </B>atlcomcli.h</P></DIV><!--NONSCROLLING BANNER END-->
<DIV>
<DIV></DIV><!-- Topic Status -->
<P>This class wraps the VARIANT type, providing a member indicating the type of data stored.</P><PRE><B>class CComVariant : public tagVARIANT</B></PRE>
<H4>Remarks</H4>
<P><B>CComVariant</B> wraps the <MSHelp:link tabIndex=0 keywords="_oa96_VARIANT_and_VARIANTARG">VARIANT</MSHelp:link> type, which consists of a union and a member indicating the type of the data stored in the union. <B>VARIANT</B>s are typically used in Automation.</P>
<P><B>CComVariant</B> derives from the <B>VARIANT</B> type so it can be used wherever a <B>VARIANT</B> can be used. You can, for example, use the <B>V_VT</B> macro to extract the type of a <B>CComVariant</B> or you can access the <B>vt</B> member directly just as you can with a <B>VARIANT</B>.</P>
<H4>Requirements</H4>
<P><B>Header: </B>atlcomcli.h</P>
<H4>See Also</H4>
<P><a href="ms-help://MS.MSDNQTR.2003FEB.2052/vclib/html/_atl_ccomvariant_class_members.htm" target="_blank" >Class Members</A> | <a href="ms-help://MS.MSDNQTR.2003FEB.2052/vclib/html/_atl_atl_class_overview.htm" target="_blank" >ATL Class Overview</A></P><!--Footer Start--></DIV>
愿意和大家交朋友! QQ:47559983 MSN:shaolun_yuan@hotmail.com eMail:shaolun-yuan@163.com
举报 回复(0) 喜欢(0)     评分
袁绍伦
路人甲
路人甲
  • 注册日期2003-08-08
  • 发帖数654
  • QQ164646905
  • 铜币1336枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2004-10-11 14:49
<DIV class=quote><B>以下是引用<I>mao__mao_</I>在2004-10-11 9:49:02的发言:</B>

<P>我的代码是这样写的</P>
<P>CMoLine l;
CMoLine g_searchLine;
l=m_Map.TrackLine();
if(LPDISPATCH(l))
g_searchLine = l;</P>
<P>CMoPolygon shpBuffer;
VARIANT va;
VariantInit(;va);
va.vt=VT_DISPATCH;
va.pdispVal=g_searchLine.GetExtent().m_lpDispatch;
shpBuffer=g_searchLine.Buffer(100,va);</P>
<P>为什么执行到最后一句shpBuffer=g_searchLine.Buffer(100,va);总是出错?还请多多指教</P></DIV>
<P>i can't find the error if you give me only these codes. but i think maybe the reason is you haven't create the shpBuffer using the "CreateDispatch" mothed. i am not sure. suggest you have a try .
<P>and variant is also ok ,but i haven't used it ,i have no time to try. you can do it by yourself. or ask somebody who have used it .
<P>besides , i strongly suggest that you should use the standard C++ ,use CComVariant . </P>
愿意和大家交朋友! QQ:47559983 MSN:shaolun_yuan@hotmail.com eMail:shaolun-yuan@163.com
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
6楼#
发布于:2004-10-11 17:50
强烈支持楼上兄弟的热情
举报 回复(0) 喜欢(0)     评分
mao__mao_
路人甲
路人甲
  • 注册日期2004-09-19
  • 发帖数41
  • QQ
  • 铜币219枚
  • 威望0点
  • 贡献值0点
  • 银元0个
7楼#
发布于:2004-10-11 19:19
<P>先谢谢袁兄</P><P>其实相关的代码只有我贴出的这些。</P><P>我开始用的是COleVariant</P><P>先在CMoPolygon shpBuffer;后加入shpBuffer.CreateDispatch(TEXT("MapObjects2.Polygon"));</P><P>还是在shpBuffer=g_searchLine.Buffer(100,va);句出错,运行错误提示如下</P><P>Unhandled exception in map.exe(OLEAUT32.DLL):OxC000000 Access Violation</P><P>后又打算用CComVariant</P><P>结果在#include <atlcomcli.h>后编译时提示我fatal error C1083: Cannot open include file: 'atlcomcli.h': No such file or directory</P><P>我改成#include "atlcomcli.h"也不行</P><P>真是愁人啊,还请列位高人多多指教!</P>
举报 回复(0) 喜欢(0)     评分
mao__mao_
路人甲
路人甲
  • 注册日期2004-09-19
  • 发帖数41
  • QQ
  • 铜币219枚
  • 威望0点
  • 贡献值0点
  • 银元0个
8楼#
发布于:2004-10-12 15:00
<P>搞定了,我用的是#include <atlbase.h></P><P>再次多谢袁兄</P><img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
ifbut
路人甲
路人甲
  • 注册日期2003-07-26
  • 发帖数111
  • QQ22278088
  • 铜币390枚
  • 威望0点
  • 贡献值0点
  • 银元0个
9楼#
发布于:2004-10-21 10:02
<DIV class=quote><B>以下是引用<I>袁绍伦</I>在2004-10-10 16:34:06的发言:</B>

<P><FONT color=#ff0000>My work. </FONT></P>
<P><FONT color=#ff0000>Hope that it can help you.</FONT></P>
<P><FONT color=#ff0000>The Function is as follows:</FONT></P>
<P>vector<CMoPolygon> CreateBuffer(CMoRecordset; BufferRecords, double; BufferTolerance, int; BufferLayerStyle, string; BufferUnits)
{
vector<CMoPolygon> TempVectorPoly;
CComVariant Extent(m_map.GetFullExtent().m_lpDispatch);
if (BufferUnits == "千米")
  BufferTolerance = 1000 * BufferTolerance;
  
switch (BufferLayerStyle)
{
case 0://点图层
  {
   BufferRecords.MoveFirst();
   while (!BufferRecords.GetEof())
   {
    CMoPoint point(BufferRecords.GetFields().Item(CComVariant("Shape")).GetValue().pdispVal);
    CMoPolygon PolygonBuffer(point.Buffer(BufferTolerance,Extent));
    TempVectorPoly.push_back(PolygonBuffer);
    BufferRecords.MoveNext();
   }
   break;
  }
case 1://线图层
  {
   BufferRecords.MoveFirst();
   while (!BufferRecords.GetEof())
   {
    CMoLine line(BufferRecords.GetFields().Item(CComVariant("Shape")).GetValue().pdispVal);
    CMoPolygon PolygonBuffer(line.Buffer(BufferTolerance,Extent));
    TempVectorPoly.push_back(PolygonBuffer);
    BufferRecords.MoveNext();  
   }
   break;
  }
case 2://面图层
  {
   BufferRecords.MoveFirst();
   while (!BufferRecords.GetEof())
   {
    CMoPolygon Polygon(BufferRecords.GetFields().Item(CComVariant("Shape")).GetValue().pdispVal);
    CMoPolygon PolygonBuffer(Polygon.Buffer(BufferTolerance,Extent));
    TempVectorPoly.push_back(PolygonBuffer);
    BufferRecords.MoveNext();  
   }
   break;
  }
}
return TempVectorPoly;
}</P>
</DIV>
<P>
<P>我想问一下其中的CMoRecordset; BufferRecords是怎么获取的,是对选中的目标进行获取的还是直接对一层数据进行buffer分析的?谢谢!我获取buffer总是空值.</P>
举报 回复(0) 喜欢(0)     评分
上一页
游客

返回顶部