This project is read-only.

Doing DotSpatial in Visual C# 2010 Express: Geographic Coordinate System GCS_WGS_1984 - Creating A DotSpatial Map for 8 GIS Points

Feb 18, 2011 at 9:03 PM

Hi all,

In the DotSpatial (with 2-12-2011 dll library) program, the following code of Visual C# 2010 Express worked:

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

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

        private void btnCoord_Click(object sender, EventArgs e)
        {
            FeatureSet fs = new FeatureSet(FeatureType.Point);
            fs.Projection = KnownCoordinateSystems.Projected.UtmNad1983.NAD1983UTMZone11N;
            fs.DataTable.Columns.Add("Elevation", typeof(int));
            
            //creates a new coordinate 
            Coordinate c = new Coordinate(2.4, 7.9);
            //passes the coordinate to a new point
            DotSpatial.Topology.Point p = new DotSpatial.Topology.Point(c);
            //displayes the new point's x and y coordiantes
            MessageBox.Show("Point p is: x= " + p.X + " & y= " + p.Y);
            
            IFeature currentFeature = fs.AddFeature(p);
            fs.SaveAs(@"C:\Temp\test-onePt.shp",true);
            MessageBox.Show("Shapefile created successfully.");
        }     
    }
}

If I tried to do "ADD Data" for a "Continental USA" shapfile with Geographic Coordinate System GCS_WGS_1984, Project Mismatch (The new layer had a project that does not match the current map project) occurred and no new Map can be added.   I try to change the "Utm1983.NAD1983UTMZone11N" to the format of GCS_WGS_1984 in the code statement of

fs.Projection = KnownCoordinateSystems.Projected.UtmNad1983.NAD1983UTMZone11N;

.  How can I do it?    Please help and advise me on this matter.

Thanks in advance,

Scott Chang

Feb 22, 2011 at 6:01 PM
Edited Feb 23, 2011 at 3:29 PM

I tried the following code:

 fs.Projection = KnownCoordinateSystems.Projected.GcsWgs1984.WGS1984WGSZone11N;

I got the following error:

Error 1 'DotSpatial.Projections.ProjectedSystems' does not contain a definition for 'GcsWgs1984' and no extension method 'GcsWgs1984' accepting a first argument of type 'DotSpatial.Projections.ProjectedSystems' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\e1enxshc\my documents\visual studio 2010\Projects\scDotSpatial_NewPoint-btnCoord\scDotSpatial_NewPoint-btnCoord\Form1.cs 26 62 scDotSpatial_NewPoint-btnCoord

I do not know whether the World Geodetic System 1984 "GCS_WGS_1984 is in DotSpatial.Projections.dll or not.  I like to read the DotSpatial.Projections.dll file.  How can I read the DotSpatial.Projections.dll file?   Please help and advise.

Thanks,

Scott Chang 

 

Feb 22, 2011 at 7:01 PM
Hi Scott,
Try:
fs.Projection =KnownCoordinateSystems.Geographic.World.WGS1984

Jiri

Feb 23, 2011 at 2:26 PM

Hi Jiri,  Thanks for your nice response.

It worked nicely.  Wonderful!!!

I have values of the XY-coordinates of 8 points in Microsoft Excel 2007(.xlsx) Table:

    FID    Id  LocationID       X          Y
0 1   EB1 -77.01507 38.870909
1 2   EB2 -77.01507 38.870745
2 3   EB3 -77.01507 38.870615
3 4   EB4 -77.01518 38.870868
4 5   EB5 -77.01531 38.87071
5 6   EB6 -77.01535 38.870614
6 7   EB7 -77.01518 38.870744
7 8   EB8 -77.01519 38.870631

           The .xlsx Sheet Name: FtMcNair.

I want to read these values by using the C# codes and create these 8 points in the DotSpatial Map.  I studied the DotSpatial Tutorial (4) - Shapefile and Attribute table operations and Printing maps in DotSpatial (in Visual Basic).   Do you have the Visual C# version of the DotSpatial Tutorial (4)?  Please kindly help and enlighten me in creating the above-mentioned 8 points in the DotSpatial Map and saving the results/files in my C:\Temp folder.

Thanks in advance,

Scott Chang