Search in sources :

Example 86 with BoundingBox

use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.

the class CreateRandomShapeFunctions method randomLineString.

public static Geometry randomLineString(final Geometry g, final int nPts) {
    final BoundingBox env = FunctionsUtil.getEnvelopeOrDefault(g);
    final GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
    final double width = env.getWidth();
    final double hgt = env.getHeight();
    final Point[] pts = new Point[nPts];
    for (int i = 0; i < nPts; i++) {
        final double xLen = width * Math.random();
        final double yLen = hgt * Math.random();
        pts[i] = randomPtInRectangleAround(env.getCentre(), xLen, yLen);
    }
    return geomFact.lineString(pts);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 87 with BoundingBox

use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.

the class CreateRandomShapeFunctions method randomSegments.

public static Geometry randomSegments(final Geometry g, final int nPts) {
    final BoundingBox env = FunctionsUtil.getEnvelopeOrDefault(g);
    final GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
    final double xLen = env.getWidth();
    final double yLen = env.getHeight();
    final List lines = new ArrayList();
    for (int i = 0; i < nPts; i++) {
        final double x0 = env.getMinX() + xLen * Math.random();
        final double y0 = env.getMinY() + yLen * Math.random();
        final double x1 = env.getMinX() + xLen * Math.random();
        final double y1 = env.getMinY() + yLen * Math.random();
        lines.add(geomFact.lineString(new Point[] { new PointDoubleXY(x0, y0), new PointDoubleXY(x1, y1) }));
    }
    return geomFact.buildGeometry(lines);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

Example 88 with BoundingBox

use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.

the class CreateRandomShapeFunctions method randomRectilinearWalk.

public static Geometry randomRectilinearWalk(final Geometry g, final int nPts) {
    final BoundingBox env = FunctionsUtil.getEnvelopeOrDefault(g);
    final GeometryFactory geomFact = FunctionsUtil.getFactoryOrDefault(g);
    final double xLen = env.getWidth();
    final double yLen = env.getHeight();
    final Point[] pts = new Point[nPts];
    boolean xory = true;
    for (int i = 0; i < nPts; i++) {
        Point pt = null;
        if (i == 0) {
            pt = randomPtInRectangleAround(env.getCentre(), xLen, yLen);
        } else {
            final double dist = xLen * (Math.random() - 0.5);
            double x = pts[i - 1].getX();
            double y = pts[i - 1].getY();
            if (xory) {
                x += dist;
            } else {
                y += dist;
            }
            // switch orientation
            xory = !xory;
            pt = new PointDoubleXY(x, y);
        }
        pts[i] = pt;
    }
    return geomFact.lineString(pts);
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

Example 89 with BoundingBox

use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.

the class CreateRandomShapeFunctions method haltonPointsWithBases.

public static Geometry haltonPointsWithBases(final Geometry g, final int nPts, final int basei, final int basej) {
    final BoundingBox env = FunctionsUtil.getEnvelopeOrDefault(g);
    final Point[] pts = new Point[nPts];
    final double baseX = env.getMinX();
    final double baseY = env.getMinY();
    int i = 0;
    while (i < nPts) {
        final double x = baseX + env.getWidth() * haltonOrdinate(i + 1, basei);
        final double y = baseY + env.getHeight() * haltonOrdinate(i + 1, basej);
        final Point p = new PointDoubleXY(x, y);
        if (!env.covers(p)) {
            continue;
        }
        pts[i++] = p;
    }
    return FunctionsUtil.getFactoryOrDefault(g).punctual(pts);
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY) Point(com.revolsys.geometry.model.Point)

Example 90 with BoundingBox

use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.

the class AffineTransformationFunctions method transformByBaseline.

public static Geometry transformByBaseline(final Geometry g, final Geometry destBaseline) {
    final BoundingBox env = g.getBoundingBox();
    final Point src0 = new PointDoubleXY(env.getMinX(), env.getMinY());
    final Point src1 = new PointDoubleXY(env.getMaxX(), env.getMinY());
    final Point[] destPts = CoordinatesListUtil.getPointArray(destBaseline);
    final Point dest0 = destPts[0];
    final Point dest1 = destPts[1];
    final AffineTransformation trans = AffineTransformationFactory.newFromBaseLines(src0, src1, dest0, dest1);
    return trans.transform(g);
}
Also used : BoundingBox(com.revolsys.geometry.model.BoundingBox) AffineTransformation(com.revolsys.geometry.model.util.AffineTransformation) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Aggregations

BoundingBox (com.revolsys.geometry.model.BoundingBox)307 Point (com.revolsys.geometry.model.Point)83 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)76 ArrayList (java.util.ArrayList)45 Geometry (com.revolsys.geometry.model.Geometry)41 LineString (com.revolsys.geometry.model.LineString)26 List (java.util.List)26 BoundingBoxDoubleXY (com.revolsys.geometry.model.impl.BoundingBoxDoubleXY)19 Polygon (com.revolsys.geometry.model.Polygon)14 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)14 Project (com.revolsys.swing.map.layer.Project)14 CreateListVisitor (com.revolsys.visitor.CreateListVisitor)12 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)11 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)11 Edge (com.revolsys.geometry.graph.Edge)10 HashMap (java.util.HashMap)10 Record (com.revolsys.record.Record)9 Graphics2D (java.awt.Graphics2D)9 MapEx (com.revolsys.collection.map.MapEx)8 LinearRing (com.revolsys.geometry.model.LinearRing)8