private static IGeometry create_J(IGeometry g)
        {
            var gf = FunctionsUtil.getFactoryOrDefault(g);

            var jTop = new Coordinate[]
            {
                new Coordinate(0, HEIGHT),
                new Coordinate(J_WIDTH, HEIGHT),
                new Coordinate(J_WIDTH, J_RADIUS)
            };
            var jBottom = new Coordinate[]
            {
                new Coordinate(J_WIDTH - J_RADIUS, 0),
                new Coordinate(0, 0)
            };

            var gsf = new GeometricShapeFactory(gf);

            gsf.Base      = new Coordinate(J_WIDTH - 2 * J_RADIUS, 0);
            gsf.Size      = 2 * J_RADIUS;
            gsf.NumPoints = 10;
            var jArc = gsf.CreateArc(1.5 * Math.PI, 0.5 * Math.PI);

            var coordList = new CoordinateList();

            coordList.Add(jTop, false);
            coordList.Add(((IGeometry)jArc).Reverse().Coordinates, false, 1, jArc.NumPoints - 1);
            coordList.Add(jBottom, false);

            return(gf.CreateLineString(coordList.ToCoordinateArray()));
        }
        public static Geometry randomSegmentsInGrid(Geometry g, int nPts)
        {
            var env      = FunctionsUtil.getEnvelopeOrDefault(g);
            var geomFact = FunctionsUtil.getFactoryOrDefault(g);

            int nCell = (int)Math.Sqrt(nPts) + 1;

            double xLen = env.Width / nCell;
            double yLen = env.Height / nCell;

            var lines = new List <Geometry>();

            for (int i = 0; i < nCell; i++)
            {
                for (int j = 0; j < nCell; j++)
                {
                    double x0 = env.MinX + i * xLen + xLen * RND.NextDouble();
                    double y0 = env.MinY + j * yLen + yLen * RND.NextDouble();
                    double x1 = env.MinX + i * xLen + xLen * RND.NextDouble();
                    double y1 = env.MinY + j * yLen + yLen * RND.NextDouble();
                    lines.Add(geomFact.CreateLineString(new[] {
                        new Coordinate(x0, y0), new Coordinate(x1, y1)
                    }));
                }
            }
            return(geomFact.BuildGeometry(lines));
        }
Example #3
0
        public static Geometry incentre(Geometry g)
        {
            var pts      = trianglePts(g);
            var cc       = Triangle.InCentre(pts[0], pts[1], pts[2]);
            var geomFact = FunctionsUtil.getFactoryOrDefault(g);

            return(geomFact.CreatePoint(cc));
        }
Example #4
0
        public static Geometry angleBisectors(Geometry g)
        {
            var pts      = trianglePts(g);
            var cc       = Triangle.InCentre(pts[0], pts[1], pts[2]);
            var geomFact = FunctionsUtil.getFactoryOrDefault(g);
            var line     = new LineString[3];

            line[0] = geomFact.CreateLineString(new Coordinate[] { pts[0], cc });
            line[1] = geomFact.CreateLineString(new Coordinate[] { pts[1], cc });
            line[2] = geomFact.CreateLineString(new Coordinate[] { pts[2], cc });
            return(geomFact.CreateMultiLineString(line));
        }
        public static IGeometry NodeWithPointwisePrecision(IGeometry geom, double scaleFactor)
        {
            var pm = new PrecisionModel(scaleFactor);

            var roundedGeom = GeometryPrecisionReducer.Reduce(geom, pm);

            var geomList = new List <IGeometry>();

            geomList.Add(roundedGeom);

            var noder = new GeometryNoder(pm);
            var lines = noder.Node(geomList);

            return(FunctionsUtil.getFactoryOrDefault(geom).BuildGeometry(CollectionUtil.Cast <IGeometry>((ICollection)lines)));
        }
Example #6
0
        public static Geometry perpendicularBisectors(Geometry g)
        {
            var pts      = trianglePts(g);
            var cc       = Triangle.Circumcentre(pts[0], pts[1], pts[2]);
            var geomFact = FunctionsUtil.getFactoryOrDefault(g);
            var line     = new LineString[3];
            var p0       = (new LineSegment(pts[1], pts[2])).ClosestPoint(cc);

            line[0] = geomFact.CreateLineString(new Coordinate[] { p0, cc });
            var p1 = (new LineSegment(pts[0], pts[2])).ClosestPoint(cc);

            line[1] = geomFact.CreateLineString(new Coordinate[] { p1, cc });
            var p2 = (new LineSegment(pts[0], pts[1])).ClosestPoint(cc);

            line[2] = geomFact.CreateLineString(new Coordinate[] { p2, cc });
            return(geomFact.CreateMultiLineString(line));
        }
        public static Geometry randomPoints(Geometry g, int nPts)
        {
            var    env      = FunctionsUtil.getEnvelopeOrDefault(g);
            var    geomFact = FunctionsUtil.getFactoryOrDefault(g);
            double xLen     = env.Width;
            double yLen     = env.Height;

            var pts = new List <Point>();

            for (int i = 0; i < nPts; i++)
            {
                double x = env.MinX + xLen * RND.NextDouble();
                double y = env.MinY + yLen * RND.NextDouble();
                pts.Add(geomFact.CreatePoint(new Coordinate(x, y)));
            }
            return(geomFact.BuildGeometry(pts.ToArray()));
        }
        public static Geometry randomLineString(Geometry g, int nPts)
        {
            var    env      = FunctionsUtil.getEnvelopeOrDefault(g);
            var    geomFact = FunctionsUtil.getFactoryOrDefault(g);
            double width    = env.Width;
            double hgt      = env.Height;

            var pts = new Coordinate[nPts];

            for (int i = 0; i < nPts; i++)
            {
                double xLen = width * RND.NextDouble();
                double yLen = hgt * RND.NextDouble();
                pts[i] = randomPtAround(env.Centre, xLen, yLen);
            }
            return(geomFact.CreateLineString(pts));
        }
        private static IGeometry create_S(IGeometry g)
        {
            var gf = FunctionsUtil.getFactoryOrDefault(g);

            double centreX = WIDTH - S_RADIUS;

            var top = new []
            {
                new Coordinate(WIDTH, HEIGHT),
                new Coordinate(centreX, HEIGHT)
            };
            var bottom = new []
            {
                new Coordinate(centreX, 0),
                new Coordinate(WIDTH - 2 * S_RADIUS, 0)
            };

            var gsf = new GeometricShapeFactory(gf);

            gsf.Centre    = new Coordinate(centreX, HEIGHT - S_RADIUS);
            gsf.Size      = 2 * S_RADIUS;
            gsf.NumPoints = 10;
            var arcTop = gsf.CreateArc(0.5 * Math.PI, Math.PI);

            var gsf2 = new GeometricShapeFactory(gf);

            gsf2.Centre    = new Coordinate(centreX, S_RADIUS);
            gsf2.Size      = 2 * S_RADIUS;
            gsf2.NumPoints = 10;
            var arcBottom = (ILineString)((IGeometry)gsf2.CreateArc(1.5 * Math.PI, Math.PI)).Reverse();

            var coordList = new CoordinateList();

            coordList.Add(top, false);
            coordList.Add(arcTop.Coordinates, false, 1, arcTop.NumPoints - 1);
            coordList.Add(new Coordinate(centreX, HEIGHT / 2));
            coordList.Add(arcBottom.Coordinates, false, 1, arcBottom.NumPoints - 1);
            coordList.Add(bottom, false);

            return(gf.CreateLineString(coordList.ToCoordinateArray()));
        }
        public static Geometry randomSegments(Geometry g, int nPts)
        {
            var    env      = FunctionsUtil.getEnvelopeOrDefault(g);
            var    geomFact = FunctionsUtil.getFactoryOrDefault(g);
            double xLen     = env.Width;
            double yLen     = env.Height;

            var lines = new List <Geometry>();

            for (int i = 0; i < nPts; i++)
            {
                double x0 = env.MinX + xLen * RND.NextDouble();
                double y0 = env.MinY + yLen * RND.NextDouble();
                double x1 = env.MinX + xLen * RND.NextDouble();
                double y1 = env.MinY + yLen * RND.NextDouble();
                lines.Add(geomFact.CreateLineString(new[] {
                    new Coordinate(x0, y0), new Coordinate(x1, y1)
                }));
            }
            return(geomFact.BuildGeometry(lines));
        }
        private static IGeometry fontGlyph(IGeometry g, String text, Font font)
        {
            var env      = FunctionsUtil.getEnvelopeOrDefault(g);
            var geomFact = FunctionsUtil.getFactoryOrDefault(g);

            var textGeom = FontGlyphReader.Read(text, font, geomFact);
            var envText  = textGeom.EnvelopeInternal;

            if (g != null)
            {
                // transform to baseline
                var baseText0 = new Coordinate(envText.MinX, envText.MinY);
                var baseText1 = new Coordinate(envText.MaxX, envText.MinY);
                var baseGeom0 = new Coordinate(env.MinX, env.MinY);
                var baseGeom1 = new Coordinate(env.MaxX, env.MinY);
                AffineTransformation trans = AffineTransformationFactory.CreateFromBaseLines(baseText0, baseText1,
                                                                                             baseGeom0, baseGeom1);
                return(trans.Transform(textGeom));
            }
            return(textGeom);
        }
        public static Geometry randomRectilinearWalk(Geometry g, int nPts)
        {
            var    env      = FunctionsUtil.getEnvelopeOrDefault(g);
            var    geomFact = FunctionsUtil.getFactoryOrDefault(g);
            double xLen     = env.Width;
            double yLen     = env.Height;

            var pts = new Coordinate[nPts];

            bool xory = true;

            for (int i = 0; i < nPts; i++)
            {
                Coordinate pt = null;
                if (i == 0)
                {
                    pt = randomPtAround(env.Centre, xLen, yLen);
                }
                else
                {
                    double dist = xLen * (RND.NextDouble() - 0.5);
                    double x    = pts[i - 1].X;
                    double y    = pts[i - 1].Y;
                    if (xory)
                    {
                        x += dist;
                    }
                    else
                    {
                        y += dist;
                    }
                    // switch orientation
                    xory = !xory;
                    pt   = new Coordinate(x, y);
                }
                pts[i] = pt;
            }
            return(geomFact.CreateLineString(pts));
        }
Example #13
0
        private static IGeometry create_T(IGeometry g)
        {
            var gf = FunctionsUtil.getFactoryOrDefault(g);

            var tTop = new []
            {
                new Coordinate(J_WIDTH, HEIGHT),
                new Coordinate(WIDTH - S_RADIUS - 5, HEIGHT)
            };
            var tBottom = new []
            {
                new Coordinate(J_WIDTH + 0.5 * T_WIDTH, HEIGHT),
                new Coordinate(J_WIDTH + 0.5 * T_WIDTH, 0)
            };
            var lines = new []
            {
                gf.CreateLineString(tTop),
                gf.CreateLineString(tBottom)
            };

            return(gf.CreateMultiLineString(lines));
        }
        public static Geometry randomPointsInGrid(Geometry g, int nPts)
        {
            var env      = FunctionsUtil.getEnvelopeOrDefault(g);
            var geomFact = FunctionsUtil.getFactoryOrDefault(g);

            int nCell = (int)Math.Sqrt(nPts) + 1;

            double xLen = env.Width / nCell;
            double yLen = env.Height / nCell;

            var pts = new List <Point>();

            for (int i = 0; i < nCell; i++)
            {
                for (int j = 0; j < nCell; j++)
                {
                    double x = env.MinX + i * xLen + xLen * RND.NextDouble();
                    double y = env.MinY + j * yLen + yLen * RND.NextDouble();
                    pts.Add(geomFact.CreatePoint(new Coordinate(x, y)));
                }
            }
            return(geomFact.BuildGeometry(pts.ToArray()));
        }
        public static Geometry randomRadialPoints(Geometry g, int nPts)
        {
            var    env      = FunctionsUtil.getEnvelopeOrDefault(g);
            var    geomFact = FunctionsUtil.getFactoryOrDefault(g);
            double xLen     = env.Width;
            double yLen     = env.Height;
            double rMax     = Math.Min(xLen, yLen) / 2.0;

            double centreX = env.MinX + xLen / 2;
            double centreY = env.MinY + yLen / 2;

            var pts = new List <Point>();

            for (int i = 0; i < nPts; i++)
            {
                double rand = RND.NextDouble();
                double r    = rMax * rand * rand;
                double ang  = 2 * Math.PI * RND.NextDouble();
                double x    = centreX + r * Math.Cos(ang);
                double y    = centreY + r * Math.Sin(ang);
                pts.Add(geomFact.CreatePoint(new Coordinate(x, y)));
            }
            return(geomFact.BuildGeometry(pts.ToArray()));
        }
        public static IGeometry grid(IGeometry g, int nCells)
        {
            var geoms = new List <IGeometry>();

            var env      = FunctionsUtil.getEnvelopeOrDefault(g);
            var geomFact = FunctionsUtil.getFactoryOrDefault(g);

            int    nCellsOnSide = (int)Math.Sqrt(nCells) + 1;
            double delX         = env.Width / nCellsOnSide;
            double delY         = env.Height / nCellsOnSide;

            for (int i = 0; i < nCellsOnSide; i++)
            {
                for (int j = 0; j < nCellsOnSide; j++)
                {
                    double x = env.MinX + i * delX;
                    double y = env.MinY + j * delY;

                    var cellEnv = new Envelope(x, x + delX, y, y + delY);
                    geoms.Add(geomFact.ToGeometry(cellEnv));
                }
            }
            return(geomFact.BuildGeometry(geoms));
        }