Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/Deltares.LayerOnSlopeTool.Importer.csproj
===================================================================
diff -u -r3140 -r3159
--- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/Deltares.LayerOnSlopeTool.Importer.csproj (.../Deltares.LayerOnSlopeTool.Importer.csproj) (revision 3140)
+++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/Deltares.LayerOnSlopeTool.Importer.csproj (.../Deltares.LayerOnSlopeTool.Importer.csproj) (revision 3159)
@@ -46,6 +46,7 @@
+
Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/LayerCreator.cs
===================================================================
diff -u -r3089 -r3159
--- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/LayerCreator.cs (.../LayerCreator.cs) (revision 3089)
+++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/LayerCreator.cs (.../LayerCreator.cs) (revision 3159)
@@ -20,7 +20,9 @@
// All rights reserved.
using System.Collections.Generic;
+using System.IO;
using Deltares.LayerOnSlopeTool.Data;
+using Deltares.LayerOnSlopeTool.Importer;
namespace Deltares.LayerOnSlopeTool.LayerCreator
{
@@ -53,6 +55,8 @@
private List locations = new List();
private List surfaceLines = new List();
+ private List errors;
+
public void Execute()
{
locations = ReadLocations(InputFolderName);
@@ -62,12 +66,15 @@
private void ProcessLocations()
{
+ var loggedLocations = new List();
foreach (var location in locations)
{
+ loggedLocations.Add(string.Format("Handling location {0} with surface line {1}", location.LocationId, location.SurfacelineId));
SurfaceLine surfaceLine = FindSurfaceLine(location.SurfacelineId);
var geometryCreator = new GeometryCreator(location, surfaceLine, OutputFolderName);
geometryCreator.Execute();
}
+ WriteToLog(loggedLocations);
throw new System.NotImplementedException();
}
@@ -79,15 +86,38 @@
private List ReadSurfaceLines(string inputFolderName)
{
- // TODO read surfaceLines
- throw new System.NotImplementedException();
+ errors.Clear();
+ if (CsvImporter.ReadSurfaceLines(inputFolderName, out surfaceLines, out errors))
+ {
+ return surfaceLines;
+ }
+ else
+ {
+ WriteToLog(errors);
+ }
+ return null;
}
private List ReadLocations(string inputFolderName)
{
- // TODO read locations
- throw new System.NotImplementedException();
+ errors.Clear();
+ if (CsvImporter.ReadLocations(inputFolderName, out locations, out errors))
+ {
+ return locations;
+ }
+ else
+ {
+ WriteToLog(errors);
+ }
+ return null;
}
+
+ private void WriteToLog(List linesToAdd)
+ {
+ const string logFile = "LayerOnSlopeTool.log";
+ string fullFilePath = Path.Combine(OutputFolderName, logFile);
+ File.AppendAllLines(fullFilePath, linesToAdd);
+ }
}
}
\ No newline at end of file
Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/Deltares.LayerOnSlopeTool.LayerCreator.csproj
===================================================================
diff -u -r3089 -r3159
--- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/Deltares.LayerOnSlopeTool.LayerCreator.csproj (.../Deltares.LayerOnSlopeTool.LayerCreator.csproj) (revision 3089)
+++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.LayerCreator/Deltares.LayerOnSlopeTool.LayerCreator.csproj (.../Deltares.LayerOnSlopeTool.LayerCreator.csproj) (revision 3159)
@@ -56,6 +56,10 @@
{83d297fb-cfc7-4154-aeb7-5e09e10e24d0}
Deltares.LayerOnSlopeTool.Data
+
+ {ebc22fc1-bf8a-49b0-9427-cffcef570ab2}
+ Deltares.LayerOnSlopeTool.Importer
+
\ No newline at end of file
Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.ImporterTests/CsvImportersTests.cs
===================================================================
diff -u -r3148 -r3159
--- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.ImporterTests/CsvImportersTests.cs (.../CsvImportersTests.cs) (revision 3148)
+++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.ImporterTests/CsvImportersTests.cs (.../CsvImportersTests.cs) (revision 3159)
@@ -22,6 +22,7 @@
using System;
using System.Collections.Generic;
using System.IO;
+using Deltares.LayerOnSlopeTool.Data;
using Deltares.LayerOnSlopeTool.Importer;
using NUnit.Framework;
@@ -248,6 +249,150 @@
Assert.AreEqual(2, csvImporterLocations.ErrorMessages.Count);
}
+ [Test]
+ public void ReadLocationsTest()
+ {
+ const string importFile = "locations.csv";
+ string testFilePath = Path.Combine(importFolder, importFile);
+ if (File.Exists(testFilePath))
+ File.Delete(testFilePath);
+ CreateValidLocationsFile(testFilePath);
+ List locations;
+ List errors;
+ var result = CsvImporter.ReadLocations(importFolder, out locations, out errors);
+ Assert.AreEqual(0, errors.Count);
+ Assert.AreEqual(true, result);
+ Assert.AreEqual(2, locations.Count);
+ }
+
+ [Test]
+ public void ReadLocationsWithMissingRequiredColumns()
+ {
+ const string importFile = "locations.csv";
+ string testFilePath = Path.Combine(importFolder, importFile);
+ if (File.Exists(testFilePath))
+ File.Delete(testFilePath);
+ CreateLocationsFileWithMissingRequiredColumn(testFilePath);
+ List locations;
+ List errors;
+ var result = CsvImporter.ReadLocations(importFolder, out locations, out errors);
+ Assert.AreEqual(1, errors.Count);
+ Assert.AreEqual(false, result);
+ Assert.IsTrue(errors[0].Contains("Fatal error whilst reading locations"));
+ }
+
+ [Test]
+ public void ReadLocationsWithInvalidDataTest()
+ {
+ const string importFile = "locations.csv";
+ string testFilePath = Path.Combine(importFolder, importFile);
+ if (File.Exists(testFilePath))
+ File.Delete(testFilePath);
+ CreateLocationsFileWithIllegalValues(testFilePath);
+ List locations;
+ List errors;
+ var result = CsvImporter.ReadLocations(importFolder, out locations, out errors);
+ Assert.AreEqual(2, errors.Count);
+ Assert.AreEqual(false, result);
+ Assert.IsTrue(errors[0].Contains("Next error occured whilst reading location"));
+ Assert.IsTrue(errors[1].Contains("Next error occured whilst reading location"));
+ }
+
+ [Test]
+ public void ReadSurfaceLineTestWithCharacteristicPointsSucceeds()
+ {
+ const string importSurfaceLineFile = "surfacelines.csv";
+ string testSurfaceLineFilePath = Path.Combine(importFolder, importSurfaceLineFile);
+ if (File.Exists(testSurfaceLineFilePath))
+ File.Delete(testSurfaceLineFilePath);
+ CreateSurfaceLinesFileForBelongingCharPoints(testSurfaceLineFilePath);
+
+ const string importFile = "characteristicpoints.csv";
+ string testFilePath = Path.Combine(importFolder, importFile);
+ if (File.Exists(testFilePath))
+ File.Delete(testFilePath);
+ CreateCharacteristicPointsForBelongingSurfaceLLine(testFilePath);
+
+ List surfaceLines;
+ List errors;
+ var result = CsvImporter.ReadSurfaceLines(importFolder, out surfaceLines, out errors);
+ Assert.AreEqual(0, errors.Count);
+ Assert.IsTrue(result);
+ Assert.AreEqual(3, surfaceLines.Count);
+ Assert.AreEqual("DWP_1", surfaceLines[0].SurfaceLineId);
+ Assert.AreEqual("DWP_2", surfaceLines[1].SurfaceLineId);
+ Assert.AreEqual("DWP_3", surfaceLines[2].SurfaceLineId);
+ }
+
+ [Test]
+ public void ReadSurfaceLineTestWithoutCharacteristicPointsFails()
+ {
+ const string importSurfaceLineFile = "surfacelines.csv";
+ string testSurfaceLineFilePath = Path.Combine(importFolder, importSurfaceLineFile);
+ if (File.Exists(testSurfaceLineFilePath))
+ File.Delete(testSurfaceLineFilePath);
+ CreateSurfaceLinesFile(testSurfaceLineFilePath);
+
+ const string importFile = "characteristicpoints.csv";
+ string testFilePath = Path.Combine(importFolder, importFile);
+ if (File.Exists(testFilePath))
+ File.Delete(testFilePath);
+ //CreateCharacteristicPointsFile(testFilePath);
+
+ List surfaceLines;
+ List errors;
+ var result = CsvImporter.ReadSurfaceLines(importFolder, out surfaceLines, out errors);
+ Assert.AreEqual(1, errors.Count);
+ Assert.IsTrue(errors[0].Contains("Fatal error whilst reading surface lines:"));
+ Assert.IsTrue(errors[0].Contains("The Characteristic Points csv file with name"));
+ Assert.IsTrue(errors[0].Contains("could not be found"));
+ }
+
+ [Test]
+ public void ReadSurfaceLineTestWithWrongCharacteristicPointsFails()
+ {
+ const string importSurfaceLineFile = "surfacelines.csv";
+ string testSurfaceLineFilePath = Path.Combine(importFolder, importSurfaceLineFile);
+ if (File.Exists(testSurfaceLineFilePath))
+ File.Delete(testSurfaceLineFilePath);
+ CreateSurfaceLinesFile(testSurfaceLineFilePath);
+
+ const string importFile = "characteristicpoints.csv";
+ string testFilePath = Path.Combine(importFolder, importFile);
+ if (File.Exists(testFilePath))
+ File.Delete(testFilePath);
+ CreateCharacteristicPointsFileWithWrongCoordinates(testFilePath);
+
+ List surfaceLines;
+ List errors;
+ var result = CsvImporter.ReadSurfaceLines(importFolder, out surfaceLines, out errors);
+ Assert.AreEqual(1, errors.Count);
+ Assert.IsTrue(errors[0].Contains("Characteristic Points csv has record"));
+ Assert.IsTrue(errors[0].Contains("that can not be matched with a surface line point."));
+ }
+
+ [Test]
+ public void ReadSurfaceLineTestWithWrongCharacteristicPointsReference()
+ {
+ const string importSurfaceLineFile = "surfacelines.csv";
+ string testSurfaceLineFilePath = Path.Combine(importFolder, importSurfaceLineFile);
+ if (File.Exists(testSurfaceLineFilePath))
+ File.Delete(testSurfaceLineFilePath);
+ CreateSurfaceLinesFile(testSurfaceLineFilePath);
+
+ const string importFile = "characteristicpoints.csv";
+ string testFilePath = Path.Combine(importFolder, importFile);
+ if (File.Exists(testFilePath))
+ File.Delete(testFilePath);
+ CreateCharacteristicPointsFileWithWrongReference(testFilePath);
+
+ List surfaceLines;
+ List errors;
+ var result = CsvImporter.ReadSurfaceLines(importFolder, out surfaceLines, out errors);
+ Assert.AreEqual(1, errors.Count);
+ Assert.IsTrue(errors[0].Contains("Characteristic Points csv has record"));
+ Assert.IsTrue(errors[0].Contains("that can not be matched with a surface line."));
+ }
private static void CheckSurfaceLine(IList surfaceLineRecords)
{
Assert.AreEqual("D1", surfaceLineRecords[0].SurfaceLineId);
@@ -291,6 +436,28 @@
}
}
+ private static void CreateCharacteristicPointsFileWithWrongCoordinates(string filePath)
+ {
+ using (var writer = File.CreateText(filePath))
+ {
+ writer.WriteLine(
+ "Profielnaam;X_Maaiveld binnenwaarts;Y_Maaiveld binnenwaarts;Z_Maaiveld binnenwaarts;X_Insteek sloot polderzijde;Y_Insteek sloot polderzijde;Z_Insteek sloot polderzijde;X_Slootbodem polderzijde;Y_Slootbodem polderzijde;Z_Slootbodem polderzijde;X_Slootbodem dijkzijde;Y_Slootbodem dijkzijde;Z_Slootbodem dijkzijde;X_Insteek sloot dijkzijde;Y_Insteek sloot dijkzijde;Z_Insteek sloot dijkzijde;X_Teen dijk binnenwaarts;Y_Teen dijk binnenwaarts;Z_Teen dijk binnenwaarts;X_Kruin binnenberm;Y_Kruin binnenberm;Z_Kruin binnenberm;X_Insteek binnenberm;Y_Insteek binnenberm;Z_Insteek binnenberm;X_Kruin binnentalud;Y_Kruin binnentalud;Z_Kruin binnentalud;X_Verkeersbelasting kant binnenwaarts;Y_Verkeersbelasting kant binnenwaarts;Z_Verkeersbelasting kant binnenwaarts;X_Verkeersbelasting kant buitenwaarts;Y_Verkeersbelasting kant buitenwaarts;Z_Verkeersbelasting kant buitenwaarts;X_Kruin buitentalud;Y_Kruin buitentalud;Z_Kruin buitentalud;X_Insteek buitenberm;Y_Insteek buitenberm;Z_Insteek buitenberm;X_Kruin buitenberm;Y_Kruin buitenberm;Z_Kruin buitenberm;X_Teen dijk buitenwaarts;Y_Teen dijk buitenwaarts;Z_Teen dijk buitenwaarts;X_Maaiveld buitenwaarts;Y_Maaiveld buitenwaarts;Z_Maaiveld buitenwaarts;X_Dijktafelhoogte;Y_Dijktafelhoogte;Z_Dijktafelhoogte;Volgnummer");
+ writer.WriteLine(
+ "D1;137.94;0;0.12;-1;-1;-1;73.99;0;-15.0;72.55;0;-1.46;67.9;0;1.07;63.31;0;1.36;-1;-1;-1;-1;-1;-1;55.17;0;4.46;54.25;0;4.69;51.75;0;4.662;50.11;0;4.46;40.48;0;1.94;32.21;0;1.67;31.6;0;1.3;0;0;0.68;52.63;0;4.77;1");
+ }
+ }
+
+ private static void CreateCharacteristicPointsFileWithWrongReference(string filePath)
+ {
+ using (var writer = File.CreateText(filePath))
+ {
+ writer.WriteLine(
+ "Profielnaam;X_Maaiveld binnenwaarts;Y_Maaiveld binnenwaarts;Z_Maaiveld binnenwaarts;X_Insteek sloot polderzijde;Y_Insteek sloot polderzijde;Z_Insteek sloot polderzijde;X_Slootbodem polderzijde;Y_Slootbodem polderzijde;Z_Slootbodem polderzijde;X_Slootbodem dijkzijde;Y_Slootbodem dijkzijde;Z_Slootbodem dijkzijde;X_Insteek sloot dijkzijde;Y_Insteek sloot dijkzijde;Z_Insteek sloot dijkzijde;X_Teen dijk binnenwaarts;Y_Teen dijk binnenwaarts;Z_Teen dijk binnenwaarts;X_Kruin binnenberm;Y_Kruin binnenberm;Z_Kruin binnenberm;X_Insteek binnenberm;Y_Insteek binnenberm;Z_Insteek binnenberm;X_Kruin binnentalud;Y_Kruin binnentalud;Z_Kruin binnentalud;X_Verkeersbelasting kant binnenwaarts;Y_Verkeersbelasting kant binnenwaarts;Z_Verkeersbelasting kant binnenwaarts;X_Verkeersbelasting kant buitenwaarts;Y_Verkeersbelasting kant buitenwaarts;Z_Verkeersbelasting kant buitenwaarts;X_Kruin buitentalud;Y_Kruin buitentalud;Z_Kruin buitentalud;X_Insteek buitenberm;Y_Insteek buitenberm;Z_Insteek buitenberm;X_Kruin buitenberm;Y_Kruin buitenberm;Z_Kruin buitenberm;X_Teen dijk buitenwaarts;Y_Teen dijk buitenwaarts;Z_Teen dijk buitenwaarts;X_Maaiveld buitenwaarts;Y_Maaiveld buitenwaarts;Z_Maaiveld buitenwaarts;X_Dijktafelhoogte;Y_Dijktafelhoogte;Z_Dijktafelhoogte;Volgnummer");
+ writer.WriteLine(
+ "D1A;117.94;0;0.12;-1;-1;-1;73.99;0;-1.0;72.55;0;-1.46;67.9;0;1.07;63.31;0;1.36;-1;-1;-1;-1;-1;-1;55.17;0;4.46;54.25;0;4.69;51.75;0;4.662;50.11;0;4.46;40.48;0;1.94;32.21;0;1.67;31.6;0;1.3;0;0;0.68;52.63;0;4.77;1");
+ }
+ }
+
private static void CheckCharacteristicPoints(IList characteristicPointsRecords)
{
Assert.AreEqual("D1", characteristicPointsRecords[0].SurfaceLineId);
@@ -481,5 +648,35 @@
"25-2-2-A-1-A;25-2-2-A-1-A;Secondstifile.sti;1.1;0qwerty.8;zand;klei2;");
}
}
+
+ private static void CreateSurfaceLinesFileForBelongingCharPoints(string filePath)
+ {
+ using (var writer = File.CreateText(filePath))
+ {
+ writer.WriteLine(
+ "Profielnaam;X1;Y1;Z1;.....;Xn;Yn;Zn;(Profiel);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
+ writer.WriteLine(
+ "DWP_1;8.42;0;0.820780171;10.14;0;0.95;17.08;0;0.88;19.45;0;0.81;20.62;0;0.3;21.84;0;-0.61;23.08;0;-0.38;24.61;0;0.63;29.24;0;1.04;33.31;0;1.46;36.26;0;2.19;37.546;0;3;42.41;0;4.08;45.23;0;4.9;46.42;0;5.24;47.38;0;5.27;47.92;0;5.32;48.09;0;5.325;49.53;0;5.37;49.96;0;5.36;50.59;0;5.36;51.8;0;5.05;55.13;0;4.09;58.6;0;3.23;60.76;0;2.89;64.81;0;2.57;69.06;0;2.31;70.19;0;2;71.55;0;0.99;72.11;0;1;73.34;0;1.32;73.866;0;2;74.75;0;2.54;80.78;0;2.54;114.42;0;2.54;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
+ writer.WriteLine(
+ "DWP_2;11.31;0;1.219278075;17.51;0;1.38;19.03;0;1.01;20.06;0;0.32;21.24;0;-0.49;22.46;0;-0.01;23.07;0;0.61;27.99;0;0.81;33.66;0;1.04;41.59;0;2.43;45.92;0;4.04;49.31;0;5.47;50.61;0;5.57;51.03;0;5.59;51.2;0;5.592;51.82;0;5.6;52.64;0;5.57;53.03;0;5.56;53.7;0;5.57;57.12;0;4.55;61.68;0;3.04;66.95;0;1.67;75.61;0;1.15;82.91;0;0.62;83;0;0.4;84;0;-0.045;84.76;0;-0.49;85;0;-0.7;85.84;0;-1.11;86;0;-1;87.46;0;-1.06;88;0;-1;88.44;0;-0.54;89.96;0;0.4;99.15;0;0.57;117.31;0;0.57;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
+ writer.WriteLine(
+ "DWP_3;11.6;0;0.490209858;16.95;0;0.39;17.37;0;-0.09;17.59;0;-0.2;17.99;0;-0.4;18;0;-0.5;18.21;0;-0.51;19;0;-0.4;19.48;0;-0.23;20;0;-0.2;20.49;0;0.59;26.75;0;0.74;32.64;0;1.18;39.56;0;2.43;45.59;0;3.94;49.6;0;5.02;50.44;0;4.99;50.86;0;5.04;51;0;5.044;51.64;0;5.06;52.48;0;5.06;52.81;0;5.04;53.5;0;5.05;56.1;0;4.21;58.42;0;3.41;60.06;0;2.93;61.9;0;2.89;65.1;0;2.89;68.17;0;2.7;69.6;0;2.48;72.69;0;1.58;75.48;0;1.15;79.67;0;0.49;82.14;0;0.24;82.98;0;-0.02;83;0;-0.2;83.72;0;-0.46;84;0;-0.5;84.39;0;-1.1;86.67;0;-1.24;87;0;-0.7;87.58;0;-0.5;88;0;-0.4;89.29;0;0.17;101.4;0;0.32;117.6;0;0.32");
+ }
+ }
+
+ private static void CreateCharacteristicPointsForBelongingSurfaceLLine(string filePath)
+ {
+ using (var writer = File.CreateText(filePath))
+ {
+ writer.WriteLine(
+ "LOCATIONID;X_Maaiveld binnenwaarts;Y_Maaiveld binnenwaarts;Z_Maaiveld binnenwaarts;X_Insteek sloot polderzijde;Y_Insteek sloot polderzijde;Z_Insteek sloot polderzijde;X_Slootbodem polderzijde;Y_Slootbodem polderzijde;Z_Slootbodem polderzijde;X_Slootbodem dijkzijde;Y_Slootbodem dijkzijde;Z_Slootbodem dijkzijde;X_Insteek sloot dijkzijde;Y_Insteek_sloot dijkzijde;Z_Insteek sloot dijkzijde;X_Teen dijk binnenwaarts;Y_Teen dijk binnenwaarts;Z_Teen dijk binnenwaarts;X_Kruin binnenberm;Y_Kruin binnenberm;Z_Kruin binnenberm;X_Insteek binnenberm;Y_Insteek binnenberm;Z_Insteek binnenberm;X_Kruin binnentalud;Y_Kruin binnentalud;Z_Kruin binnentalud;X_Verkeersbelasting kant binnenwaarts;Y_Verkeersbelasting kant binnenwaarts;Z_Verkeersbelasting kant binnenwaarts;X_Verkeersbelasting kant buitenwaarts;Y_Verkeersbelasting kant buitenwaarts;Z_Verkeersbelasting kant buitenwaarts;X_Kruin buitentalud;Y_Kruin buitentalud;Z_Kruin buitentalud;X_Insteek buitenberm;Y_Insteek buitenberm;Z_Insteek buitenberm;X_Kruin buitenberm;Y_Kruin buitenberm;Z_Kruin buitenberm;X_Teen dijk buitenwaarts;Y_Teen dijk buitenwaarts;Z_Teen dijk buitenwaarts;X_Insteek geul;Y_Insteek geul;Z_Insteek geul;X_Teen geul;Y_Teen geul;Z_Teen geul;X_Maaiveld buitenwaarts;Y_Maaiveld buitenwaarts;Z_Maaiveld buitenwaarts");
+ writer.WriteLine(
+ "DWP_1;114.42;0;2.54;74.75;0;2.54;72.11;0;1;71.55;0;0.99;69.06;0;2.31;60.76;0;2.89;-1;-1;-1;-1;-1;-1;50.59;0;5.36;50.59;0;5.36;48.09;0;5.325;46.42;0;5.24;-1;-1;-1;-1;-1;-1;24.61;0;0.63;-1;-1;-1;-1;-1;-1;8.42;0;0.820780171");
+ writer.WriteLine(
+ "DWP_2; 117.31; 0; 0.57; 89.96; 0; 0.4; 88; 0; -1; 85.84; 0; -1.11; 82.91; 0; 0.62; 66.95; 0; 1.67; -1; -1; -1; -1; -1; -1; 53.7; 0; 5.57; 53.7; 0; 5.57; 51.2; 0; 5.592; 49.31; 0; 5.47; -1; -1; -1; -1; -1; -1; 33.66; 0; 1.04; -1; -1; -1; -1; -1; -1; 11.31; 0; 1.219278075");
+ writer.WriteLine(
+ "DWP_3;117.6;0;0.32;89.29;0;0.17;86.67;0;-1.24;84.39;0;-1.1;82.98;0;-0.02;72.69;0;1.58;65.1;0;2.89;60.06;0;2.93;53.5;0;5.05;53.5;0;5.05;51;0;5.044;49.6;0;5.02;-1;-1;-1;-1;-1;-1;20.49;0;0.59;-1;-1;-1;-1;-1;-1;11.6;0;0.490209858");
+ }
+ }
}
}
Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Data/SurfaceLine.cs
===================================================================
diff -u -r3102 -r3159
--- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Data/SurfaceLine.cs (.../SurfaceLine.cs) (revision 3102)
+++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Data/SurfaceLine.cs (.../SurfaceLine.cs) (revision 3159)
@@ -30,6 +30,8 @@
{
private readonly List surfaceLinePoints = new List();
+ public string SurfaceLineId { get; set; }
+
///
/// Gets the surface line points.
///
@@ -49,8 +51,19 @@
///
public SurfaceLinePoint GetSurfaceLinePointByLocation(double x, double z)
{
- // Todo implement
- return null;
+ var index = 0;
+ var searchPoint = new SurfaceLinePoint {XCoordinate = x, ZCoordinate = z};
+ SurfaceLinePoint surfaceLinePoint = null;
+ while (surfaceLinePoint == null && index < surfaceLinePoints.Count)
+ {
+ if (surfaceLinePoints[index].LocationEquals(searchPoint))
+ {
+ surfaceLinePoint = surfaceLinePoints[index];
+ }
+
+ index++;
+ }
+ return surfaceLinePoint;
}
///
Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.ImporterTests/Deltares.LayerOnSlopeTool.ImporterTests.csproj
===================================================================
diff -u -r3140 -r3159
--- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.ImporterTests/Deltares.LayerOnSlopeTool.ImporterTests.csproj (.../Deltares.LayerOnSlopeTool.ImporterTests.csproj) (revision 3140)
+++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.ImporterTests/Deltares.LayerOnSlopeTool.ImporterTests.csproj (.../Deltares.LayerOnSlopeTool.ImporterTests.csproj) (revision 3159)
@@ -57,6 +57,10 @@
+
+ {83d297fb-cfc7-4154-aeb7-5e09e10e24d0}
+ Deltares.LayerOnSlopeTool.Data
+
{ebc22fc1-bf8a-49b0-9427-cffcef570ab2}
Deltares.LayerOnSlopeTool.Importer
Index: DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporter.cs
===================================================================
diff -u
--- DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporter.cs (revision 0)
+++ DamTools/LayerOnSlopeTool/trunk/src/Deltares.LayerOnSlopeTool.Importer/CsvImporter.cs (revision 3159)
@@ -0,0 +1,175 @@
+// Copyright (C) Stichting Deltares 2020. All rights reserved.
+//
+// This file is part of the LayerOnSlopeTool
+//
+// The LayerOnSlopeTool is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+//
+// All names, logos, and references to "Deltares" are registered trademarks of
+// Stichting Deltares and remain full property of Stichting Deltares at all times.
+// All rights reserved.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Deltares.LayerOnSlopeTool.Data;
+
+namespace Deltares.LayerOnSlopeTool.Importer
+{
+ public class CsvImporter
+ {
+ public static bool ReadLocations(string inputFolderName, out List locations, out List errors)
+ {
+ locations = new List();
+ errors = new List();
+ const string importFile = "locations.csv";
+ string fullFilePath = Path.Combine(inputFolderName, importFile);
+ try
+ {
+ var locationsImporter = new CsvImporterLocations(fullFilePath);
+ if (locationsImporter.ErrorMessages.Count > 0)
+ {
+ errors.AddRange(locationsImporter.ErrorMessages);
+ return false;
+ }
+
+ foreach (var locationRecord in locationsImporter.ImportedItems)
+ {
+ var location = new Location();
+ location.LocationId = locationRecord.LocationId;
+ location.SurfacelineId = locationRecord.SurfaceLineId;
+ location.SoilGeometryName = locationRecord.SoilGeometryName;
+ location.XOffset = locationRecord.XSoilGeometry2DOrigin.GetValueOrDefault(location.XOffset);
+ location.DikeMaterial = locationRecord.DikeEmbankmentMaterial;
+ location.LayerMaterial = locationRecord.LayerMaterial;
+ location.LayerThickness = locationRecord.LayerThickness;
+ locations.Add(location);
+ }
+
+ return true;
+ }
+ catch (Exception e)
+ {
+ errors.Add("Fatal error whilst reading locations: " + e.Message);
+ return false;
+ }
+ }
+
+ public static bool ReadSurfaceLines(string inputFolderName, out List surfaceLines, out List errors)
+ {
+ var result = ReadSurfaceLinesCsv(inputFolderName, out surfaceLines, out errors);
+ if (result)
+ {
+ result = ReadCharacteristicPointsCsv(inputFolderName, surfaceLines, errors);
+ }
+
+ return result;
+ }
+
+ private static bool ReadSurfaceLinesCsv(string inputFolderName, out List surfaceLines, out List errors)
+ {
+ surfaceLines = new List();
+ errors = new List();
+ const string importFile = "surfacelines.csv";
+ string fullFilePath = Path.Combine(inputFolderName, importFile);
+ try
+ {
+ var surfaceLinesImporter = new CsvImporterSurfaceLines(fullFilePath);
+ if (surfaceLinesImporter.ErrorMessages.Count > 0)
+ {
+ errors.AddRange(surfaceLinesImporter.ErrorMessages);
+ return false;
+ }
+
+ foreach (var surfaceLineRecord in surfaceLinesImporter.ImportedItems)
+ {
+ var surfaceLine = new SurfaceLine();
+ surfaceLine.SurfaceLineId = surfaceLineRecord.SurfaceLineId;
+ foreach (var xCoor in surfaceLineRecord.Xcoors)
+ {
+ var surfaceLinePoint = new SurfaceLinePoint();
+ surfaceLinePoint.XCoordinate = xCoor;
+ surfaceLine.SurfaceLinePoints.Add(surfaceLinePoint);
+ surfaceLinePoint.PointType = CharacteristicPointType.None;
+ }
+
+ var index = 0;
+ foreach (var zCoor in surfaceLineRecord.Zcoors)
+ {
+ surfaceLine.SurfaceLinePoints[index].ZCoordinate = zCoor;
+ index++;
+ }
+ surfaceLines.Add(surfaceLine);
+ }
+ return true;
+ }
+ catch (Exception e)
+ {
+ errors.Add("Fatal error whilst reading surface lines: " + e.Message);
+ return false;
+ }
+ }
+
+ private static bool ReadCharacteristicPointsCsv(string inputFolderName, List surfaceLines,
+ List errors)
+ {
+ const string importFile = "characteristicpoints.csv";
+ string fullFilePath = Path.Combine(inputFolderName, importFile);
+ try
+ {
+ var characteristicPointsImporter = new CsvImporterCharacteristicPoints(fullFilePath);
+ if (characteristicPointsImporter.ErrorMessages.Count > 0)
+ {
+ errors.AddRange(characteristicPointsImporter.ErrorMessages);
+ return false;
+ }
+ foreach (var characteristicPointRecord in characteristicPointsImporter.ImportedItems)
+ {
+ // See which surface line this record belongs to.
+ var surfaceLine =
+ surfaceLines.FirstOrDefault(s => s.SurfaceLineId == characteristicPointRecord.SurfaceLineId);
+ if (surfaceLine == null)
+ {
+ errors.Add(string.Format("Characteristic Points csv has record {0} that can not be matched with a surface line.",
+ characteristicPointRecord.SurfaceLineId));
+ return false;
+ }
+ //surfaceLine.SurfaceLineId = surfaceLineRecord.SurfaceLineId;
+ foreach (var point in characteristicPointRecord.Points)
+ {
+ // ignore 'unset' points
+ if (!((point.X == -1) && (point.Y == -1) && (point.Z == -1)))
+ {
+ var surfaceLinePoint = surfaceLine.GetSurfaceLinePointByLocation(point.X, point.Z);
+ if (surfaceLinePoint == null)
+ {
+ errors.Add(string.Format("Characteristic Points csv has record {0} that has a point at (x = {1}, z = {2}) " +
+ "that can not be matched with a surface line point.",
+ characteristicPointRecord.SurfaceLineId, point.X, point.Z));
+ return false;
+ }
+ surfaceLinePoint.PointType = point.Type;
+ }
+ }
+ }
+ return true;
+ }
+ catch (Exception e)
+ {
+ errors.Add("Fatal error whilst reading surface lines: " + e.Message);
+ return false;
+ }
+ }
+ }
+}