ThinkGeo.com    |     Documentation    |     Premium Support

How to set WorldStreetsLayer Mapunit to decimal degrees

WorldStreetLayer sample is set to use feet, if I change it to decimal degree it is not showing any map properly.

DetectGPS sample is all done with decimaldegrees,

Trying to simulate the feature in detect GPS in worldstreetLayer sample.

Any guidance would be appreciated

I can’t give you an exact example, but basically, you have to set the projection correctly:



protected void setProjection()
        {
            Proj4Projection proj = new Proj4Projection();
            proj.InternalProjectionParametersString = (Proj4Projection.GetEsriParametersString(srid));            
            proj.ExternalProjectionParametersString = Proj4Projection.GetDecimalDegreesParametersString();
            FeatureSource.Projection = proj;
            FeatureSource.Projection.Open();           
        }

You should be able to lookup the projection required to for feet. Basically, change srid to the value for feet in the above.
I set the projection upon construction of a layer.


private void TestForm_Load(object sender, EventArgs e)
        {
            try { 
            // winformsMap1.MapUnit = GeographyUnit.Meter;
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));

            GoogleMapsOverlay googleOverlay = new GoogleMapsOverlay(); //(@"Insert your key here!", @"C:\GoogleCache");
            googleOverlay.MapType = ThinkGeo.MapSuite.WinForms.GoogleMapsMapType.Hybrid;
            winformsMap1.Overlays.Add(googleOverlay);

            // This sets the zoom levels to map to Googles.  We next make sure we snap to the zoomlevels
            // winformsMap1.ZoomLevelSet = new SphericalMercatorZoomLevelSet();
            winformsMap1.ZoomLevelSet = new ThinkGeo.MapSuite.Layers.ZoomLevelSet();

            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();
            proj4.InternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
            proj4.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
            //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;
            proj4.Open();
            googleOverlay.ProjectionFromSphericalMercator = 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 pointOverlay = new LayerOverlay();
            pointOverlay.Layers.Add("PointLayer", pointLayer);
            winformsMap1.Overlays.Add("PointOverlay", pointOverlay);

            //Sets the extend of the map based on the GPS point.
            //proj4.Open();
            Vertex projVertex = new Vertex(Longitude, Latitude);
            //proj4.Close();

            double extendWidth = 2300;
            double extendHeight = 1200;

            winformsMap1.CurrentExtent = new RectangleShape((projVertex.X - extendWidth), (projVertex.Y + extendHeight),
                (projVertex.X + extendWidth), (projVertex.Y - extendHeight));

            winformsMap1.Refresh();
        }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

        }

This was a quick edit I did with the GPSWithGoogleMaps Example.

Hi Naren,

Thanks the answer from Brandon. If your data source is meter and you want to render that under decimal degree, you should want to reprojection it by our class Proj4Projection.

You should want to double check the mapunit can work with your data(with/without projection), and assign map a correct current extent which is suitable your data(You can also reprojection the extent).

If you still cannot make your code works after modify it refer Brandon’s sample code, please upload your test project so we can help you on it.

Regards,

Ethan

In the WorldStreetSample sample when getting the layer from SQLite added the code recommended by Brandon, now I am able to see the extent and make the vehicle moving.

And it is working. Thankyou!!!

Is the sample data in file - “DallasCounty-3857-20170218.sqlite” is stored in EPSG 3857 ??

private FeatureLayer GetFeatureLayer(string tableName)
{
FeatureLayer layer = new SqliteFeatureLayer(connectionString, tableName, featureIdColumnName, geometryColumnName);
layer.Name = ((SqliteFeatureLayer)layer).TableName;

        layer.DrawingMarginInPixel = 512;

//==============================================================================
//Added code
//Sets the projection parameters to go from Geodetic (EPSG 3857) -> decimal degrees to (Spherical Mercator).
Proj4Projection proj = new Proj4Projection();
proj.InternalProjectionParametersString = (Proj4Projection.GetEpsgParametersString(this.Srid));
proj.ExternalProjectionParametersString = Proj4Projection.GetDecimalDegreesParametersString();

        layer.FeatureSource.Projection = proj;
        layer.FeatureSource.Projection.Open();

//==============================================================================
return layer;
}

Hi Naren,

If your data named “DallasCounty-3857-20170218.sqlite” I think it should be stored in epsg 3857 (that’s the same with 900913, google projection and bing projection).

So your code is correct.

Any question please let us know.

Regards,

Ethan