Hi everybody
I can plot points out of decimaldegrees coordinates from my custom table. But I can not do the same using UTM coordinates. Can any one help me on how to do it?
Best Regards,
Vincent
Hi everybody
I can plot points out of decimaldegrees coordinates from my custom table. But I can not do the same using UTM coordinates. Can any one help me on how to do it?
Best Regards,
Vincent
Your case is the typical scenario where you have to apply projection conversion to your data before plotting it on the map in order to match the projection of the map.
You can look at the sample GPS to Google Map (desktop) that shows a case similar to yours where you have a point in decimal degrees plotted on Google Map (Spherical Mercator projection). It is a desktop application bu the projection logic is the same.
wiki.thinkgeo.com/wiki/Map_Suite_Wp...c)_Samples
In your case, instead of converting to the Google Map projection, you need to convert your point to the UTM projection.
To find UTM info, you can look at the sample, Geodetic to UTM on the fly.
wiki.thinkgeo.com/wiki/Map_Suite_Wp...on_Samples
I think that this should help. Thank you.
Hi Val
Thank you for the reply.
Basically let me tell you in detail what I want to do. I want to enable MouseCoordinates property of my Map control and then capture the x,y coordinates right way from the screen based on a shape file of the location of my interest, and save time from going physically to the field. I have already tried to capture these coordinates, and plot them without any success.
Using the projection concept, can you please give me a simple sample code showing how can this be done?
Best Regards,
Vincent
It is still not very clear to me what you are trying to do based on your explanation. You have points in UTM coordinates and you want to plot them on the Decimal Degrees map? Or is it the opposite? You have your map in UTM and you want to get the Longitude/Latitude values when clicking on the map? Can you explain a little more clearly? Thank you.
Hi Val
Thank you for the reply
I have a map in UTM and I want to get the coordinates in Longitude/Latitude when I click on the map.
Best Regards,
Vincent
Let say, for example, that your map is in the zone 16 UTM, look at the code in the Click event of the Map to get the coordinates for the Longitude and Latitude:
protected void Map1_Click(object sender, MapClickedEventArgs e)
{
ManagedProj4Projection proj4 = new ManagedProj4Projection();
//The projection of the Map in UTM
proj4.InternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(3160);//UTM zone 16 spatialreference.org/ref/epsg/3160/
//The projection you want to get the values in (Longitude/Latitude)
proj4.ExternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(4326);//Geodetic WGS 84 spatialreference.org/ref/epsg/4326/
//Converts from UTM to Geodetic to get the values for Longitude (.X) and for the Latitude (.Y)
PointShape UTMpointShape = new PointShape(e.Position.X, e.Position.Y);
proj4.Open();
PointShape GEOpointShape = (PointShape)proj4.ConvertToExternalProjection(UTMpointShape);
//Used the DecimalDegreesHelper static functions to format the Longitude and Latitude values.
string Longitude = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(GEOpointShape.X);
string Latitude = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(GEOpointShape.Y);
proj4.Close();
}
Hi Val
Thank you for the reply. I have worked on the sample code you have provided and I am now getting longitude and latitude in degrees, minutes, and seconds e.g. Longitude = "39º 15' 39''" and Latitude = "-06º 47' 55''". My GPS device reads as follows longitude = 39.25716749 and latitude = -6.79126298. How can I covert the result from your sample code to resemble my GPS device readings?
I still have problem with projection. My image is in WGS 84 / UTM zone 37S and when I plot the points from my GPS device they don't match. My code is as shown below
InMemoryMarkerOverlay inMarkerOverlay = new InMemoryMarkerOverlay("markerOverlay", columns);
foreach (DataRow item in datatable.Rows)
{
string x = item["X"].ToString();
Feature feature = new Feature(double.Parse(item["X"].ToString()), double.Parse(item["Y"].ToString()));
foreach (DataColumn col in datatable.Columns)
{
feature.ColumnValues[col.ColumnName] = item[col].ToString();
}
inMarkerOverlay.Features.Add(feature);
}
ManagedProj4Projection proj4 = new ManagedProj4Projection();
proj4.InternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(32737);
proj4.ExternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(4326);
inMarkerOverlay.FeatureSource.Projection = proj4;
To have the longitude and latitude in the format of your GPS device reads, simply use the X and Y properties of the PointShape, as you can see in the code snippet below:
protected void Map1_Click(object sender, MapClickedEventArgs e)
{
ManagedProj4Projection proj4 = new ManagedProj4Projection();
//The projection of the Map in UTM
proj4.InternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(3160);//UTM zone 16 spatialreference.org/ref/epsg/3160/
//The projection you want to get the values in (Longitude/Latitude)
proj4.ExternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(4326);//Geodetic WGS 84 spatialreference.org/ref/epsg/4326/
//Converts from UTM to Geodetic to get the values for Longitude (.X) and for the Latitude (.Y)
PointShape UTMpointShape = new PointShape(e.Position.X, e.Position.Y);
proj4.Open();
PointShape GEOpointShape = (PointShape)proj4.ConvertToExternalProjection(UTMpointShape);
//Used the DecimalDegreesHelper static functions to format the Longitude and Latitude values.
//string Longitude = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(GEOpointShape.X);
//string Latitude = DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(GEOpointShape.Y);
//Gets the Longitude and Latitude in the format of your GPS device reads.
double Longitude = GEOpointShape.X;
double Latitude = GEOpointShape.Y;
proj4.Close();
}
To answer your second question, on why the points from your GPS still don't match the map, my suspicion is that you have the Internal and External projections reversed. If you want to go from your GPS reading in Longitude/Latitude to the map in UTM, you should have the ManagedProj4Projection set as seen below:
ManagedProj4Projection proj4 = new ManagedProj4Projection();
proj4.InternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(4326);// in Geodetic (the GPS device reads).
proj4.ExternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(32737); //in UTM (the projection of the Map).
inMarkerOverlay.FeatureSource.Projection = proj4;
Hi Val
Thank you for the reply. I have tried to implement your sample code on projection, but still does not work. I can see the shape file but I don't see the point. I have attached my shape file here. Can you try to pick any point from within the shape file, then plot it in an overlay with the shape file by using your projection concept. And if it works then send me the code so that I can see where I am making mistake.
Best Regards,
Vincent
SampleData.zip (116 KB)
Thank you for the data. It always helps to have as much concrete information as possible. What I noticed is that the projection INFO in the PRJ file of the shapefile does not match the coordinates of the shapefile itself. According to the PRJ info, it should be in decimal degrees but it is obviously not. spatialreference.org/ref/esri/104000/
I think that the real problem is that we lack the correct and accurate projection information for that shapefile. Can you check with the data provider what the exact projection is for that shapefile? I did a little search on the name "Makuti", it says that it is in Zimbabwe. Zimbabwe belongs to the UTM zones 35 and 36, not 37 as EPSG 32737 suggests. spatialreference.org/ref/epsg/32737/
This is my guest but we will not know for sure until you get the exact projection info from your data provider.
Hi Val
Thank you for the reply. I will try to find out the projection for the file. Meanwhile, can you try this attached shape file.
Best Regards,
Vincent
NewSampleData.zip (7.38 KB)
I looked at that new data you just send and the projection information found in the PRJ file seems to match. I applied projection conversion to that shapefile so that it aligns with the World Map Kit in Geodetic (Longitude/Latitude) and it goes to Tanzania, near Dar Es Salam. Is it where it is supposed to go?
Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
Map1.MapUnit = GeographyUnit.DecimalDegree;
WorldMapKitWmsWebOverlay worldMapKitWmsOverlay = new WorldMapKitWmsWebOverlay();
Map1.CustomOverlays.Add(worldMapKitWmsOverlay);
ShapeFileFeatureLayer Layer1 = new ShapeFileFeatureLayer(Server.MapPath("~/App_Data/dar_ward.shp"));
Layer1.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(150,GeoColor.StandardColors.Pink), GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
Layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
ManagedProj4Projection proj4 = new ManagedProj4Projection();
proj4.InternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(32737);
proj4.ExternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(4326);
Layer1.FeatureSource.Projection = proj4;
Layer1.RequireIndex = true;
Layer1.DrawingMarginPercentage = 50;
Layer1.DrawingQuality = DrawingQuality.HighSpeed;
LayerOverlay staticOverlay = new LayerOverlay("StaticOverlay");
staticOverlay.IsBaseOverlay = false;
staticOverlay.Layers.Add("Dar_Ward", Layer1);
Map1.CustomOverlays.Add(staticOverlay);
Layer1.Open();
Map1.CurrentExtent = Layer1.GetBoundingBox();
Layer1.Close();
Hi Val
Thank you for the reply. I have obtained one point from within Dar_Ward shape file and entered it into my custom database and then plot it by creating a layer that overlays with Dar_Ward layer. The point still does not show. The following is the coordinates for that point.
Longitude = 39.153617539190265
Latitude = -6.7115343982598832
Below is my code
string worldLayerFilePath = Directory.GetParent(Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).FullName).FullName + "\\SampleData\\Dar_Ward.shp";
ShapeFileFeatureLayer MyworldLayer = new ShapeFileFeatureLayer(worldLayerFilePath);
LayerOverlay dynamicOverlay111 = new LayerOverlay();
dynamicOverlay111.IsBaseOverlay = false;
dynamicOverlay111.TileType = TileType.SingleTile;
dynamicOverlay111.Layers.Add("DynamicLayer11", MyworldLayer);
Map1.CustomOverlays.Add(dynamicOverlay111);
MyworldLayer.Open();
Map1.CurrentExtent = MyworldLayer.GetBoundingBox();
MyworldLayer.Close();
MyworldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(150, GeoColor.StandardColors.Pink), GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
MyworldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
TransformerFeatureLayer citiesLayer = new TransformerFeatureLayer("Mydata", "TransID", "XCordinate", "YCoordinate", connectionString);
citiesLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
citiesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
GetDataFromDB dbdt = new GetDataFromDB();
//Here I obtain data from my custom database
DataTable datatable = dbdt.GetDataTable(connectionString);
Collection<FeatureSourceColumn> columns = new Collection<FeatureSourceColumn>();
foreach (DataColumn item in datatable.Columns)
{
columns.Add(new FeatureSourceColumn(item.ColumnName));
}
InMemoryMarkerOverlay inMarkerOverlay = new InMemoryMarkerOverlay("markerOverlay", columns);
foreach (DataRow item in datatable.Rows)
{
string x = item["X"].ToString();
Feature feature = new Feature(double.Parse(item["X"].ToString()), double.Parse(item["Y"].ToString()));
foreach (DataColumn col in datatable.Columns)
{
feature.ColumnValues[col.ColumnName] = item[col].ToString();
}
inMarkerOverlay.Features.Add(feature);
}
ManagedProj4Projection proj4 = new ManagedProj4Projection();
proj4.InternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(4326);// in Geodetic (the GPS device reads).
proj4.ExternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(32737); //in UTM (the projection of the Map).
inMarkerOverlay.FeatureSource.Projection = proj4;
CloudPopup popup = new CloudPopup();
inMarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.ContentHtml = "[#Remarks#]";
Map1.CustomOverlays.Add(inMarkerOverlay);
Best Regards,
Vincent
I took your code simplified it to narrow down to the projection issue and I have the point (in purple in the screenshot below) showing with your shapefile. I don't know where it is supposed to go exactely with your shapefile as I am not familiar your data but the point shows up.
Map1.MapUnit = GeographyUnit.Meter;
string worldLayerFilePath = Server.MapPath("~/App_Data/dar_ward.shp");
ShapeFileFeatureLayer MyworldLayer = new ShapeFileFeatureLayer(worldLayerFilePath);
MyworldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(150, GeoColor.StandardColors.Pink), GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
MyworldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay dynamicOverlay111 = new LayerOverlay();
dynamicOverlay111.IsBaseOverlay = false;
dynamicOverlay111.TileType = TileType.SingleTile;
dynamicOverlay111.Layers.Add("DynamicLayer11", MyworldLayer);
Map1.CustomOverlays.Add(dynamicOverlay111);
MyworldLayer.Open();
Map1.CurrentExtent = MyworldLayer.GetBoundingBox();
MyworldLayer.Close();
InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.DarkBlue, 12,
GeoColor.StandardColors.Red,2);
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
Feature feature = new Feature(new PointShape(39.153617539190265, -6.7115343982598832));
inMemoryFeatureLayer.InternalFeatures.Add(feature);
ManagedProj4Projection proj4 = new ManagedProj4Projection();
proj4.InternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(4326);// in Geodetic (the GPS device reads).
proj4.ExternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(32737); //in UTM (the projection of the Map).
inMemoryFeatureLayer.FeatureSource.Projection = proj4;
LayerOverlay dynamicOverlay = new LayerOverlay();
dynamicOverlay.Layers.Add("Point", inMemoryFeatureLayer);
Map1.CustomOverlays.Add(dynamicOverlay);
Hi Val
Thank you very much. It has finally worked on my side.
I have another problem concerning legend and layerswitcher. Can you please help me.
Out of classBreakStyles and valueStyles which present features at different colors, how can I set up a layer that will specifically describe what those colors mean? (i.e Adornment or legend layer)
and
How can I set a fore color and font size/weight for my LayerSwitcher?
Best Regards,
Vincent
Now your question is more Web specific. I will let the Web team answer this. I let them know that you are waiting for an answer on this. Thank you.
Hi, Vincent
We have replied your questions in another post. Please check out it.
Thanks,
Khalil