Search in sources :

Example 46 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class RevFeatureTypeSerializationTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    RevFeatureType revFeatureType = RevFeatureTypeImpl.build(featureType);
    ObjectWriter<RevFeatureType> writer = factory.createObjectWriter(TYPE.FEATURETYPE);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    writer.write(revFeatureType, output);
    byte[] data = output.toByteArray();
    assertTrue(data.length > 0);
    ObjectReader<RevFeatureType> reader = factory.createObjectReader(TYPE.FEATURETYPE);
    ByteArrayInputStream input = new ByteArrayInputStream(data);
    RevFeatureType rft = reader.read(revFeatureType.getId(), input);
    assertNotNull(rft);
    SimpleFeatureType serializedFeatureType = (SimpleFeatureType) rft.type();
    assertEquals(serializedFeatureType.getDescriptors().size(), featureType.getDescriptors().size());
    for (int i = 0; i < featureType.getDescriptors().size(); i++) {
        assertEquals(featureType.getDescriptor(i), serializedFeatureType.getDescriptor(i));
    }
    assertEquals(featureType.getGeometryDescriptor(), serializedFeatureType.getGeometryDescriptor());
    assertEquals(featureType.getCoordinateReferenceSystem(), serializedFeatureType.getCoordinateReferenceSystem());
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) Test(org.junit.Test)

Example 47 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class GeoGigDataStoreTest method testGetSchemaProvidedNamespace.

@Test
public void testGetSchemaProvidedNamespace() throws Exception {
    String namespace = "http://www.geogig.org/test";
    dataStore.setNamespaceURI(namespace);
    insertAndAdd(lines1);
    commit();
    SimpleFeatureType lines = dataStore.getSchema(RepositoryTestCase.linesTypeName);
    Name expectedName = new NameImpl(namespace, linesName);
    assertEquals(expectedName, lines.getName());
    assertEquals(super.linesType.getAttributeDescriptors(), lines.getAttributeDescriptors());
    insertAndAdd(points1);
    commit();
    SimpleFeatureType points = dataStore.getSchema(RepositoryTestCase.pointsTypeName);
    assertEquals(new NameImpl(namespace, pointsName), points.getName());
    assertEquals(super.pointsType.getAttributeDescriptors(), points.getAttributeDescriptors());
}
Also used : NameImpl(org.geotools.feature.NameImpl) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) LineString(com.vividsolutions.jts.geom.LineString) Name(org.opengis.feature.type.Name) Test(org.junit.Test)

Example 48 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class GeoGigDataStoreTest method testFeatureWriterAppend.

@Test
public void testFeatureWriterAppend() throws Exception {
    dataStore.createSchema(linesType);
    Transaction tx = new DefaultTransaction();
    FeatureWriter<SimpleFeatureType, SimpleFeature> fw = dataStore.getFeatureWriterAppend(linesTypeName.getLocalPart(), tx);
    LineString line = new GeometryBuilder().lineString(0, 0, 1, 1);
    SimpleFeature f = (SimpleFeature) fw.next();
    f.setAttribute("sp", "foo");
    f.setAttribute("ip", 10);
    f.setAttribute("pp", line);
    fw.write();
    fw.close();
    tx.commit();
    FeatureSource<SimpleFeatureType, SimpleFeature> source = dataStore.getFeatureSource(linesTypeName);
    assertEquals(1, source.getCount(null));
    FeatureReader<SimpleFeatureType, SimpleFeature> r = dataStore.getFeatureReader(new Query(linesTypeName.getLocalPart()), Transaction.AUTO_COMMIT);
    assertTrue(r.hasNext());
    f = r.next();
    assertEquals("foo", f.getAttribute("sp"));
    assertEquals(10, f.getAttribute("ip"));
    assertTrue(line.equals((Geometry) f.getAttribute("pp")));
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Query(org.geotools.data.Query) LineString(com.vividsolutions.jts.geom.LineString) GeometryBuilder(org.geotools.geometry.jts.GeometryBuilder) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) Test(org.junit.Test)

Example 49 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class GeoGigDataStoreTest method testCreateSchemaOnBranch.

@Test
public void testCreateSchemaOnBranch() throws IOException {
    final String branchName = "testBranch";
    geogig.command(BranchCreateOp.class).setName(branchName).setOrphan(true).call();
    dataStore.setHead(branchName);
    final SimpleFeatureType featureType = super.linesType;
    dataStore.createSchema(featureType);
    List<String> typeNames;
    typeNames = getTypeNames(Ref.HEAD);
    assertTrue(typeNames.isEmpty());
    typeNames = getTypeNames(branchName);
    assertEquals(1, typeNames.size());
    assertEquals(linesName, typeNames.get(0));
    dataStore.createSchema(super.pointsType);
    typeNames = getTypeNames(Ref.HEAD);
    assertTrue(typeNames.isEmpty());
    typeNames = getTypeNames(branchName);
    assertEquals(2, typeNames.size());
    assertTrue(typeNames.contains(linesName));
    assertTrue(typeNames.contains(pointsName));
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) BranchCreateOp(org.locationtech.geogig.api.porcelain.BranchCreateOp) LineString(com.vividsolutions.jts.geom.LineString) Test(org.junit.Test)

Example 50 with SimpleFeatureType

use of org.opengis.feature.simple.SimpleFeatureType in project GeoGig by boundlessgeo.

the class GeoGigDataStoreTest method testCreateSchema.

@Test
public void testCreateSchema() throws IOException {
    final SimpleFeatureType featureType = super.linesType;
    dataStore.createSchema(featureType);
    List<String> typeNames;
    typeNames = getTypeNames(Ref.HEAD);
    assertEquals(1, typeNames.size());
    assertEquals(linesName, typeNames.get(0));
    dataStore.createSchema(super.pointsType);
    typeNames = getTypeNames(Ref.HEAD);
    assertEquals(2, typeNames.size());
    assertTrue(typeNames.contains(linesName));
    assertTrue(typeNames.contains(pointsName));
    try {
        dataStore.createSchema(super.pointsType);
        fail("Expected IOException on existing type");
    } catch (IOException e) {
        assertTrue(e.getMessage().contains("already exists"));
    }
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) LineString(com.vividsolutions.jts.geom.LineString) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)80 SimpleFeature (org.opengis.feature.simple.SimpleFeature)35 Test (org.junit.Test)22 IOException (java.io.IOException)20 ObjectId (org.locationtech.geogig.api.ObjectId)20 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)18 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)17 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)15 NodeRef (org.locationtech.geogig.api.NodeRef)15 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)15 Feature (org.opengis.feature.Feature)14 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)12 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)12 Optional (com.google.common.base.Optional)10 RevTree (org.locationtech.geogig.api.RevTree)10 CommandFailedException (org.locationtech.geogig.cli.CommandFailedException)10 GeoToolsOpException (org.locationtech.geogig.geotools.plumbing.GeoToolsOpException)10 DefaultTransaction (org.geotools.data.DefaultTransaction)9 ExportOp (org.locationtech.geogig.geotools.plumbing.ExportOp)9 Function (com.google.common.base.Function)8