public void TwoPolygonsFromDiamonds()
        {
            var nodes      = (new[] { 1, 2, 3, 4, 5, 6, 7 }).Select(x => new Node($"{x}", 0.0, 0.0)).ToArray();
            var dummyNodes = (new[] { 1, 2, 3, 4, 5, 6, 7, 8 }).Select(x => new Node($"dummy{x}", 0.0, 0.0)).ToArray(); // sit in middle of wyas
            var ways       = new Way[]
            {
                new Way("w1", new[] { nodes[0], dummyNodes[0], nodes[1] }),
                new Way("w2", new[] { nodes[1], dummyNodes[1], nodes[2] }),
                new Way("w3", new[] { nodes[2], dummyNodes[2], nodes[3] }),
                new Way("w4", new[] { nodes[3], dummyNodes[3], nodes[0] }),
                new Way("w5", new[] { nodes[2], dummyNodes[4], nodes[4] }),
                new Way("w6", new[] { nodes[4], dummyNodes[5], nodes[5] }),
                new Way("w6", new[] { nodes[5], dummyNodes[6], nodes[6] }),
                new Way("w7", new[] { nodes[6], dummyNodes[7], nodes[2] }),
            };

            var polygons = PolygonFactory.BuildPolygons(ways, new System.Collections.Generic.HashSet <string>());

            Assert.Equal(2, polygons.Count);

            ways[1].Nodes.Reverse();
            ways[3].Nodes.Reverse();

            var secondPolygons = PolygonFactory.BuildPolygons(ways, new System.Collections.Generic.HashSet <string>());

            Assert.Equal(2, secondPolygons.Count);
        }
        public void LargeGeoJson_Mississippi_Lines(TestImageProvider <Rgba32> provider, int pixelOffset)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(TestImages.GeoJson.States));

            FeatureCollection features = JsonConvert.DeserializeObject <FeatureCollection>(jsonContent);

            Feature missisipiGeom = features.Features.Single(f => (string)f.Properties["NAME"] == "Mississippi");

            Matrix3x2 transform = Matrix3x2.CreateTranslation(-87, -54)
                                  * Matrix3x2.CreateScale(60, 60)
                                  * Matrix3x2.CreateTranslation(pixelOffset, pixelOffset);
            IReadOnlyList <PointF[]> points = PolygonFactory.GetGeoJsonPoints(missisipiGeom, transform);

            using Image <Rgba32> image = provider.GetImage();

            foreach (PointF[] loop in points)
            {
                image.Mutate(c => c.DrawLines(Color.White, 1.0f, loop));
            }

            // Very strict tolerance, since the image is sparse (relaxed on .NET Framework)
            ImageComparer comparer = TestEnvironment.IsFramework
                ? ImageComparer.TolerantPercentage(1e-3f)
                : ImageComparer.TolerantPercentage(1e-7f);

            string details = $"PixelOffset({pixelOffset})";

            image.DebugSave(provider, details, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
            image.CompareToReferenceOutput(comparer, provider, testOutputDetails: details, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
        }
Beispiel #3
0
        public void BuildPolygon(bool reverse)
        {
            var n1  = new Node("1", 0, 0);
            var n2  = new Node("2", 1, 1);
            var n3  = new Node("3", 0, 2);
            var n4  = new Node("4", 4, 2);
            var n5  = new Node("5", 3, 1);
            var n6  = new Node("6", 4, 0);
            var way = new Way("5", new[] { n1, n2, n3, n4, n5, n6, n1 });

            if (reverse)
            {
                way.Nodes.Reverse();
            }
            var ll = new[]
            {
                way
            };
            var poly = PolygonFactory.BuildPolygons(ll, new System.Collections.Generic.HashSet <string>());

            Assert.Single(poly);
            Assert.Contains(n1, poly[0].Nodes);
            Assert.Contains(n2, poly[0].Nodes);
            Assert.Contains(n3, poly[0].Nodes);
            Assert.Contains(n4, poly[0].Nodes);
            Assert.Contains(n5, poly[0].Nodes);
            Assert.Contains(n6, poly[0].Nodes);
        }
        public void LargeGeoJson_Lines(TestImageProvider <Rgba32> provider, string geoJsonFile, int aa, float sx, float sy)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(geoJsonFile));

            PointF[][] points = PolygonFactory.GetGeoJsonPoints(jsonContent, Matrix3x2.CreateScale(sx, sy));

            using Image <Rgba32> image = provider.GetImage();
            var options = new DrawingOptions()
            {
                GraphicsOptions = new GraphicsOptions()
                {
                    Antialias = aa > 0, AntialiasSubpixelDepth = aa
                },
            };

            foreach (PointF[] loop in points)
            {
                image.Mutate(c => c.DrawLines(options, Color.White, 1.0f, loop));
            }

            string details = $"_{System.IO.Path.GetFileName(geoJsonFile)}_{sx}x{sy}_aa{aa}";

            image.DebugSave(
                provider,
                details,
                appendPixelTypeToFileName: false,
                appendSourceFileOrDescription: false);
        }
        private Image <Rgba32> FillGeoJsonPolygons(TestImageProvider <Rgba32> provider, string geoJsonFile, int aa, Vector2 scale, Vector2 pixelOffset)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(geoJsonFile));

            PointF[][] points = PolygonFactory.GetGeoJsonPoints(jsonContent, Matrix3x2.CreateScale(scale) * Matrix3x2.CreateTranslation(pixelOffset));

            Image <Rgba32> image   = provider.GetImage();
            var            options = new DrawingOptions()
            {
                GraphicsOptions = new GraphicsOptions()
                {
                    Antialias = aa > 0, AntialiasSubpixelDepth = aa
                },
            };
            var rnd = new Random(42);

            byte[] rgb = new byte[3];
            foreach (PointF[] loop in points)
            {
                rnd.NextBytes(rgb);

                var color = Color.FromRgb(rgb[0], rgb[1], rgb[2]);
                image.Mutate(c => c.FillPolygon(options, color, loop));
            }

            return(image);
        }
        public void SinglePolygonFromDiamond()
        {
            GlobalSettings.RouteCleanerSettings.GetInstance().PolygonsShouldConsolidateStraightEdges = false; // all our nodes are in same spot in this test.

            var nodes      = (new[] { 1, 2, 3, 4 }).Select(x => new Node($"{x}", 0.0, 0.0)).ToArray();
            var dummyNodes = (new[] { 1, 2, 3, 4 }).Select(x => new Node($"dummy{x}", 0.0, 0.0)).ToArray(); // sit in middle of wyas
            var ways       = new Way[]
            {
                new Way("w1", new[] { nodes[0], dummyNodes[0], nodes[1] }),
                new Way("w2", new[] { nodes[1], dummyNodes[1], nodes[2] }),
                new Way("w3", new[] { nodes[2], dummyNodes[2], nodes[3] }),
                new Way("w4", new[] { nodes[3], dummyNodes[3], nodes[0] }),
            };

            var polygons     = PolygonFactory.BuildPolygons(ways, new System.Collections.Generic.HashSet <string>());
            var firstPolygon = polygons.Single();

            ways[1].Nodes.Reverse();
            ways[3].Nodes.Reverse();

            var secondPolygons = PolygonFactory.BuildPolygons(ways, new System.Collections.Generic.HashSet <string>());
            var secondPolygon  = polygons.Single();

            Assert.NotEmpty(firstPolygon.Nodes);

            for (var i = 0; i < firstPolygon.Nodes.Count; i++)
            {
                Assert.Equal(firstPolygon.Nodes[i], secondPolygon.Nodes[i]);
            }
        }
        protected override PointF[][] GetPoints(FeatureCollection features)
        {
            Feature state = features.Features.Single(f => (string)f.Properties["NAME"] == "Utah");

            Matrix3x2 transform = Matrix3x2.CreateTranslation(-60, -40)
                                  * Matrix3x2.CreateScale(60, 60);

            return(PolygonFactory.GetGeoJsonPoints(state, transform).ToArray());
        }
            static PointF[][] GetPoints(FeatureCollection features)
            {
                Feature state = features.Features.Single(f => (string)f.Properties["NAME"] == "Mississippi");

                Matrix3x2 transform = Matrix3x2.CreateTranslation(-87, -54)
                                      * Matrix3x2.CreateScale(60, 60);

                return(PolygonFactory.GetGeoJsonPoints(state, transform).ToArray());
            }
Beispiel #9
0
    public static void ChamferSharpEdges(PrimitiveBrush brush, float chamferAngleThreshold, float chamferDistance, int chamferIterations)
    {
        var polygons          = new List <Polygon>(brush.GetPolygons());
        var polygonsChamfered = new List <Polygon>();

        var edgesVisited = new HashSet <VisitedEdge>();
        var edgesChamfer = new List <Edge>();

        foreach (var polygon in polygons)
        {
            var edges = polygon.GetEdges();
            foreach (var edge in edges)
            {
                var v1 = edge.Vertex1;
                var v2 = edge.Vertex2;

                if (edgesVisited.Contains(new VisitedEdge()
                {
                    pointA = v1.Position, pointB = v2.Position
                }))
                {
                    continue;
                }

                edgesVisited.Add(new VisitedEdge()
                {
                    pointA = v1.Position, pointB = v2.Position
                });
                edgesVisited.Add(new VisitedEdge()
                {
                    pointA = v1.Position, pointB = v2.Position
                });

                var edgePolygons = polygons.Where(p => Polygon.ContainsEdge(p, edge)).ToArray();
                if (edgePolygons.Length == 2)
                {
                    var normalA = edgePolygons[0].Plane.normal;
                    var normalB = edgePolygons[1].Plane.normal;

                    var angle = Vector3.Angle(normalA, normalB);
                    if (angle > chamferAngleThreshold)
                    {
                        edgesChamfer.Add(edge);
                    }
                }
            }
        }

        if (PolygonFactory.ChamferPolygons(polygons, edgesChamfer, chamferDistance, chamferIterations, out polygonsChamfered))
        {
            brush.SetPolygons(polygonsChamfered.ToArray());
            brush.Invalidate(true);
        }
    }
Beispiel #10
0
        public override AbstractFigure GetCopy()
        {
            var temp    = new MyPolygon(Thickness, FillColor, BorderColor, this.PointArray[0], this.PointArray[1]);
            var Factory = new PolygonFactory();

            for (int i = 2; i < this.PointArray.Count; i++)
            {
                temp = Factory.GetFigure(Thickness, FillColor, BorderColor, PrevPos, this.PointArray[i], temp) as MyPolygon;
            }
            return(temp);
        }
        public GoogleMapBuilder Polygons(Action <PolygonFactory> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }
            var factory = new PolygonFactory(Component);

            action(factory);
            return(this);
        }
        public void Missisippi_Skia(int offset)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(TestImages.GeoJson.States));

            FeatureCollection features = JsonConvert.DeserializeObject <FeatureCollection>(jsonContent);

            Feature missisipiGeom = features.Features.Single(f => (string)f.Properties["NAME"] == "Mississippi");

            Matrix3x2 transform = Matrix3x2.CreateTranslation(-87, -54)
                                  * Matrix3x2.CreateScale(60, 60)
                                  * Matrix3x2.CreateTranslation(offset, offset);
            IReadOnlyList <PointF[]> points = PolygonFactory.GetGeoJsonPoints(missisipiGeom, transform);

            var path = new SKPath();

            foreach (PointF[] pts in points.Where(p => p.Length > 2))
            {
                path.MoveTo(pts[0].X, pts[0].Y);

                for (int i = 0; i < pts.Length; i++)
                {
                    path.LineTo(pts[i].X, pts[i].Y);
                }

                path.LineTo(pts[0].X, pts[0].Y);
            }

            var imageInfo = new SKImageInfo(10000, 10000);

            using var paint = new SKPaint
                  {
                      Style       = SKPaintStyle.Stroke,
                      Color       = SKColors.White,
                      StrokeWidth = 1f,
                      IsAntialias = true,
                  };

            using var surface = SKSurface.Create(imageInfo);
            SKCanvas canvas = surface.Canvas;

            canvas.Clear(new SKColor(0, 0, 0));
            canvas.DrawPath(path, paint);

            string outDir = TestEnvironment.CreateOutputDirectory("Skia");
            string fn     = System.IO.Path.Combine(outDir, $"Missisippi_Skia_{offset}.png");

            using SKImage image = surface.Snapshot();
            using SKData data   = image.Encode(SKEncodedImageFormat.Png, 100);

            using FileStream fs = File.Create(fn);
            data.SaveTo(fs);
        }
        private Scene2D CreateShapes()
        {
            var scene = new Scene2D();

            scene.Shapes.Add(new Circle(new Vector2D(3, 5), 8));
            scene.Shapes.Add(RectangleFactory.CreateByDimensions(7, -2, 12, 8));
            var points = new List <Vector2D>()
            {
                new Vector2D(2, 2), new Vector2D(6, 7), new Vector2D(4, -3), new Vector2D(-2, 1)
            };

            scene.Shapes.Add(PolygonFactory.CreateByPoints(points));
            return(scene);
        }
        public void RectangleAndPolygon_DoOverlap_ShouldReturn()
        {
            var operation = new GeneralShapeOperation();
            var rectangle = RectangleFactory.CreateByDimensions(0, 0, 3, 3);
            var polygon   = PolygonFactory.CreateByPoints(new List <Vector2D>()
            {
                new Vector2D(1, 1),
                new Vector2D(1, 2),
                new Vector2D(2, 1)
            });

            var result = operation.DoOverlap(rectangle, polygon);

            result.Should().BeTrue();
        }
Beispiel #15
0
        private Polygon GetSquare(double edgeLength, double center)
        {
            var n = new Node("2", center, center);

            return(PolygonFactory.BuildPolygons(new[]
            {
                new Way("1", new[]
                {
                    n,
                    new Node("3", center, center + edgeLength),
                    new Node("4", center + edgeLength, center + edgeLength),
                    new Node("5", center + edgeLength, center),
                    n
                })
            }, new System.Collections.Generic.HashSet <string>())[0]);
        }
        public void Setup()
        {
            List <Vector2D> points = new List <Vector2D>();

            Console.WriteLine($"PolygonSize: {PolygonSides}");
            for (int p = 0; p < PolygonSides; p++)
            {
                var x = random.NextDouble() * 60000 + 20000;
                var y = random.NextDouble() * 60000 + 20000;
                points.Add(new Vector2D(x, y));
            }
            this.RandomPolygon             = PolygonFactory.CreateByPoints(points);
            this.RandomPolygon.MarginWidth = 2000;

            points = new List <Vector2D>();
            for (int p = 0; p < PolygonSides; p++)
            {
                var x = Math.Cos(Math.PI / PolygonSides * p) * OverlapProbability * 100000 + 50000;
                var y = Math.Cos(Math.PI / PolygonSides * p) * OverlapProbability * 100000 + 50000;
                points.Add(new Vector2D(x, y));
            }
            this.RegularPolygon             = PolygonFactory.CreateByPoints(points);
            this.RegularPolygon.MarginWidth = 2000;

            points = new List <Vector2D>();
            for (int p = 0; p < PolygonSides; p++)
            {
                var radius = random.NextDouble() * OverlapProbability * 50000;
                var x      = Math.Cos(Math.PI / PolygonSides * p) * radius + 50000;
                var y      = Math.Cos(Math.PI / PolygonSides * p) * radius + 50000;
                points.Add(new Vector2D(x, y));
            }
            this.RadialPolygon             = PolygonFactory.CreateByPoints(points);
            this.RadialPolygon.MarginWidth = 2000;

            for (int i = 0; i < Count; i++)
            {
                var x         = random.NextDouble() * 90000;
                var y         = random.NextDouble() * 90000;
                var width     = random.NextDouble() * 20000;
                var height    = random.NextDouble() * 20000;
                var rectangle = RectangleFactory.CreateByDimensions(x, y, width, height);
                rectangle.MarginWidth = random.NextDouble() * 3000;
                Rectangles.Add(rectangle);
            }
        }
Beispiel #17
0
        private static Polygon CreateTestPolygon1()
        {
            var points = new List <Vector2D>()
            {
                new Vector2D(-10, 5),
                new Vector2D(-5, 5),
                new Vector2D(-2, 2),
                new Vector2D(2, 2),
                new Vector2D(5, 5),
                new Vector2D(10, 5),
                new Vector2D(5, 0),
                new Vector2D(8, -5),
                new Vector2D(-8, -5)
            };
            var polygon = PolygonFactory.CreateByPoints(points);

            return(polygon);
        }
Beispiel #18
0
        /// <summary>
        /// This method produces instances of type <see cref="MultiPolygon"/>.
        /// </summary>
        /// <returns>The created geometries</returns>
        internal override Collection <Geometry> CreateGeometries(List <IFeature> features)
        {
            IPathNode multiPolygonNode     = new PathNode(Gmlns, "MultiPolygon", (NameTable)XmlReader.NameTable);
            IPathNode multiSurfaceNode     = new PathNode(Gmlns, "MultiSurface", (NameTable)XmlReader.NameTable);
            IPathNode multiPolygonNodeAlt  = new AlternativePathNodesCollection(multiPolygonNode, multiSurfaceNode);
            IPathNode polygonMemberNode    = new PathNode(Gmlns, "polygonMember", (NameTable)XmlReader.NameTable);
            IPathNode surfaceMemberNode    = new PathNode(Gmlns, "surfaceMember", (NameTable)XmlReader.NameTable);
            IPathNode polygonMemberNodeAlt = new AlternativePathNodesCollection(polygonMemberNode, surfaceMemberNode);
            IPathNode linearRingNode       = new PathNode(Gmlns, "LinearRing", (NameTable)XmlReader.NameTable);
            var       labelValues          = new Dictionary <string, string>();
            var       geomFound            = false;

            try
            {
                // Reading the entire feature's node makes it possible to collect label values that may appear before or after the geometry property
                while ((FeatureReader = GetSubReaderOf(XmlReader, null, FeatureNode)) != null)
                {
                    while (
                        (GeomReader =
                             GetSubReaderOf(FeatureReader, labelValues, multiPolygonNodeAlt, polygonMemberNodeAlt)) != null)
                    {
                        using GeometryFactory geomFactory = new PolygonFactory(GeomReader, FeatureTypeInfo)
                              {
                                  AxisOrder = AxisOrder
                              };
                        var polygons = geomFactory.CreateGeometries(features).Cast <Polygon>();
                        Geoms.Add(new MultiPolygon(polygons.ToArray()));
                        geomFound = true;
                    }
                    if (geomFound)
                    {
                        features.Add(AddLabel(labelValues, Geoms[Geoms.Count - 1]));
                    }
                    geomFound = false;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("An exception occurred while parsing a multi-polygon geometry: " + ex.Message);
                throw;
            }

            return(Geoms);
        }
        public void Setup()
        {
            List <Vector2D> points = new List <Vector2D>();

            Console.WriteLine($"PolygonSize: {PolygonSize}");
            for (int p = 0; p < PolygonSize; p++)
            {
                var x = random.NextDouble() * 100000;
                var y = random.NextDouble() * 100000;
                points.Add(new Vector2D(x, y));
            }
            this.RandomPolygon = PolygonFactory.CreateByPoints(points);

            for (int i = 0; i < Count; i++)
            {
                var x = random.NextDouble() * 100000;
                var y = random.NextDouble() * 100000;
                Points.Add(new Vector2D(x, y));
            }
        }
Beispiel #20
0
    public void ConnectCertainBodies(GameObject objA, GameObject objB)
    {
        vertices = new Vector3[4];

        vertices[0] = -objA.transform.localScale / 4;
        vertices[1] = objA.transform.localScale / 4;
        vertices[2] = objB.transform.position - objA.transform.position - objB.transform.localScale / 4;
        vertices[3] = objB.transform.position - objA.transform.position + objB.transform.localScale / 4;

        polyMesh = PolygonFactory.CreatePolygonStrip(vertices, objA);


        Vector3 v = new Vector3(3, 3, 3);

        Vector3[] vertices2 = new Vector3[3];

        vertices2[0] = vertices[0] + v;
        vertices2[1] = vertices[1] + v;
        vertices2[2] = vertices[2] + v;

        MeshRenderer mr = objA.GetComponent <MeshRenderer>();

        PolygonFactory.AddPolygonStrip(vertices2, polyMesh, mr);

        PolygonFactory.AddPolygonStripPoint(vertices[3] + v, polyMesh);


        /*
         * PolygonFactory.AddPolygonStripPoint(vertices[1], polyMesh);
         * PolygonFactory.AddPolygonStripPoint(vertices[2], polyMesh);
         * PolygonFactory.AddPolygonStripPoint(vertices[3], polyMesh);
         */

        /*
         * PolygonFactory.ExtendPolygonStrip(vertices, polyMesh);
         */
    }
Beispiel #21
0
        public Features ExecuteIntersectionQuery(BoundingBox bbox)
        {
            if (_featureTypeInfo == null)
            {
                return(null);
            }

            var features = new Features();

            string geometryTypeString = _featureTypeInfo.Geometry.GeometryType;

            GeometryFactory geomFactory = null;

            if (!string.IsNullOrEmpty(_label))
            {
                _featureTypeInfo.LableField = _label;
                _quickGeometries            = false;
            }

            // Configuration for GetFeature request */
            var config = new WFSClientHttpConfigurator(_textResources);

            config.ConfigureForWfsGetFeatureRequest(_httpClientUtil, _featureTypeInfo, _label, bbox, _ogcFilter,
                                                    _getFeatureGetRequest);

            try
            {
                switch (geometryTypeString)
                {
                /* Primitive geometry elements */

                // GML2
                case "PointPropertyType":
                    geomFactory = new PointFactory(_httpClientUtil, _featureTypeInfo);
                    break;

                // GML2
                case "LineStringPropertyType":
                    geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo);
                    break;

                // GML2
                case "PolygonPropertyType":
                    geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo);
                    break;

                // GML3
                case "CurvePropertyType":
                    geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo);
                    break;

                // GML3
                case "SurfacePropertyType":
                    geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo);
                    break;

                /* Aggregate geometry elements */

                // GML2
                case "MultiPointPropertyType":
                    if (_multiGeometries)
                    {
                        geomFactory = new MultiPointFactory(_httpClientUtil, _featureTypeInfo);
                    }
                    else
                    {
                        geomFactory = new PointFactory(_httpClientUtil, _featureTypeInfo);
                    }
                    break;

                // GML2
                case "MultiLineStringPropertyType":
                    if (_multiGeometries)
                    {
                        geomFactory = new MultiLineStringFactory(_httpClientUtil, _featureTypeInfo);
                    }
                    else
                    {
                        geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo);
                    }
                    break;

                // GML2
                case "MultiPolygonPropertyType":
                    if (_multiGeometries)
                    {
                        geomFactory = new MultiPolygonFactory(_httpClientUtil, _featureTypeInfo);
                    }
                    else
                    {
                        geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo);
                    }
                    break;

                // GML3
                case "MultiCurvePropertyType":
                    if (_multiGeometries)
                    {
                        geomFactory = new MultiLineStringFactory(_httpClientUtil, _featureTypeInfo);
                    }
                    else
                    {
                        geomFactory = new LineStringFactory(_httpClientUtil, _featureTypeInfo);
                    }
                    break;

                // GML3
                case "MultiSurfacePropertyType":
                    if (_multiGeometries)
                    {
                        geomFactory = new MultiPolygonFactory(_httpClientUtil, _featureTypeInfo);
                    }
                    else
                    {
                        geomFactory = new PolygonFactory(_httpClientUtil, _featureTypeInfo);
                    }
                    break;

                // .e.g. 'gml:GeometryAssociationType' or 'GeometryPropertyType'
                //It's better to set the geometry type manually, if it is known...
                default:
                    geomFactory = new UnspecifiedGeometryFactory_WFS1_0_0_GML2(_httpClientUtil, _featureTypeInfo,
                                                                               _multiGeometries, _quickGeometries);
                    break;
                }

                var geoms = geomFactory.CreateGeometries(features);
                geomFactory.Dispose();
                return(features);
            }
            // Free resources (net connection of geometry factory)
            finally
            {
                if (geomFactory != null)
                {
                    geomFactory.Dispose();
                }
            }
        }
 protected virtual PointF[][] GetPoints(FeatureCollection features)
 => features.Features
 .SelectMany(f => PolygonFactory.GetGeoJsonPoints(f, Matrix3x2.CreateScale(60, 60)))
 .ToArray();
Beispiel #23
0
 /// <summary>
 /// Adds a circle to the path.
 /// </summary>
 /// <param name="center">The location of the center of the circle.</param>
 /// <param name="radius">The radius of the circle in pixels.</param>
 /// <param name="clockwise">Specifies if the circle will be drawn clockwise. The direction might affect the result since the shapes are rendered using the non-zero winding rule.</param>
 public void AddCircle(PointF center, float radius, bool clockwise)
 {
     polygons.Add(PolygonFactory.FromCircle(center, radius, clockwise));
 }
Beispiel #24
0
 /// <summary>
 /// Fills the specified circle with a color.
 /// </summary>
 /// <param name="color">The fill color.</param>
 /// <param name="center">The location of the center of the circle.</param>
 /// <param name="radius">The radius of the circle in pixels.</param>
 /// <param name="clockwise">Specifies if the circle will be drawn clockwise. The direction might affect the result since the shapes are rendered using the non-zero winding rule.</param>
 public void FillCircle(Color color, PointF center, float radius, bool clockwise)
 {
     FillPolygonCore(nextID++, color, PolygonFactory.FromCircle(center, radius, clockwise));
 }
Beispiel #25
0
        public System.Collections.ObjectModel.Collection <SharpMap.Geometries.Geometry> GetGeometriesInView(SharpMap.Geometries.BoundingBox bbox)
        {
            if (_FeatureTypeInfo == null)
            {
                return(null);
            }

            System.Collections.ObjectModel.Collection <Geometry> geoms = new System.Collections.ObjectModel.Collection <Geometry>();

            string geometryTypeString = _FeatureTypeInfo.Geometry._GeometryType;

            GeometryFactory geomFactory = null;

            if (!string.IsNullOrEmpty(_Label))
            {
                _LabelInfo = new FeatureDataTable();
                _LabelInfo.Columns.Add(_Label);
                // Turn off quick geometries, if a label is applied...
                _QuickGeometries = false;
            }

            // Configuration for GetFeature request */
            WFSClientHTTPConfigurator config = new WFSClientHTTPConfigurator(_TextResources);

            config.configureForWfsGetFeatureRequest(_HttpClientUtil, _FeatureTypeInfo, _Label, bbox, _OGCFilter, _GetFeatureGETRequest);

            try
            {
                switch (geometryTypeString)
                {
                /* Primitive geometry elements */

                // GML2
                case "PointPropertyType":
                    geomFactory = new PointFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    break;

                // GML2
                case "LineStringPropertyType":
                    geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    break;

                // GML2
                case "PolygonPropertyType":
                    geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    break;

                // GML3
                case "CurvePropertyType":
                    geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    break;

                // GML3
                case "SurfacePropertyType":
                    geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    break;

                /* Aggregate geometry elements */

                // GML2
                case "MultiPointPropertyType":
                    if (_MultiGeometries)
                    {
                        geomFactory = new MultiPointFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    else
                    {
                        geomFactory = new PointFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    break;

                // GML2
                case "MultiLineStringPropertyType":
                    if (_MultiGeometries)
                    {
                        geomFactory = new MultiLineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    else
                    {
                        geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    break;

                // GML2
                case "MultiPolygonPropertyType":
                    if (_MultiGeometries)
                    {
                        geomFactory = new MultiPolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    else
                    {
                        geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    break;

                // GML3
                case "MultiCurvePropertyType":
                    if (_MultiGeometries)
                    {
                        geomFactory = new MultiLineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    else
                    {
                        geomFactory = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    break;

                // GML3
                case "MultiSurfacePropertyType":
                    if (_MultiGeometries)
                    {
                        geomFactory = new MultiPolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    else
                    {
                        geomFactory = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                    }
                    break;

                // .e.g. 'gml:GeometryAssociationType' or 'GeometryPropertyType'
                //It's better to set the geometry type manually, if it is known...
                default:
                    geomFactory = new UnspecifiedGeometryFactory_WFS1_0_0_GML2(_HttpClientUtil, _FeatureTypeInfo, _MultiGeometries, _QuickGeometries, _LabelInfo);
                    geoms       = geomFactory.createGeometries();
                    return(geoms);
                }

                geoms = _QuickGeometries ? geomFactory.createQuickGeometries(geometryTypeString) : geomFactory.createGeometries();
                geomFactory.Dispose();

                return(geoms);
            }
            // Free resources (net connection of geometry factory)
            finally
            {
                geomFactory.Dispose();
            }
        }
Beispiel #26
0
        /// <summary>
        /// This method detects the geometry type from 'GetFeature' response and uses a geometry factory to create the
        /// appropriate geometries.
        /// </summary>
        /// <returns></returns>
        internal override Collection <Geometry> CreateGeometries(List <IFeature> features)
        {
            GeometryFactory?geomFactory = null;

            var geometryTypeString = string.Empty;

            if (_quickGeometries)
            {
                _multiGeometries = false;
            }

            IPathNode pointNode              = new PathNode(Gmlns, "Point", (NameTable)XmlReader.NameTable);
            IPathNode lineStringNode         = new PathNode(Gmlns, "LineString", (NameTable)XmlReader.NameTable);
            IPathNode polygonNode            = new PathNode(Gmlns, "Polygon", (NameTable)XmlReader.NameTable);
            IPathNode multiPointNode         = new PathNode(Gmlns, "MultiPoint", (NameTable)XmlReader.NameTable);
            IPathNode multiLineStringNode    = new PathNode(Gmlns, "MultiLineString", (NameTable)XmlReader.NameTable);
            IPathNode multiCurveNode         = new PathNode(Gmlns, "MultiCurve", (NameTable)XmlReader.NameTable);
            IPathNode multiLineStringNodeAlt = new AlternativePathNodesCollection(multiLineStringNode, multiCurveNode);
            IPathNode multiPolygonNode       = new PathNode(Gmlns, "MultiPolygon", (NameTable)XmlReader.NameTable);
            IPathNode multiSurfaceNode       = new PathNode(Gmlns, "MultiSurface", (NameTable)XmlReader.NameTable);
            IPathNode multiPolygonNodeAlt    = new AlternativePathNodesCollection(multiPolygonNode, multiSurfaceNode);

            while (XmlReader.Read())
            {
                if (XmlReader.NodeType == XmlNodeType.Element)
                {
                    if (_multiGeometries)
                    {
                        if (multiPointNode.Matches(XmlReader))
                        {
                            geomFactory?.Dispose();
                            geomFactory        = new MultiPointFactory(_httpClientUtil, FeatureTypeInfo);
                            geometryTypeString = "MultiPointPropertyType";
                            break;
                        }
                        if (multiLineStringNodeAlt.Matches(XmlReader))
                        {
                            geomFactory?.Dispose();
                            geomFactory        = new MultiLineStringFactory(_httpClientUtil, FeatureTypeInfo);
                            geometryTypeString = "MultiLineStringPropertyType";
                            break;
                        }
                        if (multiPolygonNodeAlt.Matches(XmlReader))
                        {
                            geomFactory?.Dispose();
                            geomFactory        = new MultiPolygonFactory(_httpClientUtil, FeatureTypeInfo);
                            geometryTypeString = "MultiPolygonPropertyType";
                            break;
                        }
                    }

                    if (pointNode.Matches(XmlReader))
                    {
                        geomFactory?.Dispose();
                        geomFactory        = new PointFactory(_httpClientUtil, FeatureTypeInfo);
                        geometryTypeString = "PointPropertyType";
                        break;
                    }
                    if (lineStringNode.Matches(XmlReader))
                    {
                        geomFactory?.Dispose();
                        geomFactory        = new LineStringFactory(_httpClientUtil, FeatureTypeInfo);
                        geometryTypeString = "LineStringPropertyType";
                        break;
                    }
                    if (polygonNode.Matches(XmlReader))
                    {
                        geomFactory?.Dispose();
                        geomFactory        = new PolygonFactory(_httpClientUtil, FeatureTypeInfo);
                        geometryTypeString = "PolygonPropertyType";
                        break;
                    }
                    if (ServiceExceptionNode?.Matches(XmlReader) ?? false)
                    {
                        var serviceException = XmlReader.ReadInnerXml();
                        Trace.TraceError("A service exception occured: " + serviceException);
                        throw new Exception("A service exception occured: " + serviceException);
                    }
                }
            }

            FeatureTypeInfo.Geometry.GeometryType = geometryTypeString;

            if (geomFactory == null)
            {
                return(Geoms);
            }

            geomFactory.AxisOrder = AxisOrder;
            geomFactory.CreateGeometries(features);
            return(Geoms);
        }