Quantcast
Channel: DotSpatial Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 1128

Commented Unassigned: ShapeReader - Error moving from one page to the next [63623]

$
0
0
Hello,

there is a error in the [`DotSpatial.Data.ShapeReader`](http://dotspatial.codeplex.com/SourceControl/latest#Trunk/DotSpatial.Data/ShapeReader.cs).

The move next function is incrementing the internal index, while the `GetShape(...)` function does so as well. This causes the reader to skip one entry in the shape at the beginning of every shape except the first.

To fix this I suggest you initialize the `_index` variable with `0` and remove the increment in this function.
That solves the problem.

So all in all this is the fixed implementation for the enumerator I propose:
``` C#
/// <summary>
/// Creates an enumerator for pages of shapes returned as dictionaries.
/// </summary>
public class Enumerator : IEnumerator<Dictionary<int, Shape>>
{
private readonly IEnvelope _envelope;
private readonly int _pageSize;
private readonly IShapeSource _source;
private int _count;
private int _index;
private Dictionary<int, Shape> _page;

/// <summary>
/// Creates ShapePageSet.Enumerator which can be used to cycle very large datasets.
/// </summary>
/// <param name="parent"></param>
public Enumerator(ShapeReader parent)
{
_source = parent._source;
_pageSize = parent.PageSize;
_envelope = parent.Envelope;
Reset();
}

#region IEnumerator<Dictionary<int,Shape>> Members

/// <inheritdocs/>
public Dictionary<int, Shape> Current
{
get { return _page; }
}

object IEnumerator.Current
{
get { return _page; }
}

/// <inheritdocs/>
public void Dispose()
{
}

/// <inheritdocs/>
public bool MoveNext()
{
if (_count < 0) _count = _source.GetShapeCount();
if (_index >= _count) return false;
_page = _source.GetShapes(ref _index, _pageSize, _envelope);
return true;
}

/// <inheritdocs/>
public void Reset()
{
_page = null;
_index = 0;
_count = -1;
}

#endregion
}
```

Regards,
Martin
Comments: I added a pull request that resolves this issue. Please merge it! Currently I maintain a local shadowing class in my application that overwrites the DotSpatial ShapeReader in order to work around this issue. Calling this a hack is a understatement. ;-) I'd very much like to get rid of this with the next release... when ever this may come.

Viewing all articles
Browse latest Browse all 1128

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>