arcobjects for java 几何网络分析之上下游分析

String inFGDB = "D:\\share\\arcmap\\test.mdb";
        String mxdDoc = "D:\\share\\arcmap\\无标题.mxd";
        try {
            // 打开工作空间
            IWorkspaceFactory workspaceFactory = new WorkspaceFactory(new AccessWorkspaceFactory());
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace) workspaceFactory.openFromFile(inFGDB, 0);
            // 获取要素集
            IFeatureDataset featureDataset = new FeatureDataset(featureWorkspace.openFeatureDataset("QZgeo"));
            INetworkCollection networkCollection = (INetworkCollection) featureDataset;
            // 获取指定的network
            IGeometricNetwork geometricNetwork = networkCollection.getGeometricNetwork(0);
            INetwork network = geometricNetwork.getNetwork();
            ITraceFlowSolverGEN traceFlowSolverGEN = new TraceFlowSolver();
            INetSolver netSolver = (INetSolver) traceFlowSolverGEN;
            netSolver.setSourceNetworkByRef(network);

            IPoint point = new Point();
            point.putCoords(118.762761, 24.8786);

            IMap map = new com.esri.arcgis.carto.Map();
            IFeatureClassContainer featureClassContainer = (IFeatureClassContainer) featureDataset;
            int count = featureClassContainer.getClassCount();
            for(int i=0; i<count; i++){
                IFeatureClass featureClass = featureClassContainer.esri_getClass(i);
                IFeatureLayer featureLayer = new FeatureLayer();
                featureLayer.setFeatureClassByRef(featureClass);
                map.addLayer(featureLayer);
            }

            IPointToEID pointToEID = new PointToEID();
            pointToEID.setGeometricNetworkByRef(geometricNetwork);
            pointToEID.setSnapTolerance(1000);
            pointToEID.setSourceMapByRef(map);

            int[] nearestJunctionEID = new int[1];
            IPoint[] location = new Point[1];
            pointToEID.getNearestJunction(point, nearestJunctionEID, location);

            int eid = nearestJunctionEID[0];

            IEdgeFlag[] edgeFlags = new EdgeFlag[1];
            INetFlag edgeFlag = new EdgeFlag();
            INetElements netElements = new UtilityNetwork(geometricNetwork.getNetwork());
            int[] userClassId = new int[1];
            int[] userId = new int[1];
            int[] userSubId = new int[1];
            netElements.queryIDs(eid, esriElementType.esriETEdge, userClassId, userId, userSubId);
            edgeFlag.setUserClassID(userClassId[0]);
            edgeFlag.setUserID(userId[0]);
            edgeFlag.setUserSubID(userSubId[0]);
            edgeFlags[0] = (IEdgeFlag) edgeFlag;

            traceFlowSolverGEN.putEdgeOrigins(edgeFlags);

            IEnumNetEID[] junctionEIDs = new IEnumNetEID[1];
            IEnumNetEID[] edgeEIDs = new IEnumNetEID[1];
            traceFlowSolverGEN.findFlowElements(esriFlowMethod.esriFMUpstream, esriFlowElements.esriFEJunctionsAndEdges,
                    junctionEIDs, edgeEIDs);
            if(edgeEIDs[0] != null){
                System.out.println("---线---");
                int edgeEID;
                while((edgeEID = edgeEIDs[0].next()) != 0){
                    System.out.println(edgeEID);
                    IGeometry geometry = geometricNetwork.getGeometryForEdgeEID(edgeEID);
                    IPointCollection collection = (IPointCollection) geometry;
                    int pointCount = collection.getPointCount();
                    for(int i=0; i<pointCount; i++){
                        IPoint point1 = collection.getPoint(i);
                        double[] x = new double[1];
                        double[] y = new double[1];
                        point1.queryCoords(x, y);
                        System.out.print("[" + x[0] + "," + y[0] + "]");
                    }
                    System.out.println();
                }
            }
            if(junctionEIDs[0] != null){
                System.out.println("---点---");
                int junctionEID;
                while((junctionEID = junctionEIDs[0].next()) != 0){
                    System.out.println(junctionEID);
                    IGeometry geometry = geometricNetwork.getGeometryForJunctionEID(junctionEID);
                    IPoint point1 = (IPoint) geometry;
                    double[] x = new double[1];
                    double[] y = new double[1];
                    point1.queryCoords(x, y);
                    System.out.println(x[0] + " | " + y[0]);
                }
            }
        }catch(Exception e){
            e.printStackTrace();
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值