ReadProj4Strings - sindizzy/DSW GitHub Wiki
C# Code
using DotSpatial.Projections;<span style="color:green">//Code that allows the user to input a Proj4 string and reproject a WGS 1984 GCS to a Proj4 PCS</span> <span style="color:blue">private</span> <span style="color:blue">void</span> btnProjection_Click(<span style="color:blue">object</span> sender, EventArgs e) { <span style="color:green">//Declares a new ProjectionInfo and sets it to GCS_WGS_1984</span> ProjectionInfo pStart = <span style="color:blue">new</span> ProjectionInfo(); pStart = KnownCoordinateSystems.Geographic.World.WGS1984; <span style="color:green">//Declares a new ProjectionInfo and allows the user to directly input a Proj4 string</span> ProjectionInfo pEnd = ProjectionInfo.FromEsriString(<span style="color:#a31515">"+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 "</span>); <span style="color:green">//Declares the point to be projected, starts out as 0,0</span> <span style="color:blue">double</span>[] xy = <span style="color:blue">new</span> <span style="color:blue">double</span>[2]; <span style="color:blue">double</span>[] z = <span style="color:blue">new</span> <span style="color:blue">double</span>[1]; <span style="color:green">//calls the reproject function and reprojects the points</span> Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1); MessageBox.Show(<span style="color:#a31515">"Reprojection is complete."</span>); }
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 string Dim pEnd As ProjectionInfo = ProjectionInfo.FromEsriString("+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 projected, 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 complete.") End Sub