Refine search
void zoom(double f, Point p) { double ex = modelBounds.getWidth() * f; double ey = modelBounds.getHeight() * f; modelBounds.expandBy(ex / 2, ey / 2); if (p != null) { // Note: Graphics Y coordinates increase down the screen, hence the opposite signs. double tx = ex * -((p.getX() / this.width) - 0.5); double ty = ey * +((p.getY() / this.height) - 0.5); modelBounds.translate(tx, ty); } // update the display drawLevel = DRAW_PARTIAL; }
public void mouseDragged(MouseEvent e) { Point c = e.getPoint(); if (startDrag == null) { startDrag = c; dragX = c.x; dragY = c.y; } double dx = dragX - c.x; double dy = c.y - dragY; if (ctrlPressed || mouseButton == RIGHT) { zoom(dy * 0.01, startDrag); } else { double tx = modelBounds.getWidth() * dx / getWidth(); double ty = modelBounds.getHeight() * dy / getHeight(); modelBounds.translate(tx, ty); } dragX = c.x; dragY = c.y; drawLevel = DRAW_PARTIAL; }
void matchAspect() { /* Basic sinusoidal projection of lat/lon data to square pixels */ double yCenter = modelBounds.centre().y; float xScale = cos(radians((float) yCenter)); double newX = modelBounds.getHeight() * (1 / xScale) * ((float) this.getWidth() / this.getHeight()); modelBounds.expandBy((newX - modelBounds.getWidth()) / 2f, 0); }
public static PointSet regularGrid (Envelope envelope, double gridSizeMeters) { // non-ideal but for now make a grid in projected space // to see why this is wrong, look at a map of Iowa and note that it leans to the left // This is because they started surveying the township and range system (which is a grid) // from the east, and wound up further west in the north than the south, which led them // to resurvey the baseline every 24 miles, which explains why one is often driving // down a rural road in the midwestern US and comes to a point where the road makes two 90- // degree curves in quick succession to reach the new survey baseline. double gridSizeLat = SphericalDistanceLibrary.metersToDegrees(gridSizeMeters); double gridSizeLon = SphericalDistanceLibrary.metersToLonDegrees(gridSizeMeters, (envelope.getMaxY() + envelope.getMinY()) / 2); // how large will it be? int npts = (int) (envelope.getHeight() / gridSizeLat + 1) * (int) (envelope.getWidth() / gridSizeLon + 1); PointSet ret = new PointSet(npts); int idx = 0; for (double lon = envelope.getMinX(); lon < envelope.getMaxX(); lon += gridSizeLon) { for (double lat = envelope.getMinY(); lat < envelope.getMaxY(); lat += gridSizeLat) { PointFeature pf = new PointFeature("" + idx); pf.setLat(lat); pf.setLon(lon); ret.addFeature(pf, idx++); } } return ret; }
private static double OLDprecisionScaleFactor(Geometry g, double distance, int maxPrecisionDigits) { Envelope env = g.getEnvelopeInternal(); double envSize = Math.max(env.getHeight(), env.getWidth()); double expandByDistance = distance > 0.0 ? distance : 0.0; double bufEnvSize = envSize + 2 * expandByDistance; // the smallest power of 10 greater than the buffer envelope int bufEnvLog10 = (int) (Math.log(bufEnvSize) / Math.log(10) + 1.0); int minUnitLog10 = bufEnvLog10 - maxPrecisionDigits; // scale factor is inverse of min Unit size, so flip sign of exponent double scaleFactor = Math.pow(10.0, -minUnitLog10); return scaleFactor; }
private void computeBoundingBox() { Envelope vertexEnv = computeVertexEnvelope(initialVertices); Envelope segEnv = computeVertexEnvelope(segVertices); Envelope allPointsEnv = new Envelope(vertexEnv); allPointsEnv.expandToInclude(segEnv); double deltaX = allPointsEnv.getWidth() * 0.2; double deltaY = allPointsEnv.getHeight() * 0.2; double delta = Math.max(deltaX, deltaY); computeAreaEnv = new Envelope(allPointsEnv); computeAreaEnv.expandBy(delta); }