All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.common.geometry.GraphUtils Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package org.opentripplanner.common.geometry;

import java.util.Collection;
import org.locationtech.jts.algorithm.ConvexHull;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryCollection;
import org.locationtech.jts.geom.GeometryFactory;
import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.routing.graph.Vertex;
import org.opentripplanner.util.geometry.GeometryUtils;

public class GraphUtils {

  public static Geometry makeConvexHull(Graph graph) {
    return new ConvexHull(geometryCollectionFromVertices(graph)).getConvexHull();
  }

  private static GeometryCollection geometryCollectionFromVertices(Graph graph) {
    GeometryFactory gf = GeometryUtils.getGeometryFactory();
    Collection vertices = graph.getVertices();
    Geometry[] points = new Geometry[vertices.size()];
    int i = 0;
    for (Vertex v : vertices) {
      points[i++] = gf.createPoint(v.getCoordinate());
    }

    return new GeometryCollection(points, gf);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy