I have a .csv file of coordinates such as the following:

-90.19, 38.62, St Louis
-122.42, 37.82, San Francisco
-74.04, 40.68, New York

I want to create a shapefile using DotSpatial that has these points, so that I can overlay them on a shapefile of the United States. Which functions in DotSpatial would I provide these points to, to generate a shapefile?

I don't use this library, however you can write a similar code:

            string[] csv = new string[] { "-90.19, 38.62, St Louis", "-122.42, 37.82, San Francisco", "-74.04, 40.68, New York" };

            using (FeatureSet features = new FeatureSet(FeatureType.Point))
                features.CoordinateType = CoordinateType.Regular;
                features.Filename = @"c:\temp\test1.shp";
                features.Projection = ProjectionInfo.FromProj4String(KnownCoordinateSystems.Geographic.World.WGS1984.ToProj4String());
                DataColumn dt = features.DataTable.Columns.Add("City", typeof(string));
                int idxColumn = dt.Ordinal;
                foreach (var row in csv) 
                    string[] s = row.Split(',');
                    IBasicGeometry g = new Point(Convert.ToDouble(s[0], CultureInfo.InvariantCulture), Convert.ToDouble(s[1], CultureInfo.InvariantCulture));
                    IFeature f = features.AddFeature(g);
                    DataRow dr = f.DataRow;
                    dr.SetField<string>(idxColumn, s[2].Trim());

  • 1
    Looking at the DotSpatial documentation provides a few samples to do just this...I could copy and past the code but that would be cheating :-) And, you wouldn't see the rest! See Dotspatial Sample Code Have fun! – WolfOdrade Feb 4 '11 at 23:47

Browse other questions tagged or ask your own question.