chenw_1979
路人甲
路人甲
  • 注册日期2006-04-03
  • 发帖数13
  • QQ
  • 铜币151枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1384回复:1

请较MO空间统计为什么不能进行,付代码

楼主#
更多 发布于:2006-04-03 11:57
<P>CMoMapLayer CObjectSearch::CreateShpFile(CString ;ShpFilePath, int ShpFileStyle,vector<lpMoFieldInfo> fieldDesc)<BR>{<BR> Logf("创建SHAPE文件:%s.....",ShpFilePath);<BR> CMoDataConnection conn;<BR> if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection")))<BR> {<BR>  Logf("失败!Error:%s\n",TEXT("创建连接失败"));<BR>  return NULL;<BR> }<BR> CString strFileTitle( ShpFilePath );<BR> int idx = 0;<BR> while ( idx != -1 )<BR> {<BR>  idx = strFileTitle.Find( "\\" );<BR>  strFileTitle = strFileTitle.Right( strFileTitle.GetLength() - idx - 1 );<BR> }<BR> idx = ShpFilePath.Find( strFileTitle );<BR> CString strFilePath( ShpFilePath.Left( idx ) );<BR> conn.SetDatabase( strFilePath );<BR> if (!conn.Connect())<BR> {<BR>  Logf("失败!Error:%s\n",TEXT("连接失败"));<BR>  return NULL;<BR> }<BR> CMoTableDesc tDesc;<BR> if (!tDesc.CreateDispatch(TEXT("MapObjects2.TableDesc")))<BR> {<BR>  Logf("失败!Error:%s\n",TEXT("创建表失败"));<BR>  return NULL;<BR> }<BR> tDesc.SetFieldCount(fieldDesc.size());<BR> vector<lpMoFieldInfo>::const_iterator itor;<BR> int index = 0;<BR> for(itor = fieldDesc.begin();itor != fieldDesc.end();++itor)<BR> {<BR>  if((*itor)->fieldType == moString)<BR>  {<BR>   tDesc.SetFieldType(index,moString);<BR>   tDesc.SetFieldName(index, (*itor)->fieldName);<BR>   tDesc.SetFieldLength(index, (*itor)->fieldLength);<BR>  }<BR>  else if((*itor)->fieldType == moLong)<BR>  {<BR>   tDesc.SetFieldType(index,moLong);<BR>   tDesc.SetFieldName(index, (*itor)->fieldName);<BR>   tDesc.SetFieldPrecision(index, (*itor)->fieldPrecision);<BR>  }<BR>  else if((*itor)->fieldType == moDouble)<BR>  {<BR>   tDesc.SetFieldType(index,moDouble);<BR>   tDesc.SetFieldName(index,(*itor)->fieldName);<BR>   tDesc.SetFieldPrecision(index,(*itor)->fieldPrecision);<BR>   tDesc.SetFieldScale(index, (*itor)->fieldScale);<BR>  }<BR>  index++;<BR> }</P>
<P> CMoGeoDataset Geoset;<BR> if (!Geoset.CreateDispatch(TEXT("MapObjects2.DataConnection")))<BR> {<BR>  Logf("失败!Error:%s\n",TEXT("创建记录集失败"));<BR>  return NULL;<BR> }<BR> VARIANT v;<BR> ::VariantInit(;v);<BR> v.vt = VT_BOOL;<BR> v.boolVal = VARIANT_TRUE;<BR> Geoset = conn.AddGeoDataset(strFileTitle, ShpFileStyle, tDesc, v, v);<BR> ::VariantClear(;v);<BR> CMoMapLayer TempMapLayer;<BR> if (!TempMapLayer.CreateDispatch(TEXT("MapObjects2.MapLayer")))<BR> {<BR>  Logf("失败!Error:%s\n",TEXT("创建图层失败"));<BR>  return NULL;<BR> }</P>
<P> TempMapLayer.SetGeoDataset(Geoset);<BR> Logf("成功!\n");</P>
<P> for(int i=0;i<fieldDesc.size();i++)<BR> {<BR>  delete fieldDesc.at(i);<BR> }<BR> fieldDesc.clear();</P>
<P> return TempMapLayer;<BR>}</P>

<P>static DWORD WINAPI CaculateLayerObjectProc(LPVOID param)<BR>{<BR> lpCaculateParam p = (lpCaculateParam)param;<BR> ASSERT(p != NULL);<BR> CMap1 *pMap = (CMap1*)p->pMap;<BR> if(pMap == NULL)<BR>  return 0;</P>
<P> CString path;<BR> path.Format("%s",p->sShpFilePath);<BR> //获得缓存图形<BR> vector<lpCaculateBuffer>::const_iterator itor;<BR> vector<lpCpyInfo>::const_iterator itorCpyInfoBuffer;<BR> vector<lpCpyFieldInfo>::const_iterator itorCpyFieldBuffer;</P>
<P> for( itor = p->buffer.begin(); itor != p->buffer.end(); ++itor )<BR> {<BR>  ::SendMessage(p->hCaculateWnd,PROGRESS_POS_SET_MSG,0,0);<BR>  <BR>  //创建目标图层并清空<BR>  CString bufferShpFile;<BR>  bufferShpFile.Format("%s\\%s",path,(*itor)->layerName);</P>
<P>  CMoMapLayer BufferResultMapLayer(CObjectSearch::CreateShpFile(bufferShpFile,(*itor)->layerType,(*itor)->lyTableDesc));<BR>  CMoRecordset BufferResc = BufferResultMapLayer.GetRecords();<BR>  BufferResc.MoveFirst();<BR>  while(!BufferResc.GetEof())<BR>  {<BR>   BufferResc.Delete();<BR>   BufferResc.MoveNext();<BR>  }<BR>  <BR>  //过滤图形数据<BR>  int pos = 0,index=1;<BR>  long bufferSize = (*itor)->cpyInfoBuffer.size();</P>
<P>  ::SendMessage(p->hCaculateWnd,PROGRESS_POS_SET_MSG,pos,0);<BR>  switch((*itor)->layerType)<BR>  {<BR>  case 21:<BR>   {<BR>    index = 1;<BR>    for( itorCpyInfoBuffer = (*itor)->cpyInfoBuffer.begin(); itorCpyInfoBuffer != (*itor)->cpyInfoBuffer.end(); ++itorCpyInfoBuffer )<BR>    {<BR>     BufferResc.AddNew();<BR>     for( itorCpyFieldBuffer = (*itorCpyInfoBuffer)->cpyFieldBuffer.begin(); itorCpyFieldBuffer != (*itorCpyInfoBuffer)->cpyFieldBuffer.end(); ++itorCpyFieldBuffer )<BR>     {<BR>      CString sFieldName  = (*itorCpyFieldBuffer)->fieldName;<BR>      VARIANT vFieldValue = (*itorCpyFieldBuffer)->fieldValue;<BR>      BufferResc.GetFields().Item(COleVariant(sFieldName)).SetValue(vFieldValue);<BR>     }<BR>     BufferResc.Update();</P>
<P>     pos = int(index * 100.0 / bufferSize);<BR>     ::SendMessage(p->hCaculateWnd,PROGRESS_POS_SET_MSG,pos,0);<BR>     index++;<BR>    }<BR>    break;<BR>   }<BR>  case 22:<BR>   {<BR>    index = 1;<BR>    for( itorCpyInfoBuffer = (*itor)->cpyInfoBuffer.begin(); itorCpyInfoBuffer != (*itor)->cpyInfoBuffer.end(); ++itorCpyInfoBuffer )<BR>    {<BR>     BufferResc.AddNew();<BR>     for( itorCpyFieldBuffer = (*itorCpyInfoBuffer)->cpyFieldBuffer.begin(); itorCpyFieldBuffer != (*itorCpyInfoBuffer)->cpyFieldBuffer.end(); ++itorCpyFieldBuffer )<BR>     {<BR>      CString sFieldName  = (*itorCpyFieldBuffer)->fieldName;<BR>      VARIANT vFieldValue = (*itorCpyFieldBuffer)->fieldValue;<BR>      BufferResc.GetFields().Item(CComVariant(sFieldName)).SetValue(vFieldValue);<BR>     }</P>
<P>     BufferResc.Update();</P>
<P>     pos = int(index * 100.0 / bufferSize);<BR>     ::SendMessage(p->hCaculateWnd,PROGRESS_POS_SET_MSG,pos,0);<BR>     index++;<BR>    }</P>
<P>    break;<BR>   }<BR>  case 23:<BR>   {<BR>    break;<BR>   }<BR>  }</P>
<P>  ::SendMessage(p->hCaculateWnd,PROGRESS_POS_SET_MSG,0,0);<BR> }<BR> Logf("统计区域对象完毕!....\n");<BR> return 1;<BR>}<BR></P>
<P>//返回计算线程句柄<BR>HANDLE CObjectSearch::StartCaculateObject(HWND hCaculateWnd,LPDISPATCH pPoly,CString tempPath,vector<CString> srLyArray)<BR>{</P>
<P>.........</P>
<P>HANDLE hThread = CreateThread(NULL,0,CaculateLayerObjectProc,pParam,0,;threadID);</P>
<P>.........</P>
<P>}</P>
喜欢0 评分0
fanxing_gis
路人甲
路人甲
  • 注册日期2006-04-05
  • 发帖数5
  • QQ
  • 铜币120枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2006-04-06 18:01
<P>有没有VB代码?</P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部