麻辣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.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。

3.如果本文对您有所帮助,请您对我们团队进行 打赏捐助让我们在传播3S的路上可以走得更远,不胜感激。PS:如果你是学生党,请优先把经费用于购买学习资料 以及 与小哥哥/小姐姐约会上:-)

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

本站QQ群(一):291616564 加入QQ群

本站QQ群(二):166408035 加入QQ群

本站QQ群(三):627853279 加入QQ群

本站QQ群(四):436386604 加入QQ群

本站QQ群(五):606176554 加入QQ群

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

发表评论