Search in sources :

Example 61 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project hale by halestudio.

the class GridInterpolation method interpolateToLineString.

private LineString interpolateToLineString(Arc arc) {
    // arc segments to process
    Deque<ArcSegment> toProcess = new LinkedList<>();
    // start with full arc as segment
    toProcess.addFirst(new ArcGridSegment(arc, moveAllToGrid, gridSize));
    // list to collect atomic parts
    List<ArcSegment> parts = new LinkedList<>();
    // for every segment to process...
    while (!toProcess.isEmpty()) {
        ArcSegment segment = toProcess.pop();
        if (segment.isAtomic()) {
            // segment cannot be split
            // -> use for result
            parts.add(segment);
        } else {
            // otherwise split the segment in two and handle the parts
            toProcess.addFirst(segment.getSecondPart());
            toProcess.addFirst(segment.getFirstPart());
        }
    }
    // combine the segments to a single LineString
    List<Coordinate> coords = new ArrayList<>();
    for (int i = 0; i < parts.size(); i++) {
        ArcSegment part = parts.get(i);
        if (i == 0) {
            coords.add(part.getStartPoint());
        }
        Coordinate middle = part.getMiddlePoint();
        if (middle != null) {
            // should actually not occur
            InterpolationUtil.addIfDifferent(coords, middle);
        }
        InterpolationUtil.addIfDifferent(coords, part.getEndPoint());
    }
    return createLineString(coords.toArray(new Coordinate[coords.size()]), arc);
}
Also used : ArcSegment(eu.esdihumboldt.util.geometry.interpolation.ArcSegment) Coordinate(org.locationtech.jts.geom.Coordinate) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 62 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project hale by halestudio.

the class ArcByCenterPointImpl method toArcByPoints.

/**
 * {@inheritDoc}
 *
 * @author Arun Verma
 */
@Override
public ArcByPoints toArcByPoints() {
    if (pointsRepresentation == null) {
        Angle middleAngle = Angle.fromRadians(startAngle.getRadians() + 0.5 * getAngleBetween().getRadians());
        // getting start coordinate
        Coordinate startPoint = getPointAtAngle(startAngle);
        // getting end coordinate
        Coordinate endPoint = getPointAtAngle(endAngle);
        // will generate middle coordinate to use already coded arc
        // interpolation
        Coordinate middlePoint = getPointAtAngle(middleAngle);
        pointsRepresentation = new ArcByPointsImpl(startPoint, middlePoint, endPoint);
    }
    return pointsRepresentation;
}
Also used : Angle(eu.esdihumboldt.util.geometry.interpolation.model.Angle) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 63 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project sldeditor by robward-scisys.

the class ExampleLineImpl method getLine.

/*
     * (non-Javadoc)
     *
     * @see com.sldeditor.datasource.impl.ExampleLineInterface#getLine()
     */
@Override
public LineString getLine() {
    if (line == null) {
        // CHECKSTYLE:OFF
        double[][] rawLocations = new double[][] { { -123.167725, 48.502048 }, { -123.464355, 48.297812 }, { -124.738770, 48.603858 }, { -125.189209, 48.828566 }, { -125.112305, 48.951366 }, { -125.507812, 48.929718 }, { -125.870361, 49.145784 }, { -126.035156, 49.167339 }, { -126.112061, 49.253465 }, { -126.243896, 49.282140 }, { -126.287842, 49.360912 }, { -126.397705, 49.410973 }, { -126.573486, 49.375220 }, { -126.584473, 49.560852 }, { -126.815186, 49.610710 }, { -127.012939, 49.745781 }, { -126.947021, 49.788357 }, { -127.166748, 49.852152 }, { -127.518311, 50.113533 }, { -127.814941, 50.078295 }, { -127.957764, 50.120578 }, { -127.825928, 50.254230 }, { -128.012695, 50.331436 }, { -127.946777, 50.450509 }, { -128.122559, 50.457504 }, { -128.364258, 50.652943 }, { -128.342285, 50.792047 }, { -128.100586, 50.882243 }, { -127.858887, 50.944584 }, { -127.518311, 50.798991 }, { -127.221680, 50.639010 } };
        // CHECKSTYLE:ON
        GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
        Coordinate[] coords = new Coordinate[rawLocations.length];
        int index = 0;
        for (double[] point : rawLocations) {
            Coordinate c = new Coordinate(point[0], point[1]);
            coords[index] = c;
            index++;
        }
        line = geometryFactory.createLineString(coords);
    }
    return line;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 64 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project sldeditor by robward-scisys.

the class SLDEditorBufferedImageLegendGraphicBuilder method getSampleShape.

/**
 * Returns a <code>java.awt.Shape</code> appropiate to render a legend graphic given the
 * symbolizer type and the legend dimensions.
 *
 * @param symbolizer the Symbolizer for whose type a sample shape will be created
 * @param legendWidth the requested width, in output units, of the legend graphic
 * @param legendHeight the requested height, in output units, of the legend graphic
 * @return an appropiate Line2D, Rectangle2D or LiteShape(Point) for the symbolizer, wether it
 *     is a LineSymbolizer, a PolygonSymbolizer, or a Point ot Text Symbolizer
 * @throws IllegalArgumentException if an unknown symbolizer impl was passed in.
 */
private LiteShape2 getSampleShape(Symbolizer symbolizer, int legendWidth, int legendHeight) {
    LiteShape2 sampleShape;
    final float hpad = (legendWidth * LegendUtils.hpaddingFactor);
    final float vpad = (legendHeight * LegendUtils.vpaddingFactor);
    if (symbolizer instanceof LineSymbolizer) {
        Coordinate[] coords = { new Coordinate(hpad, legendHeight - vpad - 1), new Coordinate(legendWidth - hpad - 1, vpad) };
        LineString geom = geomFac.createLineString(coords);
        try {
            this.sampleLine = new LiteShape2(geom, null, null, false);
        } catch (Exception e) {
            this.sampleLine = null;
        }
        sampleShape = this.sampleLine;
    } else if ((symbolizer instanceof PolygonSymbolizer) || (symbolizer instanceof RasterSymbolizer)) {
        final float w = legendWidth - (2 * hpad) - 1;
        final float h = legendHeight - (2 * vpad) - 1;
        Coordinate[] coords = { new Coordinate(hpad, vpad), new Coordinate(hpad, vpad + h), new Coordinate(hpad + w, vpad + h), new Coordinate(hpad + w, vpad), new Coordinate(hpad, vpad) };
        LinearRing shell = geomFac.createLinearRing(coords);
        Polygon geom = geomFac.createPolygon(shell, null);
        try {
            this.sampleRect = new LiteShape2(geom, null, null, false);
        } catch (Exception e) {
            this.sampleRect = null;
        }
        sampleShape = this.sampleRect;
    } else if (symbolizer instanceof PointSymbolizer || symbolizer instanceof TextSymbolizer) {
        Coordinate coord = new Coordinate(legendWidth / 2, legendHeight / 2);
        try {
            this.samplePoint = new LiteShape2(geomFac.createPoint(coord), null, null, false);
        } catch (Exception e) {
            this.samplePoint = null;
        }
        sampleShape = this.samplePoint;
    } else {
        throw new IllegalArgumentException("Unknown symbolizer: " + symbolizer);
    }
    return sampleShape;
}
Also used : PointSymbolizer(org.geotools.styling.PointSymbolizer) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) ServiceException(org.geoserver.platform.ServiceException) SchemaException(org.geotools.feature.SchemaException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalAttributeException(org.opengis.feature.IllegalAttributeException) RasterSymbolizer(org.geotools.styling.RasterSymbolizer) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) TextSymbolizer(org.geotools.styling.TextSymbolizer) LineSymbolizer(org.geotools.styling.LineSymbolizer) LiteShape2(org.geotools.geometry.jts.LiteShape2) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon)

Example 65 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project ddf by codice.

the class JTSGeometryWrapperTest method testComputeJTSPeerWithGeometry.

@Test
public void testComputeJTSPeerWithGeometry() {
    GeometryFactory fac = new GeometryFactory();
    Geometry toWrap = fac.createPoint(new Coordinate(0, 0));
    toTest = new JTSGeometryWrapper(toWrap);
    assertEquals(toWrap, toTest.computeJTSPeer());
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Test(org.junit.Test)

Aggregations

Coordinate (org.locationtech.jts.geom.Coordinate)348 Test (org.junit.Test)145 Geometry (org.locationtech.jts.geom.Geometry)69 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)65 LineString (org.locationtech.jts.geom.LineString)57 Point (org.locationtech.jts.geom.Point)57 Polygon (org.locationtech.jts.geom.Polygon)47 LinearRing (org.locationtech.jts.geom.LinearRing)45 AbstractArcTest (eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest)37 ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)32 ArrayList (java.util.ArrayList)32 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)27 Test (org.junit.jupiter.api.Test)26 Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)20 MultiPoint (org.locationtech.jts.geom.MultiPoint)20 ArcByPointsImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl)17 ArcByCenterPointImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl)16 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)15 ArcByPoints (eu.esdihumboldt.util.geometry.interpolation.model.ArcByPoints)14 HashMap (java.util.HashMap)13