|
在 delphi 中紧缩表
//紧缩表
procedure PackTable(LayerName:string;SourceMap:TMapackMap:TMap);
var
lyr:CMapXLayer;
Ds:CMapXDataSet;
LayerInfo:CMapXLayerInfo;
TempLayerName,Path:String;
begin
Try
TempLayerName := 'TempPackTable';
Lyr := SourceMap.Layers.Item(LayerName);
ds := SourceMap.Datasets.Item(LayerName);
//选定图层的存放路径
Path := SourceMap.Layers.Item(LayerName).Filespec;
//创建临时表
LayerInfo := CoLayerInfo.Create;
LayerInfo.Type_ := miLayerInfoTypeTemp;
LayerInfo.AddParameter ('filespec', path);
LayerInfo.AddParameter ('Name', TempLayerName);
LayerInfo.AddParameter ('Fields', ds.Fields);
LayerInfo.AddParameter ('Features', lyr.AllFeatures);
LayerInfo.AddParameter ('AutoCreateDataset', 1);
LayerInfo.AddParameter ('datasetname', TempLayerName);
PackMap.Layers.add (LayerInfo, 0);
PackMap.Refresh;
//移出图层
SourceMap.Datasets.Remove (LayerName);
SourceMap.Layers.Remove (LayerName);
SourceMap.Refresh;
//删除 Tab 表文件
DeleteFile(Path);
//重新绑定
Lyr := PackMap.Layers.Item(TempLayerName);
ds := PackMap.Datasets.Item(TempLayerName);
//创建表
LayerInfo := CoLayerInfo.Create;
LayerInfo.Type_ := miLayerInfoTypeNewTable;
LayerInfo.AddParameter ('filespec', path);
LayerInfo.AddParameter ('Name', layername);
LayerInfo.AddParameter ('Fields', ds.Fields);
LayerInfo.AddParameter ('Features', lyr.AllFeatures);
LayerInfo.AddParameter ('AutoCreateDataset', 1);
LayerInfo.AddParameter ('datasetname', LayerName);
SourceMap.Layers.add (LayerInfo, 0);
SourceMap.Refresh;
//移出图层
PackMap.Datasets.Remove (TempLayerName);
PackMap.Layers.Remove (TempLayerName);
PackMap.Refresh;
except
on E:Exception do ShowMessage(E.message);
end;
end; |
|