ReadESRIPrjFiles - sindizzy/DSW GitHub Wiki

Sample code to project a point using the ESRI Projection File
This sample is now out of date, but may be used as a starting point.

VB.Net Sample Code

Imports DotSpatial.Projections

'Sample code that will conduct a reprojection by reading in the ESRI.prj file Private Sub btnProjection_Click(sender As Object, e As EventArgs) 'declares a new ProjectionInfo for the startind and ending coordinate systems 'sets the start GCS to WGS_1984 Dim pStart As ProjectionInfo = KnownCoordinateSystems.Geographic.World.WGS1984 'reads the end coordinate system from the ESRI .prj file
Dim pESRIEnd As ProjectionInfo = ProjectionInfo.Open("C:\Program Files\ArcGIS\Coordinate Systems\Projected Coordinate Systems\UTM\WGS 1984\WGS 1984 UTM Zone 1N.prj") 'declares the point(s) that will be reprojected Dim xy As Double() = New Double(1) {} Dim z As Double() = New Double(0) {} 'calls the reprojection function Reproject.ReprojectPoints(xy, z, pStart, pESRIEnd, 0, 1) MessageBox.Show("Points have been projected successfully.") End Sub



C# Sample Code

using DotSpatial.Projections;
    <span style="color:green">//Sample code that will conduct a reprojection by reading in the ESRI.prj file</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 for the startind and ending coordinate systems</span>
        <span style="color:green">//sets the start GCS to WGS_1984</span>
        ProjectionInfo pStart = KnownCoordinateSystems.Geographic.World.WGS1984;
        ProjectionInfo pESRIEnd = ProjectionInfo.Open(<span style="color:#a31515">&quot;C:\\Program Files\\ArcGIS\\Coordinate Systems\\Projected Coordinate Systems\\UTM\\WGS 1984\\WGS 1984 UTM Zone 1N.prj&quot;</span>); <br><span style="color:green">            //declares the point(s) that will be reprojected</span> <br>            <span style="color:blue">double</span>[] xy = <span style="color:blue">new</span> <span style="color:blue">double</span>[2]; <br>            <span style="color:blue">double</span>[] z = <span style="color:blue">new</span> <span style="color:blue">double</span>[1]; <br><span style="color:green">            //calls the reprojection function</span> <br>            Reproject.ReprojectPoints(xy, z, pStart, pESRIEnd, 0, 1); <br>            MessageBox.Show(<span style="color:#a31515">&quot;Points have been projected successfully.&quot;</span>); <br>        }</pre>
⚠️ **GitHub.com Fallback** ⚠️