1
votes

I have to make a 2D map of a country. I read out a GEOJson file where i get allot of coordinates wich i convert to points, with those points i create a polygon. There is no problem when i have the provence displayed seperated. When i try to connect every polygon(provence), i get allot of lines.drawing in xaml.

I have to get the same drawing, without the lines.

the code is use is this:

public void makePolygon()
    {
        double x = 0;
        double y = 0;
        PointReduction pr = new PointReduction();
        string filepath = "C:/Users/tomcr/Onedrive/Bureaublad/AppliedProgram/Belgie.GEOJSON";
        using (StreamReader streamReader = new StreamReader(filepath))
        using (JsonTextReader reader = new JsonTextReader(streamReader))
        {
            reader.SupportMultipleContent = true;

            var serializer = new JsonSerializer();
            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.StartObject)
                {
                    string jsonString = JObject.Load(reader).ToString();
                    JsonModel.Rootobject rootobject = JsonConvert.DeserializeObject<JsonModel.Rootobject>(jsonString);

                    PointCollection myPointCollection = new PointCollection();
                    List<Point> pointListOut = new List<Point>();
                    PointCollection PLO = new PointCollection();
                    Polygon myPolygon = new Polygon();

                    for (int i = 0; i < rootobject.features.Length; i++)
                    {
                        myPolygon = new Polygon();
                        string naam = rootobject.features[i].properties.localname;
                        JsonModel.Geometry geometrie = rootobject.features[i].geometry;

                        for (int p = 0; p < geometrie.coordinates.Length; p++)
                        {
                            for (int j = 0; j < geometrie.coordinates[p].Length; j++)
                            {
                                for (int z = 0; z < geometrie.coordinates[p][j].Length; z++)
                                {
                                    double lon = DegreeToRadian((geometrie.coordinates[p][j][z][0]));
                                    double lat = DegreeToRadian((geometrie.coordinates[p][j][z][1]));
                                    x = (1000 / (2 * Math.PI) * Math.Pow(2, 6) * (lon + Math.PI));
                                    y = (1000 / (2 * Math.PI) * Math.Pow(2, 6) * (Math.PI - Math.Log(Math.Tan(Math.PI / 4 + lat / 2))));
                                    myPointCollection.Add(new System.Windows.Point(x, y));
                                }
                            }
                        }

                        pr.RamerDouglasPeucker(myPointCollection, 1.0, pointListOut);
                        PLO = pr.Omvorm(pointListOut);
                        myPolygon.Points = PLO;
                        myPolygon.Stroke = Brushes.Black;
                        myPolygon.Stretch = Stretch.Fill;
                        myPolygon.StrokeThickness = 2;
                    }
                    myCanvas.Children.Add(myPolygon);
                }
            }
        }
    }

The data is use is like this: { "type" : "FeatureCollection", "features" : [{ "type":"Feature", "properties" : { "srid" : "4326", "id" : "54094", "name" : "Brussels-Capital", "localname" : "Région de Bruxelles-Capitale - Brussels Hoofdstedelijk Gewest", "official_name" : "", "boundary" : "administrative", "admin_level" : "4", "note" : "", "wikidata" : "Q240", "wikipedia" : "fr:Région de Bruxelles-Capitale", "timestamp" : "2019-12-11 22:37:02", "rpath" : "54094,52411,0", "alltags" : { "name:ar" : "بروكسل العاصمة", "name:ca" : "Brussel·les-Capital", "name:en" : "Brussels-Capital", "name:fr" : "Bruxelles-Capitale", "name:nl" : "Brussels Hoofdstedelijk Gewest", "name:ru" : "Брюссельский столичный регион", "name:sk" : "Bruselský región", "name:wa" : "Brussele-Capitåle", "ref:INS" : "04000", "website" : "http://www.bruxelles.irisnet.be/", "name:vls" : "Haaptstad Bréissel", "nat_name" : "Région de Bruxelles-Capitale - Brussels Hoofdstedelijk Gewest", "wikidata" : "Q240", "ISO3166-2" : "BE-BRU", "wikipedia" : "fr:Région de Bruxelles-Capitale", "nat_name:ar" : "إقليم بروكسل العاصمة", "nat_name:ca" : "Regió de Brussel·les-Capital", "nat_name:de" : "Region Brüssel-Hauptstadt", "nat_name:en" : "Brussels-Capital Region", "nat_name:fr" : "Région de Bruxelles-Capitale", "nat_name:lb" : "Haaptstadregioun Bréissel", "nat_name:li" : "Brussels Hoofsjtaejelik Gewes", "nat_name:nl" : "Brussels Hoofdstedelijk Gewest", "nat_name:wa" : "Redjon d'Brussele-Capitåle", "nat_name:vls" : "Brussels Oofdstedelik Gewest", "default_language" : "fr - nl"} }, "bbox" : [4.2437658, 50.763683, 4.4822712, 50.913906], "geometry": {"type":"MultiPolygon","coordinates":[[[[4.2437658,50.8195819],[4.2443812,50.8195414],[4.2444378,50.8193993],[4.2446464,50.8188349],[4.25431,50.8262863],[4.2539027,50.8258845],[4.2531563,50.8251469],[4.2511811,50.8242196],[4.2508417,50.8243805],[4.2497516,50.8235688],[4.2479386,50.8221951],[4.2476042,50.8219406],[4.2470097,50.8215331],[4.2453656,50.8205113],[4.244301,50.8198943],[4.2437658,50.8195819]]]]} },{ "type":"Feature", "properties" : { "srid" : "4326", "id" : "53114", "name" : "Antwerp", "localname" : "Antwerpen", "official_name" : "Provincie Antwerpen", "boundary" : "administrative", "admin_level" : "6", "note" : "", "wikidata" : "Q1116", "wikipedia" : "nl:Antwerpen (provincie)", "timestamp" : "2019-12-20 22:59:01", "rpath" : "53114,53134,52411,0", "alltags" : { "name:ca" : "Província d'Anvers", "name:en" : "Antwerp", "name:es" : "Amberes", "name:fr" : "Anvers", "name:lt" : "Antverpenas", "name:mk" : "Антверпен", "name:nl" : "Antwerpen", "name:pl" : "Antwerpia", "name:ru" : "Антверпен", "name:sk" : "Antverpy", "ref:INS" : "10000", "website" : "http://www.provant.be/", "name:tzl" : "Anviarça", "wikidata" : "Q1116", "ISO3166-2" : "BE-VAN", "wikipedia" : "nl:Antwerpen (provincie)", "population" : "1802719", "alt_name:mk" : "Антверп", "border_type" : "province", "wikipedia:fr" : "Province d'Anvers", "official_name" : "Provincie Antwerpen", "population:date" : "2014-01-01", "official_name:nl" : "Provincie Antwerpen"} }, "bbox" : [4.1719656, 50.990143, 5.2622542, 51.505116], "geometry": {"type":"MultiPolygon","coordinates":[[[[4.9399714,51.4361185],[4.9394687,51.4371095],[4.9457065,51.4447059],[4.9458012,51.4439747],[4.9439971,51.443798],[4.9439697,51.4437954],[4.9439041,51.4437889]]],[[[4.948755,51.4549908],[4.9490227,51.4537654],[4.949351,51.4537897],[4.9492362,51.4542513],[4.9497913,51.4543045],[4.9495907,51.4551116],[4.9490426,51.4550324],[4.948755,51.4549908]]]]} } (I removed allot of coordinates)

2

2 Answers

0
votes

Impossible to answer this with any certainty without seeing the data itself, but at first glance I can see you're not creating a new PLO PointCollection for each Polygon object you create.

I suspect that you may also need to switch from Polygon to Polyline, but again, that depends on the nature of your data.

0
votes

The problem is solved, i made an polygon for each provence and i had to remove "myPolygon.Stretch = Stretch.Fill;"