use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.
the class UnionDemo method buildFeatureUnionList.
/**
* Build the second FeatureCollection usind createSimpleType2() as FeatureType.
* It define 4 features with basic geometry and property.
* @return FeatureCollection
*/
private static FeatureCollection buildFeatureUnionList() {
try {
type = createSimpleType2();
} catch (FactoryException ex) {
Logger.getLogger("org.geotoolkit.pending.demo.processing").log(Level.SEVERE, null, ex);
}
final FeatureCollection featureList = FeatureStoreUtilities.collection("", type);
Feature myFeature1 = type.newInstance();
LinearRing ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(4.0, 4.0), new Coordinate(4.0, 8.0), new Coordinate(7.0, 8.0), new Coordinate(7.0, 4.0), new Coordinate(4.0, 4.0) });
myFeature1.setPropertyValue("id", "id-11");
myFeature1.setPropertyValue("name", "feature11");
myFeature1.setPropertyValue("color", "red");
myFeature1.setPropertyValue("geom3", geometryFactory.createPolygon(ring, null));
myFeature1.setPropertyValue("att", 20);
featureList.add(myFeature1);
Feature myFeature2 = type.newInstance();
ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(7.0, 4.0), new Coordinate(7.0, 8.0), new Coordinate(9.0, 8.0), new Coordinate(9.0, 4.0), new Coordinate(7.0, 4.0) });
myFeature2.setPropertyValue("id", "id-12");
myFeature2.setPropertyValue("name", "feature12");
myFeature2.setPropertyValue("color", "blue");
myFeature2.setPropertyValue("geom3", geometryFactory.createPolygon(ring, null));
myFeature2.setPropertyValue("att", 20);
featureList.add(myFeature2);
Feature myFeature3 = type.newInstance();
ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(6.0, 2.0), new Coordinate(6.0, 4.0), new Coordinate(9.0, 4.0), new Coordinate(9.0, 2.0), new Coordinate(6.0, 2.0) });
myFeature3.setPropertyValue("id", "id-13");
myFeature3.setPropertyValue("name", "feature13");
myFeature3.setPropertyValue("color", "grey");
myFeature3.setPropertyValue("geom3", geometryFactory.createPolygon(ring, null));
myFeature3.setPropertyValue("att", 10);
featureList.add(myFeature3);
Feature myFeature4 = type.newInstance();
ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(4.0, 2.0), new Coordinate(4.0, 3.0), new Coordinate(5.0, 3.0), new Coordinate(5.0, 2.0), new Coordinate(4.0, 2.0) });
myFeature4.setPropertyValue("id", "id-14");
myFeature4.setPropertyValue("name", "feature14");
myFeature4.setPropertyValue("color", "grey");
myFeature4.setPropertyValue("geom3", geometryFactory.createPolygon(ring, null));
myFeature4.setPropertyValue("att", 12);
featureList.add(myFeature4);
Feature myFeature5 = type.newInstance();
ring = geometryFactory.createLinearRing(new Coordinate[] { new Coordinate(2.0, 5.0), new Coordinate(2.0, 6.0), new Coordinate(3.0, 6.0), new Coordinate(3.0, 5.0), new Coordinate(2.0, 5.0) });
myFeature5.setPropertyValue("id", "id-15");
myFeature5.setPropertyValue("name", "feature15");
myFeature5.setPropertyValue("color", "grey");
myFeature5.setPropertyValue("geom3", geometryFactory.createPolygon(ring, null));
myFeature5.setPropertyValue("att", 12);
featureList.add(myFeature5);
return featureList;
}
use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method testLoadAndVerify.
@Test
public void testLoadAndVerify() throws Exception {
FeatureCollection features = loadFeatures(STATE_POP, new Query(NamesExt.create("statepop")));
// FeatureCollection<SimpleFeatureType, SimpleFeature> features = loadFeaturesM2();
int count = features.size();
assertTrue("Have features", count > 0);
// assertEquals("Number of Features loaded",49,features.size()); // FILE
// (correct value)
// assertEquals("Number of Features loaded",3, count); // JAR
Feature firstFeature = firstFeature(features);
FeatureType schema = firstFeature.getType();
assertNotNull(FeatureExt.getDefaultGeometry(schema));
assertEquals("Number of Attributes", 256, schema.getProperties(true).size());
assertEquals("Value of statename is wrong", "Illinois", firstFeature.getPropertyValue("STATE_NAME"));
assertEquals("Value of land area is wrong", 143986.61, ((Double) firstFeature.getPropertyValue("LAND_KM")).doubleValue(), 0.001);
}
use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.
the class ShapefileDataStoreTest method testUpdating.
/**
* Create a set of features, then remove every other one, updating the
* remaining. Test for removal and proper update after reloading...
*/
@Test
public void testUpdating() throws Throwable {
ShapefileFeatureStore sds = createDataStore();
loadFeatures(sds);
FeatureWriter writer = null;
try {
writer = sds.getFeatureWriter(new Query(sds.getNames().iterator().next()));
while (writer.hasNext()) {
Feature feat = writer.next();
Byte b = (Byte) feat.getPropertyValue("b");
if (b.byteValue() % 2 == 0) {
writer.remove();
} else {
feat.setPropertyValue("b", new Byte((byte) -1));
}
}
} finally {
if (writer != null) {
writer.close();
}
}
FeatureCollection fc = loadFeatures(sds);
assertEquals(10, fc.size());
FeatureIterator i = fc.iterator();
for (; i.hasNext(); ) {
assertEquals(-1, ((Byte) (i.next()).getPropertyValue("b")).byteValue());
}
i.close();
}
use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.
the class ShapefileReadWriteTest method test.
private void test(final FeatureType type, final FeatureCollection original, final File tmp, final ShapefileProvider maker, final boolean memorymapped, final Charset charset) throws IOException, MalformedURLException, Exception {
ShapefileFeatureStore shapefile;
GenericName typeName = type.getName();
final ParameterValueGroup params = maker.getOpenParameters().createValue();
params.parameter(ShapefileProvider.LOCATION).setValue(tmp.toURI());
params.parameter(ShapefileProvider.MEMORY_MAPPED.getName().toString()).setValue(memorymapped);
params.parameter(ShapefileProvider.DBFCHARSET.getName().toString()).setValue(charset);
shapefile = (ShapefileFeatureStore) maker.open(params);
shapefile.createFeatureType(type);
Session session = shapefile.createSession(true);
session.addFeatures(typeName.toString(), original);
session.commit();
assertFalse(session.hasPendingChanges());
FeatureCollection copy = session.getFeatureCollection(new Query(typeName));
compare(original, copy);
// review open
ShapefileFeatureStore review = new ShapefileFeatureStore(tmp.toURI(), memorymapped, charset);
typeName = review.getNames().iterator().next();
FeatureCollection again = review.createSession(true).getFeatureCollection(new Query(typeName));
compare(copy, again);
compare(original, again);
}
use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.
the class ShapefileTest method testHolyPolygons.
@Test
public void testHolyPolygons() throws Exception {
final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
ftb.setName("test");
ftb.addAttribute(MultiPolygon.class).setName("a").addRole(AttributeRole.DEFAULT_GEOMETRY);
final FeatureType type = ftb.build();
Collection<Feature> features = new ArrayList<>();
File tmpFile = getTempFile();
tmpFile.delete();
// write features
ShapefileProvider make = new ShapefileProvider();
String pathId = ShapefileProvider.PATH.getName().getCode();
FeatureStore s = (FeatureStore) make.create(Parameters.toParameter(Collections.singletonMap(pathId, tmpFile.toURI().toURL()), make.getOpenParameters()));
s.createFeatureType(type);
GenericName typeName = type.getName();
Session session = s.createSession(true);
session.addFeatures(typeName.toString(), features);
session.commit();
s = new ShapefileFeatureStore(tmpFile.toURI());
typeName = s.getNames().iterator().next();
FeatureCollection fc = s.createSession(true).getFeatureCollection(new Query(typeName));
ShapefileReadWriteTest.compare(features, fc);
}
Aggregations