Example #1
0
        public static IGeometry HaltonPointsWithBases(IGeometry g, int nPts, int basei, int basej)
        {
            var env   = FunctionsUtil.GetEnvelopeOrDefault(g);
            var pts   = new Coordinate[nPts];
            var baseX = env.MinX;
            var baseY = env.MinY;

            var i = 0;

            while (i < nPts)
            {
                var x = baseX + env.Width * HaltonOrdinate(i + 1, basei);
                var y = baseY + env.Height * HaltonOrdinate(i + 1, basej);
                var p = new Coordinate(x, y);
                if (env.Contains(p))
                {
                    pts[i++] = new Coordinate(p);
                }
            }
            return(FunctionsUtil.GetFactoryOrDefault(g).CreateMultiPoint(pts));
        }
        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);
        }
Example #3
0
        public static IGeometry RandomRectilinearWalk(IGeometry 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;
                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 #4
0
        public static IGeometry RandomSegments(IGeometry 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 <IGeometry>();

            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));
        }
Example #5
0
        public static IGeometry RandomPointsInGrid(IGeometry 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 <IPoint>();

            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 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));
        }