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;
}
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);
}
}
}
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;
}
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;
}
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)));
}
Aggregations