public void mouseMoved(MouseEvent e) { if (geoDisplayPopup != null) { geoDisplayPopup.hide(); } String pointMessage = ""; x = e.getX(); y = e.getY(); double minDist = -1; if (geoPoints == null || geoPoints.size() == 0) { return; } for (GeoPoint p : geoPoints) { double dist = p.distance(x, y); if (minDist > dist || minDist < 0) { pointMessage = p.getMessage(); minDist = dist; } } if (minDist > 2.5) { return; } geoPanel = GeoPolygonPanel.this; message.setText(pointMessage); PopupFactory factory = PopupFactory.getSharedInstance(); geoDisplayPopup = factory.getPopup( owner, message, (int) geoPanel.getLocationOnScreen().getX() + x, (int) geoPanel.getLocationOnScreen().getY() + y - 15); geoDisplayPopup.show(); }
/** ** Main entery point for debugging/testing */ public static void main(String argv[]) { RTConfig.setCommandLineArgs(argv); Print.setAllOutputToStdout(true); Print.setEncoding(ENCODING_UTF8); String accountID = RTConfig.getString(ARG_ACCOUNT, "demo"); GoogleGeocodeV2 gn = new GoogleGeocodeV2("google", null, null); /* reverse geocode */ if (RTConfig.hasProperty(ARG_REVGEOCODE)) { GeoPoint gp = new GeoPoint(RTConfig.getString(ARG_REVGEOCODE, null)); if (!gp.isValid()) { Print.logInfo("Invalid GeoPoint specified"); System.exit(1); } Print.logInfo("Reverse-Geocoding GeoPoint: " + gp); Print.sysPrintln( "RevGeocode = " + gn.getReverseGeocode(gp, null /*localeStr*/, false /*cache*/)); // Note: Even though the values are printed in UTF-8 character encoding, the // characters may not appear to be property displayed if the console display // does not support UTF-8. System.exit(0); } /* no options */ Print.sysPrintln("No options specified"); System.exit(1); }
/** Ensure that the pointList holds n points. */ private void updatePointsArray(int n) { GeoPoint[] oldPoints = points; int oldPointsLength = oldPoints == null ? 0 : oldPoints.length; // System.out.println("update points: " + n + " old length: " + oldPointsLength); // new points points = new GeoPoint[n]; // reuse old points for (int i = 0; i < oldPointsLength; i++) { if (i < points.length) { // reuse old point points[i] = oldPoints[i]; } else { removePoint(oldPoints[i]); } } // create new points if needed for (int i = oldPointsLength; i < points.length; i++) { GeoPoint newPoint = new GeoPoint(cons); newPoint.setCoords(0, 0, 1); // set defined newPoint.setParentAlgorithm(this); newPoint.setEuclidianVisible(true); newPoint.setAuxiliaryObject(true); points[i] = newPoint; } }
@Override public boolean isWithin(final double x, final double y, final double z) { for (final GeoPoint p : surfacePoints) { if (p.isIdentical(x, y, z)) return true; } return false; }
private String getAddressReverseGeocodeURL(GeoPoint gp) { // - // http://nominatim.openstreetmap.org/reverse?format=xml&addressdetails=1&zoom=18&lat=46.17330&lon=21.29370 StringBuffer sb = new StringBuffer(); RTProperties rtp = this.getProperties(); String url = rtp.getString(PROP_reverseURL, null); if (!StringTools.isBlank(url)) { sb.append(url); } else { String host = rtp.getString(PROP_hostName, HOST_PRIMARY); sb.append("http://"); sb.append(host); if (host.indexOf("mapquest") >= 0) { sb.append("/nominatim/v1/reverse?"); } else { sb.append("/reverse?"); } } sb.append("format=xml&"); sb.append("limit=1&"); // sb.append("osm_type=W&"); sb.append("addressdetails=").append(rtp.getString(PROP_addressdetails, "1")).append("&"); // 0,1 sb.append("zoom=").append(rtp.getString(PROP_zoom, "18")).append("&"); // 0..18 sb.append("email=").append(this.getEmail()).append("&"); // required, per usage policy sb.append("lat=").append(gp.getLatitudeString(GeoPoint.SFORMAT_DEC_5, null)).append("&"); sb.append("lon=").append(gp.getLongitudeString(GeoPoint.SFORMAT_DEC_5, null)); return sb.toString(); }
AlgoTangentCurve(Construction cons, String label, GeoPoint P, GeoCurveCartesian f) { super(cons); this.P = P; this.f = f; tangent = new GeoLine(cons); // check if P is defined as a point of the curve's graph pointOnCurve = false; if (P.getParentAlgorithm() instanceof AlgoPointOnPath) { AlgoPointOnPath algo = (AlgoPointOnPath) P.getParentAlgorithm(); pointOnCurve = algo.getPath() == f; } if (pointOnCurve) T = P; else T = new GeoPoint(cons); tangent.setStartPoint(T); // First derivative of curve f AlgoDerivative algo = new AlgoDerivative(cons, f); this.df = (GeoCurveCartesian) algo.getDerivative(); cons.removeFromConstructionList(algo); setInputOutput(); // for AlgoElement compute(); tangent.setLabel(label); }
public final String toString() { // Michael Borcherds 2008-03-30 // simplified to allow better Chinese translation if (poly != null) return app.getPlain("SegmentABofC", P.getLabel(), Q.getLabel(), poly.getNameDescription()); else return app.getPlain("SegmentAB", P.getLabel(), Q.getLabel()); }
private void removePoint(GeoPoint oldPoint) { // remove dependent algorithms (e.g. segments) from update sets of // objects further up (e.g. polygon) the tree ArrayList algoList = oldPoint.getAlgorithmList(); for (int k = 0; k < algoList.size(); k++) { AlgoElement algo = (AlgoElement) algoList.get(k); for (int j = 0; j < input.length; j++) input[j].removeFromUpdateSets(algo); } // remove old point oldPoint.setParentAlgorithm(null); // remove dependent segment algorithm that are part of this polygon // to make sure we don't remove the polygon as well for (int k = 0; k < algoList.size(); k++) { AlgoElement algo = (AlgoElement) algoList.get(k); // make sure we don't remove the polygon as well if (algo instanceof AlgoJoinPointsSegment && ((AlgoJoinPointsSegment) algo).getPoly() == poly) { } else { algo.remove(); } } algoList.clear(); // remove point oldPoint.doRemove(); }
public void stationDetailDialog(String nom, int index) { AlertDialog.Builder ad = new AlertDialog.Builder(this); ad.setTitle(nom); ad.setMessage(gpStation.getLatitudeE6() / 1E6 + " - " + gpStation.getLongitudeE6() / 1E6); ad.setNeutralButton( android.R.string.ok, new android.content.DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { mController.animateTo(gpStation); } }); ad.setPositiveButton( "Go there", new android.content.DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int arg1) { new Thread( new Runnable() { public void run() { goThere(); } }) .start(); } }); ad.show(); }
@Override public int hashCode() { int result = super.hashCode(); for (final GeoPoint p : surfacePoints) { result = 31 * result + p.hashCode(); } return result; }
@Override public Point toPixels(GeoPoint in, Point out) { double[] coords = new double[] {in.getLatitudeE6() / 1E6, in.getLongitudeE6() / 1E6}; int[] pixels = TileFactory.LatLngToPixel(coords, mView.getZoomLevel()); Point center = mView.getController().getCenter(); out.x = pixels[0] - center.x + mView.getWidth() / 2; out.y = pixels[1] - center.y + mView.getHeight() / 2; return out; }
public void setGeoPoint(GeoPoint gp) { if ((gp == null) || !gp.isValid()) { this.setLatitude(0.0); this.setLongitude(0.0); } else { this.setLatitude(gp.getLatitude()); this.setLongitude(gp.getLongitude()); } }
public void pathChanged(GeoPoint P) { PathParameter pp = P.getPathParameter(); if (pp.t < 0.0) { pp.t = 0; } // calc point for given parameter P.x = startPoint.inhomX + pp.t * y; P.y = startPoint.inhomY - pp.t * x; P.z = 1.0; }
/** * @requires name != null && p1 != null && p2 != null * @effects constructs a new GeoSegment with the specified name and endpoints */ public GeoSegment(String name, GeoPoint p1, GeoPoint p2) { if (name == null || p1 == null || p2 == null) { throw new IllegalArgumentException("Input must not be null"); } this.name = name; this.p1 = p1; this.p2 = p2; length = p1.distanceTo(p2); heading = p1.headingTo(p2); hash = (p1.hashCode() * 73 + p2.hashCode() * 137) % 7134653 * (name.hashCode() + 1) + 1; checkRep(); }
/* * Path interface */ public void pointChanged(GeoPoint P) { super.pointChanged(P); // ensure that the point doesn't get outside the ray // i.e. ensure 0 <= t <= 1 PathParameter pp = P.getPathParameter(); if (pp.t < 0.0) { P.x = startPoint.x; P.y = startPoint.y; P.z = startPoint.z; pp.t = 0.0; } }
@Override public int hashCode() { int result = createdAt != null ? createdAt.hashCode() : 0; result = 31 * result + (int) (id ^ (id >>> 32)); result = 31 * result + (text != null ? text.hashCode() : 0); result = 31 * result + (source != null ? source.hashCode() : 0); result = 31 * result + (truncated ? 1 : 0); result = 31 * result + (entities != null ? entities.hashCode() : 0); result = 31 * result + (extendedEntities != null ? extendedEntities.hashCode() : 0); result = 31 * result + (int) (inReplyToStatusId ^ (inReplyToStatusId >>> 32)); result = 31 * result + (int) (inReplyToUserId ^ (inReplyToUserId >>> 32)); result = 31 * result + (inReplyToScreenName != null ? inReplyToScreenName.hashCode() : 0); result = 31 * result + (user != null ? user.hashCode() : 0); result = 31 * result + (geo != null ? geo.hashCode() : 0); result = 31 * result + (place != null ? place.hashCode() : 0); result = 31 * result + (currentUserRetweet != null ? currentUserRetweet.hashCode() : 0); result = 31 * result + (contributors != null ? Arrays.hashCode(contributors) : 0); result = 31 * result + (int) (retweetCount ^ (retweetCount >>> 32)); result = 31 * result + (int) (favoriteCount ^ (favoriteCount >>> 32)); result = 31 * result + (int) (replyCount ^ (replyCount >>> 32)); result = 31 * result + (favorited ? 1 : 0); result = 31 * result + (retweeted ? 1 : 0); result = 31 * result + (lang != null ? lang.hashCode() : 0); result = 31 * result + (int) (descendentReplyCount ^ (descendentReplyCount >>> 32)); result = 31 * result + (retweetedStatus != null ? retweetedStatus.hashCode() : 0); result = 31 * result + (quotedStatus != null ? quotedStatus.hashCode() : 0); result = 31 * result + (card != null ? card.hashCode() : 0); result = 31 * result + (possiblySensitive ? 1 : 0); return result; }
protected final void compute() { geoOut.set(geoIn); if (mirror == mirrorLine) out.mirror(mirrorLine); else if (mirror == mirrorPoint) out.mirror(mirrorPoint); else ((GeoPoint) geoOut).mirror(mirrorConic); // Michael Borcherds 2008-02-10 }
public static BoundingBoxE6 fromGeoPoints(final ArrayList<? extends GeoPoint> partialPolyLine) { int minLat = Integer.MAX_VALUE; int minLon = Integer.MAX_VALUE; int maxLat = Integer.MIN_VALUE; int maxLon = Integer.MIN_VALUE; for (GeoPoint gp : partialPolyLine) { final int latitudeE6 = gp.getLatitudeE6(); final int longitudeE6 = gp.getLongitudeE6(); minLat = Math.min(minLat, latitudeE6); minLon = Math.min(minLon, longitudeE6); maxLat = Math.max(maxLat, latitudeE6); maxLon = Math.max(maxLon, longitudeE6); } return new BoundingBoxE6(minLat, minLon, maxLat, maxLon); }
public void goThere() { gpMyLocation = myLocationOverlay.getMyLocation(); if (gpMyLocation != null) { final double lat1 = gpStation.getLatitudeE6(); final double lat2 = gpMyLocation.getLatitudeE6(); final double lon1 = gpStation.getLongitudeE6(); final double lon2 = gpMyLocation.getLongitudeE6(); final GeoPoint gpMiddle = new GeoPoint((int) ((lat1 + lat2) / 2.0), (int) ((lon1 + lon2) / 2.0)); final Document doc = UtilsWeb.getKml(gpMyLocation, gpStation); this.runOnUiThread( new Thread( new Runnable() { public void run() { DrawPath(gpMyLocation, gpStation, Color.BLUE, mMap, doc); mController.setCenter(gpMiddle); final double spanLat; final double spanLon; if (lat1 > lat2) spanLat = (lat1 - lat2); else spanLat = (lat2 - lat1); if (lon1 > lon2) spanLon = (lon1 - lon2); else spanLon = (lon2 - lon1); mController.zoomToSpan((int) spanLat, (int) spanLon); mMap.invalidate(); } })); } else this.runOnUiThread( new Thread( new Runnable() { public void run() { Toast.makeText( MapStationActivity.this, "Waiting GPS fix\nActivate network localisation in settings or enable you GPS.", Toast.LENGTH_LONG) .show(); } })); }
// Helper function for testAddSegment. Checks the that the length and endpoint are correct. protected void checkAdd(GeoFeature gf, double length, GeoPoint end) { assertEquals( "Length should be " + length + " but it was " + gf.getLength(), length, gf.getLength(), TOLERANCE); assertTrue("The endpoint was not set correctly", end.equals(gf.getEnd())); }
private GeoSegment getQQLineSegment() { SummaryStatistics stats = new SummaryStatistics(); for (int i = 0; i < sortedData.length; i++) { stats.addValue(sortedData[i]); } double sd = stats.getStandardDeviation(); double mean = stats.getMean(); double min = stats.getMin(); double max = stats.getMax(); // qq line: y = (1/sd)x - mean/sd GeoPoint startPoint = new GeoPoint(cons); startPoint.setCoords(min, (min / sd) - mean / sd, 1.0); GeoPoint endPoint = new GeoPoint(cons); endPoint.setCoords(max, (max / sd) - mean / sd, 1.0); GeoSegment seg = new GeoSegment(cons, startPoint, endPoint); seg.calcLength(); return seg; }
protected final void compute() { if (!(f.isDefined() && P.isDefined())) { tangent.setUndefined(); return; } // first derivative if (df == null || !df.isDefined()) { tangent.setUndefined(); return; } // calc the tangent; double feval[] = new double[2]; double dfeval[] = new double[2]; double tvalue = f.getClosestParameter(P, f.getMinParameter()); f.evaluateCurve(tvalue, feval); df.evaluateCurve(tvalue, dfeval); tangent.setCoords(-dfeval[1], dfeval[0], feval[0] * dfeval[1] - dfeval[0] * feval[1]); if (!pointOnCurve) T.setCoords(feval[0], feval[1], 1.0); }
/** ** Main entery point for debugging/testing */ public static void main(String argv[]) { RTConfig.setCommandLineArgs(argv); Print.setAllOutputToStdout(true); Print.setEncoding(ENCODING_UTF8); /* host */ String host = RTConfig.getString("host", null); if (!StringTools.isBlank(host)) { HOST_PRIMARY = host; } /* GeoPoint */ GeoPoint gp = new GeoPoint(RTConfig.getString("gp", null)); if (!gp.isValid()) { Print.logInfo("Invalid GeoPoint specified"); System.exit(1); } Print.logInfo("Reverse-Geocoding GeoPoint: " + gp); /* Reverse Geocoding */ Nominatim gn = new Nominatim("nominatim", null, RTConfig.getCommandLineProperties()); Print.sysPrintln("RevGeocode = " + gn.getReverseGeocode(gp, null /*localeStr*/)); }
// calc axes protected final void compute() { // only parabola has directrix if (c.type == GeoConic.CONIC_PARABOLA) { // directrix has direction of second eigenvector // through point (b - p/2* eigenvec1) directrix.x = -eigenvec[1].y; directrix.y = eigenvec[1].x; double px = b.x - c.p / 2.0 * eigenvec[0].x; double py = b.y - c.p / 2.0 * eigenvec[0].y; directrix.z = -(directrix.x * px + directrix.y * py); P.setCoords(px, py, 1.0); } else directrix.setUndefined(); }
@Nonnull private GeoRectangle calcBoundingBox(final double c) { final double lowerLeftLat = center.getLat() - (Geo.metersToDegreesLat(radiusMeters) * c); final double lowerLeftLon = center.getLon() - (Geo.metersToDegreesLonAtLat(radiusMeters, center.getLat()) * c); final double upperRightLat = center.getLat() + (Geo.metersToDegreesLat(radiusMeters) * c); final double upperRightLon = center.getLon() + Geo.metersToDegreesLonAtLat(radiusMeters, center.getLat() * c); return new GeoRectangle( new GeoPoint(lowerLeftLat, lowerLeftLon), new GeoPoint(upperRightLat, upperRightLon)); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; StatusImpl status = (StatusImpl) o; if (id != status.id) return false; if (truncated != status.truncated) return false; if (inReplyToStatusId != status.inReplyToStatusId) return false; if (inReplyToUserId != status.inReplyToUserId) return false; if (retweetCount != status.retweetCount) return false; if (favoriteCount != status.favoriteCount) return false; if (replyCount != status.replyCount) return false; if (favorited != status.favorited) return false; if (retweeted != status.retweeted) return false; if (descendentReplyCount != status.descendentReplyCount) return false; if (possiblySensitive != status.possiblySensitive) return false; if (createdAt != null ? !createdAt.equals(status.createdAt) : status.createdAt != null) return false; if (text != null ? !text.equals(status.text) : status.text != null) return false; if (source != null ? !source.equals(status.source) : status.source != null) return false; if (entities != null ? !entities.equals(status.entities) : status.entities != null) return false; if (extendedEntities != null ? !extendedEntities.equals(status.extendedEntities) : status.extendedEntities != null) return false; if (inReplyToScreenName != null ? !inReplyToScreenName.equals(status.inReplyToScreenName) : status.inReplyToScreenName != null) return false; if (user != null ? !user.equals(status.user) : status.user != null) return false; if (geo != null ? !geo.equals(status.geo) : status.geo != null) return false; if (place != null ? !place.equals(status.place) : status.place != null) return false; if (currentUserRetweet != null ? !currentUserRetweet.equals(status.currentUserRetweet) : status.currentUserRetweet != null) return false; if (!Arrays.equals(contributors, status.contributors)) return false; if (lang != null ? !lang.equals(status.lang) : status.lang != null) return false; if (retweetedStatus != null ? !retweetedStatus.equals(status.retweetedStatus) : status.retweetedStatus != null) return false; if (quotedStatus != null ? !quotedStatus.equals(status.quotedStatus) : status.quotedStatus != null) return false; return !(card != null ? !card.equals(status.card) : status.card != null); }
@Override public boolean equals(@Nullable final Object obj) { boolean eq; if (this == obj) { eq = true; } else if ((obj != null) && (obj instanceof GeoCircle)) { final GeoCircle that = (GeoCircle) obj; eq = that.canEqual(this); // Top-level entity, so don't: super.equals(that) eq = eq && center.equals(that.center); eq = eq && radiusMeters.equals(that.radiusMeters); } else { eq = false; } return eq; }
/** * Create a circle geo area with 2 points: one is the center, the other a point on the circle. * * @param center Center. * @param point Point in circle. */ public GeoCircle(@Nonnull final GeoPoint center, @Nonnull final GeoPoint point) { super(); assert center != null; assert point != null; final double lat = Math.abs(center.getLat() - point.getLat()); final double lon = Math.abs(center.getLon() - point.getLon()); final double w = Geo.degreesLatToMeters(lat); final double h = Geo.degreesLonToMetersAtLat(lon, (center.getLat() + point.getLat()) / 2.0); final double radius = Math.sqrt((w * w) + (h * h)); this.center = center; this.radiusMeters = radius; }
public void setDefaultPointSize(int pointSize) { this.pointSize = Math.max(pointSize, 1); Iterator<GeoElement> it = defaultGeoElements.values().iterator(); while (it.hasNext()) { GeoElement geo = (GeoElement) it.next(); switch (geo.getGeoClassType()) { case GeoElement.GEO_CLASS_POINT: ((GeoPoint) geo).setPointSize(pointSize); break; case GeoElement.GEO_CLASS_LIST: ((GeoList) geo).setPointSize(pointSize); break; } } }
// Examples of distances and directions calculations public static void main(String[] args) { GeoPoint from = new GeoPoint(37.501282801564244, -122.48082160949707); // the boat GeoPoint to = new GeoPoint(37.49403906867881, -122.48468399047852); // HMB Entrance double dist = from.gcDistanceBetween(to); double heading = GreatCircle.calculateRhumLineRoute(from.degreesToRadians(), to.degreesToRadians()); dist = GreatCircle.calculateRhumLineDistance(from.degreesToRadians(), to.degreesToRadians()); System.out.println( "Loxo Dist:" + dist + " nm, " + (dist * 1852) + " m, heading " + Math.toDegrees(heading)); GreatCircle gc = new GreatCircle(); gc.setStartInDegrees(from); gc.setArrivalInDegrees(to); gc.calculateGreatCircle(10); dist = Math.toDegrees(gc.getDistance()) * 60; GreatCircleWayPoint first = gc.getRoute().get(1); heading = first.getZ().doubleValue(); System.out.println("Ortho Dist:" + dist + " nm, " + (dist * 1852) + " m, heading " + heading); }