⑴ 如何创建网络数据集
//<summary>
///创建自定义网络数据集
///</summary>
///<paramname="_pWsName"></param>
///<paramname="_pDatasetName"></param>
///<paramname="_pNetName"></param>
///<paramname="_pFtName"></param>
voidCreateNetworkDataset(string_pWsName,string_pDatasetName,string_pNetName,string_pFtName)
{
=newDENetworkDatasetClass();
pDENetworkDataset.Buildable=true;
IWorkspacepWs=GetWorkspace(_pWsName);
IFeatureWorkspacepFtWs=pWsasIFeatureWorkspace;
IFeatureDatasetpFtDataset=pFtWs.OpenFeatureDataset(_pDatasetName);
//定义空间参考,负责会出错
IDEGeoDatasetpDEGeoDataset=(IDEGeoDataset)pDENetworkDataset;
IGeoDatasetpGeoDataset=pFtDatasetasIGeoDataset;
pDEGeoDataset.Extent=pGeoDataset.Extent;
pDEGeoDataset.SpatialReference=pGeoDataset.SpatialReference;
//网络数据集的名称
IDataElementpDataElement=(IDataElement)pDENetworkDataset;
pDataElement.Name=_pNetName;
//参加建立网络数据集的要素类
=newEdgeFeatureSourceClass();
pEdgeNetworkSource.Name=_pFtName;
pEdgeNetworkSource.ElementType=esriNetworkElementType.esriNETEdge;
//要素类的连通性
=(IEdgeFeatureSource)pEdgeNetworkSource;
pEdgeFeatureSource.UsesSubtypes=false;
pEdgeFeatureSource.ClassConnectivityGroup=1;
pEdgeFeatureSource.ClassConnectivityPolicy=.esriNECPEndVertex;
//不用转弯数据
pDENetworkDataset.SupportsTurns=false;
IArraypSourceArray=newArrayClass();
pSourceArray.Add(pEdgeNetworkSource);
pDENetworkDataset.Sources=pSourceArray;
//网络数据集的属性设置
IArraypAttributeArray=newArrayClass();
//:
;
INetworkAttribute2pNetAttr2;
;
;
pEvalNetAttr=();
pNetAttr2=(INetworkAttribute2)pEvalNetAttr;
pNetAttr2.Name="Meters";
pNetAttr2.UsageType=esriNetworkAttributeUsageType.esriNAUTCost;
pNetAttr2.DataType=esriNetworkAttributeDataType.esriNADTDouble;
pNetAttr2.Units=esriNetworkAttributeUnits.esriNAUMeters;
pNetAttr2.UseByDefault=false;
pNetFieldEval=newNetworkFieldEvaluatorClass();
pNetFieldEval.Setexpression_r("[METERS]","");
//方向设置
pEvalNetAttr.set_Evaluator(pEdgeNetworkSource,esriNetworkEdgeDirection.esriNEDAlongDigitized,(INetworkEvaluator)pNetFieldEval);
pEvalNetAttr.set_Evaluator(pEdgeNetworkSource,esriNetworkEdgeDirection.esriNEDAgainstDigitized,(INetworkEvaluator)pNetFieldEval);
pNetConstEval=();
pNetConstEval.ConstantValue=0;
pEvalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge,(INetworkEvaluator)pNetConstEval);
pEvalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction,(INetworkEvaluator)pNetConstEval);
pEvalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn,(INetworkEvaluator)pNetConstEval);
//一个网络数据集可以有多个属性,我只添加了一个
pAttributeArray.Add(pEvalNetAttr);
pDENetworkDataset.Attributes=pAttributeArray;
//创建网络数据集,注意在创建几何网络的时候会锁定相应的要素类,因此不要用ArcMap或者catalog等打开参相应的数据
=Create(pFtDataset,pDENetworkDataset);
//建立网络
INetworkBuildpNetworkBuild=(INetworkBuild)pNetworkDataset;
pNetworkBuild.BuildNetwork(pGeoDataset.Extent);
}