我试了一下,生成的CAD是有数据的,用的是layer的themeToDatasetVector方法,没有问题啊。
你可以贴代码看看。
我的代码很简单,就这几行
themelabel.setUniformStyle(txtstyle); themelabel.setAlongLine(true); // mapcontrol1.getMap().getLayers().add(dset, themelabel, true).setVisible(true); mapcontrol1.getMap().refresh(); ltree.reload(); labelDialog.dispose(); //转CAD mapcontrol1.getMap().getLayers().get(0).themeToDatasetVector(workspace1. getDatasources().get(2), "CAD1");
8C可以,9D不行?我没有用过8C的iObjects Java,你能用8C弄出来说明你的代码可行啊。我才疏学浅,实在是想不到你弄不出来的原因。。。假如你自查到了,给我说说,学习一个。
你在你那里跑一下这个,看生成的CAD里面是否有数据?
import java.awt.Color; import java.io.File; import java.util.ArrayList; import java.util.List; import com.supermap.data.CursorType; import com.supermap.data.DatasetVector; import com.supermap.data.Datasource; import com.supermap.data.DatasourceConnectionInfo; import com.supermap.data.EngineType; import com.supermap.data.Recordset; import com.supermap.data.StringAlignment; import com.supermap.data.TextAlignment; import com.supermap.data.TextStyle; import com.supermap.data.Workspace; import com.supermap.data.WorkspaceConnectionInfo; import com.supermap.data.WorkspaceType; import com.supermap.mapping.Layer; import com.supermap.mapping.Map; import com.supermap.mapping.ThemeLabel; public class LineNoteAvoid { public static void main(String[] args) { String udbPath = "C:/Users/T470p/Desktop/VectrTile/NOTE/LINE.udb"; String workSpaceFile = "C:/Users/T470p/Desktop/VectrTile/NOTE/LINE.smwu"; Workspace workSpace = null; if (new File(workSpaceFile).exists()) { new File(workSpaceFile).delete(); } workSpace = createWorkspace(workSpaceFile); DatasourceConnectionInfo datasourceConnectionInfo = new DatasourceConnectionInfo(); datasourceConnectionInfo.setEngineType(EngineType.UDB); datasourceConnectionInfo.setServer(udbPath); datasourceConnectionInfo.setReadOnly(false); Datasource source = workSpace.getDatasources().open(datasourceConnectionInfo); source.getDatasets().delete("NOTE"); DatasetVector dataset = (DatasetVector)source.getDatasets().get(0); System.out.println("count:" + dataset.getRecordCount()); Map map = new Map(workSpace); ThemeLabel theme = new ThemeLabel(); // 设置注记取值字段 theme.setLabelExpression("NAME"); // 设置是否沿线显示文本 theme.setAlongLine(true); Layer layertheme = map.getLayers().add(dataset, theme, true); layertheme.setVisible(true); map.refresh(); map.setScale(0.0000007325520218248011745353122330772); layertheme.themeToDatasetVector(source, "NOTE"); map.refresh(); workSpace.getMaps().clear(); workSpace.getMaps().add("note", map.toXML()); workSpace.save(); List<NoteAvoidData> dataList = new ArrayList<NoteAvoidData>(); if(!source.getDatasets().contains("NOTE")){ System.out.println("未生成注记数据集"); }else{ DatasetVector noteSet = (DatasetVector)source.getDatasets().get("NOTE"); Recordset record = noteSet.getRecordset(false, CursorType.STATIC); System.out.println("生成注记数量:" + record.getRecordCount()); } workSpace.dispose(); } /** * * * @return */ public static TextStyle getTextStyle(){ TextStyle style = new TextStyle(); style.setFontName("宋体"); style.setAlignment(TextAlignment.TOPLEFT); style.setStringAlignment(StringAlignment.LEFT); style.setBackColor(Color.BLACK); style.setForeColor(Color.WHITE); style.setOutline(true); style.setSizeFixed(true); style.setFontHeight(3.8800705467372141); style.setFontWidth(0); style.setWeight(400); return style; } /** * * * @param workSpacePath */ public static Workspace openWorkspace(String workSpacePath) { Workspace workspace = new Workspace(); WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo(); workspaceConnectionInfo.setType(WorkspaceType.SMWU); workspaceConnectionInfo.setServer(workSpacePath); workspace.open(workspaceConnectionInfo); return workspace; } public static Workspace createWorkspace(String workSpacePath) { Workspace workspace = new Workspace(); WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo(); workspaceConnectionInfo.setType(WorkspaceType.SMWU); workspaceConnectionInfo.setServer(workSpacePath); workspace.create(workspaceConnectionInfo); return workspace; } }