Package org.geotools.data

Examples of org.geotools.data.FeatureStore


  /**
   *
   */
  private void save() throws Exception
  {
    FeatureStore fs = (FeatureStore) ds.getFeatureSource("poly_county");
    FeatureType ft = fs.getSchema();
   
    MemoryDataStore memorystore =new MemoryDataStore();
   
    ArrayList polys = new ArrayList(resultPolygon);
   
    Geometry gfinal = null;
    if (polys.size() == 1)
    {
      gfinal = (Polygon) polys.get(0);   //POLYGON
    }
    else
    {
      GeometryFactory gf = ((Polygon) polys.get(0)).getFactory();
      gfinal = new MultiPolygon((Polygon[]) polys.toArray( new Polygon[polys.size()]),   gf    );
    }
   
    gfinal = gfinal.buffer(0); // for topologic problems.
   
     
      Object[] values = new Object[5];
      values[ft.find("module")] = MODULE;
      values[ft.find("gen_full")] = gfinal;
     
      values[ft.find("gen_1")] = generalize(gfinal,tolerance1);;
      values[ft.find("gen_2")] = generalize(gfinal,tolerance1);;
      values[ft.find("gen_3")] = generalize(gfinal,tolerance1);;
     
      Feature f = ft.create(values);
      memorystore.addFeature(f);
   
    fs.addFeatures(memorystore.getFeatureReader("poly_county"));
   
  }
View Full Code Here


//               interstate int,
//               ushighway  int,
//               statehighway int,
//               otherName text     ) with oids;
   
    FeatureStore fs = (FeatureStore) ds.getFeatureSource("major_roads");
    FeatureType ft = fs.getSchema();
   
    MemoryDataStore memorystore =new MemoryDataStore();
   
    System.out.println("saving interstate");
   
    addStuff(memorystore,interstate,"interstate",ft);
   
    System.out.println("saving ushighway");
   
    addStuff(memorystore,ushighway,"ushighway",ft);
   
    System.out.println("saving statehighway");
   
    addStuff(memorystore,statehighway,"statehighway",ft);
   
    System.out.println("saving othername");
   
    addStuff(memorystore,other,"othername",ft);
   
    System.out.println("writing to DB");
   
    fs.addFeatures(memorystore.getFeatureReader("major_roads"));
  }
View Full Code Here

            // see if there is anything at all to do, if both sides have no changes there
            // is no point eating away a revision number (this avoid the local revision number to
            // skyrocket for nothing if there are frequent synchronisations)
            String tableName = request.getTypeName().getLocalPart();
            VersioningFeatureStore fs = (VersioningFeatureStore) ds.getFeatureSource(tableName);
            FeatureStore history = (FeatureStore) ds.getFeatureSource(SYNCH_HISTORY);
            PropertyIsEqualTo ftSyncRecord = ff.equals(ff.property("table_name"), ff.literal(tableName));
            TransactionType changes = request.getTransaction();
            int changesCount = core.countChanges(changes);
            // ... if we have no changes from remote
            if(changesCount == 0) {
                // ... and we have no changes locally
                String lastLocalRevisionId = lastLocalRevision != -1 ? String.valueOf(lastLocalRevision) : "FIRST";
                if(fs.getLog(lastLocalRevisionId, "LAST", null, null, 1).size() == 0) {
                    // add a new record without the need to grab a new local revision
                    // (if necessary, that is, if at least the Central revision changed or if
                    // we don't have a synch history at all)
                    long newCentralRevision = request.getToVersion();
                    if(lastCentralRevision != newCentralRevision || record == null) {
                        SimpleFeatureType hft = (SimpleFeatureType) history.getSchema();
                        SimpleFeature f = SimpleFeatureBuilder.build(hft, new Object[] { tableName,
                                lastLocalRevision, newCentralRevision }, null);
                        history.addFeatures(DataUtilities.collection(f));
                    }
                   
                    // ... let's just return directly, no need to store or do anything
                    return new PostDiffResponseType();
                }
            }
           
            // setup the commit message and author
            transaction.putProperty(VersioningDataStore.AUTHOR, "gss");
            transaction.putProperty(VersioningDataStore.MESSAGE, "Applying " + changesCount
                    + " changes coming from Central on layer '" + tableName + "'");

            // grab the feature stores and bind them all to the same transaction
            VersioningFeatureStore conflicts = (VersioningFeatureStore) ds
                    .getFeatureSource(SYNCH_CONFLICTS);
            conflicts.setTransaction(transaction);
            history.setTransaction(transaction);
            fs.setTransaction(transaction);

            // get a hold on a revision number early so that we don't get concurrent changes
            // from the user (the datastore will make it so that no new revision numbers will
            // be generated until we commit or rollback this transaction
            long newLocalRevision = Long.parseLong(conflicts.getVersion());

            // apply changes
            LOGGER.info("About to apply " + core.countChanges(changes)
                    + " changes coming from Central");
            if (core.countChanges(changes) > 0) {
                List<DeleteElementType> deletes = changes.getDelete();
                List<UpdateElementType> updates = changes.getUpdate();

                // We need to find conflicts: local changes occurred since last synchronisation
                // that hit the same features contained in this changeset. For those we need
                // to create a conflict record and revert the local changes so that we
                // can apply the central ones
                Set<FeatureId> deletedFids = getEObjectFids(deletes);
                Set<FeatureId> updatedFids = getEObjectFids(updates);
                Set<FeatureId> changedFids = new HashSet<FeatureId>();
                changedFids.addAll(deletedFids);
                changedFids.addAll(updatedFids);

                // any possibility of conflict? If empty grabbing the corresponding local changes
                // will fail
                if (changedFids.size() > 0) {
                    // limit the changeset to the window between the last and the current
                    // synchronization
                    String newLocalRevisionId = String.valueOf(newLocalRevision);
                    String lastLocalRevisionId = lastLocalRevision != -1 ? String.valueOf(lastLocalRevision) : "FIRST";
                    FeatureDiffReader localChanges = fs.getDifferences(lastLocalRevisionId,
                            newLocalRevisionId, ff.id(changedFids), null);
                    while (localChanges.hasNext()) {
                        FeatureDiff fd = localChanges.next();
                        FeatureId diffFeatureId = ff.featureId(fd.getID());
                        if (fd.getState() == FeatureDiff.INSERTED) {
                            throw new GSSException(
                                    "A new locally inserted feature has the same "
                                            + "id as a modified feature coming from Central, this is impossible, "
                                            + "there is either a bug in ID generation or someone manually tampered with it!");
                        } else if (fd.getState() == FeatureDiff.DELETED) {
                            if (deletedFids.contains(diffFeatureId)) {
                                saveCleanMergeMarker(fs, conflicts, lastLocalRevisionId,
                                        newLocalRevision, fd.getID());
                            } else {
                                handleDeletionConflict(fs, conflicts, lastLocalRevisionId,
                                        newLocalRevision, fd.getID());
                            }
                        } else {
                            if (updatedFids.contains(diffFeatureId)) {
                                if (isSameUpdate(fd, findUpdate(fd.getID(), updates))) {
                                    saveCleanMergeMarker(fs, conflicts, lastLocalRevisionId,
                                            newLocalRevision, fd.getID());
                                } else {
                                    handleUpdateConflict(fs, conflicts, lastLocalRevisionId,
                                            newLocalRevision, fd.getID());
                                }
                            } else {
                                handleUpdateConflict(fs, conflicts, lastLocalRevisionId,
                                        newLocalRevision, fd.getID());
                            }
                        }
                    }
                    localChanges.close();
                }

                // now that conflicting local changes have been moved out of the way, apply the
                // central ones
                core.applyChanges(changes, fs);

            }

            // save/update the synchronisation metadata
            long newCentralRevision = request.getToVersion();
            SimpleFeatureType hft = (SimpleFeatureType) history.getSchema();
            SimpleFeature f = SimpleFeatureBuilder.build(hft, new Object[] { tableName,
                    newLocalRevision, newCentralRevision }, null);
            history.addFeatures(DataUtilities.collection(f));

            // commit all the changes
            transaction.commit();

            LOGGER.info(core.countChanges(changes)
View Full Code Here

    public void testReadOnlyFeatureStore() throws Exception {
        // build up the mock
        SimpleFeatureType schema = createNiceMock(SimpleFeatureType.class);
        expect(schema.getName()).andReturn(new NameImpl("testFT"));
        replay(schema);
        FeatureStore fs = createNiceMock(FeatureStore.class);
        expect(fs.getSchema()).andReturn(schema);
        replay(fs);
       
        SecuredFeatureStore ro = new SecuredFeatureStore(fs, WrapperPolicy.readOnlyChallenge(null));
        try {
            ro.addFeatures(createNiceMock(FeatureCollection.class));
View Full Code Here

    }

    protected LayerInfo buildLayer(String name, WorkspaceInfo ws,
            Class<? extends ResourceInfo> resourceClass) throws Exception {
       
        FeatureStore fs = createNiceMock(FeatureStore.class);
        replay(fs);
       
        DataStore dstore = createNiceMock(DataStore.class);
        replay(dstore);
       
View Full Code Here

    }

    public void testFullAccess() throws Exception {
        FeatureSource source = getFeatureSource(MockData.LINES);
        FeatureCollection fc = source.getFeatures();
        FeatureStore store = (FeatureStore) source;
        store.removeFeatures(Filter.INCLUDE);
    }
View Full Code Here

            // fine, we should not be able to get to the feature source
        }
    }

    public void testCannotWrite() throws Exception {
        FeatureStore fs = (FeatureStore) getFeatureSource(MockData.DELETES);
               
        try {
            fs.removeFeatures(Filter.INCLUDE);
            fail("This should have failed with a security exception!");
        } catch (SpringSecurityException e) {
            // fine, we should not be able to get to the feature source
        }
    }
View Full Code Here

            GeometryDescriptor geometryType = featureType.getGeometryDescriptor();
            crs = geometryType.getCoordinateReferenceSystem();
            // crs = neo4jDataStore.getFeatureSource(layerName).getInfo().getCRS();

            shpDataStore.createSchema(featureType);
            FeatureStore store = (FeatureStore) shpDataStore.getFeatureSource();
            store.addFeatures(neo4jDataStore.getFeatureSource(layerName).getFeatures());
            tx.success();
    }
        if (crs != null)
            shpDataStore.forceSchemaCRS(crs);
        if (!file.exists()) {
View Full Code Here

        store.createSchema(tb.buildFeatureType());
       
        CatalogBuilder cb = new CatalogBuilder(cat);
        cb.setStore(ds);
       
        FeatureStore fs = (FeatureStore) store.getFeatureSource("Fifteen");
        fs.addFeatures(fs1.getFeatures());
        FeatureTypeInfo ft = cb.buildFeatureType(fs);
        cat.add(ft);
       
        fs = (FeatureStore) store.getFeatureSource("Seven");
        fs.addFeatures(fs2.getFeatures());
        ft = cb.buildFeatureType(fs);
        cat.add(ft);
    }
View Full Code Here

        store.createSchema(tb.buildFeatureType());
       
        CatalogBuilder cb = new CatalogBuilder(cat);
        cb.setStore(ds);
       
        FeatureStore fs = (FeatureStore) store.getFeatureSource("Fifteen");
        addFeatures(fs, fs1.getFeatures());
       
        FeatureTypeInfo ft = cb.buildFeatureType(fs);
        cat.add(ft);
       
View Full Code Here

TOP

Related Classes of org.geotools.data.FeatureStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.