Search in sources :

Example 6 with FieldType

use of org.locationtech.geogig.storage.FieldType in project GeoGig by boundlessgeo.

the class FormatCommonV1 method readFeature.

public static RevFeature readFeature(ObjectId id, DataInput in) throws IOException {
    final int count = in.readInt();
    final ImmutableList.Builder<Optional<Object>> builder = ImmutableList.builder();
    for (int i = 0; i < count; i++) {
        final byte fieldTag = in.readByte();
        final FieldType fieldType = FieldType.valueOf(fieldTag);
        Object value = DataStreamValueSerializerV1.read(fieldType, in);
        builder.add(Optional.fromNullable(value));
    }
    return new RevFeatureImpl(id, builder.build());
}
Also used : Optional(com.google.common.base.Optional) ImmutableList(com.google.common.collect.ImmutableList) RevFeatureImpl(org.locationtech.geogig.api.RevFeatureImpl) RevObject(org.locationtech.geogig.api.RevObject) FieldType(org.locationtech.geogig.storage.FieldType)

Example 7 with FieldType

use of org.locationtech.geogig.storage.FieldType 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 8 with FieldType

use of org.locationtech.geogig.storage.FieldType in project GeoGig by boundlessgeo.

the class FormatCommonV2 method writeFeature.

public static void writeFeature(RevFeature feature, DataOutput data) throws IOException {
    ImmutableList<Optional<Object>> values = feature.getValues();
    writeUnsignedVarInt(values.size(), data);
    for (Optional<Object> field : values) {
        FieldType type = FieldType.forValue(field);
        data.writeByte(type.getTag());
        if (type != FieldType.NULL) {
            DataStreamValueSerializerV2.write(field, data);
        }
    }
}
Also used : Optional(com.google.common.base.Optional) RevObject(org.locationtech.geogig.api.RevObject) FieldType(org.locationtech.geogig.storage.FieldType)

Example 9 with FieldType

use of org.locationtech.geogig.storage.FieldType in project GeoGig by boundlessgeo.

the class FormatCommonV2 method readFeature.

public static RevFeature readFeature(ObjectId id, DataInput in) throws IOException {
    final int count = readUnsignedVarInt(in);
    final ImmutableList.Builder<Optional<Object>> builder = ImmutableList.builder();
    for (int i = 0; i < count; i++) {
        final byte fieldTag = in.readByte();
        final FieldType fieldType = FieldType.valueOf(fieldTag);
        Object value = DataStreamValueSerializerV2.read(fieldType, in);
        builder.add(Optional.fromNullable(value));
    }
    return new RevFeatureImpl(id, builder.build());
}
Also used : Optional(com.google.common.base.Optional) ImmutableList(com.google.common.collect.ImmutableList) RevFeatureImpl(org.locationtech.geogig.api.RevFeatureImpl) RevObject(org.locationtech.geogig.api.RevObject) FieldType(org.locationtech.geogig.storage.FieldType)

Aggregations

FieldType (org.locationtech.geogig.storage.FieldType)9 Optional (com.google.common.base.Optional)5 RevObject (org.locationtech.geogig.api.RevObject)5 ImmutableList (com.google.common.collect.ImmutableList)2 RevFeatureImpl (org.locationtech.geogig.api.RevFeatureImpl)2 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)2 AttributeDescriptor (org.opengis.feature.type.AttributeDescriptor)2 Name (org.opengis.feature.type.Name)2 FactoryException (org.opengis.referencing.FactoryException)2 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 Point (com.vividsolutions.jts.geom.Point)1 Integer.toBinaryString (java.lang.Integer.toBinaryString)1 Time (java.sql.Time)1 Timestamp (java.sql.Timestamp)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)1 NodeRef (org.locationtech.geogig.api.NodeRef)1 RevCommit (org.locationtech.geogig.api.RevCommit)1