1.WrapjGeo.dll文件存在
2.我下载的是这个压缩包 SMO_Java_810_14127_58257_64_x64_win_vc11_Bin 系统是64位的,bin_x64的目录是指哪个bin目录?
3.这个工程只引用了com.supermap.data 这个jar包,而且路径是一致的。
package test.supermap;
import com.supermap.data.Datasource;import com.supermap.data.Workspace;import com.supermap.data.*;
public class EditData { private static Datasource datasource; public static void main(String[] args) { // System.setProperties("D:/tools/SuperMap/Bin"); System.out.println(System.getProperty("java.library.path")); // 打开数据源 Workspace workspace = new Workspace(); DatasourceConnectionInfo info = new DatasourceConnectionInfo(); info.setServer("C:/Users/admin/Desktop/supermap for java/editData/testData/test.udb"); info.setEngineType(EngineType.UDB); datasource = workspace.getDatasources().open(info); if (datasource!=null) { //从后台传过来的点要存储在点数据集中,如果没有对应的点数据集,创建一个点数据集,其坐标系和数据源的坐标系一致 createDataset(); } } private static void createDataset(){ DatasetVectorInfo dvinfo = new DatasetVectorInfo(); dvinfo.setType(DatasetType.POINT); dvinfo.setName("test_point"); DatasetVector datasetpoint = datasource.getDatasets().create(dvinfo); if (datasetpoint!=null) { System.out.println("点数据集创建成功!!"); //向创建的数据集中添加点对象,这个点对象可以是后台传过来的 addPoint(datasetpoint); } } private static void addPoint(DatasetVector point){ //添加5个点,点的来源可以不同,这里随意构建了5个点 Point2D point2d1 = new Point2D(1,2); Point2D point2d2 = new Point2D(3,2); Point2D point2d3 = new Point2D(4,5); Point2D point2d4 = new Point2D(3,6); Point2D point2d5 = new Point2D(6,6); Point2Ds point2Ds = new Point2Ds(); point2Ds.add(point2d1); point2Ds.add(point2d2); point2Ds.add(point2d3); point2Ds.add(point2d4); point2Ds.add(point2d5); Recordset recordset = point.getRecordset(false, CursorType.DYNAMIC); recordset.moveFirst(); for (int i = 0; i < point2Ds.getCount(); i++) { GeoPoint geoPoint = new GeoPoint(point2Ds.getItem(i)); recordset.addNew(geoPoint); recordset.update(); } System.out.println(recordset.getRecordCount()); //添加一个自定义字段 addFieldinfo(point); }
private static void addFieldinfo(DatasetVector point){ FieldInfo fieldinfo = new FieldInfo(); fieldinfo.setName("name"); fieldinfo.setType(FieldType.TEXT); fieldinfo.setRequired(true); fieldinfo.setCaption("testname"); fieldinfo.setDefaultValue("测试"); FieldInfos fieldInfos = point.getFieldInfos(); int count = fieldInfos.getCount(); fieldInfos.add(fieldinfo); Recordset recordset = point.getRecordset(false, CursorType.DYNAMIC); if (fieldInfos.get(count).getName().equals("name")) { System.out.println("自定义字段创建成功!!"); //修改字段值 editField(recordset); } } private static void editField(Recordset recordset){ recordset.moveFirst(); while (!recordset.isEOF()) { recordset.edit(); recordset.setFieldValue("name", "超图"); recordset.update(); recordset.moveNext(); } //用完recordset,关闭并释放 recordset.close(); recordset.dispose(); }
}
这是我的代码,而且我电脑上也只有这一个版本的bin目录,所以不会存在版本不一致的情况,你知道IObject java有没有相关的开发文档可供参考。
recordset.moveFirst(); for (int i = 0; i < point2Ds.getCount(); i++) { GeoPoint geoPoint = new GeoPoint(point2Ds.getItem(i)); recordset.addNew(geoPoint); recordset.update(); }
这段代码有点小问题,recordset.update();可以现在循环外部,另外对于批量添加记录和字段可用这个类Recordset.BatchEditor,效率更高,具体实现建议查看联机帮助文档的示例代码。