Example Code: Reproject a Shapefile

This code will take a feature set and project the feature set from a geographic coordinate system to the USA Contiguous Lambert Conic projected coordinate system.

VB Sample Code:

Imports System
Imports DotSpatial.Projections

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Sets up a array to contain the x and y coordinates
        Dim xy(1) As Double
        xy(0) = 0
        xy(1) = 0
        'An array for the z coordinate
        Dim z(0) As Double
        z(0) = 1
        'Defines the starting coordiante system
        Dim pStart As ProjectionInfo = KnownCoordinateSystems.Geographic.World.WGS1984
        'Defines the ending coordiante system
        Dim pEnd As ProjectionInfo = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousLambertConformalConic
        'Calls the reproject function that will transform the input location to the output locaiton
        Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1)
        MsgBox("The points have been reporjected.")

    End Sub

End Class


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 DotSpatial.Projections;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Sets up a array to contain the x and y coordinates
	        double[] xy = new double[2];
	        xy[0] = 0;
	        xy[1] = 0;
	        //An array for the z coordinate
	        double[] z = new double[1];
	        z[0] = 1;
	        //Defines the starting coordiante system
	        ProjectionInfo pStart = KnownCoordinateSystems.Geographic.World.WGS1984;
	        //Defines the ending coordiante system
	        ProjectionInfo pEnd = KnownCoordinateSystems.Projected.NorthAmerica.USAContiguousLambertConformalConic;
	        //Calls the reproject function that will transform the input location to the output locaiton
	        Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1);
	        Interaction.MsgBox("The points have been reporjected.");
        }
    }
}

Last edited Jul 13, 2010 at 2:32 PM by AlamoMan, version 15

Comments

No comments yet.