System.IndexOutOfRangeException

Topics: SharpMap Project, SharpMap v2.0
Jul 24, 2008 at 9:03 PM

Hi

I am getting the following exception when creating a shape file (a.shp from the SharpMap project samples)

System.IndexOutOfRangeException was unhandled

Message="Index was outside the bounds of the array."

Source="SharpMap.Data.Providers.ShapeFile"

 

I have traced the exception to line 1698 of file ShapeFileProvider.cs (see below). The cause appears to be the size of variable index being 5 and as can be seen from the code attempting to write featureCount times. In this case 287 times. Could someone investigate this for me. I cannot see where the array size is initially setup. If this is a bug, can someone supply a patch or let me know what lines to change to allow me to continue developing.

I have given the call stack and local windows when the exception was thrown. If more info is required, let me know.

Many thanks

Derek

ShapeFileProvider.cs

private ISpatialIndex<IExtents, IdBounds> createSpatialIndex()

{

...... snip .....

UInt32 featureCount = (UInt32)GetFeatureCount();

for (UInt32 i = 0; i < featureCount; i++)
{
    IGeometry geom = readGeometry(i);
    if (geom == null || geom.IsEmpty)
    {
        continue;
    }
    IExtents extents = geom.Extents;
    index.Insert(new IdBounds(i, extents)); <---------- EXCEPTION

}
return index;

 

Call Stack

> SharpMap.Data.Providers.ShapeFile.dll!SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.Open(bool exclusive = false) Line 664 C#

SharpMap.Data.Providers.ShapeFile.dll!SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.Open() Line 800 + 0x9 bytes C#

SharpMap.dll!SharpMap.Data.Providers.AsyncProviderAdapter.Open() Line 78 + 0x9 bytes C#

SharpMap.dll!SharpMap.Layers.FeatureLayer.FeatureLayer(string layername = "ShapeFile Layers", SharpMap.Styles.FeatureStyle style = {SharpMap.Styles.GeometryStyle}, SharpMap.Data.IFeatureProvider dataSource = {Name: ..\..\ShapeFiles\a.shp; HasDbf: True; Features: 287; Extents: Extents [240000 - 498882.32, 4250000.92 - 4455000.56]}) Line 94 + 0x11 bytes C#

SharpMap.dll!SharpMap.Layers.GeometryLayer.GeometryLayer(string layername = "ShapeFile Layers", SharpMap.Styles.GeometryStyle style = {SharpMap.Styles.GeometryStyle}, SharpMap.Data.IFeatureProvider dataSource = {Name: ..\..\ShapeFiles\a.shp; HasDbf: True; Features: 287; Extents: Extents [240000 - 498882.32, 4250000.92 - 4455000.56]}) Line 57 + 0xf bytes C#

SharpMap.dll!SharpMap.Layers.GeometryLayer.GeometryLayer(string layername = "ShapeFile Layers", SharpMap.Data.IFeatureProvider dataSource = {Name: ..\..\ShapeFiles\a.shp; HasDbf: True; Features: 287; Extents: Extents [240000 - 498882.32, 4250000.92 - 4455000.56]}) Line 48 + 0x20 bytes C#

SeeTrackDotNet.exe!SeeTrackDotNet.MainForm.AddLayer(string fileName = "..\\..\\ShapeFiles\\a.shp") Line 112 + 0x1a bytes C#

SeeTrackDotNet.exe!SeeTrackDotNet.MainForm.MainForm() Line 60 + 0xd bytes C#

SeeTrackDotNet.exe!SeeTrackDotNet.Program.Main() Line 18 + 0x13 bytes C#

[External Code]

Locals before exception is thrown

+ this {Name: ..\..\ShapeFiles\a.shp; HasDbf: True; Features: 287; Extents: Extents [240000 - 498882.32, 4250000.92 - 4455000.56]} SharpMap.Data.Providers.ShapeFile.ShapeFileProvider

+ geom {POLYGON ((469443.55 4452256.44, 469400 4452200, 468796.41 4452302.54, 468427.81 4452799.69, 467956.45 4453834.9, 468356.49 4454143.56, 468989.26 4454005.72, 469637.82 4453263.28, 469841.77 4452563.8, 469443.55 4452256.44))} GeoAPI.Geometries.IGeometry {GisSharpBlog.NetTopologySuite.Geometries.Polygon<NetTopologySuite.Coordinates.BufferedCoordinate2D>}

+ extents {Extents [467956.45 - 469841.77, 4452200 - 4454143.56]} GeoAPI.Geometries.IExtents {GisSharpBlog.NetTopologySuite.Geometries.Extents<NetTopologySuite.Coordinates.BufferedCoordinate2D>}

i 4 uint

+ restructureStrategy {SharpMap.Indexing.RTree.NullRestructuringStrategy<GeoAPI.Geometries.IExtents,SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds>} GeoAPI.Indexing.IIndexRestructureStrategy<GeoAPI.Geometries.IExtents,SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds> {SharpMap.Indexing.RTree.NullRestructuringStrategy<GeoAPI.Geometries.IExtents,SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds>}

+ restructureHeuristic {SharpMap.Indexing.RTree.RestructuringHuristic} SharpMap.Indexing.RTree.RestructuringHuristic

+ insertStrategy {SharpMap.Indexing.RTree.GuttmanQuadraticInsert<SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds>} GeoAPI.Indexing.IItemInsertStrategy<GeoAPI.Geometries.IExtents,SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds> {SharpMap.Indexing.RTree.GuttmanQuadraticInsert<SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds>}

+ nodeSplitStrategy {SharpMap.Indexing.RTree.GuttmanQuadraticSplit<SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds>} GeoAPI.Indexing.INodeSplitStrategy<GeoAPI.Geometries.IExtents,SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds> {SharpMap.Indexing.RTree.GuttmanQuadraticSplit<SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds>}

+ indexHeuristic {SharpMap.Indexing.RTree.DynamicRTreeBalanceHeuristic} SharpMap.Indexing.RTree.DynamicRTreeBalanceHeuristic

+ idleMonitor null SharpMap.Utilities.IdleMonitor

+ index {SharpMap.Indexing.RTree.SelfOptimizingDynamicSpatialIndex<SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds>} SharpMap.Indexing.RTree.DynamicRTree<SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds> {SharpMap.Indexing.RTree.SelfOptimizingDynamicSpatialIndex<SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds>}

featureCount 287 uint

 

Locals

- $exception {"Index was outside the bounds of the array."} System.Exception {System.IndexOutOfRangeException}

+ [System.IndexOutOfRangeException] {"Index was outside the bounds of the array."} System.IndexOutOfRangeException

+ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}

HelpLink null string

+ InnerException null System.Exception

Message "Index was outside the bounds of the array." string

Source "SharpMap.Data.Providers.ShapeFile" string

StackTrace " at SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.getPolyRings(IList`1 rings, Boolean[] isCounterClockWise, Int32& i) in D:\\SharpMap\\sharpmap\\SharpMap.Data.Providers\\ShapeFileProvider\\ShapeFileProvider.cs:line 2072\r\n at SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.readPolygon() in D:\\SharpMap\\sharpmap\\SharpMap.Data.Providers\\ShapeFileProvider\\ShapeFileProvider.cs:line 2044\r\n at SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.readGeometry(UInt32 oid) in D:\\SharpMap\\sharpmap\\SharpMap.Data.Providers\\ShapeFileProvider\\ShapeFileProvider.cs:line 1808\r\n at SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.createSpatialIndex() in D:\\SharpMap\\sharpmap\\SharpMap.Data.Providers\\ShapeFileProvider\\ShapeFileProvider.cs:line 1689\r\n at SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.loadSpatialIndex(Boolean forceRebuild, Boolean loadFromFile) in D:\\SharpMap\\sharpmap\\SharpMap.Data.Providers\\ShapeFileProvider\\ShapeFileProvider.cs:line 1716\r\n at SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.loadSpatialIndex(Boolean loadFromFile) in D:\\SharpMap\\sharpmap\\SharpMap.Data.Providers\\ShapeFileProvider\\ShapeFileProvider.cs:line 1706\r\n at SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.Open(Boolean exclusive) in D:\\SharpMap\\sharpmap\\SharpMap.Data.Providers\\ShapeFileProvider\\ShapeFileProvider.cs:line 664\r\n at SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.Open() in D:\\SharpMap\\sharpmap\\SharpMap.Data.Providers\\ShapeFileProvider\\ShapeFileProvider.cs:line 800\r\n at SharpMap.Data.Providers.AsyncProviderAdapter.Open() in D:\\SharpMap\\sharpmap\\SharpMap\\Data\\Providers\\AsyncProviderAdapter.cs:line 78\r\n at SharpMap.Layers.FeatureLayer..ctor(String layername, FeatureStyle style, IFeatureProvider dataSource) in D:\\SharpMap\\sharpmap\\SharpMap\\Layers\\FeatureLayer.cs:line 94\r\n at SharpMap.Layers.GeometryLayer..ctor(String layername, GeometryStyle style, IFeatureProvider dataSource) in D:\\SharpMap\\sharpmap\\SharpMap\\Layers\\GeometryLayer.cs:line 57\r\n at SharpMap.Layers.GeometryLayer..ctor(String layername, IFeatureProvider dataSource) in D:\\SharpMap\\sharpmap\\SharpMap\\Layers\\GeometryLayer.cs:line 48\r\n at SeeTrackDotNet.MainForm.AddLayer(String fileName) in D:\\SharpMap\\SeeTrackDotNet\\SeeTrackDotNet\\MainForm.cs:line 112\r\n at SeeTrackDotNet.MainForm..ctor() in D:\\SharpMap\\SeeTrackDotNet\\SeeTrackDotNet\\MainForm.cs:line 60\r\n at SeeTrackDotNet.Program.Main() in D:\\SharpMap\\SeeTrackDotNet\\SeeTrackDotNet\\Program.cs:line 18\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.Run(ExecutionContext executionContext, ContextCallback callback, Object state)\r\n at System.Threading.ThreadHelper.ThreadStart()" string

+ TargetSite {System.Collections.Generic.List`1[GeoAPI.Geometries.ILinearRing] getPolyRings(System.Collections.Generic.IList`1[GeoAPI.Geometries.ILinearRing], Boolean[], Int32 ByRef)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}

+ Static members

+ Non-Public members

- this {Name: ..\..\ShapeFiles\a.shp; HasDbf: True; Features: 287; Extents: Extents [240000 - 498882.32, 4250000.92 - 4455000.56]} SharpMap.Data.Providers.ShapeFile.ShapeFileProvider

+ _coordinateSystem {PROJCS["WGS_1984_UTM_Zone_49N", GEOGCS["GCS_WGS_1984", DATUM["D_WGS_1984", SPHEROID["WGS_1984", 6378137, 298.257223563]], PRIMEM["Greenwich", 0], UNIT["Degree", 0.0174532925199433]], PROJECTION["Transverse_Mercator"], PARAMETER["False_Easting", 500000], PARAMETER["False_Northing", 0], PARAMETER["Central_Meridian", 111], PARAMETER["Scale_Factor", 0.9996], PARAMETER["Latitude_Of_Origin", 0], UNIT["Meter", 1]]} GeoAPI.CoordinateSystems.ICoordinateSystem {ProjNet.CoordinateSystems.ProjectedCoordinateSystem<NetTopologySuite.Coordinates.BufferedCoordinate2D>}

+ _coordSysFactory {ProjNet.CoordinateSystems.CoordinateSystemFactory<NetTopologySuite.Coordinates.BufferedCoordinate2D>} GeoAPI.CoordinateSystems.ICoordinateSystemFactory {ProjNet.CoordinateSystems.CoordinateSystemFactory<NetTopologySuite.Coordinates.BufferedCoordinate2D>}

_coordsysReadFromFile true bool

_coordTransform null GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation

_currentReader null SharpMap.Data.Providers.ShapeFile.ShapeFileDataReader

+ _dbaseFile {SharpMap.Data.Providers.ShapeFile.DbaseFile} SharpMap.Data.Providers.ShapeFile.DbaseFile

_disposed false bool

_filename "..\\..\\ShapeFiles\\a.shp" string

_filterDelegate null System.Predicate<SharpMap.Data.FeatureDataRow>

+ _geoFactory {GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory<NetTopologySuite.Coordinates.BufferedCoordinate2D>} GeoAPI.Geometries.IGeometryFactory {GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory<NetTopologySuite.Coordinates.BufferedCoordinate2D>}

_hasDbf true bool

_hasFileBasedSpatialIndex false bool

+ _header {[ShapeFileHeader] ShapeType: Polygon; Envelope: Extents [240000 - 498882.32, 4250000.92 - 4455000.56]; FileLengthInWords: 145210} SharpMap.Data.Providers.ShapeFile.ShapeFileHeader

_isIndexed true bool

_isOpen false bool

_readerSync {object} object

+ _shapeFileIndex {SharpMap.Data.Providers.ShapeFile.ShapeFileIndex} SharpMap.Data.Providers.ShapeFile.ShapeFileIndex

+ _shapeFileReader {System.IO.BinaryReader} System.IO.BinaryReader

+ _shapeFileStream {System.IO.FileStream} System.IO.FileStream

+ _shapeFileWriter {System.IO.BinaryWriter} System.IO.BinaryWriter

_spatialIndex null GeoAPI.Indexing.ISpatialIndex<GeoAPI.Geometries.IExtents,SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.IdBounds>

_srid null int?

ConnectionId "..\\..\\ShapeFiles\\a.shp" string

CoordinateTransformation null GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation

DbfFilename "D:\\SharpMap\\SeeTrackDotNet\\SeeTrackDotNet\\ShapeFiles\\a.dbf" string

+ Encoding 'this.Encoding' threw an exception of type 'SharpMap.Data.Providers.ShapeFile.ShapeFileInvalidOperationException' System.Text.Encoding {SharpMap.Data.Providers.ShapeFile.ShapeFileInvalidOperationException}

Filename "..\\..\\ShapeFiles\\a.shp" string

Filter null System.Predicate<SharpMap.Data.FeatureDataRow>

+ GeometryFactory {GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory<NetTopologySuite.Coordinates.BufferedCoordinate2D>} GeoAPI.Geometries.IGeometryFactory {GisSharpBlog.NetTopologySuite.Geometries.GeometryFactory<NetTopologySuite.Coordinates.BufferedCoordinate2D>}

HasDbf true bool

IdColumnName "OID" string

IndexFilename "D:\\SharpMap\\SeeTrackDotNet\\SeeTrackDotNet\\ShapeFiles\\a.shx" string

IsDisposed false bool

IsOpen false bool

IsSpatiallyIndexed true bool

+ Locale 'this.Locale' threw an exception of type 'System.NullReferenceException' System.Globalization.CultureInfo {System.NullReferenceException}

+ ShapeType 'this.ShapeType' threw an exception of type 'SharpMap.Data.Providers.ShapeFile.ShapeFileInvalidOperationException' SharpMap.Data.Providers.ShapeFile.ShapeType {SharpMap.Data.Providers.ShapeFile.ShapeFileInvalidOperationException}

+ SpatialReference {PROJCS["WGS_1984_UTM_Zone_49N", GEOGCS["GCS_WGS_1984", DATUM["D_WGS_1984", SPHEROID["WGS_1984", 6378137, 298.257223563]], PRIMEM["Greenwich", 0], UNIT["Degree", 0.0174532925199433]], PROJECTION["Transverse_Mercator"], PARAMETER["False_Easting", 500000], PARAMETER["False_Northing", 0], PARAMETER["Central_Meridian", 111], PARAMETER["Scale_Factor", 0.9996], PARAMETER["Latitude_Of_Origin", 0], UNIT["Meter", 1]]} GeoAPI.CoordinateSystems.ICoordinateSystem {ProjNet.CoordinateSystems.ProjectedCoordinateSystem<NetTopologySuite.Coordinates.BufferedCoordinate2D>}

Srid null int?

exclusive false bool