Java Code Examples for com.nextgis.maplib.datasource.GeoGeometryFactory#fromBlob()

The following examples show how to use com.nextgis.maplib.datasource.GeoGeometryFactory#fromBlob() . 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: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected GeoGeometry getGeometryFromQuery(
        String[] columns,
        String selection,
        SQLiteDatabase db)
{
    Cursor cursor = db.query(mPath.getName(), columns, selection, null, null, null, null);
    if (null != cursor) {
        if (cursor.moveToFirst()) {
            try {
                GeoGeometry result = GeoGeometryFactory.fromBlob(cursor.getBlob(0));
                cursor.close();
                return result;
            } catch (IOException e) {
                // e.printStackTrace();
            }
        }
        cursor.close();
    }
    return null;
}
 
Example 2
Source File: RulerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onRestoreState(Bundle bundle) {
    if (bundle.containsKey(BUNDLE_GEOMETRY))
        try {
            mRulerString = (GeoLineString) GeoGeometryFactory.fromBlob(bundle.getByteArray(BUNDLE_GEOMETRY));
        } catch (IOException e) {
            e.printStackTrace();
        }

    super.onRestoreState(bundle);
}
 
Example 3
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected String cursorToJson(Cursor cursor)
        throws JSONException, IOException
{
    JSONObject rootObject = new JSONObject();
    if (0 != (mSyncType & Constants.SYNC_ATTRIBUTES)) {
        JSONObject valueObject = new JSONObject();
        for (int i = 0; i < cursor.getColumnCount(); i++) {
            String name = cursor.getColumnName(i);
            if (name.equals(Constants.FIELD_ID) || name.equals(Constants.FIELD_GEOM)) {
                continue;
            }

            Field field = mFields.get(cursor.getColumnName(i));
            if (null == field) {
                continue;
            }

            switch (field.getType()) {
                case GeoConstants.FTReal:
                    valueObject.put(name, cursor.getFloat(i));
                    break;
                case GeoConstants.FTInteger:
                    valueObject.put(name, cursor.getInt(i));
                    break;
                case GeoConstants.FTString:
                    String stringVal = cursor.getString(i);
                    if (null != stringVal && !stringVal.equals("null")) {
                        valueObject.put(name, stringVal);
                    }
                    break;
                case GeoConstants.FTDateTime:
                    TimeZone timeZoneDT = TimeZone.getDefault();
                    timeZoneDT.setRawOffset(0); // set to UTC
                    Calendar calendarDT = Calendar.getInstance(timeZoneDT);
                    calendarDT.setTimeInMillis(cursor.getLong(i));
                    JSONObject jsonDateTime = new JSONObject();
                    jsonDateTime.put("year", calendarDT.get(Calendar.YEAR));
                    jsonDateTime.put("month", calendarDT.get(Calendar.MONTH) + 1);
                    jsonDateTime.put("day", calendarDT.get(Calendar.DAY_OF_MONTH));
                    jsonDateTime.put("hour", calendarDT.get(Calendar.HOUR_OF_DAY));
                    jsonDateTime.put("minute", calendarDT.get(Calendar.MINUTE));
                    jsonDateTime.put("second", calendarDT.get(Calendar.SECOND));
                    valueObject.put(name, jsonDateTime);
                    break;
                case GeoConstants.FTDate:
                    TimeZone timeZoneD = TimeZone.getDefault();
                    timeZoneD.setRawOffset(0); // set to UTC
                    Calendar calendarD = Calendar.getInstance(timeZoneD);
                    calendarD.setTimeInMillis(cursor.getLong(i));
                    JSONObject jsonDate = new JSONObject();
                    jsonDate.put("year", calendarD.get(Calendar.YEAR));
                    jsonDate.put("month", calendarD.get(Calendar.MONTH) + 1);
                    jsonDate.put("day", calendarD.get(Calendar.DAY_OF_MONTH));
                    valueObject.put(name, jsonDate);
                    break;
                case GeoConstants.FTTime:
                    TimeZone timeZoneT = TimeZone.getDefault();
                    timeZoneT.setRawOffset(0); // set to UTC
                    Calendar calendarT = Calendar.getInstance(timeZoneT);
                    calendarT.setTimeInMillis(cursor.getLong(i));
                    JSONObject jsonTime = new JSONObject();
                    jsonTime.put("hour", calendarT.get(Calendar.HOUR_OF_DAY));
                    jsonTime.put("minute", calendarT.get(Calendar.MINUTE));
                    jsonTime.put("second", calendarT.get(Calendar.SECOND));
                    valueObject.put(name, jsonTime);
                    break;
                default:
                    break;
            }
        }
        rootObject.put(NGWUtil.NGWKEY_FIELDS, valueObject);
    }

    if (0 != (mSyncType & Constants.SYNC_GEOMETRY)) {
        //may be found geometry in cache by id is faster
        GeoGeometry geometry = GeoGeometryFactory.fromBlob(
                cursor.getBlob(cursor.getColumnIndex(Constants.FIELD_GEOM)));

        geometry.setCRS(GeoConstants.CRS_WEB_MERCATOR);
        if (mCRS != GeoConstants.CRS_WEB_MERCATOR)
            geometry.project(mCRS);

        rootObject.put(NGWUtil.NGWKEY_GEOM, geometry.toWKT(true));
        //rootObject.put("id", cursor.getLong(cursor.getColumnIndex(FIELD_ID)));
    }

    return rootObject.toString();
}
 
Example 4
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void rebuildCache(IProgressor progressor)
{
    if (null != progressor) {
        progressor.setMessage(mContext.getString(R.string.rebuild_cache));
    }

    String columns[] = {FIELD_ID, FIELD_GEOM};
    Cursor cursor = query(columns, null, null, null, null);
    if (null != cursor) {
        if (cursor.moveToFirst()) {
            if (null != progressor) {
                progressor.setMax(cursor.getCount());
            }

            mIsCacheRebuilding = true;
            mCache = createNewCache();
            int counter = 0;
            do {
                GeoGeometry geometry = null;
                try {
                    geometry = GeoGeometryFactory.fromBlob(cursor.getBlob(1));
                } catch (IOException e) {
                    e.printStackTrace();
                }

                if (null != geometry) {
                    long rowId = cursor.getLong(0);
                    mCache.addItem(rowId, geometry.getEnvelope());
                }

                if (null != progressor) {
                    if (progressor.isCanceled()) {
                        break;
                    }
                    progressor.setValue(++counter);
                    progressor.setMessage(
                            mContext.getString(R.string.process_features) + ": " + counter);
                }

            } while (cursor.moveToNext());

            mIsCacheRebuilding = false;
        }
        cursor.close();
        save();
    }
}