Search in sources :

Example 1 with GlobalCoords3D

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", "");
}
Also used : Context(org.thymeleaf.context.Context) DxccEntity(uk.m0nom.dxcc.DxccEntity) GlobalCoords3D(uk.m0nom.coords.GlobalCoords3D) QrzCallsign(uk.m0nom.qrz.QrzCallsign) ActivityType(uk.m0nom.activity.ActivityType) TemplateSpec(org.thymeleaf.TemplateSpec) LocationInfo(uk.m0nom.coords.LocationInfo)

Example 2 with GlobalCoords3D

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);
    }
}
Also used : GlobalCoords3D(uk.m0nom.coords.GlobalCoords3D)

Example 3 with GlobalCoords3D

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;
}
Also used : Adif3Record(org.marsik.ham.adif.Adif3Record) GlobalCoords3D(uk.m0nom.coords.GlobalCoords3D) Activity(uk.m0nom.activity.Activity)

Example 4 with GlobalCoords3D

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;
}
Also used : GlobalCoords3D(uk.m0nom.coords.GlobalCoords3D) GeodeticCurve(org.gavaghan.geodesy.GeodeticCurve) ApSatellite(uk.m0nom.satellite.ApSatellite) GeodeticCalculator(org.gavaghan.geodesy.GeodeticCalculator)

Example 5 with GlobalCoords3D

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;
}
Also used : GlobalCoords3D(uk.m0nom.coords.GlobalCoords3D) Address(fr.dudie.nominatim.model.Address) JsonNominatimClient(fr.dudie.nominatim.client.JsonNominatimClient) LocationAccuracy(uk.m0nom.coords.LocationAccuracy) Date(java.util.Date)

Aggregations

GlobalCoords3D (uk.m0nom.coords.GlobalCoords3D)22 Adif3Record (org.marsik.ham.adif.Adif3Record)5 Test (org.junit.Test)4 GeodeticCalculator (org.gavaghan.geodesy.GeodeticCalculator)3 GeodeticCurve (org.gavaghan.geodesy.GeodeticCurve)3 GlobalCoordinates (org.gavaghan.geodesy.GlobalCoordinates)3 QrzCallsign (uk.m0nom.qrz.QrzCallsign)3 File (java.io.File)2 Activity (uk.m0nom.activity.Activity)2 ActivityType (uk.m0nom.activity.ActivityType)2 Station (uk.m0nom.adif3.contacts.Station)2 CommsLinkResult (uk.m0nom.comms.CommsLinkResult)2 PropagationApex (uk.m0nom.comms.PropagationApex)2 ApSatellite (uk.m0nom.satellite.ApSatellite)2 GroundStationPosition (com.github.amsacode.predict4java.GroundStationPosition)1 SatPos (com.github.amsacode.predict4java.SatPos)1 Document (de.micromata.opengis.kml.v_2_2_0.Document)1 Folder (de.micromata.opengis.kml.v_2_2_0.Folder)1 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)1 JsonNominatimClient (fr.dudie.nominatim.client.JsonNominatimClient)1