Search in sources :

Example 16 with SimpleFeatureType

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

the class OSMUtils method nodeType.

public static synchronized SimpleFeatureType nodeType() {
    if (NodeType == null) {
        String typeSpec = "visible:Boolean,version:Integer,timestamp:java.lang.Long,tags:String," + "changeset:java.lang.Long,user:String,location:Point:srid=4326";
        try {
            SimpleFeatureType type = DataUtilities.createType(NAMESPACE, OSMUtils.NODE_TYPE_NAME, typeSpec);
            boolean longitudeFirst = true;
            CoordinateReferenceSystem forceLonLat = CRS.decode("EPSG:4326", longitudeFirst);
            NodeType = DataUtilities.createSubType(type, null, forceLonLat);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
    return NodeType;
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 17 with SimpleFeatureType

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

the class OSMUtils method wayType.

public static synchronized SimpleFeatureType wayType() {
    if (WayType == null) {
        String typeSpec = "visible:Boolean,version:Integer,timestamp:java.lang.Long,tags:String," + "changeset:java.lang.Long,user:String,nodes:String,way:LineString:srid=4326";
        try {
            SimpleFeatureType type = DataUtilities.createType(NAMESPACE, OSMUtils.WAY_TYPE_NAME, typeSpec);
            boolean longitudeFirst = true;
            CoordinateReferenceSystem forceLonLat = CRS.decode("EPSG:4326", longitudeFirst);
            WayType = DataUtilities.createSubType(type, null, forceLonLat);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
    return WayType;
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 18 with SimpleFeatureType

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

the class RevFeatureTypeSerializationTest method testSerializationWGS84.

@Test
public void testSerializationWGS84() throws Exception {
    SimpleFeatureTypeBuilder ftb = new SimpleFeatureTypeBuilder();
    ftb.add("geom", Polygon.class, DefaultGeographicCRS.WGS84);
    ftb.setName("type");
    SimpleFeatureType ftype = ftb.buildFeatureType();
    RevFeatureType revFeatureType = RevFeatureTypeImpl.build(ftype);
    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);
    FeatureType serializedFeatureType = rft.type();
    assertEquals("EPSG:4326", CRS.toSRS(serializedFeatureType.getCoordinateReferenceSystem()));
}
Also used : RevFeatureType(org.locationtech.geogig.api.RevFeatureType) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) FeatureType(org.opengis.feature.type.FeatureType) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) 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 19 with SimpleFeatureType

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

the class GeoGigFeatureStoreTest method testAddFeaturesOnASeparateBranch.

@Test
public void testAddFeaturesOnASeparateBranch() throws Exception {
    final String branchName = "addtest";
    final Ref branchRef = geogig.command(BranchCreateOp.class).setName(branchName).call();
    dataStore.setHead(branchName);
    FeatureCollection<SimpleFeatureType, SimpleFeature> collection;
    collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3));
    Transaction tx = new DefaultTransaction();
    points.setTransaction(tx);
    assertSame(tx, points.getTransaction());
    try {
        List<FeatureId> addedFeatures = points.addFeatures(collection);
        assertNotNull(addedFeatures);
        assertEquals(3, addedFeatures.size());
        // assert transaction isolation
        assertEquals(3, points.getFeatures().size());
        assertEquals(0, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
        tx.commit();
        assertEquals(3, dataStore.getFeatureSource(pointsTypeName).getFeatures().size());
    } catch (Exception e) {
        tx.rollback();
        throw e;
    } finally {
        tx.close();
    }
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) Ref(org.locationtech.geogig.api.Ref) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) Test(org.junit.Test)

Example 20 with SimpleFeatureType

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

the class GeoGigFeatureStoreTest method testUseProvidedFIDSupported.

@Test
public void testUseProvidedFIDSupported() throws Exception {
    assertTrue(points.getQueryCapabilities().isUseProvidedFIDSupported());
    FeatureCollection<SimpleFeatureType, SimpleFeature> collection;
    collection = DataUtilities.collection(Arrays.asList((SimpleFeature) points1, (SimpleFeature) points2, (SimpleFeature) points3));
    Transaction tx = new DefaultTransaction();
    points.setTransaction(tx);
    try {
        List<FeatureId> newFids = points.addFeatures(collection);
        assertNotNull(newFids);
        assertEquals(3, newFids.size());
        FeatureId fid1 = newFids.get(0);
        FeatureId fid2 = newFids.get(1);
        FeatureId fid3 = newFids.get(2);
        // new ids should have been generated...
        assertFalse(idP1.equals(fid1.getID()));
        assertFalse(idP1.equals(fid1.getID()));
        assertFalse(idP1.equals(fid1.getID()));
        // now force the use of provided feature ids
        points1.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
        points2.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
        points3.getUserData().put(Hints.USE_PROVIDED_FID, Boolean.TRUE);
        List<FeatureId> providedFids = points.addFeatures(collection);
        assertNotNull(providedFids);
        assertEquals(3, providedFids.size());
        FeatureId fid11 = providedFids.get(0);
        FeatureId fid21 = providedFids.get(1);
        FeatureId fid31 = providedFids.get(2);
        // ids should match provided
        assertEquals(idP1, fid11.getID());
        assertEquals(idP2, fid21.getID());
        assertEquals(idP3, fid31.getID());
        tx.commit();
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid1))).size());
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid2))).size());
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid3))).size());
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid11))).size());
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid21))).size());
        assertEquals(1, points.getFeatures(ff.id(Collections.singleton(fid31))).size());
    } catch (Exception e) {
        tx.rollback();
        throw e;
    } finally {
        tx.close();
    }
}
Also used : FeatureId(org.opengis.filter.identity.FeatureId) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Transaction(org.geotools.data.Transaction) DefaultTransaction(org.geotools.data.DefaultTransaction) SimpleFeature(org.opengis.feature.simple.SimpleFeature) DefaultTransaction(org.geotools.data.DefaultTransaction) Test(org.junit.Test)

Aggregations

SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)149 SimpleFeature (org.opengis.feature.simple.SimpleFeature)75 Test (org.junit.Test)47 IOException (java.io.IOException)46 SimpleFeatureSource (org.geotools.data.simple.SimpleFeatureSource)29 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)24 DataStore (org.geotools.data.DataStore)23 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)23 SimpleFeatureStore (org.geotools.data.simple.SimpleFeatureStore)21 HashMap (java.util.HashMap)20 ObjectId (org.locationtech.geogig.api.ObjectId)20 SimpleFeatureTypeBuilder (org.geotools.feature.simple.SimpleFeatureTypeBuilder)19 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)18 Feature (org.opengis.feature.Feature)18 ArrayList (java.util.ArrayList)16 File (java.io.File)15 SimpleFeatureIterator (org.geotools.data.simple.SimpleFeatureIterator)15 NodeRef (org.locationtech.geogig.api.NodeRef)15 InvalidParameterException (org.locationtech.geogig.cli.InvalidParameterException)15 DefaultTransaction (org.geotools.data.DefaultTransaction)14