Adding a Geographic Coordinate System to a Feature Set - sindizzy/DSW GitHub Wiki

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

    <span style="color:green">'Get's the first layer in the Table of Contents</span>
    fs = MapControl.Layers.Item(0).DataSet

    <span style="color:green">'Copies the selected layer to a new feature set</span>
    <span style="color:green">'Prevents the original file from being edited</span>
    CopyFS.CopyFeatures(fs, <span style="color:blue">True</span>)

    dest = KnownCoordinateSystems.Geographic.World.WGS1984
    <span style="color:green">'Adds the geographic coordinate system to the feature set</span>
    CopyFS.Projection = dest
    <span style="color:green">'Saves the feature set</span>
    CopyFS.SaveAs(<span style="color:#a31515">&quot;C:\Temp\US_Cities_GCS_WGS1984.shp&quot;</span>, <span style="color:blue">True</span>)

    MessageBox.Show(<span style="color:#a31515">&quot;The feature was successfully been projected.&quot;</span>)

<span style="color:blue">End</span> <span style="color:blue">Sub</span>



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);
<span style="color:green">//Get's the first layer in the Table of Contents</span>
fs = MapControl.Layers.Item(0).DataSet;

<span style="color:green">//Copies the selected layer to a new feature set</span>
<span style="color:green">//Prevents the original file from being edited</span>
CopyFS.CopyFeatures(fs, <span style="color:blue">true</span>);

dest = KnownCoordinateSystems.Geographic.World.WGS1984;
<span style="color:green">//Adds the geographic coordinate system to the feature set</span>
CopyFS.Projection = dest;
<span style="color:green">//Saves the feature set</span>
CopyFS.SaveAs(<span style="color:#a31515">&quot;C:\\Temp\\US_Cities_GCS_WGS1984.shp&quot;</span>, <span style="color:blue">true</span>);

MessageBox.Show(<span style="color:#a31515">&quot;The feature was successfully been projected.&quot;</span>);

}

⚠️ **GitHub.com Fallback** ⚠️