|
[GIS资料] MapX4.5实现表紧缩
年做了MapX方面的毕业设计,现在找到这个方面的资料,和大家共享。下面是转贴。
MapX4.5实现表紧缩
CMapXLayer layer = m_ctrlMapX.GetLayers().Item(m_ctrlMapX.GetLayers().GetCount());
VARIANT vtLayer;
vtLayer.vt = VT_DISPATCH;
vtLayer.pdispVal = layer.m_lpDispatch;
CMapXDataset dataSet = m_ctrlMapX.GetDatasets().Add(miDataSetLayer, vtLayer,"pack");
CString dsname = m_ctrlMapX.GetDatasets().Item(1).GetName();
CString layername = layer.GetName();
CString layerFilespec = layer.GetFilespec();
//将layer上的内容复制到临时表中
CMapXLayerInfo m_LayerInfo;
m_LayerInfo.CreateDispatch(m_LayerInfo.GetClsid());
m_LayerInfo.SetType(6); //临时表(miLayerInfoTypeTemp)
VARIANT vtparam1;
vtparam1.vt = VT_BSTR;
vtparam1.bstrVal = CString("MemTable").AllocSysString();
m_LayerInfo.AddParameter("TableStorageType", vtparam1);
VARIANT vtparam2;
vtparam2.vt = VT_BSTR;
vtparam2.bstrVal = CString("lyrpack").AllocSysString();
m_LayerInfo.AddParameter("Name", vtparam2);
VARIANT m_Fields;
CMapXFields n_Fields;
n_Fields.CreateDispatch(n_Fields.GetClsid());
n_Fields=dataSet.GetFields();
m_Fields.vt = VT_DISPATCH;
m_Fields.pdispVal = n_Fields.m_lpDispatch;
m_LayerInfo.AddParameter("Fields", m_Fields);
VARIANT m_Features;
CMapXFeatures n_Features=layer.AllFeatures();
m_Features.vt = VT_DISPATCH;
m_Features.pdispVal=n_Features.m_lpDispatch;
m_LayerInfo.AddParameter("Features", m_Features);
CMapXLayer packlyr = m_ctrlMapX.GetLayers().Add(m_LayerInfo);
//已将layer复制到临时表中
//从地图窗口
m_ctrlMapX.GetDatasets().Remove("pack");
m_ctrlMapX.GetLayers().Remove(layername);
//创建dataset for packlyr
vtLayer.vt = VT_DISPATCH;
vtLayer.pdispVal = packlyr.m_lpDispatch;
dataSet = m_ctrlMapX.GetDatasets().Add(miDataSetLayer, vtLayer,"pack");
//创建新表
CMapXLayerInfo newlayerInfo;
newlayerInfo.CreateDispatch(newlayerInfo.GetClsid());
newlayerInfo.SetType(7); //新表(miLayerInfoTypeNewTalbe)
newlayerInfo.AddParameter("filespec",COleVariant(layerFilespec));
newlayerInfo.AddParameter("Name", COleVariant(layername));
n_Fields=dataSet.GetFields();
m_Fields.vt = VT_DISPATCH;
m_Fields.pdispVal = n_Fields.m_lpDispatch;
newlayerInfo.AddParameter("Fields", m_Fields);
CMapXFeatures features = packlyr.AllFeatures();
VARIANT fs;
fs.vt = VT_DISPATCH;
fs.pdispVal=features.m_lpDispatch;
newlayerInfo.AddParameter("features",fs);
newlayerInfo.AddParameter("OverwriteFile",COleVariant("1"));
long lPosition = 4;//m_ctrlMapX.GetLayers().GetCount();
VARIANT newlyr;
newlyr.vt=VT_DISPATCH;
newlyr.pdispVal=newlayerInfo.m_lpDispatch;
VARIANT lp;
lp.vt = VT_I4;
lp.lVal = lPosition;
m_ctrlMapX.GetLayers().Add(newlayerInfo.m_lpDispatch);
m_ctrlMapX.GetLayers().Move(2,(short)m_ctrlMapX.GetLayers().GetCount());
//删除临时表
m_ctrlMapX.GetDatasets().Remove("pack");
m_ctrlMapX.GetLayers().Remove("lyrpack"); |
|