Search in sources :

Example 76 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project osm4j-geometry by topobyte.

the class CoordinateSequencesBuilder method addToResult.

private void addToResult(GeometryFactory factory, WayBuilderResult result, List<Coordinate> coords) {
    if (coords.size() == 1) {
        result.getCoordinates().add(coords.get(0));
    } else {
        CoordinateSequence cs = factory.getCoordinateSequenceFactory().create(coords.toArray(new Coordinate[0]));
        result.getLineStrings().add(factory.createLineString(cs));
    }
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Example 77 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project coastal-hazards by USGS-CIDA.

the class Bbox method envelopeToPolygon.

public static Polygon envelopeToPolygon(Envelope e) {
    GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING_SINGLE), SRID);
    Coordinate coordA = new Coordinate(e.getMinX(), e.getMinY());
    Coordinate coordB = new Coordinate(e.getMinX(), e.getMaxY());
    Coordinate coordC = new Coordinate(e.getMaxX(), e.getMaxY());
    Coordinate coordD = new Coordinate(e.getMaxX(), e.getMinY());
    Coordinate coordE = coordA;
    Polygon bboxPoly = factory.createPolygon(new Coordinate[] { coordA, coordB, coordC, coordD, coordE });
    return bboxPoly;
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) PrecisionModel(com.vividsolutions.jts.geom.PrecisionModel) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 78 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project coastal-hazards by USGS-CIDA.

the class CRSUtils method buildLineString.

private static LineString buildLineString(List<Coordinate> coords) {
    LineString line;
    try {
        CoordinateSequence seq = new CoordinateArraySequence(coords.toArray(new Coordinate[coords.size()]));
        line = new LineString(seq, geometryFactory);
    } catch (Exception e) {
        LOGGER.error("Failed to build line string from list of coordinates", e);
        line = null;
    }
    return line;
}
Also used : CoordinateSequence(com.vividsolutions.jts.geom.CoordinateSequence) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) Coordinate(com.vividsolutions.jts.geom.Coordinate) FactoryException(org.opengis.referencing.FactoryException) UnsupportedFeatureTypeException(gov.usgs.cida.coastalhazards.exceptions.UnsupportedFeatureTypeException) TransformException(org.opengis.referencing.operation.TransformException) AttributeNotANumberException(gov.usgs.cida.coastalhazards.exceptions.AttributeNotANumberException) CoordinateArraySequence(com.vividsolutions.jts.geom.impl.CoordinateArraySequence)

Example 79 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project onebusaway-application-modules by camsys.

the class EnterpriseFilteredGeocoderBase method filterResultsByWktPolygon.

protected List<EnterpriseGeocoderResult> filterResultsByWktPolygon(List<EnterpriseGeocoderResult> input) {
    if (_wktFilterPolygon == null) {
        return input;
    }
    List<EnterpriseGeocoderResult> output = new ArrayList<EnterpriseGeocoderResult>();
    for (EnterpriseGeocoderResult result : input) {
        Coordinate coordinate = new Coordinate(result.getLongitude(), result.getLatitude());
        Geometry point = _geometryFactory.createPoint(coordinate);
        if (_wktFilterPolygon.intersects(point)) {
            output.add(result);
        }
    }
    return output;
}
Also used : EnterpriseGeocoderResult(org.onebusaway.geocoder.enterprise.services.EnterpriseGeocoderResult) Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList)

Example 80 with Coordinate

use of com.vividsolutions.jts.geom.Coordinate in project onebusaway-application-modules by camsys.

the class GtfsStopsInPolygonMain method readPoints.

private static Geometry readPoints(String arg) throws NumberFormatException, IOException {
    BufferedReader reader = new BufferedReader(new FileReader(arg));
    String line = null;
    List<Coordinate> points = new ArrayList<Coordinate>();
    while ((line = reader.readLine()) != null) {
        String[] tokens = line.trim().split("[,\\s]+");
        double lat = Double.parseDouble(tokens[0]);
        double lon = Double.parseDouble(tokens[1]);
        points.add(new Coordinate(lat, lon));
    }
    points.add(points.get(0));
    LinearRing ring = _factory.createLinearRing(points.toArray(new Coordinate[points.size()]));
    return _factory.createPolygon(ring, new LinearRing[0]);
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) LinearRing(com.vividsolutions.jts.geom.LinearRing)

Aggregations

Coordinate (com.vividsolutions.jts.geom.Coordinate)336 LineString (com.vividsolutions.jts.geom.LineString)70 Geometry (com.vividsolutions.jts.geom.Geometry)67 ArrayList (java.util.ArrayList)65 Test (org.junit.Test)60 Point (com.vividsolutions.jts.geom.Point)52 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)48 Polygon (com.vividsolutions.jts.geom.Polygon)30 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)27 SimpleFeature (org.opengis.feature.simple.SimpleFeature)23 LinearRing (com.vividsolutions.jts.geom.LinearRing)22 Vertex (org.opentripplanner.routing.graph.Vertex)22 Envelope (com.vividsolutions.jts.geom.Envelope)21 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)20 Edge (org.opentripplanner.routing.graph.Edge)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 CoordinateSequence (com.vividsolutions.jts.geom.CoordinateSequence)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)13 File (java.io.File)11 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)11