Skip to content

Commit

Permalink
Update attribute names (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr authored May 7, 2024
2 parents 47f7393 + f7108c1 commit 4f43da7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Geodatenbezug.Test/Processors/NutzungsflaechenProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,20 @@ public async Task RunGdalProcessingAsync()
"bewirtschaftungsgrad",
"flaeche_m2",
"kanton",
"ist_bff_qi",
"bff_qualitaet_1",
"hauptkategorie_de",
"hauptkategorie_fr",
"hauptkategorie_it",
"nutzung_de",
"nutzung_fr",
"nutzung_it",
"bewe_betriebsnummer",
"betriebsnummer",
};
GdalAssert.AssertLayerFields(resultLayer, expectedLayerFields);

GdalAssert.AssertFieldType(resultLayer, "t_id", FieldType.OFTInteger);
GdalAssert.AssertFieldType(resultLayer, "bezugsjahr", FieldType.OFTDateTime);
GdalAssert.AssertFieldType(resultLayer, "ist_bff_qi", FieldType.OFTInteger, FieldSubType.OFSTInt16);
GdalAssert.AssertFieldType(resultLayer, "bff_qualitaet_1", FieldType.OFTInteger, FieldSubType.OFSTInt16);

GdalAssert.AssertOnlyValidLnfCodes(resultLayer);

Expand All @@ -142,14 +142,14 @@ public async Task RunGdalProcessingAsync()
Assert.AreEqual(firstInputFeature.GetFieldAsInteger("bewirtschaftungsgrad"), firstResultFeature.GetFieldAsInteger("bewirtschaftungsgrad"));
Assert.AreEqual(firstInputFeature.GetFieldAsInteger("flaeche_m2"), firstResultFeature.GetFieldAsInteger("flaeche_m2"));
Assert.AreEqual(firstInputFeature.GetFieldAsString("kanton"), firstResultFeature.GetFieldAsString("kanton"));
Assert.AreEqual(0, firstResultFeature.GetFieldAsInteger("ist_bff_qi"));
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("bewe_betriebsnummer"));
Assert.AreEqual("NE65020007", firstResultFeature.GetFieldAsString("betriebsnummer"));
GdalAssert.AssertGeometry(firstInputFeature, firstResultFeature);
}
}
35 changes: 16 additions & 19 deletions Geodatenbezug/Processors/NutzungsflaechenProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,30 +110,14 @@ protected async override Task ProcessTopicAsync()
{
var fieldDefn = nutzungsflaechenJoinedLayer.GetLayerDefn().GetFieldDefn(i);
var originalFieldName = fieldDefn.GetName();
string fieldName = originalFieldName;

// Drop the fields that where only needed for the join
if (originalFieldName == $"{NutzungsartLayerName}_lnf_code" || originalFieldName == $"{NutzungsflaechenLayerName}_identifikator_be")
if (originalFieldName == $"{NutzungsartLayerName}_{LnfCodeFieldName}" || originalFieldName == $"{NutzungsflaechenLayerName}_{IdentifikatorBeFieldName}")
{
continue;
}

// Rename the fields to remove the layer name prefix
if (originalFieldName.Contains(NutzungsflaechenLayerName, StringComparison.InvariantCulture))
{
fieldName = originalFieldName.Replace($"{NutzungsflaechenLayerName}_", string.Empty, StringComparison.InvariantCulture);
}

if (originalFieldName.Contains(NutzungsartLayerName, StringComparison.InvariantCulture))
{
fieldName = originalFieldName.Replace($"{NutzungsartLayerName}_", string.Empty, StringComparison.InvariantCulture);
}

if (originalFieldName == $"{BewirtschaftungseinheitLayerName}_{BetriebsnummerFieldName}")
{
fieldName = "bewe_betriebsnummer";
}

var fieldName = RemoveLayerPrefix(originalFieldName);
fieldNameMapping[fieldName] = originalFieldName;

// Booleans are represented as an Int16 FieldSubTypes, so we have to apply the subtype to the field definition if it's available
Expand Down Expand Up @@ -215,7 +199,7 @@ private async Task CreateNutzungsartLayerAsync()
using var lnfCode = new FieldDefn(LnfCodeFieldName, FieldType.OFTInteger);
nutzungsartLayer.CreateField(lnfCode, 1);

var istBffQiName = "ist_bff_qi";
var istBffQiName = "bff_qualitaet_1";
using var istBffQi = new FieldDefn(istBffQiName, FieldType.OFTInteger);
istBffQi.SetSubType(FieldSubType.OFSTInt16);
nutzungsartLayer.CreateField(istBffQi, 1);
Expand Down Expand Up @@ -338,4 +322,17 @@ private async Task<List<LnfKatalogNutzungsart>> GetLnfKatalogNutzungsartAsync()
throw new InvalidOperationException("Deserialization failed or returned null.");
}
}

private string RemoveLayerPrefix(string originalFieldName)
{
foreach (var layerName in new[] { NutzungsflaechenLayerName, NutzungsartLayerName, BewirtschaftungseinheitLayerName })
{
if (originalFieldName.Contains(layerName, StringComparison.Ordinal))
{
return originalFieldName.Replace($"{layerName}_", string.Empty, StringComparison.Ordinal);
}
}

return originalFieldName;
}
}

0 comments on commit 4f43da7

Please sign in to comment.