SuperMap iObject Java implements pipe network data modeling

 Author: Jiang Er


Table of contents

1. Technical ideas

2. Main code

3. Complete sample code

4. Display of running results


1. Technical ideas

        In SuperMap iDesktopX, you can configure the 3D pipe network model through [Topological Networking], [Making Thematic Map] and other methods. However, fixed software operations are occasionally not satisfied for business scenarios with high freedom of processing, so the benefits of SuperMap iObject Java can be reflected. Using component products to develop by yourself, matching functions to achieve functional combinations, and one-click generation have become the favorites of many people.

        The common raw data of pipe network data are [3D line data set], [3D line data set] and [3D point data set] and [network data set]. If the data does not have a network data set, you need to build a network first. Therefore, the basic technical idea of ​​using SuperMap iObject Java to build a pipe network model is to first construct a network data set from the original data, then create a [custom thematic map] configuration style, such as pipe point model symbols, and finally add it to [Scene] for browsing.

        In the SuperMap iObject Java sample program, you can also refer to the sample code for creating custom thematic maps for pipe points in [Scene Operation and Underground Mode], or the [3D Thematic Map] sample. 

2. Main code

        The NetworkBuilder3D class is mainly used to build network data sets. Three-dimensional network modeling class. This class provides functions such as the construction of three-dimensional network data sets and the creation of flow directions for three-dimensional network data sets.

        The three-dimensional network data set is the data basis for three-dimensional network analysis. Like the two-dimensional network model, the three-dimensional network model is divided into a three-dimensional facility network model and a three-dimensional transportation network model; arc segments and nodes and their spatial topological relationships are also used to describe the network. The fundamental difference between the two is that the three-dimensional network model uses (x, y, z) to express spatial position.

        This class provides three methods for building network datasets (three buildNetwork overloaded methods) to meet the requirements for building three-dimensional network datasets based on different data:

        1. Existing three-dimensional point and line data do not need to be interrupted, and have fields expressing point-line topological relationships (corresponding to the arc segment ID, node ID, starting node ID and ending node ID of the network data set), For example, to collect pipe points and pipe segments to build a pipe network, you can use the buildNetwork method;

        2. Constructed only from the three-dimensional line data set, you can determine whether to break at the intersection of the lines by setting the break mode. For details, see the buildNetwork method;

        3. Constructed from three-dimensional point (optional) and line data sets, you can set the break mode to determine whether to break at the intersection of points and lines, see the buildNetwork method for details.

        It is important to emphasize that the data used to construct the three-dimensional network dataset must have the same coordinate system, otherwise the construction will fail.

        Use the buildNetwork interface to build a 3D network dataset. Saved non-system fields and interruption mode can be set. This method only uses the three-dimensional line data set to build a three-dimensional network. You need to pay attention to the setting of the interruption mode: when the interruption mode is set to LINE_SPLIT_BY_POINT_AND_LINE, it will interrupt and add network nodes at the intersection of the lines; when the interruption mode is set to NONE, it will not be used anywhere. Position interruption, only add network nodes at both ends of the line; setting the interruption mode to LINE_SPLIT_BY_POINT is not allowed, otherwise an exception will be thrown.

        The main codes can be referenced as follows:

// 构建三维网络数据集
        DatasetVector resultNetwork = NetworkBuilder3D.buildNetwork(
                lineDataset, pointDataset, new String[] { "SymbolID", "LineWidth",
                        "color" }, new String[] { "Name", "RotationX", "RotationY" , "RotationZ" , "SymbolID" , "ScaleX" , "ScaleY" , "ScaleZ" , "NodeID"  },
                datasource, networkName,
                NetworkSplitMode3D.LINE_SPLIT_BY_POINT_AND_LINE, 0.02);//打断模式指定为“线线打断,同时点打断线”

        To build a thematic map, you can use the Theme3DCustom class. Three-dimensional custom thematic map class, which can dynamically set the display style through field expressions. You can refer to the online help document ( Online Help ) for detailed instructions:

 The main codes can be referenced as follows:

//网络数据集线图层设置专题图
        Theme3DCustom Theme3DCustom=new Theme3DCustom();
        Theme3DCustom.setAltitudeModeExpression("1");
        Theme3DCustom.setLineSymbolIDExpression("964513");//设置线型符号
        Theme3DCustom.setLineWidthExpression("1");//设置线型宽度
        Theme3DCustom.setAltitudeModeExpression("1");//设置表示高度模式的字段表达式。字段值为0表示贴地高度模式,为1表示绝对高度模式,为2表示相对地面高度模式,为3表示相对地下高度模式。当字段值不为0或1或2或3时,采用默认字段值0,即采用贴地高度模式。
        Layer3DDataset  Layer3DDatasetline =layer3Ds.add(resultNetwork,Theme3DCustom,true,"Layer3DDatasetlineTheme3DCustom");//添加网络专题图图层

3. Complete sample code


//        打开工作空间
        Workspace workspace = new Workspace();
        WorkspaceConnectionInfo info = new WorkspaceConnectionInfo();
        info.setServer("D:\\supermap\\iobjectsjava\\1101\\supermap-iobjectsjava-11.1.0-22010-101668-win64-all-Bin\\GettingStarted\\Gettingstarted\\NetworkTheme3DCustom\\Pipe3D\\Pipe3D\\Pipe3D\\Pipe.smwu");
        info.setType(WorkspaceType.SMWU);
        System.out.println("是否打开工作空间:" + workspace.open(info));

//        打开数据源
        Datasource datasource = workspace.getDatasources().get(0);
        System.out.println("打开数据源别名为:" + datasource.getAlias() + "  数据源打开的状态:" + datasource.isOpened() + "  数据源是否以只读方式打开:" + datasource.isReadOnly());//打印查询其描述信息

        // 获取数据集,用于构建三维网络数据集的三维线数据集和三维点数数据集
        DatasetVector lineDataset = (DatasetVector) datasource.getDatasets().get("PipeLine3D");
        DatasetVector pointDataset = (DatasetVector) datasource.getDatasets().get("PipePoint3D");
        String networkName = datasource.getDatasets().getAvailableDatasetName("testnetwork");// 获取一个合法的名称作为结果网络数据集的名称
        // 构建三维网络数据集
        DatasetVector resultNetwork = NetworkBuilder3D.buildNetwork(
                lineDataset, pointDataset, new String[] { "SymbolID", "LineWidth",
                        "color" }, new String[] { "Name", "RotationX", "RotationY" , "RotationZ" , "SymbolID" , "ScaleX" , "ScaleY" , "ScaleZ" , "NodeID"  },
                datasource, networkName,
                NetworkSplitMode3D.LINE_SPLIT_BY_POINT_AND_LINE, 0.02);//打断模式指定为“线线打断,同时点打断线”
        System.out.println("打开数据集名称为:" + resultNetwork.getName()+"数据集类型为:"+resultNetwork.getType());//打印查询其描述信息
        //判断构网是否创建成功
        if (datasource.getDatasets().get(networkName) == null) {
            System.out.println("网络数据集创建失败");
        } else {
            System.out.println("网络数据集创建成功!"+" 数据集个数为:"+datasource.getDatasets().getCount());
            //判断成功,输出数据集名称
            Datasets  Datasets =datasource.getDatasets();
            String[] DatasetsCount = new String[Datasets.getCount()];
            for (int i = 0; i < Datasets.getCount(); i++) {
                DatasetsCount[i]=Datasets.get(i).getName();
            }
            System.out.println("结果数据源数据集名称为 = " + StringUtils.join(DatasetsCount,","));
        }

        //创建场景,设置场景控件
        Scene sceneObject = new Scene(workspace);//返回三维地图场景(Scene)对象
        sceneObject.open("Pipe3D");//通过名称打开工作空间中的地图
        Atmosphere atmosphere = sceneObject.getAtmosphere();
        atmosphere.setVisible(false);//大气不可见
        Underground Underground=sceneObject.getUnderground();
        Underground.setVisible(true);//地下可见
        GlobalImage GlobalImage=sceneObject.getGlobalImage();
        GlobalImage.setVisible(false);//地球底图不可见
        sceneObject.setSceneType(SceneType.GLOBE);//设置三维场景的类型,选择球体模式(Globe)和平面模式(Flat)两种。
        System.out.println("场景数量:" + workspace.getScenes().getCount() + "场景名称:" + sceneObject.getName());

//添加图层
        Layer3Ds layer3Ds = sceneObject.getLayers();
        System.out.println("场景中原有图层数量:" + layer3Ds.getCount());//打印数据集名称
//线专题图
        Theme3DCustom Theme3DCustom=new Theme3DCustom();
        Theme3DCustom.setAltitudeModeExpression("1");
        Theme3DCustom.setLineSymbolIDExpression("964513");//设置线型符号
        Theme3DCustom.setLineWidthExpression("1");//设置线型宽度
        Theme3DCustom.setAltitudeModeExpression("1");//设置表示高度模式的字段表达式。字段值为0表示贴地高度模式,为1表示绝对高度模式,为2表示相对地面高度模式,为3表示相对地下高度模式。当字段值不为0或1或2或3时,采用默认字段值0,即采用贴地高度模式。
        Layer3DDataset  Layer3DDatasetline =layer3Ds.add(resultNetwork,Theme3DCustom,true,"Layer3DDatasetlineTheme3DCustom");//添加网络专题图图层
        Layer3DDatasetline.updateData();
        sceneControl.getScene().refresh();
        System.out.println(" 添加线专题图刷新三维场景");
//点专题图
        Theme3DCustom Theme3DCustompoint=new Theme3DCustom();
        Theme3DCustompoint.setAltitudeModeExpression("1");//设置高度模式,绝对
        Theme3DCustompoint.setMarkerSymbolIDExpression("54440");//设置点符号
        Theme3DCustompoint.setMarker3DRotateXExpression("1");//X旋转
        Theme3DCustompoint.setMarker3DRotateYExpression("1");//Y旋转
        Theme3DCustompoint.setMarker3DRotateZExpression("1");//Z旋转
        Theme3DCustompoint.setMarker3DScaleXExpression("10");//X缩放
        Theme3DCustompoint.setMarker3DScaleYExpression("10");//Y缩放
        Theme3DCustompoint.setMarker3DScaleZExpression("10");//Z缩放
        Layer3DDataset  Layer3DDatasetpoint =layer3Ds.add(resultNetwork.getChildDataset(),Theme3DCustompoint,true,"Layer3DDatasetpointTheme3DCustom");//添加网络子图层专题图
        Layer3DDatasetpoint.updateData();
        sceneControl.getScene().refresh();
        System.out.println(" 添加点专题图刷新三维场景");
        System.out.println("场景中现有图层数量:" + layer3Ds.getCount());//打印数据集名称

4. Display of running results

 

Guess you like

Origin blog.csdn.net/supermapsupport/article/details/135294668