diff --git a/opdracht2/GeoJsonParser.cs b/opdracht2/GeoJsonParser.cs index caf5ea9..be782d6 100644 --- a/opdracht2/GeoJsonParser.cs +++ b/opdracht2/GeoJsonParser.cs @@ -23,9 +23,7 @@ namespace opdracht2 { public static class GeoJsonParser { - //public GeoJsonParser(string json) - //{ - //} + public static double maximumXWaarde, maximumYWaarde, minimumXWaarde, @@ -34,7 +32,7 @@ namespace opdracht2 schaalYWaarde; public static double epsilon; - public static Tuple, List> TriangulateJsonData(string json, + public static List TriangulateJsonData(string json, double x, double y) { epsilon = .003; @@ -49,31 +47,15 @@ namespace opdracht2 { try { - List> PolygonsInPolygonsLijst = maakPolygonLijst(JsonConvert.DeserializeObject(v["geometry"].ToString())); - List EnkelePolygonLijst = maakPolygonLijn(PolygonsInPolygonsLijst, maximumXWaarde, maximumYWaarde, - minimumXWaarde, minimumYWaarde); + List EnkelePolygonLijst = maakPolygonLijn(maakPolygonLijst(JsonConvert.DeserializeObject(v["geometry"].ToString()))); returnWaarde.AddRange(maakDriehoeken(EnkelePolygonLijst)); } catch (Exception e) { - Debug.WriteLine("couldnt parse " + v["properties"]["name"]); + Debug.WriteLine("couldn't parse " + v["properties"]["name"]); } - - //JsonConvert.DeserializeObject(JObject.Parse(v.ToString())["geometry"].ToString()); } - - return new Tuple, List>(NormalizePolygon(returnWaarde), new - List()); - /* - * List> PolygonsInPolygonsLijst = - maakPolygonLijst( - JsonConvert.DeserializeObject(JObject.Parse(json)["features"][0]["geometry"] - .ToString())); - List EnkelePolygonLijst = maakPolygonLijn(PolygonsInPolygonsLijst, maximumXWaarde, maximumYWaarde, - minimumXWaarde, minimumYWaarde); - return new Tuple, List>(maakDriehoeken(EnkelePolygonLijst), - maakPunten(EnkelePolygonLijst)); - */ + return NormalizePolygon(returnWaarde); } private static List maakPunten(List enkelePolygonLijst) @@ -118,11 +100,6 @@ namespace opdracht2 polygonLijst[punt3Index])); break; } - //double angle = getAngle(f2[i], f2[i + 1], f2[i + 2]); - //double hoek = berekenHoekVanPunten(polygonLijst[punt2Index].X, polygonLijst[punt2Index].Y, - - // polygonLijst[punt1Index].X, polygonLijst[punt1Index].Y, polygonLijst[punt3Index].X, - //polygonLijst[punt3Index].Y); double hoek = getAngle(polygonLijst[punt1Index], polygonLijst[punt2Index], polygonLijst[punt3Index]); if (hoek < 180) { @@ -144,40 +121,10 @@ namespace opdracht2 //https://stackoverflow.com/a/31334882 private static double getAngle(Point p1, Point p2, Point p3) { - //double p12 = neemLengteTussen2Punten(p2, p1); - //double p13 = neemLengteTussen2Punten(p2, p3); - //double p23 = neemLengteTussen2Punten(p1, p3); - //double top = Math.Pow(p12, 2) + Math.Pow(p13, 2) + Math.Pow(p23, 2); - //double bottom = 2 * p12 * p13; - - //return Math.Acos(top/bottom); - //double t = Math.Atan2(p3.Y - p1.Y, p3.X - p1.X); - //double v = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X); - - //return t - v; return Math.Atan2(p3.Y - p1.Y, p3.X - p1.X) - Math.Atan2(p2.Y - p1.Y, p2.X - p1.X); } - //https://stackoverflow.com/a/39673693 - private static double berekenHoekVanPunten(double P1X, double P1Y, double P2X, double P2Y, - double P3X, double P3Y) - { - double numerator = P2Y * (P1X - P3X) + P1Y * (P3X - P2X) + P3Y * (P2X - P1X); - double denominator = (P2X - P1X) * (P1X - P3X) + (P2Y - P1Y) * (P1Y - P3Y); - double ratio = numerator / denominator; - double angleRad = Math.Atan(ratio); - double angleDeg = (angleRad * 180) / Math.PI; - if (angleDeg < 0) - { - angleDeg = 180 + angleDeg; - } - return angleDeg; - } - private static double neemLengteTussen2Punten(Point punt1, Point punt2) - { - return Math.Sqrt((Math.Pow((punt1.X - punt2.X), 2) + (Math.Pow(punt1.Y - punt2.Y, 2)))); - } private static System.Windows.Shapes.Polygon createNewPolygon(Point punt1, Point punt2, Point punt3) { @@ -204,12 +151,11 @@ namespace opdracht2 private static List> maakPolygonLijst(MultiPolygon multiPolygon) { - List> polygonAlsVectorLijst = new List>(); - - foreach (GeoJSON.Net.Geometry.Polygon p in multiPolygon.Coordinates) + List> polygonAlsPuntenLijst = new List>(); + foreach (GeoJSON.Net.Geometry.Polygon geojsonPolygon in multiPolygon.Coordinates) { - List polygonLijst = new List(); - foreach (LineString lineString in p.Coordinates) + List puntenLijst = new List(); + foreach (LineString lineString in geojsonPolygon.Coordinates) { foreach (Position positie in lineString.Coordinates) { @@ -233,25 +179,25 @@ namespace opdracht2 maximumYWaarde = positie.Latitude; } Point punt = new Point(positie.Longitude, positie.Latitude); - if (!polygonLijst.Contains(punt)) polygonLijst.Add(new Point( positie.Longitude, positie.Latitude)); + if (!puntenLijst.Contains(punt)) puntenLijst.Add(new Point( positie.Longitude, positie.Latitude)); } } - polygonLijst = DP(polygonLijst); - polygonAlsVectorLijst.Add(polygonLijst); - if (polygonAlsVectorLijst.Count > 1) + puntenLijst = douglasPeuker(puntenLijst); + polygonAlsPuntenLijst.Add(puntenLijst); + /* TODO waarom is dit hier??? + if (polygonAlsPuntenLijst.Count > 1) { break; - } + }*/ } - maximumXWaarde = maximumXWaarde - minimumXWaarde; - maximumYWaarde = maximumYWaarde - minimumYWaarde; - return polygonAlsVectorLijst; + maximumXWaarde -= minimumXWaarde; + maximumYWaarde -= minimumYWaarde; + return polygonAlsPuntenLijst; } - private static List maakPolygonLijn(List> multiPolygon, double Xmax, double Ymax, - double Xmin, double Ymin) + private static List maakPolygonLijn(List> multiPolygon) { //zoek dichtsbijzijnde punt wanneer toevoegen volgende vector en voeg pas vanaf dat punt toe. bool richting = true; //richting van inlezen polygon (met klok mee, tegen in klok) @@ -343,7 +289,7 @@ namespace opdracht2 return returnWaarde; } - private static List DP(List punten) + private static List douglasPeuker(List punten) { double dmax = -1; int index = 0; @@ -368,8 +314,8 @@ namespace opdracht2 if (dmax > epsilon) { - List recResults1 = DP(punten.GetRange(0, index)); - List recResults2 = DP(punten.GetRange(index, end-1-index)); + List recResults1 = douglasPeuker(punten.GetRange(0, index)); + List recResults2 = douglasPeuker(punten.GetRange(index, end-1-index)); returnWaarde.AddRange(recResults1); diff --git a/opdracht2/MainWindow.xaml.cs b/opdracht2/MainWindow.xaml.cs index d7ef21e..ffea5da 100644 --- a/opdracht2/MainWindow.xaml.cs +++ b/opdracht2/MainWindow.xaml.cs @@ -41,9 +41,10 @@ namespace opdracht2 OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == true) { - Tuple, List> t = GeoJsonParser.TriangulateJsonData(File.ReadAllText(openFileDialog.FileName), c.Width, c.Height); - f = t.Item1; - el = t.Item2; + //TODO remove + //Tuple, List> t = GeoJsonParser.TriangulateJsonData(File.ReadAllText(openFileDialog.FileName), c.Width, c.Height); + f = GeoJsonParser.TriangulateJsonData(File.ReadAllText(openFileDialog.FileName), c.Width, c.Height); + el = new List(); } var st = new ScaleTransform(); c.RenderTransform = st; diff --git a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll index 75305c5..a779770 100644 Binary files a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll and b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.dll differ diff --git a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb index 1f268e7..e221896 100644 Binary files a/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb and b/opdracht2/bin/Debug/netcoreapp3.1/opdracht2.pdb differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/MainWindow.baml b/opdracht2/obj/Debug/netcoreapp3.1/MainWindow.baml index 76c584d..f023a44 100644 Binary files a/opdracht2/obj/Debug/netcoreapp3.1/MainWindow.baml and b/opdracht2/obj/Debug/netcoreapp3.1/MainWindow.baml differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll index 75305c5..a779770 100644 Binary files a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll and b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.dll differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.g.resources b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.g.resources index 84fbe1f..99add43 100644 Binary files a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.g.resources and b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.g.resources differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb index 1f268e7..e221896 100644 Binary files a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb and b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2.pdb differ diff --git a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2_MarkupCompile.cache b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2_MarkupCompile.cache index 654d46c..be05267 100644 --- a/opdracht2/obj/Debug/netcoreapp3.1/opdracht2_MarkupCompile.cache +++ b/opdracht2/obj/Debug/netcoreapp3.1/opdracht2_MarkupCompile.cache @@ -10,10 +10,10 @@ none false TRACE;DEBUG;NETCOREAPP;NETCOREAPP3_1 C:\Users\Beppe\source\repos\opdracht2\opdracht2\App.xaml -1583495661 +11316880640 -42060119627 -195-1654818392 +41434824894 +195-1386093099 MainWindow.xaml; False