Java Code Examples for com.nextgis.maplib.datasource.GeoPoint#setCoordinates()

The following examples show how to use com.nextgis.maplib.datasource.GeoPoint#setCoordinates() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportGPXTask.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void appendTrack(File temp, String name, StringBuilder sb, Formatter f, Cursor trackpoints) throws IOException {
    GeoPoint point = new GeoPoint();
    int latId = trackpoints.getColumnIndex(TrackLayer.FIELD_LAT);
    int lonId = trackpoints.getColumnIndex(TrackLayer.FIELD_LON);
    int timeId = trackpoints.getColumnIndex(TrackLayer.FIELD_TIMESTAMP);
    int eleId = trackpoints.getColumnIndex(TrackLayer.FIELD_ELE);
    int satId = trackpoints.getColumnIndex(TrackLayer.FIELD_SAT);
    int fixId = trackpoints.getColumnIndex(TrackLayer.FIELD_FIX);

    DecimalFormat df = new DecimalFormat("0", new DecimalFormatSymbols(Locale.ENGLISH));
    df.setMaximumFractionDigits(340); //340 = DecimalFormat.DOUBLE_FRACTION_DIGITS

    sb.setLength(0);
    sb.append(GPX_TAG_TRACK);

    if (name != null) {
        sb.append(GPX_TAG_NAME);
        sb.append(name);
        sb.append(GPX_TAG_NAME_CLOSE);
    }

    sb.append(GPX_TAG_TRACK_SEGMENT);
    FileUtil.writeToFile(temp, sb.toString(), true);

    do {
        sb.setLength(0);
        point.setCoordinates(trackpoints.getDouble(lonId), trackpoints.getDouble(latId));
        point.setCRS(CRS_WEB_MERCATOR);
        point.project(CRS_WGS84);
        String sLon = df.format(point.getX());
        String sLat = df.format(point.getY());
        f.format(GPX_TAG_TRACK_SEGMENT_POINT, sLat, sLon);
        f.format(GPX_TAG_TRACK_SEGMENT_POINT_TIME, getTimeStampAsString(trackpoints.getLong(timeId)));
        f.format(GPX_TAG_TRACK_SEGMENT_POINT_ELE, df.format(trackpoints.getDouble(eleId)));
        f.format(GPX_TAG_TRACK_SEGMENT_POINT_SAT, trackpoints.getString(satId));
        f.format(GPX_TAG_TRACK_SEGMENT_POINT_FIX, trackpoints.getString(fixId));
        sb.append(GPX_TAG_TRACK_SEGMENT_POINT_CLOSE);
        FileUtil.writeToFile(temp, sb.toString(), true);
    } while (trackpoints.moveToNext());

    sb.setLength(0);
    sb.append(GPX_TAG_TRACK_SEGMENT_CLOSE);
    sb.append(GPX_TAG_TRACK_CLOSE);
    FileUtil.writeToFile(temp, sb.toString(), true);
}
 
Example 2
Source File: MapContentProviderHelper.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
    super.onUpgrade(sqLiteDatabase, oldVersion, newVersion);

    Cursor data;
    boolean tableExists = false;

    try {
        data = sqLiteDatabase.query(TrackLayer.TABLE_TRACKS, null, null, null, null, null, null);
        tableExists = true;
        data.close();
    } catch (Exception ignored) { }

    if (oldVersion <= 2 && tableExists) {
        sqLiteDatabase.execSQL("alter table " + TrackLayer.TABLE_TRACKS + " add column " + TrackLayer.FIELD_COLOR + " integer;");

        GeoPoint point = new GeoPoint();
        ContentValues cv = new ContentValues();
        data = sqLiteDatabase.query(TrackLayer.TABLE_TRACKPOINTS,
                new String[]{TrackLayer.FIELD_TIMESTAMP, TrackLayer.FIELD_LON, TrackLayer.FIELD_LAT}, null, null, null, null, null);

        if (data != null) {
            if (data.moveToFirst()) {
                do {
                    point.setCoordinates(data.getDouble(1), data.getDouble(2));
                    point.setCRS(GeoConstants.CRS_WGS84);
                    point.project(GeoConstants.CRS_WEB_MERCATOR);
                    cv.clear();
                    cv.put(TrackLayer.FIELD_LON, point.getX());
                    cv.put(TrackLayer.FIELD_LAT, point.getY());
                    sqLiteDatabase.update(TrackLayer.TABLE_TRACKPOINTS, cv, TrackLayer.FIELD_TIMESTAMP + " = ?", new String[]{data.getLong(0) + ""});
                } while (data.moveToNext());
            }

            data.close();
        }
    }

    if (oldVersion <= 3 && tableExists) {
        sqLiteDatabase.execSQL("alter table " + TrackLayer.TABLE_TRACKPOINTS + " add column " + TrackLayer.FIELD_SENT + " integer not null default 1;");
        sqLiteDatabase.execSQL("alter table " + TrackLayer.TABLE_TRACKPOINTS + " add column " + TrackLayer.FIELD_ACCURACY + " real;");
        sqLiteDatabase.execSQL("alter table " + TrackLayer.TABLE_TRACKPOINTS + " add column " + TrackLayer.FIELD_SPEED + " real;");
    }
}