ArcEngine新建几何网络_GeometricNetwork

本文介绍如何使用ArcGIS Engine 10.1在GeoDatabase中构建几何网络的过程,包括创建网络加载器、设置网络名称及类型、添加要素类等内容,并强调了中文名称可能导致的问题。

前几天需要写两个方法,一个是需要构建网络数据集NetowrkDataset,一个是需要构建几何网络GeometricNetwork;
代码在AE的帮助文档中都是有的;如果你找不到的话直接百度也是有的,不过建议有些基础的还是直接看文档比较好~如果不知道在哪,直接百度**
How to create geometric networks within a geodatabase**


ArcGIS Engine 10.1 EN

Win7 64位

VS2010


本文说说在写的过程中遇到的问题;首先这篇主要是介绍几何网络的构建,后面将会讲到网络数据集;

**下面的代码方法是直接从文档中拷贝过来我修改的,修改依据是在ArcCatalog中
在Dataset中右键新建几何网络的默认设置流程,所以下面的有些代码我会进行删改;**

我会在代码中直接加注释进行解释,重点内容还会在末尾解释!~

        public void CreateGeometricNetwork(IWorkspace workspace, IFeatureDatasetName
          featureDatasetName)//这里的参数不要告诉我你不会写代码得到~
        {
            // Create a network loader.//创建一个网络加载器
            INetworkLoader2 networkLoader2 = new NetworkLoaderClass();

            // Set the network name.//给加载器命名--此名称一定不能为中文!
            networkLoader2.NetworkName = "Water_Net";

            // Set the network type.//类型,效用网络就是几何网络
            networkLoader2.NetworkType = esriNetworkType.esriNTUtilityNetwork;

            // Set the containing feature dataset.//设置关联的数据集IName
            networkLoader2.FeatureDatasetName = (IDatasetName)featureDatasetName;

            //添加featureclass到网络中,这里的featureclassname一定不能是中文!!!
            // Add the two classes to the network.
            if (networkLoader2.CanUseFeatureClass("featureclassname") ==
              esriNetworkLoaderFeatureClassCheck.esriNLFCCValid)
            {
                networkLoader2.AddFeatureClass("featureclassname",
                  esriFeatureType.esriFTComplexEdge, null, false);
            }

            //由于只有一个线图层,所以这个示例代码中的线图层就不用判断了
            //if (networkLoader2.CanUseFeatureClass("Tanks") == esriNetworkLoaderFeatureClassCheck.esriNLFCCValid)
            //{
            //networkLoader2.AddFeatureClass("Tanks",esriFeatureType.esriFTSimpleJunction, null, false);
            //}

            // Set the enabled field for the distribmains class.//这个可以直接注释掉,也可以根据线图层做修改,这里直接注释
            //INetworkLoaderProps networkLoaderProps = (INetworkLoaderProps)networkLoader2;
            //String defaultEnabledFieldName = networkLoaderProps.DefaultEnabledField;
            //esriNetworkLoaderFieldCheck enabledFieldCheck =
            //  networkLoader2.CheckEnabledDisabledField("Tanks", defaultEnabledFieldName);
            //switch (enabledFieldCheck)
            //{
            //    case esriNetworkLoaderFieldCheck.esriNLFCValid:
            //    case esriNetworkLoaderFieldCheck.esriNLFCNotFound:
            //        networkLoader2.PutEnabledDisabledFieldName("Tanks",
            //          defaultEnabledFieldName);
            //        break;
            //    default:
            //        Console.WriteLine(
            //          "The field {0} could not be used as an enabled/disabled field.",
            //          defaultEnabledFieldName);
            //        break;
            //}

            //networkLoader2.PreserveEnabledValues = true;

            //这个是设置源和汇的,主要针对点图层,这里不需要就注释掉
            // Set the ancillary role field for the tanks class.
            //String defaultAncillaryRoleFieldName =
            //  networkLoaderProps.DefaultAncillaryRoleField;
            //esriNetworkLoaderFieldCheck ancillaryRoleFieldCheck =
            //  networkLoader2.CheckAncillaryRoleField("Tanks",
            //  defaultAncillaryRoleFieldName);
            //switch (ancillaryRoleFieldCheck)
            //{
            //    case esriNetworkLoaderFieldCheck.esriNLFCValid:
            //    case esriNetworkLoaderFieldCheck.esriNLFCNotFound:
            //        networkLoader2.PutAncillaryRole("Tanks",
            //          esriNetworkClassAncillaryRole.esriNCARSourceSink,
            //          defaultAncillaryRoleFieldName);
            //        break;
            //    default:
            //        Console.WriteLine(
            //          "The field {0} could not be used as an ancillary role field.",
            //          defaultAncillaryRoleFieldName);
            //        break;
            //}

            //这里针对的是GDB,不是SDE,所以也注释掉
            // If the geodatabase is an SDE GDB, set the configuration keyword.
            //if (workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
            //{
            //    networkLoader2.ConfigurationKeyword = "Network_Defaults";
            //}

            //这里我们不设置Snap
            // Set the snap tolerance for the network.
            //networkLoader2.SnapTolerance = networkLoader2.MinSnapTolerance;
            ((INetworkLoader3)networkLoader2).UseXYsForSnapping = false;

            //不设置权重
            //// Add a weight with a double type to the network.
            //networkLoader2.AddWeight("MainWeight", esriWeightType.esriWTDouble, 0);

            //// For weights of type esriWTBitGate, the BitGateSize parameter should be set:
            //networkLoader2.AddWeight("WTBitGateEx", esriWeightType.esriWTBitGate, 5);

            //// Associate the MainWeight weight with the DIAMETER field of Distribmains.
            //networkLoader2.AddWeightAssociation("MainWeight", "Distribmains", "DIAMETER");

            //构建几何网络
            // Load the network.
            networkLoader2.LoadNetwork();

            //不管ErrorTable
            // Get the name of the network's error table.
            //String errorTableName = networkLoader2.ErrorTableName;

            //// Display the number of invalid features in the Distribmains class.
            //int numInvalidFeatures = networkLoader2.get_NumInvalidFeatures("Distribmains")
            //  ;
            //Console.WriteLine("Distribmains contains {0} invalid features.",
            //  numInvalidFeatures);

            //// Display the number of invalid features in the network.
            //int totalNumInvalidFeatures = networkLoader2.TotalNumInvalidFeatures;
            //Console.WriteLine("The network contains {0} invalid features.",
            //  totalNumInvalidFeatures);
        }

上面的代码除了//networkLoader2.PreserveEnabledValues = true;其他我是根据全部默认设置进行修改的,大家有其他需求可以自己修改;


尤其需要大家注意的是两个地方,一个是NetworkName这个属性,就是网络数据集的名称一定不能为中文;另一个就是我们需要创建网络数据集的featureclass的名称;二者如果有一个存在中文,那么在最后构建几何网络的时候都会出现各种乱七八糟的异常;包括The Table was not found此版本的地理数据库不支持表格附件。等,异常信息主要是看你的ArcGIS是中文还是英文了~!

PyG(Torch Geometric)是一个用于图神经网络(Graph Neural Networks, GNNs)的Python库,它是基于PyTorch构建的。如果你想使用PyG搭建GCN(Graph Convolutional Network网络,首先需要安装`torch_geometric`库。以下是一个简单的步骤概述: 1. **安装**: ```bash pip install torch torchvision torchaudio -f https://download.pytorch.org/whl/torch_stable.html pip install torch-scatter -f https://github.com/rusty1s/pytorch_scatter/blobs/main/dist/ pip install torch-sparse -f https://github.com/rusty1s/pytorch_sparse/blobs/main/dist/ pip install torch-cluster -f https://github.com/rusty1s/pytorch_cluster/blobs/main/dist/ pip install torch-geometric ``` 2. **导入所需模块**: ```python import torch from torch_geometric.nn import GCNConv, global_mean_pool ``` 3. **构建数据结构**: 使用`torch_geometric.data.Data`类来创建图的数据结构,包括节点特征和边的信息。 4. **定义模型**: ```python class GCN(torch.nn.Module): def __init__(self, in_channels, hidden_channels, out_channels): super(GCN, self).__init__() self.conv1 = GCNConv(in_channels, hidden_channels) self.conv2 = GCNConv(hidden_channels, out_channels) def forward(self, data): x, edge_index = data.x, data.edge_index x = F.relu(self.conv1(x, edge_index)) x = self.conv2(x, edge_index) return global_mean_pool(x, data.batch) ``` 5. **训练和预测**: 定义损失函数、优化器,并通过`DataLoader`加载数据进行训练。 ```python model = GCN(...).to(device) optimizer = torch.optim.Adam(model.parameters(), lr=0.01) for epoch in range(100): # 假设这是训练循环 optimizer.zero_grad() output = model(data) loss = F.nll_loss(output[data.train_mask], data.y[data.train_mask]) loss.backward() optimizer.step() # 预测阶段 with torch.no_grad(): pred = model(data) ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值