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;
}
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);
}
}
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);
}
}
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);
}
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;
}
Aggregations