麻辣GIS微信平台

更多 GIS 干货

微信关注不错过

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 开发手册

麻辣GIS-Sailor

作者:

GIS爱好者,学GIS,更爱玩GIS。

声明

1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。

2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。

手机阅读
微信打赏
支付宝打赏
手机阅读
麻辣GIS微信打赏
请小编吃包辣条
麻辣GIS支付宝打赏
请小编吃支雪糕

留言板(小编看到第一时间回复)