Skip to content

Commit

Permalink
Update tests data
Browse files Browse the repository at this point in the history
to cover invalid lnf codes and multipart geometries
  • Loading branch information
tschumpr committed Jun 13, 2024
1 parent 7f55916 commit 6989eda
Show file tree
Hide file tree
Showing 21 changed files with 98 additions and 46 deletions.
19 changes: 11 additions & 8 deletions Geodatenbezug.Test/Geodatenbezug.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,34 @@
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

<ItemGroup>
<ItemGroup>
<None Include="testdata\lwb_perimeter_terrassenreben_lv95.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_perimeter_terrassenreben_lv95_no_gpkg.zip">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_bewirtschaftungseinheit_v2_0_lv95_NE_202404191123.gpkg">
<None Include="testdata\lwb_bewirtschaftungseinheit_v2_0_lv95_testdaten.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_biodiversitaetsfoerderflaechen_v2_0_lv95_testdaten.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_biodiversitaetsfoerderflaechen_v2_0_lv95_NE_202404191123.gpkg">
<None Include="testdata\lwb_nutzungsflaechen_v2_0_lv95_testdaten.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_nutzungsflaechen_v2_0_lv95_NE_202404191123.gpkg">
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_NE_202404191123.gpkg">
<None Include="testdata\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_geometry.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_perimeter_terrassenreben_v2_0_lv95_NE_202404191123.gpkg">
<None Include="testdata\lwb_perimeter_terrassenreben_v2_0_lv95_testdaten.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="testdata\lwb_rebbaukataster_v2_0_lv95_NE_202404191123.gpkg">
<None Include="testdata\lwb_rebbaukataster_v2_0_lv95_testdaten.gpkg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Geodatenbezug.Processors;

[TestClass]
[DeploymentItem("testdata/lwb_bewirtschaftungseinheit_v2_0_lv95_NE_202404191123.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_bewirtschaftungseinheit_v2_0_lv95_testdaten.gpkg", "testdata")]
public class BewirtschaftungseinheitProcessorTest
{
private readonly Topic topic = new ()
Expand Down Expand Up @@ -42,7 +42,7 @@ public async Task RunGdalProcessingAsync()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_bewirtschaftungseinheit_v2_0_lv95_NE_202404191123.gpkg";
processor.InputDataPath = "testdata\\lwb_bewirtschaftungseinheit_v2_0_lv95_testdaten.gpkg";
await processor.RunGdalProcessingAsync();

var inputSource = Ogr.Open(processor.InputDataPath, 0);
Expand Down Expand Up @@ -71,7 +71,7 @@ public async Task RunGdalProcessingAsync()
var firstBetriebInputFeature = betriebInputLayer.GetNextFeature();
betriebResultLayer.ResetReading();
var firstBetriebResultFeature = betriebResultLayer.GetNextFeature();
Assert.AreEqual(firstBetriebInputFeature.GetFID(), firstBetriebResultFeature.GetFieldAsInteger("t_id"));
Assert.AreEqual(firstBetriebInputFeature.GetFieldAsInteger("t_id"), firstBetriebResultFeature.GetFieldAsInteger("t_id"));
GdalAssert.AssertDateTime(firstBetriebInputFeature, firstBetriebResultFeature, "bezugsjahr");
Assert.AreEqual(firstBetriebInputFeature.GetFieldAsString("betriebsnummer"), firstBetriebResultFeature.GetFieldAsString("betriebsnummer"));
Assert.AreEqual(firstBetriebInputFeature.GetFieldAsString("betriebsname"), firstBetriebResultFeature.GetFieldAsString("betriebsname"));
Expand Down Expand Up @@ -107,7 +107,7 @@ public async Task RunGdalProcessingAsync()
var firstBewirtschaftungseinheitInputFeature = bewirtschaftungseinheitInputLayer.GetNextFeature();
bewirtschaftungseinheitResultLayer.ResetReading();
var firstBewirtschaftungseinheitResultFeature = bewirtschaftungseinheitResultLayer.GetNextFeature();
Assert.AreEqual(firstBewirtschaftungseinheitInputFeature.GetFID(), firstBewirtschaftungseinheitResultFeature.GetFieldAsInteger("t_id"));
Assert.AreEqual(firstBewirtschaftungseinheitInputFeature.GetFieldAsInteger("t_id"), firstBewirtschaftungseinheitResultFeature.GetFieldAsInteger("t_id"));
GdalAssert.AssertDateTime(firstBewirtschaftungseinheitInputFeature, firstBewirtschaftungseinheitResultFeature, "bezugsjahr");
Assert.AreEqual(firstBewirtschaftungseinheitInputFeature.GetFieldAsInteger("ist_definitiv"), firstBewirtschaftungseinheitResultFeature.GetFieldAsInteger("ist_definitiv"));
Assert.AreEqual(firstBewirtschaftungseinheitInputFeature.GetFieldAsString("betriebsnummer"), firstBewirtschaftungseinheitResultFeature.GetFieldAsString("betriebsnummer"));
Expand Down Expand Up @@ -143,7 +143,7 @@ public async Task RunGdalProcessingAsync()
var firstProduktionsstaetteInputFeature = produktionsstaetteInputLayer.GetNextFeature();
produktionsstaetteResultLayer.ResetReading();
var firstProduktionsstaetteResultFeature = produktionsstaetteResultLayer.GetNextFeature();
Assert.AreEqual(firstProduktionsstaetteInputFeature.GetFID(), firstProduktionsstaetteResultFeature.GetFieldAsInteger("t_id"));
Assert.AreEqual(firstProduktionsstaetteInputFeature.GetFieldAsInteger("t_id"), firstProduktionsstaetteResultFeature.GetFieldAsInteger("t_id"));
GdalAssert.AssertDateTime(firstProduktionsstaetteInputFeature, firstProduktionsstaetteResultFeature, "bezugsjahr");
Assert.AreEqual(firstProduktionsstaetteInputFeature.GetFieldAsString("ps_nr"), firstProduktionsstaetteResultFeature.GetFieldAsString("ps_nr"));
Assert.AreEqual(firstProduktionsstaetteInputFeature.GetFieldAsString("ps_name"), firstProduktionsstaetteResultFeature.GetFieldAsString("ps_name"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Geodatenbezug.Processors;

[TestClass]
[DeploymentItem("testdata/lwb_biodiversitaetsfoerderflaechen_v2_0_lv95_NE_202404191123.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_biodiversitaetsfoerderflaechen_v2_0_lv95_testdaten.gpkg", "testdata")]
public class BiodiversitaetsfoerderflaechenProcessorTest
{
private readonly Topic topic = new ()
Expand Down Expand Up @@ -42,7 +42,7 @@ public async Task RunGdalProcessingAsync()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_biodiversitaetsfoerderflaechen_v2_0_lv95_NE_202404191123.gpkg";
processor.InputDataPath = "testdata\\lwb_biodiversitaetsfoerderflaechen_v2_0_lv95_testdaten.gpkg";
await processor.RunGdalProcessingAsync();

var inputSource = Ogr.Open(processor.InputDataPath, 0);
Expand Down Expand Up @@ -81,13 +81,28 @@ public async Task RunGdalProcessingAsync()
GdalAssert.AssertFieldType(qualitaetResultLayer, "beitragsberechtigt", FieldType.OFTInteger, FieldSubType.OFSTInt16);

GdalAssert.AssertOnlyValidLnfCodes(qualitaetResultLayer);

GdalAssert.AssertOnlySinglePartGeometries(qualitaetResultLayer);

var t_ids = new List<int>();
qualitaetResultLayer.ResetReading();
for (var i = 0; i < qualitaetResultLayer.GetFeatureCount(1); i++)
{
var feature = qualitaetResultLayer.GetNextFeature();
t_ids.Add(feature.GetFieldAsInteger("t_id"));
}

// Delete feature with invalid lnf_code
Assert.AreEqual(0, t_ids.FindAll(t_id => t_id == 550616).Count);

// Feature with multipart geometry was split into three features
Assert.AreEqual(2, t_ids.FindAll(t_id => t_id == 584805).Count);

// The first feature was deleted so we want to compare the second one
qualitaetInputLayer.GetNextFeature();
var firstQualitaetInputFeature = qualitaetInputLayer.GetNextFeature();
qualitaetResultLayer.ResetReading();
var firstQualitaetResultFeature = qualitaetResultLayer.GetNextFeature();
Assert.AreEqual(firstQualitaetInputFeature.GetFID(), firstQualitaetResultFeature.GetFieldAsInteger("t_id"));
Assert.AreEqual(firstQualitaetInputFeature.GetFieldAsInteger("t_id"), firstQualitaetResultFeature.GetFieldAsInteger("t_id"));
GdalAssert.AssertDateTime(firstQualitaetInputFeature, firstQualitaetResultFeature, "bezugsjahr");
Assert.AreEqual(firstQualitaetInputFeature.GetFieldAsInteger("anzahl_baeume"), firstQualitaetResultFeature.GetFieldAsInteger("anzahl_baeume"));
Assert.AreEqual(firstQualitaetInputFeature.GetFieldAsInteger("ist_definitiv"), firstQualitaetResultFeature.GetFieldAsInteger("ist_definitiv"));
Expand Down Expand Up @@ -130,24 +145,33 @@ public async Task RunGdalProcessingAsync()
GdalAssert.AssertFieldType(vernetzungResultLayer, "verpflichtung_von", FieldType.OFTDateTime);
GdalAssert.AssertFieldType(vernetzungResultLayer, "verpflichtung_bis", FieldType.OFTDateTime);
GdalAssert.AssertFieldType(vernetzungResultLayer, "schnittzeitpunkt", FieldType.OFTDateTime);
GdalAssert.AssertFieldType(qualitaetResultLayer, "ist_definitiv", FieldType.OFTInteger, FieldSubType.OFSTInt16);
GdalAssert.AssertFieldType(qualitaetResultLayer, "beitragsberechtigt", FieldType.OFTInteger, FieldSubType.OFSTInt16);
GdalAssert.AssertFieldType(qualitaetResultLayer, "nhg", FieldType.OFTInteger, FieldSubType.OFSTInt16);
GdalAssert.AssertFieldType(vernetzungResultLayer, "ist_definitiv", FieldType.OFTInteger, FieldSubType.OFSTInt16);
GdalAssert.AssertFieldType(vernetzungResultLayer, "beitragsberechtigt", FieldType.OFTInteger, FieldSubType.OFSTInt16);

GdalAssert.AssertOnlyValidLnfCodes(qualitaetResultLayer);
GdalAssert.AssertOnlyValidLnfCodes(vernetzungResultLayer);
GdalAssert.AssertOnlySinglePartGeometries(vernetzungResultLayer);
t_ids = new List<int>();
vernetzungResultLayer.ResetReading();
for (var i = 0; i < vernetzungResultLayer.GetFeatureCount(1); i++)
{
var feature = vernetzungResultLayer.GetNextFeature();
t_ids.Add(feature.GetFieldAsInteger("t_id"));
}

GdalAssert.AssertOnlySinglePartGeometries(qualitaetResultLayer);
// Delete feature with invalid lnf_code
Assert.AreEqual(0, t_ids.FindAll(t_id => t_id == 914572).Count);

var firstVernetzungInputFeature = vernetzungInputLayer.GetNextFeature();
vernetzungResultLayer.ResetReading();
var firstVernetzungResultFeature = vernetzungResultLayer.GetNextFeature();
Assert.AreEqual(firstVernetzungInputFeature.GetFID(), firstVernetzungResultFeature.GetFieldAsInteger("t_id"));
var tid = firstVernetzungInputFeature.GetFieldAsInteger("t_id");
Assert.AreEqual(firstVernetzungInputFeature.GetFieldAsInteger("t_id"), firstVernetzungResultFeature.GetFieldAsInteger("t_id"));
GdalAssert.AssertDateTime(firstVernetzungInputFeature, firstVernetzungResultFeature, "bezugsjahr");
Assert.AreEqual(firstVernetzungInputFeature.GetFieldAsInteger("anzahl_baeume"), firstVernetzungResultFeature.GetFieldAsInteger("anzahl_baeume"));
Assert.AreEqual(firstVernetzungInputFeature.GetFieldAsInteger("ist_definitiv"), firstVernetzungResultFeature.GetFieldAsInteger("ist_definitiv"));
GdalAssert.AssertDateTime(firstVernetzungInputFeature, firstVernetzungResultFeature, "verpflichtung_von");
GdalAssert.AssertDateTime(firstQualitaetInputFeature, firstQualitaetResultFeature, "verpflichtung_bis");
GdalAssert.AssertDateTime(firstVernetzungInputFeature, firstQualitaetResultFeature, "schnittzeitpunkt");
GdalAssert.AssertDateTime(firstVernetzungInputFeature, firstVernetzungResultFeature, "verpflichtung_bis");
GdalAssert.AssertDateTime(firstVernetzungInputFeature, firstVernetzungResultFeature, "schnittzeitpunkt");
Assert.AreEqual(firstVernetzungInputFeature.GetFieldAsInteger("beitragsberechtigt"), firstVernetzungResultFeature.GetFieldAsInteger("beitragsberechtigt"));
Assert.AreEqual(firstVernetzungInputFeature.GetFieldAsInteger("lnf_code"), firstVernetzungResultFeature.GetFieldAsInteger("lnf_code"));
Assert.AreEqual(firstVernetzungInputFeature.GetFieldAsString("identifikator"), firstVernetzungResultFeature.GetFieldAsString("identifikator"));
Expand Down
39 changes: 26 additions & 13 deletions Geodatenbezug.Test/Processors/NutzungsflaechenProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
namespace Geodatenbezug.Processors;

[TestClass]
[DeploymentItem("testdata/lwb_nutzungsflaechen_v2_0_lv95_NE_202404191123.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_bewirtschaftungseinheit_v2_0_lv95_NE_202404191123.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_nutzungsflaechen_v2_0_lv95_testdaten.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_bewirtschaftungseinheit_v2_0_lv95_testdaten.gpkg", "testdata")]
public class NutzungsflaechenProcessorTest
{
private readonly Topic topic = new ()
Expand Down Expand Up @@ -83,8 +83,8 @@ public async Task RunGdalProcessingAsync()
loggerMock.Setup(LogLevel.Information, $"Kopiere Features vom Joined Layer zum neuen Nutzungsflächenlayer");
loggerMock.Setup(LogLevel.Information, $"Lösche temporäre Layer");

processor.InputDataPath = "testdata\\lwb_nutzungsflaechen_v2_0_lv95_NE_202404191123.gpkg";
processor.BewirtschaftungseinheitDataPath = "testdata\\lwb_bewirtschaftungseinheit_v2_0_lv95_NE_202404191123.gpkg";
processor.InputDataPath = "testdata\\lwb_nutzungsflaechen_v2_0_lv95_testdaten.gpkg";
processor.BewirtschaftungseinheitDataPath = "testdata\\lwb_bewirtschaftungseinheit_v2_0_lv95_testdaten.gpkg";
await processor.RunGdalProcessingAsync();

var layerName = "nutzungsflaechen";
Expand Down Expand Up @@ -125,14 +125,27 @@ public async Task RunGdalProcessingAsync()
GdalAssert.AssertFieldType(resultLayer, "bff_qualitaet_1", FieldType.OFTInteger, FieldSubType.OFSTInt16);

GdalAssert.AssertOnlyValidLnfCodes(resultLayer);

GdalAssert.AssertOnlySinglePartGeometries(resultLayer);

var t_ids = new List<int>();
resultLayer.ResetReading();
for (var i = 0; i < resultLayer.GetFeatureCount(1); i++)
{
var feature = resultLayer.GetNextFeature();
t_ids.Add(feature.GetFieldAsInteger("t_id"));
}

// Delete feature with invalid lnf_code
Assert.AreEqual(0, t_ids.FindAll(t_id => t_id == 6225522).Count);

// Feature with multipart geometry was split into three features
Assert.AreEqual(3, t_ids.FindAll(t_id => t_id == 6225610).Count);

var firstInputFeature = inputLayer.GetNextFeature();
resultLayer.ResetReading();
var firstResultFeature = resultLayer.GetNextFeature();

Assert.AreEqual(firstInputFeature.GetFID(), firstResultFeature.GetFieldAsInteger("t_id"));
Assert.AreEqual(firstInputFeature.GetFieldAsInteger("t_id"), firstResultFeature.GetFieldAsInteger("t_id"));
GdalAssert.AssertDateTime(firstInputFeature, firstResultFeature, "bezugsjahr");
Assert.AreEqual(firstInputFeature.GetFieldAsInteger("lnf_code"), firstResultFeature.GetFieldAsInteger("lnf_code"));
Assert.AreEqual(firstInputFeature.GetFieldAsString("code_programm"), firstResultFeature.GetFieldAsString("code_programm"));
Expand All @@ -142,13 +155,13 @@ public async Task RunGdalProcessingAsync()
Assert.AreEqual(firstInputFeature.GetFieldAsInteger("flaeche_m2"), firstResultFeature.GetFieldAsInteger("flaeche_m2"));
Assert.AreEqual(firstInputFeature.GetFieldAsString("kanton"), firstResultFeature.GetFieldAsString("kanton"));
Assert.AreEqual(0, firstResultFeature.GetFieldAsInteger("bff_qualitaet_1"));
Assert.AreEqual("Ackerfläche", firstResultFeature.GetFieldAsString("hauptkategorie_de"));
Assert.AreEqual("Terres cultivées", firstResultFeature.GetFieldAsString("hauptkategorie_fr"));
Assert.AreEqual("Superficie coltiva", firstResultFeature.GetFieldAsString("hauptkategorie_it"));
Assert.AreEqual("Sommergerste", firstResultFeature.GetFieldAsString("nutzung_de"));
Assert.AreEqual("Orge de printemps", firstResultFeature.GetFieldAsString("nutzung_fr"));
Assert.AreEqual("Orzo primaverile", firstResultFeature.GetFieldAsString("nutzung_it"));
Assert.AreEqual("NE65020007", firstResultFeature.GetFieldAsString("betriebsnummer"));
Assert.AreEqual("Reben", firstResultFeature.GetFieldAsString("hauptkategorie_de"));
Assert.AreEqual("Vignobles", firstResultFeature.GetFieldAsString("hauptkategorie_fr"));
Assert.AreEqual("Vigna", firstResultFeature.GetFieldAsString("hauptkategorie_it"));
Assert.AreEqual("Reben", firstResultFeature.GetFieldAsString("nutzung_de"));
Assert.AreEqual("Vignes", firstResultFeature.GetFieldAsString("nutzung_fr"));
Assert.AreEqual("Vigna", firstResultFeature.GetFieldAsString("nutzung_it"));
Assert.AreEqual("BEB102228", firstResultFeature.GetFieldAsString("betriebsnummer"));
Assert.AreEqual(string.Empty, firstResultFeature.GetFieldAsString("bur_nr"));
GdalAssert.AssertGeometry(firstInputFeature, firstResultFeature);
}
Expand Down
18 changes: 15 additions & 3 deletions Geodatenbezug.Test/Processors/PerimeterLnSfProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
namespace Geodatenbezug.Processors;

[TestClass]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_NE_202404191123.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten.gpkg", "testdata")]
[DeploymentItem("testdata/lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_geometry.gpkg", "testdata")]
public class PerimeterLnSfProcessorTest
{
private readonly Topic topic = new ()
Expand Down Expand Up @@ -42,7 +43,7 @@ public async Task RunGdalProcessingAsync()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_NE_202404191123.gpkg";
processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_testdaten.gpkg";
await processor.RunGdalProcessingAsync();

var layerName = "perimeter_ln_sf";
Expand All @@ -68,16 +69,27 @@ public async Task RunGdalProcessingAsync()
GdalAssert.AssertFieldType(resultLayer, "bezugsjahr", FieldType.OFTDateTime);

GdalAssert.AssertOnlySinglePartGeometries(resultLayer);
Assert.AreEqual(2, inputLayer.GetFeatureCount(0));
Assert.AreEqual(3, resultLayer.GetFeatureCount(0));

var firstInputFeature = inputLayer.GetNextFeature();
resultLayer.ResetReading();
var firstResultFeature = resultLayer.GetNextFeature();
Assert.AreEqual(firstInputFeature.GetFID(), firstResultFeature.GetFieldAsInteger("t_id"));
Assert.AreEqual(firstInputFeature.GetFieldAsInteger("t_id"), firstResultFeature.GetFieldAsInteger("t_id"));
GdalAssert.AssertDateTime(firstInputFeature, firstResultFeature, "bezugsjahr");
Assert.AreEqual(firstInputFeature.GetFieldAsString("typ"), firstResultFeature.GetFieldAsString("typ"));
Assert.AreEqual(firstInputFeature.GetFieldAsString("identifikator"), firstResultFeature.GetFieldAsString("identifikator"));
Assert.AreEqual(firstInputFeature.GetFieldAsInteger("flaeche_m2"), firstResultFeature.GetFieldAsInteger("flaeche_m2"));
Assert.AreEqual(firstInputFeature.GetFieldAsString("kanton"), firstResultFeature.GetFieldAsString("kanton"));
GdalAssert.AssertGeometry(firstInputFeature, firstResultFeature);
}

[TestMethod]
public async Task RunGdalProcessingAsyncInvalidGeometry()
{
loggerMock.Setup(LogLevel.Information, $"Starte GDAL-Prozessierung");

processor.InputDataPath = "testdata\\lwb_perimeter_ln_sf_v2_0_lv95_testdaten_invalid_geometry.gpkg";
await Assert.ThrowsExceptionAsync<InvalidGeometryException>(processor.RunGdalProcessingAsync);
}
}
Loading

0 comments on commit 6989eda

Please sign in to comment.