⑴ 如何創建網路數據集
//<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);
}