com.nextgis.maplib.datasource.GeoGeometry Java Examples

The following examples show how to use com.nextgis.maplib.datasource.GeoGeometry. 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: SimpleLineStyle.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onDraw(GeoGeometry geoGeometry, GISDisplay display) {
    mColor = Color.argb(mInnerAlpha, Color.red(mColor), Color.green(mColor), Color.blue(mColor));
    mOutColor = Color.argb(mOuterAlpha, Color.red(mOutColor), Color.green(mOutColor), Color.blue(mOutColor));

    switch (geoGeometry.getType()) {
        case GTLineString:
            onDraw((GeoLineString) geoGeometry, display);
            break;

        case GTMultiLineString:
            GeoMultiLineString multiLineString = (GeoMultiLineString) geoGeometry;
            for (int i = 0; i < multiLineString.size(); i++) {
                onDraw(multiLineString.get(i), display);
            }
            break;

        //throw new IllegalArgumentException(
        //        "The input geometry type is not support by this style");
    }

}
 
Example #2
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 #3
Source File: SimpleFeatureRenderer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void run() {
    android.os.Process.setThreadPriority(
            Constants.DEFAULT_DRAW_THREAD_PRIORITY);

    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    SQLiteDatabase db = map.getDatabase(true);

    for(Long id : mFeatureIds) {
        if(mLayer.isFeatureHidden(id))
            continue;
        final GeoGeometry geometry = mLayer.getGeometryForId(id, mZoom, db);
        if (geometry != null) {
            final Style style = getStyle(id);
            style.onDraw(geometry, mDisplay);
        }
    }
}
 
Example #4
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
public GeoGeometry getGeometryForId(
        long rowId,
        int zoom)
{
    if (zoom > GeoConstants.DEFAULT_CACHE_MAX_ZOOM) {
        return getGeometryForId(rowId);
    }

    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    if (null == map) {
        throw new IllegalArgumentException(
                "The map should extends MapContentProviderHelper or inherited");
    }
    SQLiteDatabase db = map.getDatabase(true);
    String[] columns = new String[] {Constants.FIELD_GEOM_ + zoom};
    String selection = Constants.FIELD_ID + " = " + rowId;

    return getGeometryFromQuery(columns, selection, db);
}
 
Example #5
Source File: ModifyAttributesActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void createView(final IGISApplication app, Bundle savedState)
{
    //create and fill controls
    Bundle extras = getIntent().getExtras();

    if (extras != null) {
        int layerId = extras.getInt(KEY_LAYER_ID);
        MapBase map = app.getMap();
        mLayer = (VectorLayer) map.getLayerById(layerId);

        if (null != mLayer) {
            mSharedPreferences = mLayer.getPreferences();

            mFields = new HashMap<>();
            mFeatureId = extras.getLong(KEY_FEATURE_ID);
            mIsViewOnly = extras.getBoolean(KEY_VIEW_ONLY, false);
            mIsGeometryChanged = extras.getBoolean(KEY_GEOMETRY_CHANGED, true);
            mGeometry = (GeoGeometry) extras.getSerializable(KEY_GEOMETRY);
            LinearLayout layout = findViewById(R.id.controls_list);
            fillControls(layout, savedState);
        } else {
            Toast.makeText(this, R.string.error_layer_not_inited, Toast.LENGTH_SHORT).show();
            finish();
        }
    }
}
 
Example #6
Source File: SimpleMarkerStyle.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onDraw(GeoGeometry geoGeometry, GISDisplay display) {
    switch (geoGeometry.getType()) {
        case GTPoint:
            GeoPoint pt = (GeoPoint) geoGeometry;
            onDraw(pt, display);
            break;
        case GTMultiPoint:
            GeoMultiPoint multiPoint = (GeoMultiPoint) geoGeometry;
            for (int i = 0; i < multiPoint.size(); i++) {
                onDraw(multiPoint.get(i), display);
            }
            break;

        //throw new IllegalArgumentException(
        //        "The input geometry type is not support by this style");
    }
}
 
Example #7
Source File: SimplePolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onDraw(GeoGeometry geoGeometry, GISDisplay display) {
    Float textSize = (null == mTextSize) ? null : 12f;
    float scaledTextSize = (float) (mTextSize * (mWidth / display.getScale()));
    GeoPoint center = geoGeometry.getEnvelope().getCenter();
    switch (geoGeometry.getType()) {
        case GTPolygon:
            drawPolygon((GeoPolygon) geoGeometry, display);
            drawText(scaledTextSize, center, display);
            break;
        case GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) geoGeometry;

            for (int i = 0; i < multiPolygon.size(); i++) {
                drawPolygon(multiPolygon.get(i), display);
                drawText(scaledTextSize, center, display);
            }
            break;

        //throw new IllegalArgumentException(
        //        "The input geometry type is not support by this style");
    }
}
 
Example #8
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GeoGeometry getGeometryForId(long rowId)
{
    MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance();
    if (null == map) {
        throw new IllegalArgumentException(
                "The map should extends MapContentProviderHelper or inherited");
    }
    SQLiteDatabase db = map.getDatabase(true);
    String[] columns = new String[] {Constants.FIELD_GEOM};
    String selection = Constants.FIELD_ID + " = " + rowId;
    return getGeometryFromQuery(columns, selection, db);
}
 
Example #9
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void notifyUpdate(
        long rowId,
        long oldRowId,
        boolean attributesOnly)
{
    if (Constants.DEBUG_MODE) {
        Log.d(Constants.TAG, "notifyUpdate id: " + rowId + ", old_id: " + oldRowId);
    }

    boolean needSave = false;
    if (oldRowId != Constants.NOT_FOUND) {
        mCache.changeId(oldRowId, rowId);
        if (DEBUG_MODE)
            Log.d(Constants.TAG, "mCache: changing id from " + oldRowId + " to " + rowId);
        needSave = true;
    }

    GeoGeometry geom = getGeometryForId(rowId);
    if (null != geom && !attributesOnly) {
        mCache.removeItem(rowId);
        cacheGeometryEnvelope(rowId, geom);
        if (DEBUG_MODE)
            Log.d(Constants.TAG, "mCache: removing item " + oldRowId + " and caching env");
        needSave = true;
    }

    if (needSave) {
        save();
    }

    notifyLayerChanged();
}
 
Example #10
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void notifyInsert(long rowId)
{

    if (Constants.DEBUG_MODE) {
        Log.d(Constants.TAG, "notifyInsert id: " + rowId);
    }

    GeoGeometry geom = getGeometryForId(rowId);
    if (null != geom) {
        cacheGeometryEnvelope(rowId, geom);
        save();
        notifyLayerChanged();
    }
}
 
Example #11
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GeoGeometry getGeometryForId(
        long rowId,
        SQLiteDatabase db)
{
    String[] columns = new String[] {Constants.FIELD_GEOM};
    String selection = Constants.FIELD_ID + " = " + rowId;
    return getGeometryFromQuery(columns, selection, db);
}
 
Example #12
Source File: SimpleTiledPolygonStyle.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onDraw(GeoGeometry geoGeometry, GISDisplay display) {
    switch (geoGeometry.getType()) {
        case GTPolygon:
            drawPolygon((GeoPolygon) geoGeometry, display);
            break;
        case GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) geoGeometry;

            for (int i = 0; i < multiPolygon.size(); i++) {
                drawPolygon(multiPolygon.get(i), display);
            }
            break;
        case GTPoint:
            drawPoint((GeoPoint) geoGeometry, display);
            break;
        case GTMultiPoint:
            GeoMultiPoint multiPoint = (GeoMultiPoint) geoGeometry;
            for (int i = 0; i < multiPoint.size(); i++) {
                drawPoint(multiPoint.get(i), display);
            }
            break;
        case GTLineString:
            drawLineString((GeoLineString) geoGeometry, display);
            break;
        case GTMultiLineString:
            GeoMultiLineString multiLineString = (GeoMultiLineString) geoGeometry;
            for (int i = 0; i < multiLineString.size(); i++) {
                drawLineString(multiLineString.get(i), display);
            }
            break;
    }
}
 
Example #13
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GeoGeometry getGeometryForId(
        long rowId,
        int zoom,
        SQLiteDatabase db)
{
    if (zoom > GeoConstants.DEFAULT_CACHE_MAX_ZOOM) {
        return getGeometryForId(rowId, db);
    }

    String[] columns = new String[] {Constants.FIELD_GEOM_ + zoom};
    String selection = Constants.FIELD_ID + " = " + rowId;

    return getGeometryFromQuery(columns, selection, db);
}
 
Example #14
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setGeometryFromWalkEdit(GeoGeometry geometry) {
    int selectedGeometry = mDrawItems.indexOf(mSelectedItem);
    int selectedRing = mSelectedItem.getSelectedRingId();

    switch (mLayer.getGeometryType()) {
        case GeoConstants.GTLineString:
            mFeature.setGeometry(geometry);
            break;
        case GeoConstants.GTMultiLineString:
            GeoMultiLineString multiLine = (GeoMultiLineString) mFeature.getGeometry();
            multiLine.set(selectedGeometry, geometry);
            mFeature.setGeometry(multiLine);
            break;
        case GeoConstants.GTPolygon:
            GeoPolygon polygon = (GeoPolygon) mFeature.getGeometry();

            if (selectedRing == 0)
                polygon.setOuterRing((GeoLinearRing) geometry);
            else
                polygon.setInnerRing(selectedRing - 1, (GeoLinearRing) geometry);

            mFeature.setGeometry(polygon);
            break;
        case GeoConstants.GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) mFeature.getGeometry();
            GeoPolygon selectedPolygon = multiPolygon.get(selectedGeometry);
            selectedPolygon.setOuterRing((GeoLinearRing) geometry);

            if (selectedRing == 0)
                selectedPolygon.setOuterRing((GeoLinearRing) geometry);
            else
                selectedPolygon.setInnerRing(selectedRing - 1, (GeoLinearRing) geometry);

            multiPolygon.set(selectedGeometry, selectedPolygon);
            mFeature.setGeometry(multiPolygon);
            break;
    }
}
 
Example #15
Source File: MapUtil.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static boolean isGeometryIntersects(Context context, GeoGeometry geometry) {
    if (geometry instanceof GeoPolygon) {
        if (((GeoPolygon) geometry).intersects()) {
            Toast.makeText(context, R.string.self_intersection, Toast.LENGTH_SHORT).show();
            return true;
        }

        if (!((GeoPolygon) geometry).isHolesInside()) {
            Toast.makeText(context, R.string.ring_outside, Toast.LENGTH_SHORT).show();
            return true;
        }

        if (((GeoPolygon) geometry).isHolesIntersect()) {
            Toast.makeText(context, R.string.rings_intersection, Toast.LENGTH_SHORT).show();
            return true;
        }
    }

    if (geometry instanceof GeoMultiPolygon) {
        if (((GeoMultiPolygon) geometry).isSelfIntersects()) {
            Toast.makeText(context, R.string.self_intersection, Toast.LENGTH_SHORT).show();
            return true;
        }

        if (!((GeoMultiPolygon) geometry).isHolesInside()) {
            Toast.makeText(context, R.string.ring_outside, Toast.LENGTH_SHORT).show();
            return true;
        }

        if (((GeoMultiPolygon) geometry).isHolesIntersect()) {
            Toast.makeText(context, R.string.rings_intersection, Toast.LENGTH_SHORT).show();
            return true;
        }
    }

    return false;
}
 
Example #16
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Feature readNGWFeature(
        JsonReader reader,
        List<Field> fields,
        int nSRS)
        throws IOException, IllegalStateException, NumberFormatException, OutOfMemoryError
{
    final Feature feature = new Feature(Constants.NOT_FOUND, fields);

    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals(NGWUtil.NGWKEY_ID)) {
            feature.setId(reader.nextLong());
        } else if (name.equals(NGWUtil.NGWKEY_GEOM)) {
            String wkt = reader.nextString();
            GeoGeometry geom = GeoGeometryFactory.fromWKT(wkt, nSRS);
            geom.setCRS(nSRS);
            if (nSRS != GeoConstants.CRS_WEB_MERCATOR) {
                geom.project(GeoConstants.CRS_WEB_MERCATOR);
            }
            feature.setGeometry(geom);
        } else if (name.equals(NGWUtil.NGWKEY_FIELDS)) {
            readNGWFeatureFields(feature, reader, fields);
        } else if (name.equals(NGWUtil.NGWKEY_EXTENSIONS)) {
            if (reader.peek() != JsonToken.NULL) {
                readNGWFeatureAttachments(feature, reader);
            }
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
    return feature;
}
 
Example #17
Source File: Tabs.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void init(VectorLayer layer, long featureId, GeoGeometry geometry, Map<String, List<String>> table, int row,
                 SharedPreferences sharedPreferences, SharedPreferences preferences,
                 FragmentManager supportFragmentManager, boolean isViewOnly) {
    mLayer = layer;
    mFeatureId = featureId;
    mIsViewOnly = isViewOnly;
    mGeometry = geometry;
    mTable = table;
    mRow = row;
    mSharedPreferences = sharedPreferences;
    mPreferences = preferences;
    mFragmentManager = supportFragmentManager;
    mTag = ViewCompat.generateViewId();
    findViewById(R.id.tab).setId(mTag);
}
 
Example #18
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();
    }
}
 
Example #19
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 4 votes vote down vote up
public boolean onOptionsItemSelected(int id) {
    boolean result;
    switch (id) {
        case android.R.id.home:
            cancelEdits();
            return true;
        case 0:
            mMap.setLockMap(false);
            setMode(MODE_EDIT);
            return true;
        case R.id.menu_edit_by_touch:
            setMode(MODE_EDIT_BY_TOUCH);
            result = mEditLayerOverlay.onOptionsItemSelected(id);
            return result;
        case R.id.menu_edit_undo:
        case R.id.menu_edit_redo:
            result = mUndoRedoOverlay.onOptionsItemSelected(id);
            if (result) {
                Feature undoRedoFeature = mUndoRedoOverlay.getFeature();
                Feature feature = mEditLayerOverlay.getSelectedFeature();
                feature.setGeometry(undoRedoFeature.getGeometry());
                mEditLayerOverlay.fillDrawItems(undoRedoFeature.getGeometry());

                GeoGeometry original = mSelectedLayer.getGeometryForId(feature.getId());
                boolean hasEdits = original != null && undoRedoFeature.getGeometry().equals(original);

                mEditLayerOverlay.setHasEdits(!hasEdits);

                mMap.buffer();
                mMap.postInvalidate();
            }

            return result;
        case R.id.menu_edit_by_walk:
            setMode(MODE_EDIT_BY_WALK);
        default:
            result = mEditLayerOverlay.onOptionsItemSelected(id);
            if (result)
                mUndoRedoOverlay.saveToHistory(mEditLayerOverlay.getSelectedFeature());
            return result;
    }
}
 
Example #20
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 4 votes vote down vote up
public boolean saveEdits() {
    Feature feature = mEditLayerOverlay.getSelectedFeature();
    long featureId = NOT_FOUND;
    GeoGeometry geometry = null;

    if (mMode == MODE_EDIT_BY_WALK) {
        mEditLayerOverlay.stopGeometryByWalk();
        setMode(MODE_EDIT);
        mUndoRedoOverlay.clearHistory();
        mUndoRedoOverlay.defineUndoRedo();
        return true;
    }

    if (feature != null) {
        geometry = feature.getGeometry();
        featureId = feature.getId();
    }

    if (geometry == null || !geometry.isValid()) {
        Toast.makeText(getContext(), R.string.not_enough_points, Toast.LENGTH_SHORT).show();
        return false;
    }
    if (isGeometryIntersects(getContext(), geometry))
        return false;

    mMap.setLockMap(false);
    mEditLayerOverlay.setHasEdits(false);

    if (mMode == MODE_EDIT_BY_TOUCH) {
        setMode(MODE_EDIT);
        mUndoRedoOverlay.clearHistory();
        mUndoRedoOverlay.defineUndoRedo();
    }

    if (mSelectedLayer != null) {
        if (featureId == NOT_FOUND) {
            //show attributes edit activity
            IVectorLayerUI vectorLayerUI = (IVectorLayerUI) mSelectedLayer;
            vectorLayerUI.showEditForm(mActivity, featureId, geometry);
        } else {
            Uri uri = Uri.parse("content://" + mApp.getAuthority() + "/" + mSelectedLayer.getPath().getName());
            uri = ContentUris.withAppendedId(uri, featureId);
            ContentValues values = new ContentValues();

            try {
                values.put(FIELD_GEOM, geometry.toBlob());
            } catch (IOException e) {
                e.printStackTrace();
            }

            mActivity.getContentResolver().update(uri, values, null, null);
            setMode(MODE_SELECT_ACTION);
        }
    }

    return true;
}
 
Example #21
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 #22
Source File: NGWVectorLayerUI.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void showEditForm(Context context, long featureId, GeoGeometry geometry) {
    LayerUtil.showEditForm(this, context, featureId, geometry);
}
 
Example #23
Source File: VectorLayerUI.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void showEditForm(Context context, long featureId, GeoGeometry geometry) {
    LayerUtil.showEditForm(this, context, featureId, geometry);
}
 
Example #24
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    GeoGeometry geometry = (GeoGeometry) intent.getSerializableExtra(ConstantsUI.KEY_GEOMETRY);
    setGeometryFromWalkEdit(geometry);
    mMapViewOverlays.postInvalidate();
}
 
Example #25
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void fillDrawItems(GeoGeometry geom) {
    int lastItemsCount = mDrawItems.size();
    int lastSelectedItemPosition = mDrawItems.indexOf(mSelectedItem);
    DrawItem lastSelectedItem = mSelectedItem;
    mDrawItems.clear();

    if (null == geom) {
        Log.w(Constants.TAG, "the geometry is null in fillDrawItems method");
        return;
    }

    GeoPoint[] geoPoints = new GeoPoint[1];
    Location last = mGpsEventSource.getLastKnownLocation();
    switch (geom.getType()) {
        case GeoConstants.GTPoint:
            geoPoints[0] = (GeoPoint) geom;
            mSelectedItem = new DrawItem(DrawItem.TYPE_VERTEX, mapToScreen(geoPoints));
            mDrawItems.add(mSelectedItem);
            break;
        case GeoConstants.GTMultiPoint:
            GeoMultiPoint geoMultiPoint = (GeoMultiPoint) geom;
            for (int i = 0; i < geoMultiPoint.size(); i++) {
                geoPoints[0] = geoMultiPoint.get(i);
                mSelectedItem = new DrawItem(DrawItem.TYPE_VERTEX, mapToScreen(geoPoints));
                mDrawItems.add(mSelectedItem);
            }
            break;
        case GeoConstants.GTLineString:
            fillDrawLine((GeoLineString) geom);
            break;
        case GeoConstants.GTMultiLineString:
            GeoMultiLineString multiLineString = (GeoMultiLineString) geom;
            for (int i = 0; i < multiLineString.size(); i++)
                fillDrawLine(multiLineString.get(i));
            break;
        case GeoConstants.GTPolygon:
            fillDrawPolygon((GeoPolygon) geom);
            break;
        case GeoConstants.GTMultiPolygon:
            GeoMultiPolygon multiPolygon = (GeoMultiPolygon) geom;
            for (int i = 0; i < multiPolygon.size(); i++)
                fillDrawPolygon(multiPolygon.get(i));
            break;
        case GeoConstants.GTGeometryCollection:
            GeoGeometryCollection collection = (GeoGeometryCollection) geom;
            for (int i = 0; i < collection.size(); i++) {
                GeoGeometry geoGeometry = collection.get(i);
                fillDrawItems(geoGeometry);
            }
            break;
        default:
            break;
    }

    if (mDrawItems.size() == lastItemsCount && lastSelectedItem != null &&
            lastSelectedItemPosition != Constants.NOT_FOUND) {
        mSelectedItem = mDrawItems.get(lastSelectedItemPosition);
        mSelectedItem.setSelectedRing(lastSelectedItem.getSelectedRingId());
        mSelectedItem.setSelectedPoint(lastSelectedItem.getSelectedPointId());
    } else {
        mSelectedItem = mDrawItems.get(0);
    }

    switch (geom.getType()) {
        case GeoConstants.GTPoint:
        case GeoConstants.GTMultiPoint:
            updateDistance(last, null);
            break;
    }
}
 
Example #26
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void startGeometryByWalk() {
    // register broadcast events
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WalkEditService.WALKEDIT_CHANGE);
    mReceiver = new WalkEditReceiver();
    mContext.registerReceiver(mReceiver, intentFilter);
    mHasEdits = true;

    if (WalkEditService.isServiceRunning(mContext))
        return;

    // start service if not started yet
    GeoGeometry geometry = mFeature.getGeometry();
    int selectedRing = mSelectedItem.getSelectedRingId();
    int selectedGeometry = mDrawItems.indexOf(mSelectedItem);

    switch (mLayer.getGeometryType()) {
        case GeoConstants.GTLineString:
            break;
        case GeoConstants.GTPolygon:
            GeoPolygon polygon = ((GeoPolygon) geometry);
            geometry = selectedRing == 0 ? polygon.getOuterRing() : polygon.getInnerRing(selectedRing - 1);
            break;
        case GeoConstants.GTMultiLineString:
            geometry = ((GeoMultiLineString) geometry).get(selectedGeometry);
            break;
        case GeoConstants.GTMultiPolygon:
            GeoPolygon selectedPolygon = ((GeoMultiPolygon) geometry).get(selectedGeometry);
            geometry = selectedRing == 0 ? selectedPolygon.getOuterRing() : selectedPolygon.getInnerRing(selectedRing - 1);
            break;
        default:
            return;
    }

    Intent trackerService = new Intent(mContext, WalkEditService.class);
    trackerService.setAction(WalkEditService.ACTION_START);
    trackerService.putExtra(ConstantsUI.KEY_LAYER_ID, mLayer.getId());
    trackerService.putExtra(ConstantsUI.KEY_GEOMETRY, geometry);
    trackerService.putExtra(ConstantsUI.TARGET_CLASS, mContext.getClass().getName());
    ContextCompat.startForegroundService(mContext, trackerService);
}
 
Example #27
Source File: EditLayerOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 4 votes vote down vote up
public GeoGeometry getSelectedFeatureGeometry() {
    return mFeature == null ? null : mFeature.getGeometry();
}
 
Example #28
Source File: IVectorLayerUI.java    From android_maplibui with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * This method executed, when the form need to be shown
 * @param context activity context
 * @param featureId a feature identificator to fill form controls
 * @param geometry a new geometry for feature
 */
void showEditForm(
        Context context,
        long featureId,
        GeoGeometry geometry);
 
Example #29
Source File: Style.java    From android_maplib with GNU Lesser General Public License v3.0 votes vote down vote up
public abstract void onDraw(GeoGeometry geoGeometry, GISDisplay display);