Skip to content

Commit

Permalink
Renamed ILayerProvider interface hierarchy to remove "Layer" from name
Browse files Browse the repository at this point in the history
Removed many IFeatureProvider query method variations leaving only methods returning IFeatureDataReader
Created new IFeatureAdaptor interface containing removed methods as temporary holding ground until the correct configuration for methods dealing with FeatureDataSet, FeatureDataTable, and asynchronous versions is determined.
Updated FeatureProvider, GeometryProvider, and ShapeFileProvider and tests to conform to new interface
  • Loading branch information
justsome.handle committed May 13, 2008
1 parent 3a993d2 commit 014d775
Show file tree
Hide file tree
Showing 28 changed files with 827 additions and 656 deletions.
77 changes: 47 additions & 30 deletions SharpMap.Data.Providers.ShapeFile.Tests/ShapeFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,31 +404,33 @@ public void CloseExclusiveTest()
}

[Test]
[Ignore("Retarget or delete test; IEnumerable<IGeometry> method variations obsoleted in favor of returning IFeatureDataReader")]
public void GetGeometriesInViewTest()
{
ShapeFileProvider shapeFile = new ShapeFileProvider(
@"..\..\..\TestData\BCROADS.SHP", _geoFactory, _coordSysFactory);
shapeFile.Open();
List<IGeometry> geometries = new List<IGeometry>();

geometries.AddRange(shapeFile.ExecuteGeometryIntersectionQuery(shapeFile.GetExtents()));
//geometries.AddRange(shapeFile.ExecuteGeometryIntersectionQuery(shapeFile.GetExtents()));
Assert.AreEqual(shapeFile.GetFeatureCount(), geometries.Count);
geometries.Clear();

IGeometry empty = _geoFactory.CreatePoint();
geometries.AddRange(shapeFile.ExecuteGeometryIntersectionQuery(empty));
//geometries.AddRange(shapeFile.ExecuteGeometryIntersectionQuery(empty));
Assert.AreEqual(0, geometries.Count);
}

[Test]
[ExpectedException(typeof (ShapeFileInvalidOperationException))]
[Ignore("Retarget or delete test; IEnumerable<IGeometry> method variations obsoleted in favor of returning IFeatureDataReader")]
[ExpectedException(typeof(ShapeFileInvalidOperationException))]
public void GetGeometriesInViewWhenClosedThrowsExceptionTest()
{
ShapeFileProvider shapeFile = new ShapeFileProvider(
@"..\..\..\TestData\BCROADS.SHP", _geoFactory, _coordSysFactory);

IGeometry empty = _geoFactory.CreatePoint();
new List<IGeometry>(shapeFile.ExecuteGeometryIntersectionQuery(empty));
//new List<IGeometry>(shapeFile.ExecuteGeometryIntersectionQuery(empty));
}

[Test]
Expand All @@ -437,10 +439,10 @@ public void ExecuteIntersectionQueryByBoundingBoxTest()
ShapeFileProvider shapeFile = new ShapeFileProvider(
@"..\..\..\TestData\BCROADS.SHP", _geoFactory, _coordSysFactory);
shapeFile.Open();
FeatureDataSet data = new FeatureDataSet("ShapeFile test", _geoFactory);
shapeFile.ExecuteIntersectionQuery(shapeFile.GetExtents(), data);
Assert.AreEqual(1, data.Tables.Count);
Assert.AreEqual(shapeFile.GetFeatureCount(), data.Tables[0].Rows.Count);
FeatureDataTable data = new FeatureDataTable("ShapeFile test", _geoFactory);
IFeatureDataReader reader = shapeFile.ExecuteIntersectionQuery(shapeFile.GetExtents());
data.Load(reader, LoadOption.OverwriteChanges, null);
Assert.AreEqual(shapeFile.GetFeatureCount(), data.Rows.Count);
shapeFile.Close();
}

Expand All @@ -450,8 +452,7 @@ public void ExecuteIntersectionQueryByBoundingBoxWhenClosedThrowsExceptionTest()
{
ShapeFileProvider shapeFile = new ShapeFileProvider(
@"..\..\..\TestData\BCROADS.SHP", _geoFactory, _coordSysFactory);
FeatureDataSet data = new FeatureDataSet("ShapeFile test", _geoFactory);
shapeFile.ExecuteIntersectionQuery(shapeFile.GetExtents(), data);
IFeatureDataReader reader = shapeFile.ExecuteIntersectionQuery(shapeFile.GetExtents());
}

[Test]
Expand Down Expand Up @@ -578,14 +579,13 @@ public void InsertFeatureTest()

Assert.AreEqual(1, shapeFile.GetFeatureCount());

FeatureDataSet dataSet = new FeatureDataSet("ShapeFile test", _geoFactory);

shapeFile.ExecuteIntersectionQuery(_geoFactory.CreateExtents2D(0.9, 0.9, 1, 1), dataSet);
FeatureDataTable dataTable = new FeatureDataTable("ShapeFile test", _geoFactory);
IFeatureDataReader reader = shapeFile.ExecuteIntersectionQuery(_geoFactory.CreateExtents2D(0.9, 0.9, 1, 1));
dataTable.Load(reader, LoadOption.OverwriteChanges, null);

Assert.AreEqual(1, dataSet.Tables.Count);
Assert.AreEqual(1, dataSet.Tables[0].Rows.Count);
Assert.AreEqual(1, dataTable.Rows.Count);

FeatureDataRow<UInt32> newFeature = dataSet.Tables[0].Rows[0] as FeatureDataRow<UInt32>;
FeatureDataRow newFeature = dataTable.Rows[0] as FeatureDataRow;
Assert.AreEqual(_geoFactory.CreatePoint2D(1, 1), newFeature.Geometry);
Assert.AreEqual(newFeature["Name"], "Test feature");
DateTime dateCreatedActual = (DateTime) newFeature["DateCreated"];
Expand Down Expand Up @@ -653,12 +653,11 @@ ICoordinateSequence coordinates
Assert.AreEqual(10000, shapeFile.GetFeatureCount());
Assert.AreEqual(computedBounds, shapeFile.GetExtents());

FeatureDataSet dataSet = new FeatureDataSet("ShapeFile test", _geoFactory);

shapeFile.ExecuteIntersectionQuery(shapeFile.GetExtents(), dataSet);
FeatureDataTable dataTable = new FeatureDataTable("ShapeFile test", _geoFactory);
IFeatureDataReader reader = shapeFile.ExecuteIntersectionQuery(shapeFile.GetExtents());
dataTable.Load(reader, LoadOption.OverwriteChanges, null);

Assert.AreEqual(1, dataSet.Tables.Count);
Assert.AreEqual(10000, dataSet.Tables[0].Rows.Count);
Assert.AreEqual(10000, dataTable.Rows.Count);
}

[Test]
Expand Down Expand Up @@ -726,6 +725,28 @@ private IProjectedCoordinateSystem createExpectedCoordinateSystem()
return expected;
}

[Test]
[ExpectedException(typeof(ShapeFileInvalidOperationException))]
public void GetSchemaTableFailsifShapeFileNotOpen()
{
ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP", _geoFactory);

DataTable schemaTable = shapeFile.GetSchemaTable();
}

[Test]
public void GetSchemaTableReturnsOid()
{
ShapeFileProvider shapeFile = new ShapeFileProvider(
@"..\..\..\TestData\BCROADS.SHP", _geoFactory, _coordSysFactory);
shapeFile.Open();

DataTable schemaTable = shapeFile.GetSchemaTable();

Assert.AreEqual(34, schemaTable.Rows.Count);
Assert.AreEqual("OID", schemaTable.Rows[0][ProviderSchemaHelper.ColumnNameColumn]);
}

[Test]
[ExpectedException(typeof (ShapeFileInvalidOperationException))]
public void SetTableSchemaShouldFailIfShapeFileNotOpen()
Expand All @@ -743,8 +764,7 @@ public void SetTableSchemaShouldMatchShapeFileSchema()
@"..\..\..\TestData\BCROADS.SHP", _geoFactory, _coordSysFactory);
shapeFile.Open();
IGeometry empty = _geoFactory.CreatePoint();
FeatureDataTable<UInt32> queryTable = new FeatureDataTable<UInt32>("OID", _geoFactory);
shapeFile.ExecuteIntersectionQuery(empty, queryTable);
FeatureDataTable<UInt32> queryTable = shapeFile.CreateNewTable() as FeatureDataTable<UInt32>;

FeatureDataTable nonKeyedTable = new FeatureDataTable(_geoFactory);
shapeFile.SetTableSchema(nonKeyedTable);
Expand All @@ -762,12 +782,9 @@ public void SetTableSchemaWithDifferentKeyCase()
ShapeFileProvider shapeFile = new ShapeFileProvider(@"..\..\..\TestData\BCROADS.SHP", _geoFactory);
shapeFile.Open();
IGeometry empty = _geoFactory.CreatePoint();
FeatureDataTable<UInt32> queryTable = new FeatureDataTable<UInt32>("OID", _geoFactory);
shapeFile.ExecuteIntersectionQuery(empty, queryTable);

FeatureDataTable<UInt32> keyedTable = new FeatureDataTable<UInt32>("oid", _geoFactory);
shapeFile.SetTableSchema(keyedTable);
DataTableHelper.AssertTableStructureIdentical(keyedTable, queryTable);
}

[Test]
Expand All @@ -778,8 +795,8 @@ public void SetTableSchemaWithDifferentKeyCaseAndSchemaMergeAction()
@"..\..\..\TestData\BCROADS.SHP", _geoFactory, _coordSysFactory);
shapeFile.Open();
IGeometry empty = _geoFactory.CreatePoint();
FeatureDataTable<UInt32> queryTable = new FeatureDataTable<UInt32>("OID", _geoFactory);
shapeFile.ExecuteIntersectionQuery(empty, queryTable);
FeatureDataTable<UInt32> queryTable = shapeFile.CreateNewTable() as FeatureDataTable<UInt32>;
// expecting a new FeatureDataTable<UInt32>("OID", _geoFactory);

FeatureDataTable<UInt32> keyedTable = new FeatureDataTable<UInt32>("oid", _geoFactory);
shapeFile.SetTableSchema(keyedTable, SchemaMergeAction.CaseInsensitive);
Expand All @@ -794,8 +811,8 @@ public void SetTableSchemaWithDifferentKeyNameAndSchemaMergeAction()
@"..\..\..\TestData\BCROADS.SHP", _geoFactory, _coordSysFactory);
shapeFile.Open();
IGeometry empty = _geoFactory.CreatePoint();
FeatureDataTable<UInt32> queryTable = new FeatureDataTable<UInt32>("OID", _geoFactory);
shapeFile.ExecuteIntersectionQuery(empty, queryTable);
FeatureDataTable<UInt32> queryTable = shapeFile.CreateNewTable() as FeatureDataTable<UInt32>;
// expecting a new FeatureDataTable<UInt32>("OID", _geoFactory);

FeatureDataTable<UInt32> keyedTable = new FeatureDataTable<UInt32>("FID", _geoFactory);
shapeFile.SetTableSchema(keyedTable, SchemaMergeAction.KeyByType);
Expand Down
44 changes: 26 additions & 18 deletions SharpMap.Data.Providers.ShapeFile/ShapeFileDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,18 @@ public Boolean HasOid
{
get
{
checkState();
return true;
checkDisposed();
return true;
}
}

public Boolean IsFullyLoaded
{
get { return _options == QueryExecutionOptions.FullFeature; }
get
{
return (_options | QueryExecutionOptions.BoundingBoxes)
== (QueryExecutionOptions.FullFeature | QueryExecutionOptions.BoundingBoxes);
}
}

public Type OidType
Expand All @@ -173,15 +177,15 @@ public Int32 Depth
{
get
{
checkState();
return 0;
checkDisposed();
return 0;
}
}

public DataTable GetSchemaTable()
{
checkState();
return _schemaTable.Copy();
checkDisposed();
return _schemaTable.Copy();
}

public Boolean IsClosed
Expand All @@ -197,7 +201,7 @@ public Boolean NextResult()

public Boolean Read()
{
checkState();
checkDisposed();

Boolean reading = _objectEnumerator.MoveNext();

Expand All @@ -222,12 +226,12 @@ public Int32 FieldCount
{
get
{
checkState();
return _schemaTable.Rows.Count;
checkDisposed();
return _schemaTable.Rows.Count;
}
}

public Boolean GetBoolean(Int32 i)
public Boolean GetBoolean(Int32 i)
{
checkState();
checkIndex(i);
Expand Down Expand Up @@ -302,8 +306,7 @@ public Type GetFieldType(Int32 i)
{
checkState();
checkIndex(i);

return _currentFeature[i].GetType();
return _currentFeature.GetFieldType(i);
}

public Single GetFloat(Int32 i)
Expand Down Expand Up @@ -370,13 +373,13 @@ public Int64 GetInt64(Int32 i)

public String GetName(Int32 i)
{
checkState();
return _schemaTable.Rows[i][0] as String;
checkDisposed();
return _schemaTable.Rows[i][0] as String;
}

public Int32 GetOrdinal(String name)
{
checkState();
checkDisposed();

if (name == null) throw new ArgumentNullException("name");

Expand Down Expand Up @@ -475,14 +478,19 @@ private void checkIndex(Int32 i)

private void checkState()
{
if (IsDisposed) throw new ObjectDisposedException(GetType().ToString());
checkDisposed();
if (_currentFeature == null)
{
throw new InvalidOperationException("The Read method must be called before accessing values.");
}
}

#endregion
private void checkDisposed()
{
if (IsDisposed) throw new ObjectDisposedException(GetType().ToString());
}

#endregion

#region IEnumerable<IFeatureDataRecord> Members

Expand Down
Loading

0 comments on commit 014d775

Please sign in to comment.