Read Proj4 strings - sindizzy/DSW GitHub Wiki
This is sample code for reprojecting a point by reading a Proj4 String
C# Sample Code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Spatial.Projections;
using System.IO;
namespace Sample_Code_Reading_Proj4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//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](2);
double[]() z = new double[1](1);
//calls the reproject function and reprojects the points
Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1);
MessageBox.Show("Reprojection is compelte.");
}
}
}
VB.Net Sample Code
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Spatial.Projections
Imports System.IO
Namespace Sample_Code_Reading_Proj4
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
'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
End Class
End Namespace