Sample Code_ Adding a Geographic Coordinate System to a Feature Set - sindizzy/DSW GitHub Wiki
This code will take a feature set that does not have any spatial information and applies a geographic coordinate system to the feature set.
Sample code for VB.net
Imports DotSpatial.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)
CopyFS.Projection = fs.Projection
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
End Class
Sample Code for C#
Imports DotSpatial.Projections
//Code for defining a geographic coordinate system for a feature set
private void btnDefine_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);
CopyFS.Projection = fs.Projection;
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.");
}