Search in sources :

Example 16 with Name

use of org.opengis.feature.type.Name in project GeoGig by boundlessgeo.

the class FormatCommonV1 method readFeatureType.

public static RevFeatureType readFeatureType(ObjectId id, DataInput in, FeatureTypeFactory typeFactory) throws IOException {
    Name name = readName(in);
    int propertyCount = in.readInt();
    List<AttributeDescriptor> attributes = new ArrayList<AttributeDescriptor>();
    for (int i = 0; i < propertyCount; i++) {
        attributes.add(readAttributeDescriptor(in, typeFactory));
    }
    SimpleFeatureType ftype = typeFactory.createSimpleFeatureType(name, attributes, null, false, Collections.<Filter>emptyList(), BasicFeatureTypes.FEATURE, null);
    return new RevFeatureTypeImpl(id, ftype);
}
Also used : RevFeatureTypeImpl(org.locationtech.geogig.api.RevFeatureTypeImpl) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) ArrayList(java.util.ArrayList) AttributeDescriptor(org.opengis.feature.type.AttributeDescriptor) Name(org.opengis.feature.type.Name)

Example 17 with Name

use of org.opengis.feature.type.Name in project GeoGig by boundlessgeo.

the class FormatCommonV1 method readAttributeDescriptor.

private static AttributeDescriptor readAttributeDescriptor(DataInput in, FeatureTypeFactory typeFactory) throws IOException {
    final Name name = readName(in);
    final boolean nillable = in.readBoolean();
    final int minOccurs = in.readInt();
    final int maxOccurs = in.readInt();
    final AttributeType type = readAttributeType(in, typeFactory);
    if (type instanceof GeometryType)
        return typeFactory.createGeometryDescriptor((GeometryType) type, name, minOccurs, maxOccurs, nillable, null);
    else
        return typeFactory.createAttributeDescriptor(type, name, minOccurs, maxOccurs, nillable, null);
}
Also used : GeometryType(org.opengis.feature.type.GeometryType) AttributeType(org.opengis.feature.type.AttributeType) Name(org.opengis.feature.type.Name)

Example 18 with Name

use of org.opengis.feature.type.Name in project GeoGig by boundlessgeo.

the class FormatCommonV1 method readAttributeType.

private static AttributeType readAttributeType(DataInput in, FeatureTypeFactory typeFactory) throws IOException {
    final Name name = readName(in);
    final byte typeTag = in.readByte();
    final FieldType type = FieldType.valueOf(typeTag);
    if (Geometry.class.isAssignableFrom(type.getBinding())) {
        // as opposed to a raw
        final boolean isCRSCode = in.readBoolean();
        // WKT string
        final String crsText = in.readUTF();
        final CoordinateReferenceSystem crs;
        try {
            if (isCRSCode) {
                if ("urn:ogc:def:crs:EPSG::0".equals(crsText)) {
                    crs = null;
                } else {
                    boolean forceLongitudeFirst = crsText.startsWith("EPSG:");
                    crs = CRS.decode(crsText, forceLongitudeFirst);
                }
            } else {
                crs = CRS.parseWKT(crsText);
            }
        } catch (FactoryException e) {
            throw new RuntimeException(e);
        }
        return typeFactory.createGeometryType(name, type.getBinding(), crs, false, false, Collections.<Filter>emptyList(), null, null);
    } else {
        return typeFactory.createAttributeType(name, type.getBinding(), false, false, Collections.<Filter>emptyList(), null, null);
    }
}
Also used : FactoryException(org.opengis.referencing.FactoryException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Name(org.opengis.feature.type.Name) FieldType(org.locationtech.geogig.storage.FieldType)

Example 19 with Name

use of org.opengis.feature.type.Name in project GeoGig by boundlessgeo.

the class FormatCommonV2 method readAttributeType.

private static AttributeType readAttributeType(DataInput in, FeatureTypeFactory typeFactory) throws IOException {
    final Name name = readName(in);
    final byte typeTag = in.readByte();
    final FieldType type = FieldType.valueOf(typeTag);
    if (Geometry.class.isAssignableFrom(type.getBinding())) {
        // as opposed to a raw WKT string
        final boolean isCRSCode = in.readBoolean();
        final String crsText = in.readUTF();
        final CoordinateReferenceSystem crs;
        try {
            if (isCRSCode) {
                if ("urn:ogc:def:crs:EPSG::0".equals(crsText)) {
                    crs = null;
                } else {
                    boolean forceLongitudeFirst = crsText.startsWith("EPSG:");
                    crs = CRS.decode(crsText, forceLongitudeFirst);
                }
            } else {
                crs = CRS.parseWKT(crsText);
            }
        } catch (FactoryException e) {
            throw new RuntimeException(e);
        }
        return typeFactory.createGeometryType(name, type.getBinding(), crs, false, false, Collections.<Filter>emptyList(), null, null);
    } else {
        return typeFactory.createAttributeType(name, type.getBinding(), false, false, Collections.<Filter>emptyList(), null, null);
    }
}
Also used : FactoryException(org.opengis.referencing.FactoryException) Integer.toBinaryString(java.lang.Integer.toBinaryString) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) Name(org.opengis.feature.type.Name) FieldType(org.locationtech.geogig.storage.FieldType)

Example 20 with Name

use of org.opengis.feature.type.Name in project GeoGig by boundlessgeo.

the class WorkingTreeTest method testDeleteCollection.

@Test
public void testDeleteCollection() throws Exception {
    List<Feature> featureList = new LinkedList<Feature>();
    featureList.add(points1);
    featureList.add(points2);
    featureList.add(points3);
    workTree.insert(pointsName, featureList.iterator(), LISTENER, null, 3);
    assertTrue(workTree.findUnstaged(appendChild(pointsName, idP1)).isPresent());
    assertTrue(workTree.findUnstaged(appendChild(pointsName, idP2)).isPresent());
    assertTrue(workTree.findUnstaged(appendChild(pointsName, idP3)).isPresent());
    List<Feature> deleteFeatures = new LinkedList<Feature>();
    deleteFeatures.add(points1);
    deleteFeatures.add(points3);
    Name typeName = points1.getName();
    workTree.delete(typeName, null, deleteFeatures.iterator());
    assertFalse(workTree.findUnstaged(appendChild(pointsName, idP1)).isPresent());
    assertTrue(workTree.findUnstaged(appendChild(pointsName, idP2)).isPresent());
    assertFalse(workTree.findUnstaged(appendChild(pointsName, idP3)).isPresent());
}
Also used : SimpleFeature(org.opengis.feature.simple.SimpleFeature) Feature(org.opengis.feature.Feature) LinkedList(java.util.LinkedList) Name(org.opengis.feature.type.Name) Test(org.junit.Test)

Aggregations

Name (org.opengis.feature.type.Name)26 WorkingTree (org.locationtech.geogig.repository.WorkingTree)9 Test (org.junit.Test)6 Node (org.locationtech.geogig.api.Node)5 SimpleFeatureType (org.opengis.feature.simple.SimpleFeatureType)5 ObjectId (org.locationtech.geogig.api.ObjectId)4 Feature (org.opengis.feature.Feature)4 SimpleFeature (org.opengis.feature.simple.SimpleFeature)4 ArrayList (java.util.ArrayList)3 GeoGIG (org.locationtech.geogig.api.GeoGIG)3 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)3 Optional (com.google.common.base.Optional)2 LinkedList (java.util.LinkedList)2 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)2 RevFeatureTypeImpl (org.locationtech.geogig.api.RevFeatureTypeImpl)2 FieldType (org.locationtech.geogig.storage.FieldType)2 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)2 AttributeType (org.opengis.feature.type.AttributeType)2 GeometryType (org.opengis.feature.type.GeometryType)2 FactoryException (org.opengis.referencing.FactoryException)2