ThinkGeo.com    |     Documentation    |     Premium Support

Projection Issue

Hi there,


I seem to have a projection issue when creating an InMemoryFeatureLayer.  I have the following code and with it my markers appear in the right spot with the LayerOverlay commented out but if I uncomment I end up in the South Atlantic someplace.  I am adding the points using Decimal Degrees with no projecting happening when adding the point.  However, you will see that I am adding the projection to the FeatureSource.


Any idea why I may be ending up with my points where they are?


Thanks

Curtis



ISignInventoryDAL signInventoryDAL = new SignInventoryDAL();
List<ISignInventoryItem> signs = signInventoryDAL.getSignsWithinDistanceToPoint(latitude, longitude, distance);

Proj4Projection proj4 = new Proj4Projection();
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
LayerOverlay layerOverlay = new LayerOverlay("PointOverlay", false, TileType.SingleTile);
layerOverlay.TransitionEffect = TransitionEffect.None;
//mapControl.CustomOverlays.Add(layerOverlay);
InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer();
pointLayer.FeatureSource.Projection = proj4;
layerOverlay.Layers.Add(pointLayer);

SimpleMarkerOverlay markerOverlay = new SimpleMarkerOverlay("MarkerOverlay");
mapControl.CustomOverlays.Add(markerOverlay);

pointLayer.FeatureSource.Open();
pointLayer.FeatureSource.BeginTransaction();
for(int i = 0; i < signs.Count; i++){
signs[i].renderToMap(markerOverlay, pointLayer, urlString);
}
//mapControl.CurrentExtent = pointLayer.GetBoundingBox();
pointLayer.FeatureSource.CommitTransaction();
pointLayer.FeatureSource.Close();


I slightly modified your code to have it working on my app. I took the example of our office location in Longitude/Latitude and plotted it on Google Map using projection. I think that by looking at my code, you will have a better idea of is wrong on your side.




 Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
                Map1.CurrentExtent = new RectangleShape(-10608900,4716556,-10604285,4714110);
                Map1.MapUnit = GeographyUnit.Meter;

                Map1.MapTools.OverlaySwitcher.Enabled = true;
                Map1.MapTools.MouseCoordinate.Enabled = true;

                //Adds the Google Map as an overlay
                GoogleOverlay google = new GoogleOverlay("Google Map");
                google.JavaScriptLibraryUri = new Uri(ConfigurationManager.AppSettings["GoogleUri"]);
                google.GoogleMapType = GoogleMapType.Normal;
                Map1.CustomOverlays.Add(google);

                LayerOverlay layerOverlay = new LayerOverlay("PointOverlay", false, TileType.SingleTile);
                layerOverlay.TransitionEffect = TransitionEffect.None;

                InMemoryFeatureLayer pointLayer = new InMemoryFeatureLayer();
                pointLayer.Open();
                pointLayer.Columns.Add(new FeatureSourceColumn("Text"));
                pointLayer.Close();

                //Sets the projection parameters to go from Geodetic (EPSG 4326) or decimal degrees to Google Map projection (Spherical Mercator).
                Proj4Projection proj4 = new Proj4Projection();
                proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
                proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
                //Applies the projection to the InMemoryFeatureLayer so that the point in decimal degrees (Longitude/Latitude) can be 
                //match the projection of Google Map.
                pointLayer.FeatureSource.Projection = proj4;

                //Values in Longitude and Latitude.
                double Longitude = -95.2809;
                double Latitude = 38.9543;

                //Creates the feature made of a PointShape with the Longitude and Latitude values.
                Feature GPSFeature = new Feature(new PointShape(Longitude, Latitude));

                //Format the Longitude and Latitude into a nice string as Degrees Minutes and Seconds
                string LongLat = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegreePoint(GPSFeature);

                //Sets the InMemoryFeatureLayer to have it displayed with Square symbol and with text.
                GPSFeature.ColumnValues.Add("Text",LongLat);
                pointLayer.InternalFeatures.Add(GPSFeature);

                pointLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Square, 
                                                                        GeoColor.StandardColors.Red, GeoColor.StandardColors.Black, 2, 12);
                pointLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("Text", "Arial", 12, DrawingFontStyles.Bold, 
                                                                        GeoColor.StandardColors.Black, GeoColor.StandardColors.White, 3, -10, 10);
                pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                layerOverlay.Layers.Add(pointLayer);

                Map1.CustomOverlays.Add(layerOverlay);