Sample code that demonstrates how to read a prog4 string and then project a point

C# Code
using DotSpatial.Projections;

        //Code that allows the user to input a Proj4 string and reproject a WGS 1984 GCS to a Proj4 PCS
        private void btnProjection_Click(object sender, EventArgs e)
        {
            //Declares a new ProjectionInfo and sets it to GCS_WGS_1984
            ProjectionInfo pStart = new ProjectionInfo();
            pStart = KnownCoordinateSystems.Geographic.World.WGS1984;
            //Declares a new ProjectionInfo and allows the user to directly input a Proj4 sring
            ProjectionInfo pEnd = new ProjectionInfo("+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs ");
            //Declares the point to be project, starts out as 0,0
            double[] xy = new double[2];
            double[] z = new double[1];
            //calls the reproject function and reprojects the points
            Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1);
            MessageBox.Show("Reprojection is compelte.");          
        }      

VB.net Code
Imports DotSpatial.Projections

'Code that allows the user to input a Proj4 string and reproject a WGS 1984 GCS to a Proj4 PCS
Private Sub btnProjection_Click(sender As Object, e As EventArgs)
	'Declares a new ProjectionInfo and sets it to GCS_WGS_1984
	Dim pStart As New ProjectionInfo()
	pStart = KnownCoordinateSystems.Geographic.World.WGS1984
	'Declares a new ProjectionInfo and allows the user to directly input a Proj4 sring
	Dim pEnd As New ProjectionInfo("+proj=aea +lat_1=20 +lat_2=-23 +lat_0=0 +lon_0=25 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs ")
	'Declares the point to be project, starts out as 0,0
	Dim xy As Double() = New Double(1) {}
	Dim z As Double() = New Double(0) {}
	'calls the reproject function and reprojects the points
	Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1)
	MessageBox.Show("Reprojection is compelte.")
End Sub

Last edited Jul 13, 2010 at 3:23 PM by AlamoMan, version 2