Example #1
0
        private static void generateLines(IGeometryFactory geometryFactory,
                                          ICollection <IGeometry> geometry,
                                          Random rndGen)
        {
            ICoordinateSequenceFactory coordinateSequenceFactory =
                geometryFactory.CoordinateSequenceFactory;
            ICoordinateFactory  coordinateFactory = geometryFactory.CoordinateFactory;
            ICoordinateSequence coords            = coordinateSequenceFactory.Create(CoordinateDimensions.Two);

            Int32 lineCount = rndGen.Next(10, 100);

            for (Int32 lineIndex = 0; lineIndex < lineCount; lineIndex++)
            {
                Int32 vertexCount = rndGen.Next(4, 15);

                ICoordinate coordinate = coordinateFactory.Create(rndGen.NextDouble() * 1000,
                                                                  rndGen.NextDouble() * 1000);
                coords.Add(coordinate);

                for (Int32 vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++)
                {
                    ICoordinate next = coordinateFactory.Create(coordinate[Ordinates.X] + rndGen.Next(-50, 50),
                                                                coordinate[Ordinates.Y] + rndGen.Next(-50, 50));
                    coords.Add(next);
                    coordinate = next;
                }

                ILineString line = geometryFactory.CreateLineString(coords);

                geometry.Add(line);
            }
        }
Example #2
0
        private static void generatePolygons(IGeometryFactory geometryFactory,
                                             ICollection <IGeometry> geometry,
                                             Random rndGen)
        {
            ICoordinateSequenceFactory coordinateSequenceFactory =
                geometryFactory.CoordinateSequenceFactory;
            ICoordinateFactory  coordinateFactory = geometryFactory.CoordinateFactory;
            ICoordinateSequence coords            = coordinateSequenceFactory.Create(CoordinateDimensions.Two);

            Int32 polyCount = rndGen.Next(10, 100);

            for (Int32 polyIndex = 0; polyIndex < polyCount; polyIndex++)
            {
                ICoordinate upperLeft = coordinateFactory.Create(rndGen.NextDouble() * 1000,
                                                                 rndGen.NextDouble() * 1000);

                Double sideLength = rndGen.NextDouble() * 50;

                // Make a square
                coords.Add(upperLeft);
                coords.Add(coordinateFactory.Create(upperLeft[Ordinates.X] + sideLength,
                                                    upperLeft[Ordinates.Y]));
                coords.Add(coordinateFactory.Create(upperLeft[Ordinates.X] + sideLength,
                                                    upperLeft[Ordinates.Y] - sideLength));
                coords.Add(coordinateFactory.Create(upperLeft[Ordinates.X],
                                                    upperLeft[Ordinates.Y] - sideLength));

                IPolygon polygon = geometryFactory.CreatePolygon(coords);
                geometry.Add(polygon);
            }
        }