Search in sources :

Example 21 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class GeometryFactory method getGeometryDataTypes.

private static Set<DataType> getGeometryDataTypes(final Collection<? extends Geometry> geometries) {
    final Set<DataType> dataTypes = new LinkedHashSet<>();
    for (final Geometry geometry : geometries) {
        final DataType dataType = geometry.getDataType();
        dataTypes.add(dataType);
    }
    return dataTypes;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataType(com.revolsys.datatype.DataType)

Example 22 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class GeometryFactory method buildGeometry.

/**
 *  Build an appropriate <code>Geometry</code>, <code>MultiGeometry</code>, or
 *  <code>GeometryCollection</code> to contain the <code>Geometry</code>s in
 *  it.
 * For example:<br>
 *
 *  <ul>
 *    <li> If <code>geomList</code> contains a single <code>Polygon</code>,
 *    the <code>Polygon</code> is returned.
 *    <li> If <code>geomList</code> contains several <code>Polygon</code>s, a
 *    <code>MultiPolygon</code> is returned.
 *    <li> If <code>geomList</code> contains some <code>Polygon</code>s and
 *    some <code>LineString</code>s, a <code>GeometryCollection</code> is
 *    returned.
 *    <li> If <code>geomList</code> is empty, an empty <code>GeometryCollection</code>
 *    is returned
 *  </ul>
 *
 * Note that this method does not "flatten" Geometries in the input, and hence if
 * any MultiGeometries are contained in the input a GeometryCollection containing
 * them will be returned.
 *
 *@param  geometries  the <code>Geometry</code>s to combine
 *@return           a <code>Geometry</code> of the "smallest", "most
 *      type-specific" class that can contain the elements of <code>geomList</code>
 *      .
 */
public Geometry buildGeometry(final Iterable<? extends Geometry> geometries) {
    DataType collectionDataType = null;
    boolean isHeterogeneous = false;
    boolean hasGeometryCollection = false;
    final List<Geometry> geometryList = new ArrayList<>();
    for (final Geometry geometry : geometries) {
        if (geometry != null) {
            geometryList.add(geometry);
            DataType geometryDataType = geometry.getDataType();
            if (geometry instanceof LinearRing) {
                geometryDataType = DataTypes.LINE_STRING;
            }
            if (collectionDataType == null) {
                collectionDataType = geometryDataType;
            } else if (geometryDataType != collectionDataType) {
                isHeterogeneous = true;
            }
            if (geometry.isGeometryCollection()) {
                hasGeometryCollection = true;
            }
        }
    }
    /**
     * Now construct an appropriate geometry to return
     */
    if (collectionDataType == null) {
        return geometryCollection();
    } else if (isHeterogeneous || hasGeometryCollection) {
        return geometryCollection(geometryList);
    } else if (geometryList.size() == 1) {
        return geometryList.iterator().next();
    } else if (DataTypes.POINT.equals(collectionDataType)) {
        return punctual(geometryList);
    } else if (DataTypes.LINE_STRING.equals(collectionDataType)) {
        return lineal(geometryList);
    } else if (DataTypes.POLYGON.equals(collectionDataType)) {
        return polygonal(geometryList);
    } else {
        throw new IllegalArgumentException("Unknown geometry type " + collectionDataType);
    }
}
Also used : ArrayList(java.util.ArrayList) DataType(com.revolsys.datatype.DataType)

Example 23 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class JsonRecordWriter method write.

@Override
public void write(final Record record) {
    try {
        final Writer out = this.out;
        if (this.written) {
            out.write(",\n");
        } else {
            writeHeader();
        }
        startObject();
        boolean hasValue = false;
        for (final FieldDefinition field : this.recordDefinition.getFields()) {
            final int fieldIndex = field.getIndex();
            final Object value;
            if (isWriteCodeValues()) {
                value = record.getCodeValue(fieldIndex);
            } else {
                value = record.getValue(fieldIndex);
            }
            if (isValueWritable(value)) {
                if (hasValue) {
                    this.out.write(",\n");
                } else {
                    hasValue = true;
                }
                final String name = field.getName();
                label(name);
                final DataType dataType = field.getDataType();
                value(dataType, value);
            }
        }
        endObject();
    } catch (final IOException e) {
        throw Exceptions.wrap(e);
    }
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) IOException(java.io.IOException) AbstractRecordWriter(com.revolsys.io.AbstractRecordWriter) Writer(java.io.Writer)

Example 24 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class JsonSchemaWriter method write.

public void write(final RecordDefinition recordDefinition) {
    final Map<String, Object> recordDefinitionMap = new LinkedHashMap<>();
    recordDefinitionMap.put("name", recordDefinition.getPath());
    final List<Map<String, Object>> fields = new ArrayList<>();
    recordDefinitionMap.put("fields", fields);
    for (final FieldDefinition attribute : recordDefinition.getFields()) {
        final Map<String, Object> field = new LinkedHashMap<>();
        final String name = attribute.getName();
        field.put("name", name);
        final DataType dataType = attribute.getDataType();
        final String dataTypeName = dataType.getName();
        field.put("type", dataTypeName);
        final int length = attribute.getLength();
        if (length > 0) {
            field.put("length", length);
        }
        final int scale = attribute.getScale();
        if (scale > 0) {
            field.put("scale", scale);
        }
        final boolean required = attribute.isRequired();
        field.put("required", required);
        final Map<String, ?> attributeProperties = attribute.getProperties();
        final Map<String, Object> fieldProperties = toJsonMap(attributeProperties);
        if (!fieldProperties.isEmpty()) {
            field.put("properties", fieldProperties);
        }
        fields.add(field);
    }
    this.writer.write(recordDefinitionMap);
}
Also used : FieldDefinition(com.revolsys.record.schema.FieldDefinition) ArrayList(java.util.ArrayList) DataType(com.revolsys.datatype.DataType) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 25 with DataType

use of com.revolsys.datatype.DataType in project com.revolsys.open by revolsys.

the class FeatureLayer method getGeometryDataType.

private DataType getGeometryDataType(final String geometryType) {
    DataType geometryDataType = null;
    if (Property.hasValue(geometryType)) {
        final GeometryType esriGeometryType = GeometryType.valueOf(geometryType);
        geometryDataType = esriGeometryType.getDataType();
        if (geometryDataType == null) {
            throw new IllegalArgumentException("Unsupported geometryType=" + geometryType + " for " + getServiceUrl());
        }
    }
    return geometryDataType;
}
Also used : GeometryType(com.revolsys.record.io.format.esri.gdb.xml.model.enums.GeometryType) DataType(com.revolsys.datatype.DataType)

Aggregations

DataType (com.revolsys.datatype.DataType)85 FieldDefinition (com.revolsys.record.schema.FieldDefinition)32 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)23 PathName (com.revolsys.io.PathName)13 RecordDefinition (com.revolsys.record.schema.RecordDefinition)11 Geometry (com.revolsys.geometry.model.Geometry)10 Record (com.revolsys.record.Record)10 RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)10 ArrayList (java.util.ArrayList)8 ArrayRecord (com.revolsys.record.ArrayRecord)6 PrintWriter (java.io.PrintWriter)6 EsriGeodatabaseXmlFieldType (com.revolsys.record.io.format.esri.gdb.xml.type.EsriGeodatabaseXmlFieldType)5 MapEx (com.revolsys.collection.map.MapEx)4 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)4 Point (com.revolsys.geometry.model.Point)4 IOException (java.io.IOException)4 Map (java.util.Map)4 CollectionDataType (com.revolsys.datatype.CollectionDataType)3 EnumerationDataType (com.revolsys.datatype.EnumerationDataType)3 CodeTable (com.revolsys.record.code.CodeTable)3