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

The following examples show how to use com.nextgis.maplib.datasource.GeoPoint#setCRS() . 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: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected boolean movePointToLocation() {
    Activity parent = (Activity) mContext;
    Location location = mGpsEventSource.getLastKnownLocation();

    if (null != location) {
        //change to screen coordinates
        GeoPoint pt = new GeoPoint(location.getLongitude(), location.getLatitude());
        pt.setCRS(GeoConstants.CRS_WGS84);
        pt.project(GeoConstants.CRS_WEB_MERCATOR);
        GeoPoint screenPt = mMap.mapToScreen(pt);
        return moveSelectedPoint((float) screenPt.getX(), (float) screenPt.getY());
    } else
        Toast.makeText(parent, R.string.error_no_location, Toast.LENGTH_SHORT).show();

    return false;
}
 
Example 2
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onRestoreState(Bundle bundle) {
    if (null != bundle && mType == bundle.getInt(BUNDLE_KEY_TYPE, 0)) {
        mMode = bundle.getInt(BUNDLE_KEY_MODE);
        mHasEdits = bundle.getBoolean(BUNDLE_KEY_HAS_EDITS);

        if (bundle.containsKey(BUNDLE_KEY_OVERLAY_POINT)) {
            GeoPoint point = (GeoPoint) bundle.getSerializable(BUNDLE_KEY_OVERLAY_POINT);

            if (point != null) {
                point.setCRS(GeoConstants.CRS_WGS84);
                mOverlayPoint.setCoordinates(point);
                mOverlayPoint.setVisible(true);
            }
        }
    }

    super.onRestoreState(bundle);
}
 
Example 3
Source File: CurrentLocationOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void autopanTo(Location autopanLocation, Location location) {
    GeoPoint oldLocation = new GeoPoint(autopanLocation.getLongitude(), autopanLocation.getLatitude());
    GeoPoint newLocation = new GeoPoint(location.getLongitude(), location.getLatitude());
    oldLocation.setCRS(GeoConstants.CRS_WGS84);
    oldLocation.project(GeoConstants.CRS_WEB_MERCATOR);
    newLocation.setCRS(GeoConstants.CRS_WGS84);
    newLocation.project(GeoConstants.CRS_WEB_MERCATOR);

    double dx = oldLocation.getX() - newLocation.getX();
    double dy = oldLocation.getY() - newLocation.getY();
    GeoPoint newCenter = mMapViewOverlays.getMapCenter();
    newCenter.setX(newCenter.getX() - dx);
    newCenter.setY(newCenter.getY() - dy);

    mMapViewOverlays.panTo(newCenter);
}
 
Example 4
Source File: OverlayItem.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GeoPoint getCoordinates(int CRS)
{
    if (CRS == GeoConstants.CRS_WGS84) {
        GeoPoint wgs = new GeoPoint(mCoordinates.getX(), mCoordinates.getY());
        wgs.setCRS(GeoConstants.CRS_WEB_MERCATOR);
        wgs.project(GeoConstants.CRS_WGS84);
        return wgs;
    }

    return mCoordinates;
}
 
Example 5
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setOverlayPoint(MotionEvent event) {
    GeoPoint mapPoint = mMap.screenToMap(new GeoPoint(event.getX(), event.getY()));
    mapPoint.setCRS(GeoConstants.CRS_WEB_MERCATOR);
    mapPoint.project(GeoConstants.CRS_WGS84);
    mOverlayPoint.setCoordinates(mapPoint);
    mOverlayPoint.setVisible(true);
}
 
Example 6
Source File: GISDisplay.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GeoPoint[] screenToMap(final float[] points)
{
    mInvertTransformMatrix.mapPoints(points);
    GeoPoint[] ret = new GeoPoint[points.length / 2];
    int count = 0;
    for (int i = 0; i < points.length - 1; i += 2) {
        GeoPoint point = new GeoPoint(points[i], points[i + 1]);
        point.setCRS(CRS_WEB_MERCATOR);
        ret[count++] = point;
    }
    return ret;
}
 
Example 7
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
protected String getRulerText() {
    GeoPoint p1 = new GeoPoint(mScaleRuler.getLeft(), mScaleRuler.getBottom());
    GeoPoint p2 = new GeoPoint(mScaleRuler.getRight(), mScaleRuler.getBottom());
    p1 = mMap.getMap().screenToMap(p1);
    p2 = mMap.getMap().screenToMap(p2);
    p1.setCRS(GeoConstants.CRS_WEB_MERCATOR);
    p2.setCRS(GeoConstants.CRS_WEB_MERCATOR);
    GeoLineString s = new GeoLineString();
    s.add(p1);
    s.add(p2);

    return LocationUtil.formatLength(getContext(), s.getLength(), 1);
}
 
Example 8
Source File: AttributesFragment.java    From android_gisapp with GNU General Public License v3.0 5 votes vote down vote up
protected String formatCoordinates(GeoPoint pt) {
    pt.setCRS(CRS_WEB_MERCATOR);
    pt.project(CRS_WGS84);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    int format = Integer.parseInt(prefs.getString(SettingsConstantsUI.KEY_PREF_COORD_FORMAT, Location.FORMAT_DEGREES + ""));
    int fraction = prefs.getInt(SettingsConstantsUI.KEY_PREF_COORD_FRACTION, DEFAULT_COORDINATES_FRACTION_DIGITS);

    String lat = getString(com.nextgis.maplibui.R.string.latitude_caption_short) + ": " +
            LocationUtil.formatLatitude(pt.getY(), format, fraction, getResources());
    String lon = getString(com.nextgis.maplibui.R.string.longitude_caption_short) + ": " +
            LocationUtil.formatLongitude(pt.getX(), format, fraction, getResources());

    return lat + "<br \\>" + lon;
}
 
Example 9
Source File: CurrentLocationOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void draw(Canvas canvas, MapDrawable mapDrawable) {
    if (mCurrentLocation != null && isMarkerEnabled()) {
        double lat = mCurrentLocation.getLatitude();
        double lon = mCurrentLocation.getLongitude();
        mMarker.setMarker(getDefaultMarker());
        mMarker.setCoordinatesFromWGS(lon, lat);

        if (null != mapDrawable) {
            // set accuracy marker with proper meter radius
            double accuracy = mCurrentLocation.getAccuracy();
            accuracy = getAccuracyRadius(lat, accuracy);

            GeoPoint centerPoint = new GeoPoint(lon, lat);
            centerPoint.setCRS(GeoConstants.CRS_WGS84);
            centerPoint.project(GeoConstants.CRS_WEB_MERCATOR);
            centerPoint = mapDrawable.mapToScreen(centerPoint);
            GeoPoint newPoint = new GeoPoint(lon, accuracy);
            newPoint.setCRS(GeoConstants.CRS_WGS84);
            newPoint.project(GeoConstants.CRS_WEB_MERCATOR);
            newPoint = mapDrawable.mapToScreen(newPoint);

            int radius = (int) (centerPoint.getY() - newPoint.getY());
            mAccuracy.setMarker(getAccuracyMarker(radius));
            mAccuracy.setCoordinatesFromWGS(lon, lat);

            // set marker in current map and screen bounds flags
            newPoint = mMarker.getCoordinates(GeoConstants.CRS_WEB_MERCATOR);
            mIsInBounds = mapDrawable.getCurrentBounds().contains(newPoint);
            GeoEnvelope screenBounds = mapDrawable.getFullScreenBounds();
            mIsInScreenBounds = mapDrawable.screenToMap(screenBounds).contains(newPoint);
        }

        if (mIsInBounds) {
            if (mIsAccuracyEnabled) {
                drawOverlayItem(canvas, mAccuracy);
            }

            drawOverlayItem(canvas, mMarker);
        }
    }
}
 
Example 10
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 11
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;");
    }
}
 
Example 12
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 4 votes vote down vote up
void testUpdate()
{
    //test sync
    IGISApplication application = (IGISApplication) getApplication();
    MapBase map = application.getMap();
    NGWVectorLayer ngwVectorLayer = null;
    for (int i = 0; i < map.getLayerCount(); i++) {
        ILayer layer = map.getLayer(i);
        if (layer instanceof NGWVectorLayer) {
            ngwVectorLayer = (NGWVectorLayer) layer;
        }
    }
    if (null != ngwVectorLayer) {
        Uri uri = Uri.parse(
                "content://" + AppSettingsConstants.AUTHORITY + "/" +
                ngwVectorLayer.getPath().getName());
        Uri updateUri = ContentUris.withAppendedId(uri, 29);
        ContentValues values = new ContentValues();
        values.put("width", 4);
        values.put("azimuth", 8.0);
        values.put("status", "test4");
        values.put("temperatur", -10);
        values.put("name", "xxx");

        Calendar calendar = new GregorianCalendar(2014, Calendar.JANUARY, 23);
        values.put("datetime", calendar.getTimeInMillis());
        try {
            GeoPoint pt = new GeoPoint(67, 65);
            pt.setCRS(CRS_WGS84);
            pt.project(CRS_WEB_MERCATOR);
            GeoMultiPoint mpt = new GeoMultiPoint();
            mpt.add(pt);
            values.put(Constants.FIELD_GEOM, mpt.toBlob());
        } catch (IOException e) {
            e.printStackTrace();
        }
        int result = getContentResolver().update(updateUri, values, null, null);
        if(Constants.DEBUG_MODE){
            if (result == 0) {
                Log.d(TAG, "update failed");
            } else {
                Log.d(TAG, "" + result);
            }
        }
    }
}
 
Example 13
Source File: MainActivity.java    From android_gisapp with GNU General Public License v3.0 4 votes vote down vote up
void testInsert()
{
    //test sync
    IGISApplication application = (IGISApplication) getApplication();
    MapBase map = application.getMap();
    NGWVectorLayer ngwVectorLayer = null;
    for (int i = 0; i < map.getLayerCount(); i++) {
        ILayer layer = map.getLayer(i);
        if (layer instanceof NGWVectorLayer) {
            ngwVectorLayer = (NGWVectorLayer) layer;
        }
    }
    if (null != ngwVectorLayer) {
        Uri uri = Uri.parse(
                "content://" + AppSettingsConstants.AUTHORITY + "/" +
                        ngwVectorLayer.getPath().getName());
        ContentValues values = new ContentValues();
        //values.put(VectorLayer.FIELD_ID, 26);
        values.put("width", 1);
        values.put("azimuth", 2.0);
        values.put("status", "grot");
        values.put("temperatur", -13);
        values.put("name", "get");

        Calendar calendar = new GregorianCalendar(2015, Calendar.JANUARY, 23);
        values.put("datetime", calendar.getTimeInMillis());

        try {
            GeoPoint pt = new GeoPoint(37, 55);
            pt.setCRS(CRS_WGS84);
            pt.project(CRS_WEB_MERCATOR);
            GeoMultiPoint mpt = new GeoMultiPoint();
            mpt.add(pt);
            values.put(Constants.FIELD_GEOM, mpt.toBlob());
        } catch (IOException e) {
            e.printStackTrace();
        }
        Uri result = getContentResolver().insert(uri, values);
        if(Constants.DEBUG_MODE){
            if (result == null) {
                Log.d(TAG, "insert failed");
            } else {
                Log.d(TAG, result.toString());
            }
        }
    }
}