Java Code Examples for com.nextgis.maplib.datasource.Feature#getGeometry()

The following examples show how to use com.nextgis.maplib.datasource.Feature#getGeometry() . 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
public void createFeatureBatch(
        final Feature feature,
        final SQLiteDatabase db)
        throws SQLiteException
{
    if (null == feature.getGeometry() || !checkGeometryType(feature)) {
        return;
    }

    final ContentValues values = getFeatureContentValues(feature);

    long rowId = db.insert(mPath.getName(), "", values);
    if (rowId != Constants.NOT_FOUND) {
        //update bbox
        cacheGeometryEnvelope(rowId, feature.getGeometry());
    }
}
 
Example 2
Source File: MapFragment.java    From android_gisapp with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onSaveInstanceState(Bundle outState)
{
    super.onSaveInstanceState(outState);
    outState.putBoolean(BUNDLE_KEY_IS_MEASURING, mRulerOverlay.isMeasuring());
    outState.putInt(KEY_MODE, mMode);
    outState.putInt(BUNDLE_KEY_LAYER, null == mSelectedLayer ? Constants.NOT_FOUND : mSelectedLayer.getId());

    Feature feature = mEditLayerOverlay.getSelectedFeature();
    outState.putLong(BUNDLE_KEY_FEATURE_ID, null == feature ? Constants.NOT_FOUND : feature.getId());

    if (null != feature && feature.getGeometry() != null) {
        try {
            outState.putByteArray(BUNDLE_KEY_SAVED_FEATURE, feature.getGeometry().toBlob());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
Example 3
Source File: UndoRedoOverlay.java    From android_maplibui with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void saveToHistory(Feature feature) {
    if (null == feature || null == feature.getGeometry())
        return;

    for (int i = mHistory.size() - 1; i > mHistoryState; i--)
        mHistory.remove(i);

    if (mHistory.size() >= MAX_UNDO + 1)
        mHistory.removeFirst();

    mHistoryState++;
    mHistory.add(feature.getGeometry().copy());
    mFeature.setGeometry(mHistory.getLast());
    defineUndoRedo();
}
 
Example 4
Source File: NGWVectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void readFeatures(JsonReader reader, List<Feature> features) throws IOException, IllegalStateException, NumberFormatException, OutOfMemoryError {
    reader.beginArray();
    while (reader.hasNext()) {
        final Feature feature = NGWUtil.readNGWFeature(reader, getFields(), mCRS);
        if (feature.getGeometry() == null || !feature.getGeometry().isValid())
            continue;
        features.add(feature);
    }
    reader.endArray();
}
 
Example 5
Source File: VectorLayer.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
public long createFeature(Feature feature)
        throws SQLiteException
{
    if (null == feature.getGeometry() || !checkGeometryType(feature)) {
        return NOT_FOUND;
    }

    if (!mCacheLoaded) {
        reloadCache();
    }

    // check if such id already used
    // maybe was added previous session
    if (mCache.getItem(feature.getId()) != null) {
        return NOT_FOUND;
    }

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

    final ContentValues values = getFeatureContentValues(feature);

    if (Constants.DEBUG_MODE) {
        Log.d(TAG, "Inserting " + values);
    }
    long rowId = db.insert(mPath.getName(), "", values);
    if (rowId != Constants.NOT_FOUND) {
        //update bbox
        cacheGeometryEnvelope(rowId, feature.getGeometry());
        save();
    }

    return rowId;
}
 
Example 6
Source File: GeoJSONUtil.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void fillLayerFromGeoJSONStream(VectorLayer layer, InputStream in, int srs, IProgressor progressor) throws IOException, NGException {
    int streamSize = in.available();
    if(null != progressor){
        progressor.setIndeterminate(false);
        progressor.setMax(streamSize);
        progressor.setMessage(layer.getContext().getString(R.string.start_fill_layer) + " " + layer.getName());
    }

    SQLiteDatabase db = null;
    if(layer.getFields() != null && layer.getFields().isEmpty()){
        db = DatabaseContext.getDbForLayer(layer);
    }

    JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
    boolean isWGS84 = srs == GeoConstants.CRS_WGS84;
    long counter = 0;
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if(name.equals(GeoConstants.GEOJSON_TYPE_FEATURES)){
            reader.beginArray();
            while (reader.hasNext()) {
                Feature feature = readGeoJSONFeature(reader, layer, isWGS84);
                if (null != feature) {
                    if(layer.getFields() != null && !layer.getFields().isEmpty()){
                        if (feature.getGeometry() != null)
                            layer.create(feature.getGeometry().getType(), feature.getFields());

                        db = DatabaseContext.getDbForLayer(layer);
                    }

                    if(feature.getGeometry() != null) {
                        layer.createFeatureBatch(feature, db);
                        if(null != progressor){
                            if (progressor.isCanceled()) {
                                layer.save();
                                return;
                            }
                            progressor.setValue(streamSize - in.available());
                            progressor.setMessage(layer.getContext().getString(R.string.process_features) + ": " + counter++);
                        }
                    }
                }
            }
            reader.endArray();
        }
        else {
            reader.skipValue();
        }
    }
    reader.endObject();
    reader.close();

    //if(null != db)
    //    db.close(); // return pragma to init

    layer.save();
}
 
Example 7
Source File: GeoJSONUtil.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void createLayerFromGeoJSONStream(VectorLayer layer, InputStream in, IProgressor progressor, boolean isWGS84) throws IOException, NGException {
    int streamSize = in.available();
    if(null != progressor){
        progressor.setIndeterminate(false);
        progressor.setMax(streamSize);
        progressor.setMessage(layer.getContext().getString(R.string.start_fill_layer) + " " + layer.getName());
    }

    SQLiteDatabase db = null;
    if(layer.getFields() != null && layer.getFields().isEmpty()){
        db = DatabaseContext.getDbForLayer(layer);
    }

    JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
    long counter = 0;
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals(GeoConstants.GEOJSON_TYPE_FEATURES)) {
            reader.beginArray();
            while (reader.hasNext()) {
                Feature feature = readGeoJSONFeature(reader, layer, isWGS84);
                if (null != feature) {
                    if (layer.getFields() == null || layer.getFields().isEmpty()) {
                        if (feature.getGeometry() != null)
                            layer.create(feature.getGeometry().getType(), feature.getFields());

                        db = DatabaseContext.getDbForLayer(layer);
                    }

                    if (feature.getGeometry() != null) {
                        layer.createFeatureBatch(feature, db);
                        if(null != progressor){
                            if (progressor.isCanceled()) {
                                layer.save();
                                return;
                            }
                            progressor.setValue(streamSize - in.available());
                            progressor.setMessage(layer.getContext().getString(R.string.process_features) + ": " + counter++);
                        }
                    }
                }
            }
            reader.endArray();
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
    reader.close();

    //if(null != db)
    //   db.close(); // return pragma to init
    layer.save();
}
 
Example 8
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;
}