// Adds Directions points to point collection private void AddPointsToPolyline(ISMDirections objDirections, ref IPointCollection objPoints) { Point objPoint = new PointClass(); // copy points from DD to line int nItemsCount = objDirections.Count; for (int i = 0; i < nItemsCount; i++) { // get shape from Direction ISMDirItem objItem = null; objItem = objDirections.get_Item(i) as ISMDirItem; ISMPointsCollection objShape = null; objShape = objItem.Shape; // Add point from Direction to received collection int nPointsCount = objShape.Count - 1; for (int j = 0; j <= nPointsCount; j++) { // get point from route SMRouterPoint objRouterPoint = objShape.get_Item(j); // Optimization: Not add point if last added point has similar coords bool bAddPoint = false; if (objPoint.IsEmpty) bAddPoint = true; else if ((objPoint.X != objRouterPoint.X) & (objPoint.Y != objRouterPoint.Y)) bAddPoint = true; if (bAddPoint) { // Add point if need objPoint.X = objRouterPoint.X; objPoint.Y = objRouterPoint.Y; objPoint.SpatialReference = m_objSpatialReference; object missing = System.Reflection.Missing.Value; objPoints.AddPoint(objPoint, ref missing, ref missing); } } } }
// Creates Stop by Stop Point, Index and Description and adds it to Stops collection private void CreateStop(SMRouter objRouter, string strAddress, string strCity, string strState, string strCode, SMStopsCollection objStopsCol, int nID) { // geocode point IPoint objPoint = new PointClass(); objPoint = GeocodeAddress(strAddress, strCity, strState, strCode); if (objPoint.IsEmpty) throw new Exception("Cannot geocode address."); // project point objPoint.Project(m_objSpatialReference); // create and initialize router point SMRouterPoint objRouterPoint = null; objRouterPoint = new SMRouterPointClass(); objRouterPoint.X = objPoint.X; objRouterPoint.Y = objPoint.Y; // create flag ISMFlagCreator2 objFlagCreator2 = null; objFlagCreator2 = objRouter.FlagCreator as ISMFlagCreator2; if (objFlagCreator2 != null) objFlagCreator2.SearchTolerance = 5; SMFlag objFlag = null; objFlag = objRouter.FlagCreator.CreateFlag(objRouterPoint); // create and initialize stop SMStop objStop = null; objStop = new SMStop(); objStop.StopID = nID; objStop.Duration = 0; objStop.Flag = objFlag; objStop.Description = GetAddressString(strAddress, strCity, strState, strCode); objStopsCol.Add(objStop); }