Search in sources :

Example 1 with LatLng

use of uk.me.jstott.jcoord.LatLng in project eol-globi-data by jhpoelen.

the class StudyImporterForSimons method getOrCreateSampleLocation.

private Location getOrCreateSampleLocation(LabeledCSVParser csvParser, Map<String, String> columnToNormalizedTermMapper) throws StudyImporterException {
    Double northing = parseAsDouble(csvParser, columnToNormalizedTermMapper.get(NORTHING));
    Double easting = parseAsDouble(csvParser, columnToNormalizedTermMapper.get(EASTING));
    Double latitude = null;
    Double longitude = null;
    if (easting != null && northing != null) {
        UTMRef utmRef = new UTMRef(easting, northing, 'R', 16);
        LatLng latLng = utmRef.toLatLng();
        latitude = latLng.getLat();
        longitude = latLng.getLng();
    }
    Double depth = parseAsDouble(csvParser, columnToNormalizedTermMapper.get(DEPTH));
    Double altitude = depth == null ? null : -depth;
    try {
        return nodeFactory.getOrCreateLocation(new LocationImpl(latitude, longitude, altitude, null));
    } catch (NodeFactoryException e) {
        throw new StudyImporterException("failed to create location", e);
    }
}
Also used : LocationImpl(org.eol.globi.domain.LocationImpl) UTMRef(uk.me.jstott.jcoord.UTMRef) LatLng(uk.me.jstott.jcoord.LatLng)

Example 2 with LatLng

use of uk.me.jstott.jcoord.LatLng in project satstat by mvglasow.

the class GpsSectionFragment method onLocationChanged.

/**
 * Called by {@link MainActivity} when a new location is found by the GPS location provider.
 * Stores the location and updates GPS display and map view.
 */
public void onLocationChanged(Location location) {
    if (location.hasAccuracy()) {
        Float getAcc = (float) 0.0;
        if (mainActivity.prefUnitType) {
            getAcc = (float) (location.getAccuracy());
        } else {
            getAcc = (float) (location.getAccuracy() * (float) 3.28084);
        }
        gpsAccuracy.setText(String.format("%.0f", getAcc));
        gpsAccuracyUnit.setText(getString(((mainActivity.prefUnitType) ? R.string.unit_meter : R.string.unit_feet)));
    } else {
        gpsAccuracy.setText(getString(R.string.value_none));
        gpsAccuracyUnit.setText("");
    }
    if (mainActivity.prefCoord == Const.KEY_PREF_COORD_DECIMAL) {
        gpsCoordLayout.setVisibility(View.GONE);
        gpsLatLayout.setVisibility(View.VISIBLE);
        gpsLonLayout.setVisibility(View.VISIBLE);
        gpsLat.setText(String.format("%.5f%s", location.getLatitude(), getString(R.string.unit_degree)));
        gpsLon.setText(String.format("%.5f%s", location.getLongitude(), getString(R.string.unit_degree)));
    } else if (mainActivity.prefCoord == Const.KEY_PREF_COORD_MIN) {
        gpsCoordLayout.setVisibility(View.GONE);
        gpsLatLayout.setVisibility(View.VISIBLE);
        gpsLonLayout.setVisibility(View.VISIBLE);
        double dec = location.getLatitude();
        double deg = (int) dec;
        double min = Math.abs(60.0 * (dec - deg));
        gpsLat.setText(String.format("%.0f%s %.3f'", deg, getString(R.string.unit_degree), min + /*rounding*/
        0.0005));
        dec = location.getLongitude();
        deg = (int) dec;
        min = Math.abs(60.0 * (dec - deg));
        gpsLon.setText(String.format("%.0f%s %.3f'", deg, getString(R.string.unit_degree), min + /*rounding*/
        0.0005));
    } else if (mainActivity.prefCoord == Const.KEY_PREF_COORD_SEC) {
        gpsCoordLayout.setVisibility(View.GONE);
        gpsLatLayout.setVisibility(View.VISIBLE);
        gpsLonLayout.setVisibility(View.VISIBLE);
        double dec = location.getLatitude();
        double deg = (int) dec;
        double tmp = 60.0 * (dec - deg);
        double min = (int) Math.abs(tmp);
        double sec = Math.abs(60.0 * (tmp - min));
        gpsLat.setText(String.format("%.0f%s %.0f' %.1f\"", deg, getString(R.string.unit_degree), min, sec + /*rounding*/
        0.05));
        dec = location.getLongitude();
        deg = (int) dec;
        tmp = 60.0 * (dec - deg);
        min = (int) Math.abs(tmp);
        sec = Math.abs(60.0 * (tmp - min));
        gpsLon.setText(String.format("%.0f%s %.0f' %.1f\"", deg, getString(R.string.unit_degree), min, sec + /*rounding*/
        0.05));
    } else if (mainActivity.prefCoord == Const.KEY_PREF_COORD_MGRS) {
        gpsLatLayout.setVisibility(View.GONE);
        gpsLonLayout.setVisibility(View.GONE);
        gpsCoordLayout.setVisibility(View.VISIBLE);
        gpsCoord.setText(new LatLng(location.getLatitude(), location.getLongitude()).toMGRSRef().toString(MGRSRef.PRECISION_1M));
    } else if (mainActivity.prefCoord == Const.KEY_PREF_COORD_UTM) {
        gpsLatLayout.setVisibility(View.GONE);
        gpsLonLayout.setVisibility(View.GONE);
        gpsCoordLayout.setVisibility(View.VISIBLE);
        gpsCoord.setText(UTM.lat_lon_to_utm(location.getLatitude(), location.getLongitude(), this.getContext()));
    }
    if (mainActivity.prefUtc)
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
    else
        df.setTimeZone(TimeZone.getDefault());
    gpsTime.setText(df.format(new Date(location.getTime())));
    if (location.hasAltitude()) {
        Float getAltitude = (float) 0.0;
        if (mainActivity.prefUnitType) {
            getAltitude = (float) (location.getAltitude());
        } else {
            getAltitude = (float) (location.getAltitude() * (float) 3.28084);
        }
        gpsAlt.setText(String.format("%.0f", getAltitude));
        gpsAltUnit.setText(getString(((mainActivity.prefUnitType) ? R.string.unit_meter : R.string.unit_feet)));
        orDeclination.setText(String.format("%.0f%s", new GeomagneticField((float) location.getLatitude(), (float) location.getLongitude(), (float) (getAltitude), location.getTime()).getDeclination(), getString(R.string.unit_degree)));
    } else {
        gpsAlt.setText(getString(R.string.value_none));
        gpsAltUnit.setText("");
        orDeclination.setText(getString(R.string.value_none));
    }
    if (location.hasBearing()) {
        gpsBearing.setText(String.format("%.0f%s", location.getBearing(), getString(R.string.unit_degree)));
        gpsOrientation.setText(MainActivity.formatOrientation(this.getContext(), location.getBearing()));
    } else {
        gpsBearing.setText(getString(R.string.value_none));
        gpsOrientation.setText(getString(R.string.value_none));
    }
    if (location.hasSpeed()) {
        Float getSpeed = (float) 0.0;
        if (mainActivity.prefKnots) {
            getSpeed = (float) (location.getSpeed() * 1.943844f);
        } else if (mainActivity.prefUnitType) {
            getSpeed = (float) (location.getSpeed() * 3.6f);
        } else {
            getSpeed = (float) (location.getSpeed() * 2.23694f);
        }
        gpsSpeed.setText(String.format("%.0f", getSpeed));
        gpsSpeedUnit.setText(getString(((mainActivity.prefKnots) ? R.string.unit_kn : (mainActivity.prefUnitType) ? R.string.unit_km_h : R.string.unit_mph)));
    } else {
        gpsSpeed.setText(getString(R.string.value_none));
        gpsSpeedUnit.setText("");
    }
// note: getting number of sats in fix by looking for "satellites"
// in location's extras doesn't seem to work, always returns 0 sats
}
Also used : GeomagneticField(android.hardware.GeomagneticField) LatLng(uk.me.jstott.jcoord.LatLng) Date(java.util.Date)

Example 3 with LatLng

use of uk.me.jstott.jcoord.LatLng in project satstat by mvglasow.

the class PasvLocListenerService method onLocationChanged.

@Override
public void onLocationChanged(Location location) {
    if (!location.getProvider().equals(LocationManager.GPS_PROVIDER))
        return;
    if (mNotifyFix && (mStatus != GPS_INACTIVE)) {
        mStatus = GPS_FIX;
        GpsStatus status = mLocationManager.getGpsStatus(null);
        int satsInView = 0;
        int satsUsed = 0;
        Iterable<GpsSatellite> sats = status.getSatellites();
        for (GpsSatellite sat : sats) {
            satsInView++;
            if (sat.usedInFix()) {
                satsUsed++;
            }
        }
        double lat = Math.abs(location.getLatitude());
        double lon = Math.abs(location.getLongitude());
        String ns = (location.getLatitude() > 0) ? getString(R.string.value_N) : (location.getLatitude() < 0) ? getString(R.string.value_S) : "";
        String ew = (location.getLongitude() > 0) ? getString(R.string.value_E) : (location.getLongitude() < 0) ? getString(R.string.value_W) : "";
        String title = "";
        if (prefCoord == Const.KEY_PREF_COORD_DECIMAL) {
            title = String.format("%.5f%s%s %.5f%s%s", lat, getString(R.string.unit_degree), ns, lon, getString(R.string.unit_degree), ew);
        } else if (prefCoord == Const.KEY_PREF_COORD_MIN) {
            double decY = lat;
            double degY = (int) decY;
            double minY = Math.abs(60.0 * (decY - degY));
            double decX = lon;
            double degX = (int) decX;
            double minX = Math.abs(60.0 * (decX - degX));
            title = String.format("%.0f%s %.3f' %s %.0f%s %.3f' %s", degY, getString(R.string.unit_degree), minY + /*rounding*/
            0.0005, ns, degX, getString(R.string.unit_degree), minX + /*rounding*/
            0.0005, ew);
        } else if (prefCoord == Const.KEY_PREF_COORD_SEC) {
            double decY = lat;
            double degY = (int) decY;
            double tmp = 60.0 * (decY - degY);
            double minY = (int) Math.abs(tmp);
            double secY = Math.abs(60.0 * (tmp - minY));
            double decX = lon;
            double degX = (int) decX;
            tmp = 60.0 * (decX - degX);
            double minX = (int) Math.abs(tmp);
            double secX = Math.abs(60.0 * (tmp - minX));
            title = String.format("%.0f%s %.0f' %.1f\" %s %.0f%s %.0f' %.1f\" %s", degY, getString(R.string.unit_degree), minY, secY + /*rounding*/
            0.05, ns, degX, getString(R.string.unit_degree), minX, secX + /*rounding*/
            0.05, ew);
        } else if (prefCoord == Const.KEY_PREF_COORD_MGRS) {
            title = new LatLng(location.getLatitude(), location.getLongitude()).toMGRSRef().toString(MGRSRef.PRECISION_1M);
        } else if (prefCoord == Const.KEY_PREF_COORD_UTM) {
            title = UTM.lat_lon_to_utm(location.getLatitude(), location.getLongitude(), this.getApplicationContext());
        }
        String text = "";
        if (location.hasAltitude()) {
            text = text + String.format("%.0f%s", (location.getAltitude() * (prefUnitType ? 1 : 3.28084)), getString(((prefUnitType) ? R.string.unit_meter : R.string.unit_feet)));
        }
        if (location.hasSpeed()) {
            text = text + (text.equals("") ? "" : ", ") + String.format("%.0f%s", (location.getSpeed() * (prefKnots ? 1.943844 : prefUnitType ? 3.6 : 2.23694)), getString(((prefKnots) ? R.string.unit_kn : (prefUnitType) ? R.string.unit_km_h : R.string.unit_mph)));
        }
        if (location.hasAccuracy()) {
            text = text + (text.equals("") ? "" : ", ") + String.format("\u03b5 = %.0f%s", (location.getAccuracy() * (prefUnitType ? 1 : 3.28084)), getString(((prefUnitType) ? R.string.unit_meter : R.string.unit_feet)));
        }
        text = text + (text.equals("") ? "" : ", ") + String.format("%d/%d", satsUsed, satsInView);
        text = text + (text.equals("") ? "" : ",\n") + String.format("TTFF %d s", status.getTimeToFirstFix() / 1000);
        mBuilder.setSmallIcon(R.drawable.ic_stat_notify_location);
        mBuilder.setContentTitle(title);
        mBuilder.setContentText(text);
        mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(text));
        startForeground(ONGOING_NOTIFICATION, mBuilder.build());
    } else {
        stopForeground(true);
    }
}
Also used : GpsStatus(android.location.GpsStatus) GpsSatellite(android.location.GpsSatellite) LatLng(uk.me.jstott.jcoord.LatLng)

Example 4 with LatLng

use of uk.me.jstott.jcoord.LatLng in project eol-globi-data by jhpoelen.

the class StudyImporterForSimonsTest method convertLatLongIntoUMT.

@Test
public void convertLatLongIntoUMT() {
    LatLng latLng = new LatLng(30.031055, -88.066406);
    UTMRef utmRef = latLng.toUTMRef();
    assertEquals(397176.66307791235, utmRef.getEasting());
    assertEquals(3322705.434795696, utmRef.getNorthing());
    assertEquals('R', utmRef.getLatZone());
    assertEquals(16, utmRef.getLngZone());
}
Also used : UTMRef(uk.me.jstott.jcoord.UTMRef) LatLng(uk.me.jstott.jcoord.LatLng) Test(org.junit.Test)

Aggregations

LatLng (uk.me.jstott.jcoord.LatLng)4 UTMRef (uk.me.jstott.jcoord.UTMRef)2 GeomagneticField (android.hardware.GeomagneticField)1 GpsSatellite (android.location.GpsSatellite)1 GpsStatus (android.location.GpsStatus)1 Date (java.util.Date)1 LocationImpl (org.eol.globi.domain.LocationImpl)1 Test (org.junit.Test)1