use of uk.m0nom.coords.GlobalCoords3D in project adif-processor by urbancamo.
the class KmlStationInfoPanel method getPanelContentForStation.
public String getPanelContentForStation(TransformControl control, Station station) {
String callSign = station.getCallsign();
final Context context = new Context();
QrzCallsign qrzInfo = station.getQrzInfo();
if (qrzInfo != null) {
setVariable(context, "call", station.getQrzInfo().getCall());
if (qrzInfo.getImage() != null) {
context.setVariable("image", station.getQrzInfo().getImage());
}
} else {
context.setVariable("call", callSign);
}
for (ActivityType activityType : ActivityType.values()) {
if (station.isDoing(activityType)) {
context.setVariable(activityType.getActivityName().toLowerCase(), station.getActivity(activityType));
}
}
if (qrzInfo != null) {
setVariable(context, "name", String.format("%s %s", StringUtils.defaultIfBlank(qrzInfo.getFname(), ""), StringUtils.defaultIfBlank(qrzInfo.getName(), "")));
setVariable(context, "country", qrzInfo.getCountry());
if (StringUtils.isNotEmpty(qrzInfo.getDxcc())) {
setVariable(context, "dxcc", qrzInfo.getDxcc());
int dxccCode = Integer.parseInt(qrzInfo.getDxcc());
DxccEntity dxcc = control.getDxccEntities().getEntity(dxccCode);
setVariable(context, "flag", dxcc.getFlag());
}
setVariable(context, "ituZone", qrzInfo.getItuzone());
setVariable(context, "cqZone", qrzInfo.getCqzone());
}
String grid = station.getGrid();
if (grid == null && qrzInfo != null) {
grid = qrzInfo.getGrid();
}
setVariable(context, "grid", grid);
GlobalCoords3D coordinates = station.getCoordinates();
if (coordinates == null && qrzInfo != null) {
coordinates = new GlobalCoords3D(qrzInfo.getLat(), qrzInfo.getLon());
}
if (coordinates != null) {
context.setVariable("lat", String.format("%.3f", coordinates.getLatitude()));
context.setVariable("long", String.format("%.3f", coordinates.getLongitude()));
LocationInfo info = coordinates.getLocationInfo();
context.setVariable("locationSource", info.getSource().getDescription());
context.setVariable("locationAccuracy", info.getAccuracy().getDescription());
}
String html = control.getTemplateEngine().process(new TemplateSpec("KmlStationInfo", TemplateMode.XML), context);
return html.replace("\n", "");
}
use of uk.m0nom.coords.GlobalCoords3D in project adif-processor by urbancamo.
the class ToLocationDeterminer method setTheirLocationFromActivity.
public void setTheirLocationFromActivity(Qso qso, Activity activity) {
// Do nothing here if the location is already overridden via a COORD comment in the ADIF record
if (qso.getTo().getCoordinates() != null && qso.getTo().getCoordinates().getLocationInfo().getSource() == LocationSource.OVERRIDE) {
return;
}
if (activity.hasCoords()) {
GlobalCoords3D coords = activity.getCoords();
String grid = MaidenheadLocatorConversion.coordsToLocator(coords);
qso.getTo().setCoordinates(coords);
qso.getRecord().setCoordinates(coords);
qso.getTo().setGrid(grid);
qso.getRecord().setGridsquare(grid);
} else if (activity.hasGrid()) {
String grid = activity.getGrid();
qso.getTo().setGrid(grid);
qso.getRecord().setGridsquare(grid);
}
}
use of uk.m0nom.coords.GlobalCoords3D in project adif-processor by urbancamo.
the class ToLocationDeterminer method setTheirLocationFromActivity.
public String setTheirLocationFromActivity(Qso qso, ActivityType activity, String reference, Map<String, String> unmapped) {
Activity info = activities.getDatabase(activity).get(reference);
Adif3Record rec = qso.getRecord();
if (info != null) {
if (info.hasCoords()) {
rec.setCoordinates(info.getCoords());
String grid = MaidenheadLocatorConversion.coordsToLocator(info.getCoords());
rec.setGridsquare(grid);
qso.getTo().setGrid(grid);
qso.getTo().setCoordinates(info.getCoords());
} else if (info.hasGrid()) {
GlobalCoords3D coords = MaidenheadLocatorConversion.locatorToCoords(LocationSource.ACTIVITY, info.getGrid());
rec.setCoordinates(coords);
rec.setGridsquare(info.getGrid());
qso.getTo().setGrid(info.getGrid());
qso.getTo().setCoordinates(coords);
}
// If the SIG isn't set, add it here
if (StringUtils.isEmpty(rec.getSig())) {
rec.setSig(activity.getActivityName());
rec.setSigInfo(reference);
}
// Add the activity to the unmapped list
unmapped.put(activity.getActivityName(), reference);
} else {
return String.format(BAD_ACTIVITY_REPORT, qso.getTo().getCallsign(), activity.getActivityName(), reference);
}
return null;
}
use of uk.m0nom.coords.GlobalCoords3D in project adif-processor by urbancamo.
the class SatellitePropagation method getCommunicationsLink.
@Override
public CommsLinkResult getCommunicationsLink(TransformControl control, GlobalCoords3D start, GlobalCoords3D end, Adif3Record rec) {
CommsLinkResult result = new CommsLinkResult();
if (rec.getSatName() != null) {
ApSatellite apSatellite = apSatellites.getSatellite(rec.getSatName());
if (apSatellite == null) {
result.setError(String.format("Unknown satellite: %s", rec.getSatName()));
return result;
}
apSatellite.updateAdifRec(control, rec);
GlobalCoords3D satelliteLocation = apSatellite.getPosition(start, rec.getQsoDate(), rec.getTimeOn());
result.setSatellitePosition(satelliteLocation);
GeodeticCalculator calculator = new GeodeticCalculator();
GeodeticCurve betweenStationsCurve = calculator.calculateGeodeticCurve(Ellipsoid.WGS84, start, end);
GeodeticCurve fromSatelliteCurve = calculator.calculateGeodeticCurve(Ellipsoid.WGS84, start, satelliteLocation);
GeodeticCurve toSatelliteCurve = calculator.calculateGeodeticCurve(Ellipsoid.WGS84, satelliteLocation, end);
double distance = betweenStationsCurve.getEllipsoidalDistance();
double distanceInKm = distance / 1000;
result.setDistanceInKm(distanceInKm);
List<GlobalCoords3D> path = result.getPath();
path.add(start);
path.add(satelliteLocation);
path.add(end);
result.setSkyDistance(satelliteLocation.getAltitude() * 2 / 1000);
result.setPropagation(Propagation.SATELLITE);
result.setAltitude(satelliteLocation.getAltitude());
// In order to complete this right angle calculation we need to shorten the geodesic distance
// so that it is a straight line through the earth between the two points, not across the surface
double fromDistance = GeodesicUtils.geodesicDistanceToStraightLineDistance(fromSatelliteCurve.getEllipsoidalDistance());
double fromAngle = Math.tanh(satelliteLocation.getAltitude() / fromDistance);
result.setFromAngle(90 - Math.toDegrees(fromAngle));
double toDistance = GeodesicUtils.geodesicDistanceToStraightLineDistance(toSatelliteCurve.getEllipsoidalDistance());
double toAngle = Math.tanh(satelliteLocation.getAltitude() / toDistance);
result.setToAngle(90 - Math.toDegrees(toAngle));
result.setBounces(1);
}
return result;
}
use of uk.m0nom.coords.GlobalCoords3D in project adif-processor by urbancamo.
the class NominatimGeocodingProvider method addressSearch.
private GlobalCoords3D addressSearch(String callsign, String searchString, int accuracy) throws IOException, InterruptedException {
long timeDiff = new Date().getTime() - lastTimestamp;
if (timeDiff < DELAY) {
long pause = DELAY - timeDiff;
// Ensure at least a second between calls to comply with fair usage policy
logger.info(String.format("Pausing for a %d ms to comply with NominatimGeocodingProvider fair usage policy", pause));
Thread.sleep(pause);
}
logger.info(String.format("Searching for a location for %s based on address search string: %s", callsign, searchString));
List<Address> addressMatches = new JsonNominatimClient(HttpClientBuilder.create().build(), "mark@wickensonline.co.uk").search(StringUtils.trim(searchString));
lastTimestamp = new Date().getTime();
if (addressMatches.size() > 0) {
Address match = addressMatches.get(0);
LocationAccuracy locationAccuracy = getLocationAccuracy(accuracy);
return new GlobalCoords3D(match.getLatitude(), match.getLongitude(), LocationSource.GEOCODING, locationAccuracy);
}
return null;
}
Aggregations