Quantcast
Channel: DotSpatial
Viewing all articles
Browse latest Browse all 3973

Closed Issue: ArgumentOutOfRange exception in LineShapeFile.cs [22528]

$
0
0
A counter in LineShapeFile.cs can get out of sync with what it is iterating over if there are any ShapeType.NullShape objects in the shp file. See the bottom of this bug report for what the I think the problem and solution is.
 
File that causes the exception can be found here: http://ocs-gis.ncd.noaa.gov/cm_vs/Merged_Vector_Shoreline.zip
 
Download this zip file, extract contents, then pass the path of the extracted .shp file to DataManager.DefaultDataManager.OpenFile(path) - it will throw the following exception:
 
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at DotSpatial.Data.LineShapefile.FillLines(String fileName, IProgressHandler progressHandler) in C:\src\DotSpatial\DotSpatial.Data\LineShapefile.cs:line 299
at DotSpatial.Data.LineShapefile.Open(String fileName, IProgressHandler progressHandler) in C:\src\DotSpatial\DotSpatial.Data\LineShapefile.cs:line 88
at DotSpatial.Data.Shapefile.OpenFile(String fileName, IProgressHandler progressHandler) in C:\src\DotSpatial\DotSpatial.Data\Shapefile.cs:line 328
at DotSpatial.Data.Shapefile.OpenFile(String fileName) in C:\src\DotSpatial\DotSpatial.Data\Shapefile.cs:line 269
at DotSpatial.Data.ShapefileDataProvider.Open(String fileName) in C:\src\DotSpatial\DotSpatial.Data\ShapefileDataProvider.cs:line 119
at DotSpatial.Data.ShapefileDataProvider.DotSpatial.Data.IDataProvider.Open(String fileName) in C:\src\DotSpatial\DotSpatial.Data\ShapefileDataProvider.cs:line 65
at DotSpatial.Data.DataManager.OpenFile(String fileName, Boolean inRam, IProgressHandler progressHandler) in C:\src\DotSpatial\DotSpatial.Data\DataManager.cs:line 375
at DotSpatial.Data.DataManager.OpenFile(String fileName) in C:\src\DotSpatial\DotSpatial.Data\DataManager.cs:line 312
at Entiat.Cartography.ShapefileMap.InitializeFromPath(String path) in C:\src\entiat\Entiat\Cartography\ShapefileMap.cs:line 78
 
Specific lines of code that lead to the error:
 
200:
int numShapes = shapeHeaders.Count;
 
236: [[[causes ShapeIndices to no longer have a Count of numShapes]]]
 
if (shape.ShapeType == ShapeType.NullShape)
{
continue;
}
 
288:
ShapeIndices.Add(shape);
 
293:
List<ShapeRange> shapes = ShapeIndices;
 
297:
for (int shp = 0; shp < numShapes; shp++)
{
ShapeRange shape = shapes[shp];
BOOM.
 
Fix (I think): line 297 should read:
for (int shp = 0 ; shp < shapes.Count ; shp++)
 
But I'm not a shapefile expert. It is worth taking a hard look at whether the code in the offending for loop also needs to execute for NullShape...(?)

Viewing all articles
Browse latest Browse all 3973

Trending Articles