This project is read-only.

Create a simply Shape File with some Line String inside..

Dec 27, 2010 at 12:25 PM

Ciao, 

i get an error while saving a shapefile with just a LineString inside as feature!   The code i use is this one:

 

  IFeatureSet shape = new FeatureSet(DotSpatial.Topology.FeatureType.Line);
            Console.WriteLine("ShapeFile created in memory...");

            shape.Projection = DotSpatial.Projections.KnownCoordinateSystems.Geographic.World.WGS1984;
            shape.DataTable.Columns.Add(new DataColumn("isCoastLine", typeof(bool)));
            
            
            List<DotSpatial.Topology.Coordinate> coordinates = new List<DotSpatial.Topology.Coordinate>(); 

            foreach (var point in data)
            {
                coordinates.Add(new DotSpatial.Topology.Coordinate(point.Lon,point.Lat));
            }

            var line = new DotSpatial.Topology.LineString(coordinates);


            IFeature feature = shape.AddFeature(line);
            feature.DataRow.BeginEdit();
            feature.DataRow["isCoastLine"] = aWay.Tags.Any( t => ((t.Key == "natural") && (t.Value == "coastline")));
            feature.DataRow.EndEdit();


            shape.UpdateExtent();
            shape.SaveAs(@"C:\MapData\Open Street Map\coastShape.shp",true);
            

And executing it at "SaveAs" i got this error:

"Object reference not set to an instance of an object."

stack trace:

"   at DotSpatial.Data.ShapefileHeader.SetExtent(IExtent extent) in C:\\Dev\\DotSpatial\\DotSpatial.Data\\DotSpatial.Data\\ShapefileHeader.cs:line 331\r\n   at DotSpatial.Data.LineShapefile.SaveAs(String fileName, Boolean overwrite) in C:\\Dev\\DotSpatial\\DotSpatial.Data\\DotSpatial.Data\\LineShapefile.cs:line 364\r\n   at DotSpatial.Data.FeatureSet.Save() in C:\\Dev\\DotSpatial\\DotSpatial.Data\\DotSpatial.Data\\FeatureSet.cs:line 935\r\n   at DotSpatial.Data.FeatureSet.SaveAs(String fileName, Boolean overwrite) in C:\\Dev\\DotSpatial\\DotSpatial.Data\\DotSpatial.Data\\FeatureSet.cs:line 990\r\n   at OsmExplorer.Program.Main(String[] args) in C:\\Code\\OsmScout-6642\\OsmExplorer\\Program.cs:line 77\r\n   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)\r\n   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)\r\n   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()\r\n   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)\r\n   at System.Threading.ExecutionContext.runTryCode(Object userData)\r\n   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)\r\n   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n   at System.Threading.ThreadHelper.ThreadStart()"

 

What can be???

Thanks

Alberto