using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThinkGeo.MapSuite.Core;
namespace ProjectionInFeet
{
class LambertInFeetProjection : Projection
{
Proj4Projection proj4Projection = new Proj4Projection();
public LambertInFeetProjection()
{
//Lambert projection as internal projection.
proj4Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
//Geodetic (Longitude/Latitude) as external projection.
proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetEsriParametersString(102004);
}
protected override Vertex[] ConvertToExternalProjectionCore(double[] x, double[] y)
{
proj4Projection.Open();
Vertex[] vertices = new Vertex[x.Length];
for (int i = 0; i < vertices.Length; i++)
{
//converts Longitude/Latitude to Meters for Lambert.
vertices[i] = proj4Projection.ConvertToExternalProjection(x[i], y[i]);
//Then we need to convert meters to feet.
vertices[i].X = Conversion.ConvertMeasureUnits(vertices[i].X, DistanceUnit.Meter, DistanceUnit.Feet);
vertices[i].Y = Conversion.ConvertMeasureUnits(vertices[i].Y, DistanceUnit.Meter, DistanceUnit.Feet);
}
proj4Projection.Close();
return vertices;
}
protected override Vertex[] ConvertToInternalProjectionCore(double[] x, double[] y)
{
proj4Projection.Open();
Vertex[] vertices = new Vertex[x.Length];
for (int i = 0; i < vertices.Length; i++)
{
//First, we need to convert feet to meters.
x[i] = Conversion.ConvertMeasureUnits(x[i], DistanceUnit.Feet, DistanceUnit.Meter);
y[i] = Conversion.ConvertMeasureUnits(y[i], DistanceUnit.Feet, DistanceUnit.Meter);
//Then, we can convert from meters to geodetic (Longitude/Latitude).
vertices[i] = proj4Projection.ConvertToInternalProjection(x[i], y[i]);
}
proj4Projection.Close();
return vertices;
}
}
}
using System;
using System.Drawing;
using System.Windows.Forms;
using ThinkGeo.MapSuite.Core;
namespace ProjectionInFeet
{
public partial class TestForm : Form
{
private MapEngine mapEngine = new MapEngine();
private Bitmap bitmap = null;
ShapeFileFeatureLayer worldLayer = null;
public TestForm()
{
InitializeComponent();
}
private void TestForm_Load(object sender, EventArgs e)
{
// Set the full extent and the background color
mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-7948051,5116233,7630384,-5296296), Map.Width, Map.Height);
mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
// Add the static layers to the MapEngine
worldLayer = new ShapeFileFeatureLayer(@"..\..\Data\USStates_lambert.shp", ShapeFileReadWriteMode.ReadOnly);
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.County1;
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
mapEngine.StaticLayers.Add("StatesLayer", worldLayer);
//Add the dynamic layer to the MapEngine
InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
//The feature has its coordinate in Longitude/Latitude.
Feature newFeature1 = new Feature(new PointShape(-95.83, 39.15));
inMemoryFeatureLayer.InternalFeatures.Add("myFeature", newFeature1);
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.Red, 10);
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
//Applies the projection to the InMemoryFeatureLayer.
//LambertInFeetProjection has the internal projection as Lambert (feet) and
//external projection as geodetic (Longitude/Latitude).
LambertInFeetProjection lambertProj = new LambertInFeetProjection();
inMemoryFeatureLayer.FeatureSource.Projection = lambertProj;
mapEngine.DynamicLayers.Add(inMemoryFeatureLayer);
DrawImage();
}
private void DrawImage()
{
if (bitmap != null) { bitmap.Dispose(); }
bitmap = new Bitmap(Map.Width, Map.Height);
mapEngine.OpenAllLayers();
mapEngine.DrawStaticLayers(bitmap, GeographyUnit.Feet);
mapEngine.DrawDynamicLayers(bitmap, GeographyUnit.Feet);
mapEngine.CloseAllLayers();
Map.Image = bitmap;
}
private void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
{
switch (e.Button.Tag.ToString())
{
case "Zoom In":
mapEngine.CurrentExtent.ScaleDown(50);
break;
case "Zoom Out":
mapEngine.CurrentExtent.ScaleUp(50);
break;
case "Full Extent":
mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-180.0, 83.0, 180.0, -90.0), Map.Width, Map.Height);
break;
case "Pan Left":
mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Left, 20);
break;
case "Pan Right":
mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Right, 20);
break;
case "Pan Up":
mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Up, 20);
break;
case "Pan Down":
mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Down, 20);
break;
default:
break;
}
DrawImage();
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}