Search in sources :

Example 76 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.

the class OSMHistoryImport method parseBbox.

private Envelope parseBbox() {
    final String bbox = args.bbox;
    if (bbox != null) {
        String[] split = bbox.split(",");
        checkParameter(split.length == 4, String.format("Invalid bbox format: '%s'. Expected minx,miny,maxx,maxy", bbox));
        try {
            double x1 = Double.parseDouble(split[0]);
            double y1 = Double.parseDouble(split[1]);
            double x2 = Double.parseDouble(split[2]);
            double y2 = Double.parseDouble(split[3]);
            Envelope envelope = new Envelope(x1, x2, y1, y2);
            checkParameter(!envelope.isNull(), "Provided envelope is nil");
            return envelope;
        } catch (NumberFormatException e) {
            String message = String.format("One or more bbox coordinate can't be parsed to double: '%s'", bbox);
            throw new InvalidParameterException(message, e);
        }
    }
    return null;
}
Also used : InvalidParameterException(org.locationtech.geogig.cli.InvalidParameterException) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 77 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.

the class OSMHistoryImport method runInternal.

@Override
protected void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(args.numThreads > 0 && args.numThreads < 7, "numthreads must be between 1 and 6");
    ConsoleReader console = cli.getConsole();
    final String osmAPIUrl = resolveAPIURL();
    final long startIndex;
    final long endIndex = args.endIndex;
    if (args.resume) {
        GeoGIG geogig = cli.getGeogig();
        long lastChangeset = getCurrentBranchChangeset(geogig);
        startIndex = 1 + lastChangeset;
    } else {
        startIndex = args.startIndex;
    }
    console.println(String.format("Obtaining OSM changesets %,d to %,d from %s", startIndex, args.endIndex, osmAPIUrl));
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("osm-history-fetch-thread-%d").build();
    final ExecutorService executor = Executors.newFixedThreadPool(args.numThreads, threadFactory);
    final File targetDir = resolveTargetDir();
    console.println("Downloading to " + targetDir.getAbsolutePath());
    console.flush();
    HistoryDownloader downloader;
    downloader = new HistoryDownloader(osmAPIUrl, targetDir, startIndex, endIndex, executor);
    Envelope env = parseBbox();
    Predicate<Changeset> filter = parseFilter(env);
    downloader.setChangesetFilter(filter);
    try {
        importOsmHistory(cli, console, downloader, env);
    } finally {
        executor.shutdownNow();
        try {
            executor.awaitTermination(30, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            throw new CommandFailedException(e);
        }
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) HistoryDownloader(org.locationtech.geogig.osm.internal.history.HistoryDownloader) ConsoleReader(jline.console.ConsoleReader) Envelope(com.vividsolutions.jts.geom.Envelope) CommandFailedException(org.locationtech.geogig.cli.CommandFailedException) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) File(java.io.File) Changeset(org.locationtech.geogig.osm.internal.history.Changeset) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 78 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project sldeditor by robward-scisys.

the class MapRender method convertToWGS84.

/**
 * Convert referenced envelope to WGS 84.
 *
 * @param bounds the bounds
 * @return the referenced envelope
 */
private ReferencedEnvelope convertToWGS84(ReferencedEnvelope bounds) {
    if (bounds == null) {
        return null;
    }
    CoordinateReferenceSystem wgs84 = CoordManager.getInstance().getWGS84();
    if (wgs84.equals(bounds.getCoordinateReferenceSystem())) {
        return bounds;
    }
    if (bounds.getCoordinateReferenceSystem() == null) {
        return bounds;
    }
    MathTransform transform = null;
    try {
        transform = CRS.findMathTransform(bounds.getCoordinateReferenceSystem(), wgs84, true);
    } catch (FactoryException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    Envelope targetGeometry = null;
    try {
        targetGeometry = JTS.transform(bounds, transform);
    } catch (TransformException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    if (targetGeometry != null) {
        ReferencedEnvelope refEnv = new ReferencedEnvelope(targetGeometry.getMinY(), targetGeometry.getMaxY(), targetGeometry.getMinX(), targetGeometry.getMaxX(), wgs84);
        return refEnv;
    }
    return null;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) MathTransform(org.opengis.referencing.operation.MathTransform) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 79 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project activityinfo by bedatadriven.

the class BatchGeocoder method queryEntities.

private List<AdminEntity> queryEntities() {
    // to do the job efficiently on the set of points, we'll use a SweepLine algorithm.
    // but first we need to compute the bounds of the bounds so we know what to fetch
    Envelope pointsMbr = new Envelope();
    for (Point point : points) {
        pointsMbr.expandToInclude(point.getCoordinate());
    }
    // now query the x/y ranges of all admin entities that
    // might intersect with the ranges
    Criteria criteria = session.createCriteria(AdminEntity.class);
    criteria.add(SpatialRestrictions.intersects("geometry", gf.toGeometry(pointsMbr)));
    List<AdminEntity> entities = criteria.list();
    return entities;
}
Also used : AdminEntity(org.activityinfo.server.database.hibernate.entity.AdminEntity) Point(com.vividsolutions.jts.geom.Point) Criteria(org.hibernate.Criteria) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 80 with Envelope

use of com.vividsolutions.jts.geom.Envelope in project activityinfo by bedatadriven.

the class SimpleTableStorage method updateGeometry.

@Override
public void updateGeometry(ResourceId recordId, ResourceId fieldId, Geometry geometry) {
    // Only applies to admin table
    if (!mapping.getBaseTable().equals("adminentity")) {
        throw new UnsupportedOperationException();
    }
    Envelope envelope = geometry.getEnvelopeInternal();
    executor.update("UPDATE adminentity SET X1 = ?, Y1 = ?, X2 = ?, Y2 = ?, geometry = GeomFromWKB(?, 4326) " + "WHERE adminentityid = ?", Arrays.asList(envelope.getMinX(), envelope.getMinY(), envelope.getMaxX(), envelope.getMaxY(), toBinary(geometry), CuidAdapter.getLegacyIdFromCuid(recordId)));
}
Also used : Envelope(com.vividsolutions.jts.geom.Envelope)

Aggregations

Envelope (com.vividsolutions.jts.geom.Envelope)111 Coordinate (com.vividsolutions.jts.geom.Coordinate)21 Node (org.locationtech.geogig.api.Node)16 Geometry (com.vividsolutions.jts.geom.Geometry)13 ObjectId (org.locationtech.geogig.api.ObjectId)13 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)12 STRtree (com.vividsolutions.jts.index.strtree.STRtree)11 ArrayList (java.util.ArrayList)11 Vertex (org.opentripplanner.routing.graph.Vertex)11 Test (org.junit.Test)9 NodeRef (org.locationtech.geogig.api.NodeRef)9 Edge (org.opentripplanner.routing.graph.Edge)9 LineString (com.vividsolutions.jts.geom.LineString)8 RevTree (org.locationtech.geogig.api.RevTree)8 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)7 Map (java.util.Map)6 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)6 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)6 RevFeature (org.locationtech.geogig.api.RevFeature)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5