首页 / 浏览问题 / 组件GIS / 问题详情
组件如何打散模型
2EXP 2021年08月03日
supermap iobject java 打散模型  示例代码

1个回答

你好,思路是通过模型数据集获取Recordset记录集,然后通过记录集获取model对象,用model.decompose()方法进行打散
2,842EXP 2021年08月04日
您好 我试了一下 Geomodel 没有decopose的方法
抱歉,是model,不是geomodel,已改正
我之前用过这种方式  但是发现打散的集合还是1 , 和桌面软件打散做了对比发现不一样。这个是什么原因导致的呢  

Recordset recordset = dataset.getRecordset(false, CursorType.DYNAMIC);

GeoModel3D geometry = null;

while (!recordset.isEOF()) {

recordset.edit(); geometry = (GeoModel3D) recordset.getGeometry();

Model model = geometry.getModel();

ArrayList<Model> models = model.decompose();

recordset.moveNext();

}
你好,可以参考如下打散demo:

public static void main(String[] args) {
        // TODO Auto-generated method stub

        Workspace workspace = new Workspace();
        DatasourceConnectionInfo datasourceConnectionInfo = new DatasourceConnectionInfo();
        datasourceConnectionInfo.setEngineType(EngineType.UDBX);
        datasourceConnectionInfo.setServer("F:\\supermap\\CBD.udbx");
        Datasource targetDatasource = workspace.getDatasources().open(datasourceConnectionInfo);
        if (targetDatasource == null) {
            System.out.println("打开数据源失败");
            return;
        } else {
            System.out.println("数据源打开成功!");
        }
            
        //源数据集
        Dataset srcdataset = targetDatasource.getDatasets().get("Building");//照明设备_jidi17    Building
        DatasetVector vtr = (DatasetVector) srcdataset;
        Recordset recordset = vtr.getRecordset(false, CursorType.DYNAMIC);        
        
        //创建模板结果数据集
        String resultname = targetDatasource.getDatasets().getAvailableDatasetName("resultmdos");
        DatasetVector resultdatavector = (DatasetVector) targetDatasource.getDatasets().createFromTemplate(resultname, srcdataset);
        Recordset resultRecordset = resultdatavector.getRecordset(false, CursorType.DYNAMIC);
        Map<String, Object> tarFieldInfos = new HashMap<String, Object>();
        
        ModelEntityManager em = new ModelEntityManager(resultdatavector);
        FieldInfos fieldinfos = recordset.getFieldInfos();
        Boolean isLonlat = (srcdataset.getPrjCoordSys().getType() == PrjCoordSysType.PCS_EARTH_LONGITUDE_LATITUDE);
        Boolean isUpdtaSkeleton =false;
        resultRecordset.getBatch().begin();
        
        while (!recordset.isEOF() ) {//&& i<50
            
            for(int k=0;k<fieldinfos.getCount();k++) {
                if(!fieldinfos.get(k).isSystemField() && !fieldinfos.get(k).getName().startsWith("Sm")) {
                    tarFieldInfos.put(fieldinfos.get(k).getName(),  recordset.getFieldValue(fieldinfos.get(k).getName()));
                    
                }
            }

            GeoModel3D srcmodel3d  = (GeoModel3D) recordset.getGeometry();

            Model model = srcmodel3d.getModel();
            int count = model.getSkeletonCount(-1);
            for(int j=0;j<count;j++) {
                double[] matrix = new double[16];
                SkeletonID id = new SkeletonID(-1, j);
                Skeleton skeleton = model.getSkeleton(id,matrix);
                if(skeleton != null ) {
                    isUpdtaSkeleton = true;
                    String naaeme = em.append(skeleton).getName();
                    Model tarModel = new Model();
                    tarModel.addSkeleton(em, naaeme,matrix);
                    GeoModel3D tarmodel3D = new GeoModel3D(tarModel);
                    tarmodel3D.setIsLonLat(isLonlat);
                    tarmodel3D.setPosition(srcmodel3d.getPosition());
                    resultRecordset.addNew(tarmodel3D, tarFieldInfos);
                }
            }
            srcmodel3d.dispose();
            tarFieldInfos.clear();
            
            recordset.moveNext();

        }
        
        resultRecordset.getBatch().update();
        if(isUpdtaSkeleton) {
            em.updateDataset();
            em.dispose();
        }
        System.out.println("end");

    }
可以了   非常感谢
...