ArcGIS Engine 10 开发手册(11-16)线性参考使用示例

本文目录
  • 正文

本文将使用代码实现如下示例:

在一个道路网络中利用线性参考找到ID为 20000013, 并且长度是 0-25 的区间:

示例代码

IPolyline FindRoutByMeasure (IFeatureClass _pRouteFC, string _pPKName, object _pID, double _pFrom, double _pTo)

{

  IDataset pDataset = (IDataset) _pRouteFC;
  IName pName = pDataset.FullName;

  IRouteLocatorName pRouteLocatorName = new RouteMeasureLocatorNameClass ();
  pRouteLocatorName.RouteFeatureClassName = pName;

  pRouteLocatorName.RouteIDFieldName = _pPKName;
  pRouteLocatorName.RouteMeasureUnit = esriUnits.esriFeet;
  pName = (IName) pRouteLocatorName;

  IRouteLocator2 pRouteLocator = (IRouteLocator2) pName.Open ();

  IRouteLocation pRouteLoc = new RouteMeasureLineLocationClass ();
  pRouteLoc.MeasureUnit = esriUnits.esriFeet;

  pRouteLoc.RouteID = _pID;

  IRouteMeasureLineLocation rMLineLoc = (IRouteMeasureLineLocation) pRouteLoc;

  rMLineLoc.FromMeasure = _pFrom;
  rMLineLoc.ToMeasure = _pTo;

  IGeometry pGeo = null;
  esriLocatingError locError;

  pRouteLocator.Locate (pRouteLoc, out pGeo, out locError);

  return pGeo as IPolyline;

}

IMap pMap = axMapControl1.Map;

IFeatureWorkspace pFtWs = GetFGDBWorkspace (@"E:\arcgis\Engine\Rout.gdb") as IFeatureWorkspace;

IFeatureLayer pFeatureLayer = new FeatureLayerClass ();
pFeatureLayer.FeatureClass = pFtWs.OpenFeatureClass ("routes");
pFeatureLayer.Name = "路径";
axMapControl1.Map.AddLayer (pFeatureLayer as ILayer);
axMapControl1.Refresh ();

IPolyline pPolyline = FindRoutByMeasure (pFeatureLayer.FeatureClass, "ROUTE1", 20000013, 0, 25);

IRgbColor pColor = new RgbColorClass ();
pColor.Red = 255;

IElement pElement = new LineElementClass ();
ILineSymbol pLinesymbol = new SimpleLineSymbolClass ();
pLinesymbol.Color = pColor as IColor;
pLinesymbol.Width = 100;

pElement.Geometry = pPolyline as IGeometry;
IGraphicsContainer pGrahicsC = pMap as IGraphicsContainer;
pGrahicsC.AddElement (pElement, 0);

axMapControl1.ActiveView.PartialRefresh (esriViewDrawPhase.esriViewGraphics, null, null);

运行结果

ArcGIS Engine 10 开发手册全集

ArcGIS Engine 10 开发手册全集: ArcGIS Engine 10 开发手册

如果本文对你有所帮助,欢迎对我们团队进行打赏捐助,让我们在传播3S的路上可以走得更远。
赞赏支持
微信捐助麻辣GIS 支付宝捐助麻辣GIS

麻辣GIS-Sailor
作者:
GIS爱好者,学GIS,更爱玩GIS。

如您有疑问,可在文末留言,或到QQ群中提问。

本站QQ群(一):291616564 麻辣GIS

本站QQ群(二):166408035 麻辣GIS(二)

本站QQ群(三):627853279 麻辣GIS(三)

微信公众号:malagis,扫描右边二维码直接关注。

发表评论