发表用户:讨论贴
收集整理:James.Liu
相关讨论:http://www.mygis.com.cn/forum/dispbbs.asp?boardID=4&ID=8052
信息原始来源:James MapInfo技术论坛

文章标题:画线求助,怎样使线圆滑?

jeason

我想做gis的光纤管理系统,现在我已经有了光纤每隔5米的经纬度,我怎样画在我的地图上啊?我用了如下代码(vc+mapX),能画出线来,但画出的是一个一个的小折线,并不是那种和光纤的线路走势相同的圆滑的线路,请问我应该怎么做?哪位救救我啊????
//以下用于改变线型
    CMapXStyle s;
 s = m_Map->m_MapXInit->GetLayers().Item(2).GetStyle().Clone();
 // Let the user modify the style
 s.PickLine();
 
 //改变线性结束
 extern _ConnectionPtr m_pConnection;
 _RecordsetPtr m_pRecordset;
 _variant_t RecordsAffected;
 m_pRecordset.CreateInstance("ADODB.Recordset");
 m_pRecordset=m_pConnection->Execute("select * from gisline",&RecordsAffected,adCmdText);
 long count=m_pRecordset->RecordCount;
 while(!m_pRecordset->adoEOF)
 {
  CMapXFeature obj,newobj;
  CMapXPoints pts;
  CMapXPoint pt;
  if(!newobj.CreateDispatch(newobj.GetClsid())) {
   TRACE0("Failed to create Feature object");
   return;
  }
  if(!pts.CreateDispatch(pts.GetClsid())) {
   TRACE0("Failed to create Points collection");
   return;
  }
  if(!pt.CreateDispatch(pt.GetClsid())) {
   TRACE0("Failed to create Point object");
   return;
   
  }
  CMapXLayer layer;
  //设置该图层可编辑
  layer.SetEditable(TRUE);
  //设置该地图的可编辑图层为lyrinsertion
  m_Map->m_MapXInit->GetLayers().SetInsertionLayer(layer);
  
  try {
   newobj.Attach(m_Map->m_MapXInit->GetDispatch());
   newobj.SetType(miFeatureTypeLine);
   
   //以下用于改变线型
   // CMapXStyle s;
   // s = m_Map->m_MapXInit->GetLayers().Item(2).GetStyle().Clone();
   // Let the user modify the style
   // s.PickLine();
   
   //改变线性结束
   
   newobj.SetStyle(s); // Use the map's default symbol stylezz
   int a,b;
   _variant_t value1 =m_pRecordset->GetCollect("line_startpoint");
   a=value1.intVal;
   _variant_t value2 =m_pRecordset->GetCollect("line_endpoint");
   b=value2.intVal;
   CString s1,s2;
   s1.Format("%d",a);
   s2.Format("%d",b);
   
   _RecordsetPtr m_pRecordset2;
   _variant_t RecordsAffected2;
   m_pRecordset2.CreateInstance("ADODB.Recordset");
   _bstr_t bsr="select * from gispoint where point_id='"+s1+"'";
   m_pRecordset2=m_pConnection->Execute(bsr,&RecordsAffected2,adCmdText);
   while (!m_pRecordset2->adoEOF)
   {
    double x1,y1,x2,y2;
    _variant_t value=m_pRecordset2->GetCollect("point_posx");
    x1=value.dblVal;
    value=m_pRecordset2->GetCollect("point_posy");
    y1=value.dblVal;
    pt.Set(x1,y1);
    pts.Add(pt);
    _bstr_t bsr2="select * from gispoint where point_id='"+s2+"'";
    m_pRecordset2=m_pConnection->Execute(bsr2,&RecordsAffected2,adCmdText);
    value=m_pRecordset2->GetCollect("point_posx");
    x2=value.dblVal;
    value=m_pRecordset2->GetCollect("point_posy");
    y2=value.dblVal;
    pt.Set(x2,y2);
    pts.Add(pt);
    newobj.GetParts().Add(pts);
    obj = m_Map->m_MapXInit->GetLayers().Item("line1").AddFeature(newobj);
    m_pRecordset2->MoveNext();
   }
   m_pRecordset2->Close();
  } 
  catch (COleDispatchException *e)
  {
   e->ReportError();
   e->Delete();
   
  } 
  catch (COleException *e)
  {
   e->ReportError();
   e->Delete();
  }
  
  
  
  m_pRecordset->MoveNext();///移到下一条记录
 }
 m_pRecordset->Close();
  

rodger

问题有两个,一个就是你的图层的分辨率。因为mapinfo使用ieee的float,所以,如果你选取的长度单位是km,精度就很难达到你的要求,结果就是曲曲折折的。就算单位是mm也不可能在放到足够大的时候保证平滑。
另外,如果你的点确实很密,就像你说的5m一个,那么 完全可以在让曲线自动平滑,近似成b线,或者给出一个近似直线的阈值,将阈值内的节点统统取消,就不会出现那种折线了