Java Code Examples for com.vividsolutions.jts.geom.Envelope#getMaxX()
The following examples show how to use
com.vividsolutions.jts.geom.Envelope#getMaxX() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OSMMap.java From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void drawDebugTapEnvelope(MapView pMapView, ILatLng pPosition, float zoom) { Envelope env = jtsModel.createTapEnvelope(pPosition, zoom); PathOverlay path; if (debugTapEnvelopePath == null) { path = new PathOverlay(); debugTapEnvelopePath = path; pMapView.getOverlays().add(path); } else { path = debugTapEnvelopePath; } Paint paint = path.getPaint(); paint.setStrokeWidth(0); // hairline mode paint.setARGB(200, 0, 255, 255); double maxX = env.getMaxX(); double maxY = env.getMaxY(); double minX = env.getMinX(); double minY = env.getMinY(); path.clearPath(); path.addPoint(minY, minX); path.addPoint(maxY, minX); path.addPoint(maxY, maxX); path.addPoint(minY, maxX); path.addPoint(minY, minX); }
Example 2
Source File: Quadtree.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
/** * Ensure that the envelope for the inserted item has non-zero extents. * Use the current minExtent to pad the envelope, if necessary */ public static Envelope ensureExtent(Envelope itemEnv, double minExtent) { //The names "ensureExtent" and "minExtent" are misleading -- sounds like //this method ensures that the extents are greater than minExtent. //Perhaps we should rename them to "ensurePositiveExtent" and "defaultExtent". //[Jon Aquino] double minx = itemEnv.getMinX(); double maxx = itemEnv.getMaxX(); double miny = itemEnv.getMinY(); double maxy = itemEnv.getMaxY(); // has a non-zero extent if (minx != maxx && miny != maxy) return itemEnv; // pad one or both extents if (minx == maxx) { minx = minx - minExtent / 2.0; maxx = minx + minExtent / 2.0; } if (miny == maxy) { miny = miny - minExtent / 2.0; maxy = miny + minExtent / 2.0; } return new Envelope(minx, maxx, miny, maxy); }
Example 3
Source File: Envelope3D.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Computes the distance between this and another <code>Envelope</code>. The distance between overlapping Envelopes * is 0. Otherwise, the distance is the Euclidean distance between the closest points. */ @Override public double distance(final Envelope env) { if (intersects(env)) { return 0; } double dx = 0.0; if (getMaxX() < env.getMinX()) { dx = env.getMinX() - getMaxX(); } else if (getMinX() > env.getMaxX()) { dx = getMinX() - env.getMaxX(); } double dy = 0.0; if (getMaxY() < env.getMinY()) { dy = env.getMinY() - getMaxY(); } else if (getMinY() > env.getMaxY()) { dy = getMinY() - env.getMaxY(); } double dz = 0.0; final double otherMinZ = getMinZOf(env); final double otherMaxZ = getMaxZOf(env); if (maxz < otherMinZ) { dz = otherMinZ - maxz; } else if (minz > otherMaxZ) { dz = minz - otherMaxZ; } // if either is zero, the envelopes overlap either vertically or // horizontally if (dx == 0.0 && dz == 0.0) { return dy; } if (dy == 0.0 && dz == 0.0) { return dx; } if (dx == 0.0 && dy == 0.0) { return dz; } return Math.sqrt(dx * dx + dy * dy + dz * dz); }
Example 4
Source File: SVGTestWriter.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public String write(Testable testable) { StringBuffer text = new StringBuffer(); Geometry ga = testable.getGeometry(0); Geometry gb = testable.getGeometry(1); Envelope env = new Envelope(); if (ga != null) env.expandToInclude(ga.getEnvelopeInternal()); if (gb != null) env.expandToInclude(gb.getEnvelopeInternal()); String viewBox = env.getMinX() + " " + env.getMinY() + " " + env.getMaxX() + " " + env.getMaxY(); text.append("<?xml version='1.0' standalone='no'?>\n"); text.append("<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>\n"); text.append("<svg width='400' height='400' viewBox='" + viewBox + "' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>\n"); String name = testable.getName() == null ? "" : testable.getName(); String description = testable.getDescription() == null ? "" : testable.getDescription(); //text.append(" \"" + name + "\",\n"); text.append(" <desc>" + description + "</desc>\n"); String a = writeGeometryStyled(ga, "#bbbbff", "#0000ff"); String b = writeGeometryStyled(gb, "#ffbbbb", "#ff0000"); text.append(a + "\n"); text.append("\n"); text.append(b + "\n"); text.append("</svg>\n"); return text.toString(); }
Example 5
Source File: KdTree.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private void queryNode(KdNode currentNode, Envelope queryEnv, boolean odd, KdNodeVisitor visitor) { if (currentNode == null) return; double min; double max; double discriminant; if (odd) { min = queryEnv.getMinX(); max = queryEnv.getMaxX(); discriminant = currentNode.getX(); } else { min = queryEnv.getMinY(); max = queryEnv.getMaxY(); discriminant = currentNode.getY(); } boolean searchLeft = min < discriminant; boolean searchRight = discriminant <= max; // search is computed via in-order traversal if (searchLeft) { queryNode(currentNode.getLeft(), queryEnv, !odd, visitor); } if (queryEnv.contains(currentNode.getCoordinate())) { visitor.visit(currentNode); } if (searchRight) { queryNode(currentNode.getRight(), queryEnv, !odd, visitor); } }
Example 6
Source File: NodeBase.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Gets the index of the subquad that wholly contains the given envelope. * If none does, returns -1. * * @return the index of the subquad that wholly contains the given envelope * or -1 if no subquad wholly contains the envelope */ public static int getSubnodeIndex(Envelope env, double centrex, double centrey) { int subnodeIndex = -1; if (env.getMinX() >= centrex) { if (env.getMinY() >= centrey) subnodeIndex = 3; if (env.getMaxY() <= centrey) subnodeIndex = 1; } if (env.getMaxX() <= centrex) { if (env.getMinY() >= centrey) subnodeIndex = 2; if (env.getMaxY() <= centrey) subnodeIndex = 0; } return subnodeIndex; }
Example 7
Source File: Node.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
public Node(Envelope env, int level) { //this.parent = parent; this.env = env; this.level = level; centrex = (env.getMinX() + env.getMaxX()) / 2; centrey = (env.getMinY() + env.getMaxY()) / 2; }
Example 8
Source File: CrsTransformImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Constructor. * * @param id id * @param source source CRS * @param target target CRS * @param mathTransform transformation * @param transformableEnvelope bounding bow of transformable area */ public CrsTransformImpl(String id, Crs source, Crs target, MathTransform mathTransform, Envelope transformableEnvelope) { this(id, source, target, mathTransform); if (null != transformableEnvelope) { this.transformableEnvelope = transformableEnvelope; this.transformableBbox = new Bbox(transformableEnvelope.getMinX(), transformableEnvelope.getMinY(), transformableEnvelope.getMaxX(), transformableEnvelope.getMaxY()); this.transformableGeometry = JTS.toGeometry(transformableEnvelope); } }
Example 9
Source File: FeatureStoreImpl.java From sensorhub with Mozilla Public License 2.0 | 4 votes |
public Iterator<AbstractFeature> getFeatures(IFeatureFilter filter) { // case of requesting by IDs Collection<String> foiIDs = filter.getFeatureIDs(); if (foiIDs != null && !foiIDs.isEmpty()) { final Set<String> ids = new LinkedHashSet<String>(); ids.addAll(filter.getFeatureIDs()); final Iterator<String> it = ids.iterator(); Iterator<AbstractFeature> it2 = new Iterator<AbstractFeature>() { AbstractFeature nextFeature; public boolean hasNext() { return (nextFeature != null); } public AbstractFeature next() { AbstractFeature currentFeature = nextFeature; nextFeature = null; while (nextFeature == null && it.hasNext()) nextFeature = idIndex.get(it.next()); return currentFeature; } public void remove() { } }; it2.next(); return it2; } // case of ROI if (filter.getRoi() != null) { // iterate through spatial index using bounding rectangle // TODO filter on exact polygon geometry using JTS Envelope env = filter.getRoi().getEnvelopeInternal(); double[] coords = new double[] {env.getMinX(), env.getMinY(), Double.NEGATIVE_INFINITY, env.getMaxX(), env.getMaxY(), Double.POSITIVE_INFINITY}; return geoIndex.iterator(new RectangleRn(coords)); } // TODO handle ROI + IDs? return idIndex.iterator(); }
Example 10
Source File: GeometryEditPanel.java From jts with GNU Lesser General Public License v2.1 | 4 votes |
private void drawMark(Graphics2D g) { if (markPoint == null) return; String markLabel = markPoint.x + ", " + markPoint.y; int strWidth = g.getFontMetrics().stringWidth(markLabel); double markSize = AppConstants.HIGHLIGHT_SIZE; Point2D highlightPointView = viewport.toView(markPoint); double markX = highlightPointView.getX(); double markY = highlightPointView.getY(); Ellipse2D.Double shape = new Ellipse2D.Double( markX - markSize / 2, markY - markSize / 2, markSize, markSize); AWTUtil.setStroke(g, 4); g.setColor(AppConstants.HIGHLIGHT_CLR); g.draw(shape); // draw label box Envelope viewEnv = viewport.getViewEnv(); int bottomOffset = 10; int boxHgt = 20; int boxPadX = 20; int boxWidth = strWidth + 2 * boxPadX; int arrowWidth = 10; int arrowOffset = 2; int labelOffsetY = 5; int bottom = (int) viewEnv.getMaxY() - bottomOffset; int centreX = (int) (viewEnv.getMinX() + viewEnv.getMaxX()) / 2; int boxMinX = centreX - boxWidth/2; int boxMaxX = centreX + boxWidth/2; int boxMinY = bottom - boxHgt; int boxMaxY = bottom; int[] xpts = new int[] { boxMinX, centreX - arrowWidth/2, (int) markX, centreX + arrowWidth/2, boxMaxX, boxMaxX, boxMinX }; int[] ypts = new int[] { boxMinY, boxMinY, (int) (markY + arrowOffset), boxMinY, boxMinY, boxMaxY, boxMaxY }; Polygon poly = new Polygon(xpts, ypts, xpts.length); g.setColor(AppConstants.HIGHLIGHT_FILL_CLR); g.fill(poly); AWTUtil.setStroke(g, 1); g.setColor(ColorUtil.opaque(AppConstants.HIGHLIGHT_CLR)); g.draw(poly); // draw mark point label g.setColor(Color.BLACK); g.drawString(markLabel, centreX - strWidth/2, boxMaxY - labelOffsetY); }
Example 11
Source File: GoogleLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
@Override public List<RasterTile> paint(CoordinateReferenceSystem targetCrs, Envelope bounds, double scale) throws GeomajasException { if (isTilesEnabled()) { try { CrsTransform layerToMap = geoService.getCrsTransform(crs, targetCrs); CrsTransform mapToLayer = geoService.getCrsTransform(targetCrs, crs); CrsTransform layerToWsg84 = geoService.getCrsTransform(crs, geoService.getCrs2(WSG_84)); // find the center of the map in map coordinates (positive y-axis) Coordinate boundsCenter = new Coordinate((bounds.getMinX() + bounds.getMaxX()) / 2, (bounds.getMinY() + bounds.getMaxY()) / 2); // Translate the map coordinates to layer coordinates, assumes equal x-y orientation Envelope layerBounds = geoService.transform(bounds, mapToLayer); // double layerScale = bounds.getWidth() * scale / layerBounds.getWidth(); layerBounds = clipBounds(layerBounds); if (layerBounds.isNull()) { return new ArrayList<RasterTile>(0); } // find zoomlevel // scale in pix/m should just above the given scale so we have at least one // screen pixel per google pixel ! (otherwise text unreadable) int zoomLevel = getBestZoomLevelForScaleInPixPerMeter(mapToLayer, boundsCenter, scale); log.debug("zoomLevel={}", zoomLevel); RasterGrid grid = getRasterGrid(layerBounds, tileSize * resolutions[zoomLevel], tileSize * resolutions[zoomLevel]); // We calculate the first tile's screen box with this assumption List<RasterTile> result = new ArrayList<RasterTile>(); for (int i = grid.getXmin(); i < grid.getXmax(); i++) { for (int j = grid.getYmin(); j < grid.getYmax(); j++) { double x = grid.getLowerLeft().x + (i - grid.getXmin()) * grid.getTileWidth(); double y = grid.getLowerLeft().y + (j - grid.getYmin()) * grid.getTileHeight(); // layer coordinates Bbox worldBox; Bbox layerBox; layerBox = new Bbox(x, y, grid.getTileWidth(), grid.getTileHeight()); // Transforming back to map coordinates will only result in a proper grid if the transformation // is nearly affine worldBox = geoService.transform(layerBox, layerToMap); // Rounding to avoid white space between raster tiles lower-left becomes upper-left in inverted // y-space Bbox screenBox = new Bbox(Math.round(scale * worldBox.getX()), -Math.round(scale * worldBox.getMaxY()), Math.round(scale * worldBox.getMaxX()) - Math.round(scale * worldBox.getX()), Math.round(scale * worldBox.getMaxY()) - Math.round(scale * worldBox.getY())); RasterTile image = new RasterTile(screenBox, getId() + "." + zoomLevel + "." + i + "," + j); String url = tileUrl; Coordinate center = new Coordinate((layerBox.getX() + layerBox.getMaxX()) / 2, (layerBox.getY() + layerBox.getMaxY()) / 2); Coordinate centerInWsg84 = JTS.transform(center, new Coordinate(), layerToWsg84); url = url.replace("${center}", Double.toString(centerInWsg84.y) + "," + Double.toString(centerInWsg84.x)); url = url.replace("${level}", Integer.toString(zoomLevel)); // When we are trying to display the tiles on a different coordinate system, use double scaled // images so that renderings are more smooth. This will return an image tileSize*2 x tileSize*2. // Disabled becausd the printing plugin can't handle this! // if (!layerToMap.isIdentity()) { // url += "&scale=2"; // } image.setCode(new TileCode(zoomLevel, i, j)); image.setUrl(url); log.debug("adding image {}", image); result.add(image); } } return result; } catch (TransformException e) { throw new GeomajasException(e, ExceptionCode.RENDER_TRANSFORMATION_FAILED); } } else { return Collections.emptyList(); } }