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

VC+MO to Create Buffer

楼主#
更多 发布于:2004-10-10 16:34

My work.

Hope that it can help you.

The Function is as follows:

vector CreateBuffer(CMoRecordset; BufferRecords, double; BufferTolerance, int; BufferLayerStyle, string; BufferUnits) { vector 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; }

[此贴子已经被作者于2004-10-10 16:35:29编辑过]
喜欢0 评分0
愿意和大家交朋友! QQ:47559983 MSN:shaolun_yuan@hotmail.com eMail:shaolun-yuan@163.com
默认头像
路人甲
路人甲
  • 注册日期2004-09-19
  • 发帖数41
  • QQ
  • 铜币219枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2004-10-10 17:29

不用CComVariant用COleVariant不行吗?

我用CComVariant为什么说未定义?

俺还是个初学者,请多指教!先行谢过

举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2004-09-19
  • 发帖数41
  • QQ
  • 铜币219枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2004-10-11 09:49

我的代码是这样写的

CMoLine l; CMoLine g_searchLine; l=m_Map.TrackLine(); if(LPDISPATCH(l))  g_searchLine = l;

CMoPolygon shpBuffer; VARIANT va; VariantInit(;va); va.vt=VT_DISPATCH; va.pdispVal=g_searchLine.GetExtent().m_lpDispatch; shpBuffer=g_searchLine.Buffer(100,va);

为什么执行到最后一句shpBuffer=g_searchLine.Buffer(100,va);总是出错?还请多多指教

举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2003-12-25
  • 发帖数768
  • QQ28796446
  • 铜币27枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2004-10-11 11:37
西门吹血,有了鼓风机,就不用吹啦!
举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2003-08-08
  • 发帖数654
  • QQ164646905
  • 铜币1336枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2004-10-11 14:42
以下是引用mao__mao_在2004-10-10 17:29:24的发言:

不用CComVariant用COleVariant不行吗?

我用CComVariant为什么说未定义?

俺还是个初学者,请多指教!先行谢过

#include

then you can use CComVariant

you can see MSDN , to search CComVairant ,then you will find:

CComVariant Class

Requirements

Header: atlcomcli.h

This class wraps the VARIANT type, providing a member indicating the type of data stored.

class CComVariant : public tagVARIANT

Remarks

CComVariant wraps the VARIANT type, which consists of a union and a member indicating the type of the data stored in the union. VARIANTs are typically used in Automation.

CComVariant derives from the VARIANT type so it can be used wherever a VARIANT can be used. You can, for example, use the V_VT macro to extract the type of a CComVariant or you can access the vt member directly just as you can with a VARIANT.

Requirements

Header: atlcomcli.h

See Also

Class Members | ATL Class Overview

愿意和大家交朋友! 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
以下是引用mao__mao_在2004-10-11 9:49:02的发言:

我的代码是这样写的

CMoLine l; CMoLine g_searchLine; l=m_Map.TrackLine(); if(LPDISPATCH(l)) g_searchLine = l;

CMoPolygon shpBuffer; VARIANT va; VariantInit(;va); va.vt=VT_DISPATCH; va.pdispVal=g_searchLine.GetExtent().m_lpDispatch; shpBuffer=g_searchLine.Buffer(100,va);

为什么执行到最后一句shpBuffer=g_searchLine.Buffer(100,va);总是出错?还请多多指教

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 .

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 .

besides , i strongly suggest that you should use the standard C++ ,use CComVariant .

愿意和大家交朋友! QQ:47559983 MSN:shaolun_yuan@hotmail.com eMail:shaolun-yuan@163.com
举报 回复(0) 喜欢(0)     评分
默认头像
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15951
  • QQ
  • 铜币25345枚
  • 威望15368点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
6楼#
发布于:2004-10-11 17:50
强烈支持楼上兄弟的热情
GIS麦田守望者,期待与您交流。
举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2004-09-19
  • 发帖数41
  • QQ
  • 铜币219枚
  • 威望0点
  • 贡献值0点
  • 银元0个
7楼#
发布于:2004-10-11 19:19

先谢谢袁兄

其实相关的代码只有我贴出的这些。

我开始用的是COleVariant

先在CMoPolygon shpBuffer;后加入shpBuffer.CreateDispatch(TEXT("MapObjects2.Polygon"));

还是在shpBuffer=g_searchLine.Buffer(100,va);句出错,运行错误提示如下

Unhandled exception in map.exe(OLEAUT32.DLL):OxC000000 Access Violation

后又打算用CComVariant

结果在#include 后编译时提示我fatal error C1083: Cannot open include file: 'atlcomcli.h': No such file or directory

我改成#include "atlcomcli.h"也不行

真是愁人啊,还请列位高人多多指教!

举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2004-09-19
  • 发帖数41
  • QQ
  • 铜币219枚
  • 威望0点
  • 贡献值0点
  • 银元0个
8楼#
发布于:2004-10-12 15:00

搞定了,我用的是#include

再次多谢袁兄

举报 回复(0) 喜欢(0)     评分
默认头像
路人甲
路人甲
  • 注册日期2003-07-26
  • 发帖数111
  • QQ22278088
  • 铜币390枚
  • 威望0点
  • 贡献值0点
  • 银元0个
9楼#
发布于:2004-10-21 10:02
以下是引用袁绍伦在2004-10-10 16:34:06的发言:

My work.

Hope that it can help you.

The Function is as follows:

vector CreateBuffer(CMoRecordset; BufferRecords, double; BufferTolerance, int; BufferLayerStyle, string; BufferUnits) { vector 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; }

我想问一下其中的CMoRecordset; BufferRecords是怎么获取的,是对选中的目标进行获取的还是直接对一层数据进行buffer分析的?谢谢!我获取buffer总是空值.

举报 回复(0) 喜欢(0)     评分
上一页
默认头像

返回顶部