This project is read-only.

This code will add a geographic coordinate system (GCS) to a feature set that does not contain a GCS.

VB Sample Code:

Imports System.Spatial.Projections

'Code for defining a geographic coordinate system for a feature set
    Private Sub BbtnDefineGeographicProjection_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BbtnDefineGeographicProjection.Click
        Dim fs As New FeatureSet
        Dim CopyFS As New FeatureSet
        Dim dest As ProjectionInfo

        'Get's the first layer in the Table of Contents
        fs = MapControl.Layers.Item(0).DataSet

        'Copies the selected layer to a new feature set
        'Prevents the original file from being edited
        CopyFS.CopyFeatures(fs, True)

        dest = KnownCoordinateSystems.Geographic.World.WGS1984
        'Adds the geographic coordinate system to the feature set
        CopyFS.Projection = dest
        'Saves the feature set
        CopyFS.SaveAs("C:\Temp\US_Cities_GCS_WGS1984.shp", True)

        MessageBox.Show("The feature was successfully been projected.")

    End Sub



C# Sample Code:

//Code for defining a geographic coordinate system for a feature set
private void BbtnDefineGeographicProjection_Click(System.Object sender, System.EventArgs e)
{
	FeatureSet fs = new FeatureSet();
	FeatureSet CopyFS = new FeatureSet();
	ProjectionInfo dest = default(ProjectionInfo);

	//Get's the first layer in the Table of Contents
	fs = MapControl.Layers.Item(0).DataSet;

	//Copies the selected layer to a new feature set
	//Prevents the original file from being edited
	CopyFS.CopyFeatures(fs, true);

	dest = KnownCoordinateSystems.Geographic.World.WGS1984;
	//Adds the geographic coordinate system to the feature set
	CopyFS.Projection = dest;
	//Saves the feature set
	CopyFS.SaveAs("C:\\Temp\\US_Cities_GCS_WGS1984.shp", true);

	MessageBox.Show("The feature was successfully been projected.");

}

Last edited May 5, 2015 at 6:37 PM by mbayles, version 4