Apr 20, 2012 at 8:21 AM
Edited Apr 20, 2012 at 8:46 AM
|
Hi all
I encounter the exception of point array must contain 0 or >1 elements serval times which happen in the LineString class constructor public LineString(IList<Coordinate> points) : base(DefaultFactory);
I add a layer to the map with shapefilename by the method map.addlayer(filename),then I will save the shapefile which featuretype is line, so I check if the features count is 0 like this
if (featureSet.Features.Count != 0)
{
featureSet.IndexMode = false;
featureSet.Save();
}
the exception occur here if (featureSet.Features.Count != 0).
Also I open the file dspx then click a button to do like below
foreach (IMapLayer layer in map1.Layers)
{
testfs = layer.DataSet as FeatureSet;
if (testfs==null)
{
continue;
}
if (testfs.Features.Count != 0)
{
testfs.IndexMode = false;
testfs.Save();
}
else
{
testfs.IndexMode = false;
testfs.Save();
}
}
the exception occurs too.
well I don't know why this is happen,so anyone can tell me or give me some tips is very appreciated!
Besides,I want to know how to save a shapefile and whether while saving the file relates with featureset.indexmode or not, when and where I should use featureset.indexmode and featurelayer.editmode!
|
|
Developer
Apr 20, 2012 at 5:32 PM
Edited Apr 20, 2012 at 5:33 PM
|
By definition a LineString has at least two points (or zero points). You can see Create an Extension to Analyze Vector and Raster Data for
a related example.
Does this help?
|
|
|
|
Hi mudnug,
I can't see anything, this link I click shows nothing, I don't know why!
|
|
|
|
Hi mudnug,
Today I open the link and see the code for creating a line feature, I find that creating a line feature code is similar to mine , my code for creating the line feature is List<Coordinate> newList= new List<Coordinate>(){ },the newList contains
a few coordinates, LineString lineGeometry = new LineString(newList), ifeature line=featureset.addfeature(lineGeometry),then set the attribute for the line feature;
the code from the link is Creating an line ifeature doesn't contains any coordinates, then add coordinates from mouse clicking,
I think there is nothing different from my code to the code , so is there anything more helpful?
|
|
Developer
Apr 23, 2012 at 6:28 PM
|
I'm not able to reproduce this issue, yet. You say the exception occurs in the LineString constructor. Can you send the whole stack trace at that point?
|
|
|
|
Hi mudnug,
here is the constructor
/// <summary>
/// Creates a new LineString using the default factory
/// </summary>
/// <param name="points">
/// The points of the linestring, or <c>null</c>
/// to create the empty point. Consecutive points may not be equal.
/// </param>
public LineString(IList<Coordinate> points)
: base(DefaultFactory)
{
if (points == null)
points = new Coordinate[] { };
if (points.Count == 1)
throw new ArgumentException("point array must contain 0 or >1 elements");
_points = points;
}
and the exception stack
未处理 System.ArgumentException
Message=point array must contain 0 or >1 elements
Source=DotSpatial.Topology
StackTrace:
在 DotSpatial.Topology.LineString..ctor(IList`1 points)
在 DotSpatial.Data.FeatureSet.GetLine(Int32 index)
在 DotSpatial.Data.LineShapefile.GetFeature(Int32 index)
在 DotSpatial.Data.FeatureSet.FeaturesFromVertices()
在 DotSpatial.Data.FeatureSet.get_Features()
在 SunWin.RIVSCS.ELECTRONICMAP.MAPMAKE.FormCallMethod.SaveProjectSHP(Object mapobject) 位置 G:\MapDotSpatial\SunWin.Map\SunWin.RIVSCS.ELECTRONICMAP.MAPMAKE\SunWin.RIVSCS.ELECTRONICMAP.MAPMAKE\FormCallMethod.cs:行号 116
在 SunWin.RIVSCS.ELECTRONICMAP.MAPMAKE.FormCallMethod.SaveProjectManageList(String file, AppManager appManager, Map map) 位置 G:\MapDotSpatial\SunWin.Map\SunWin.RIVSCS.ELECTRONICMAP.MAPMAKE\SunWin.RIVSCS.ELECTRONICMAP.MAPMAKE\FormCallMethod.cs:行号
1785
在 WindowsFormsApplication1.MainForm.saveproject() 位置 G:\MapDotSpatial\SunWin.Map\SunWin.RIVSCS.ELECTRONICMAP.MAPMAKE\WindowsFormsApplication1\MainForm.cs:行号 509
在 WindowsFormsApplication1.MainForm.ImportLayerCAD_Click(Object sender, EventArgs e) 位置 G:\MapDotSpatial\SunWin.Map\SunWin.RIVSCS.ELECTRONICMAP.MAPMAKE\WindowsFormsApplication1\MainForm.cs:行号 3365
在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
在 System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
在 System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 WindowsFormsApplication1.Program.Main() 位置 G:\MapDotSpatial\SunWin.Map\SunWin.RIVSCS.ELECTRONICMAP.MAPMAKE\WindowsFormsApplication1\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
|
|
Developer
Apr 25, 2012 at 6:09 PM
|
I can't tell how your stack trace and your previous post match, but it looks like the shapes that are being processed have only one vertex (point). Should
FeatureType == FeatureType.Point
instead of FeatureType.Line?
I think the key to your issue is looking at the code in GetLine(int)
ShapeRange shape = ShapeIndices[index];
List<IBasicLineString> lines = new List<IBasicLineString>();
foreach (PartRange part in shape.Parts)
{
int i = part.StartIndex;
List<Coordinate> coords = new List<Coordinate>();
foreach (Vertex d in part)
{
You can see that it is finding only one Vertex in each part and this causes the issue.
|
|