Closed vishnu4 closed 4 years ago
replied in develop branch using this test
List<IShapefileFeature> data = null;
using (var reader = new ShapeDataReader("TestShapefiles/crustal_test.shp"))
{
var mbr = reader.ShapefileBounds;
data = reader.ReadByMBRFilter(mbr).ToList();
}
Assert.IsNotNull(data);
Assert.IsNotEmpty(data);
foreach (var item in data)
{
Assert.IsNotNull(item.Geometry);
Assert.IsNotNull(item.Attributes["ID_GTR"]);
}
Both asserts actually throws an InvalidOperationException
in ShapeReader.ThrowIfDisposed
method
@airbreather fix is straightforward, as long as it's acceptable to remove the Lazy objects that are the source of the error...
public ShapefileFeature(ShapeReader shapeReader, DbaseReader dbfReader, ShapeLocationInFileInfo shapeLocation, GeometryFactory geoFactory)
{
FeatureId = shapeLocation.ShapeIndex;
_lazyGeometry = new Lazy<Geometry>(() => shapeReader.ReadShapeAtOffset(shapeLocation.OffsetFromStartOfFile, geoFactory), LazyThreadSafetyMode.ExecutionAndPublication);
_lazyAttributeTable = new Lazy<IAttributesTable>(() => dbfReader.ReadEntry(shapeLocation.ShapeIndex), LazyThreadSafetyMode.ExecutionAndPublication);
// see https://github.com/NetTopologySuite/NetTopologySuite.IO.ShapeFile/issues/27
var tempGeom = _lazyGeometry.Value;
var tempAttrs = _lazyAttributeTable.Value;
}
see patch.zip simply as a suggestion.
@FObermaier @airbreather if you agree I can commit the code by myself
as long as it's acceptable to remove the Lazy objects that are the source of the error
Sounds fine to me
please see PR #30
having an issue where i would like to read from a shape file, dispose the reader but hold the shape file information to do something with later. something like:
and then later, in another method that
on the attribute line, i get the following error:
_System.InvalidOperationException: Reader was disposed, cannot read from a disposed reader Stack Trace: DbaseReader.ReadEntry(Int32 index) <.ctor>b__1() Lazy
1.CreateValue() Lazy
1.LazyInitValue() Lazy`1.get_Value() IFeature.getAttributes()is there any way to get what i'm looking for here, or can i not centralize the shape file loading/disposing like i'm hoping to?