ThinkGeo.com    |     Documentation    |     Premium Support

I can't draw between two coordinates

 


The code below is copied from "HowDoISample" but does not draw between two coordinates.


Not : files are attached only change file extension zip to rar


 



        static RectangleShape turkeyShape = new RectangleShape(2888708.1725842, 5172748.5338836, 4927301.9983436, 4265512.2928742);


        private MapManager _mapManager;

        private static RoutingEngine routingEngine;
        private static RoutingSource RoutingSourceForShortest;
        private static RoutingSource RoutingSourceForFastest;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                ShapeFileFeatureSource featureSource = new ShapeFileFeatureSource(Server.MapPath("RoutingData/Kadikoy_polyline.shp"));

                RoutingSourceForShortest = new RtgRoutingSource(Server.MapPath("RoutingData/Kadikoy_polyline.rtg"));
                routingEngine = new RoutingEngine(RoutingSourceForShortest, featureSource);
                routingEngine.GeographyUnit = GeographyUnit.Meter;

                RenderMap();

                FindPath();
            }
        }

        private void RenderMap()
        {
          
            Map1.MapUnit = GeographyUnit.Meter;
            Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
            Map1.CurrentExtent = turkeyShape;// new RectangleShape(-10884474.4001792, 3542175.58734002, -10877416.7249544, 3537139.84069311);
           // Map1.RestrictedExtent = turkeyShape;

            PointShape point = Map1.CurrentExtent.GetCenterPoint();
            Map1.ZoomTo(point, Map1.ClientZoomLevelScales[6]);

            GoogleOverlay google = new GoogleOverlay("Google Map");
            google.JavaScriptLibraryUri = new Uri(ConfigurationManager.AppSettings["GoogleUri"]);
            google.GoogleMapType = GoogleMapType.Normal;
            Map1.BackgroundOverlay = google;

 
            RoutingLayer routingLayer = new RoutingLayer();
            routingLayer.StartPoint = new PointShape(double.Parse("29.0439132097907", CultureInfo.InvariantCulture), double.Parse("40.9922252527833", CultureInfo.InvariantCulture));           
            routingLayer.EndPoint = new PointShape(double.Parse("29.0481970808968", CultureInfo.InvariantCulture), double.Parse("40.9782405733082", CultureInfo.InvariantCulture));           
            Map1.DynamicOverlay.Layers.Add("RoutingLayer", routingLayer);

            InMemoryFeatureLayer routingExtentLayer = new InMemoryFeatureLayer();
            routingExtentLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Green));
            routingExtentLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            routingExtentLayer.InternalFeatures.Add(new Feature(turkeyShape));
            Map1.DynamicOverlay.Layers.Add("RoutingExtentLayer", routingExtentLayer);
        }

        private void FindPath()
        {
            RoutingLayer routingLayer = (RoutingLayer)Map1.DynamicOverlay.Layers["RoutingLayer"];

            routingLayer.Routes.Clear();
            RoutingResult routingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.EndPoint);
            routingLayer.Routes.Add(routingResult.Route);           
            Map1.DynamicOverlay.Redraw();
        }


004_003_002_001_Routing_Data.zip (479 KB)

do you think to help me ?

 


Ayhan,
Sorry for the delayed response.
After checking the data you attached, I found where the issue lies. In you sample you used GoogleOverlay and set the MapUnit to Meter, but your rtg data is built in DecimalDegree, so the Route you get from this file is also in DecimalDegree, that’s why the Route won’t be displayed on the Map.
You can try to apply the code snippet below to your FindPath method in the application; there we add a projection process to the Route you got from the original rtg file.
RoutingLayer routingLayer = (RoutingLayer)Map1.DynamicOverlay.Layers["RoutingLayer"];
 
            routingLayer.Routes.Clear();
            ManagedProj4Projection projection = new ManagedProj4Projection();
 
            projection.InternalProjectionParameters = Proj4Projection.GetEpsgParametersString(4326);
            projection.ExternalProjectionParameters = Proj4Projection.GetGoogleMapParametersString();
            projection.Open();
 
            MultilineShape projectedRoute = projection.ConvertToExternalProjection(routingEngine.GetRoute(txtStartFeatureId.Value, txtEndFeatureId.Value).Route) as MultilineShape;
 
            routingLayer.Routes.Add(projectedRoute);
            projection.Close();
            //routingLayer.Routes.Add(routingEngine.GetRoute(txtStartFeatureId.Value, txtEndFeatureId.Value).Route);
            Map1.DynamicOverlay.Redraw();
 
Further questions please let me know.
 
Thank you.
James

Thank you james. 
  
 Ayhan

Thank you, James.


 There is also a Code Community sample that deals with that issue, Routing with Projections wiki.thinkgeo.com/wiki/Map_Suite_De...rojections


 In this sample, the projections scenario is different but the principle applies. Ayhan, you can check it out, if you'd like.