use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class CsvRecordWriter method write.
@Override
public void write(final Record record) {
Writer out = this.out;
if (this.paused) {
this.paused = false;
final Resource resource = getResource();
out = this.out = resource.newWriterAppend();
}
if (out != null) {
try {
final RecordDefinition recordDefinition = this.recordDefinition;
final char fieldSeparator = this.fieldSeparator;
boolean first = true;
for (final FieldDefinition field : recordDefinition.getFields()) {
if (first) {
first = false;
} else {
out.write(fieldSeparator);
}
final String fieldName = field.getName();
final Object value;
if (isWriteCodeValues()) {
value = record.getCodeValue(fieldName);
} else {
value = record.getValue(fieldName);
}
if (value instanceof Geometry) {
final Geometry geometry = (Geometry) value;
if (this.useQuotes) {
out.write('"');
EWktWriter.write(out, geometry, this.ewkt);
out.write('"');
} else {
EWktWriter.write(out, geometry, this.ewkt);
}
} else if (value != null) {
final DataType dataType = field.getDataType();
final String stringValue = dataType.toString(value);
if (dataType.isRequiresQuotes()) {
string(stringValue);
} else {
out.write(stringValue, 0, stringValue.length());
}
}
}
out.write('\n');
} catch (final IOException e) {
throw Exceptions.wrap(e);
}
}
}
use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class DirectoryRecordWriter method getWriter.
private Writer<Record> getWriter(final Record record) {
final RecordDefinition recordDefinition = record.getRecordDefinition();
final String path = recordDefinition.getPath();
Writer<Record> writer = this.writers.get(path);
if (writer == null) {
final File directory = getDirectory(recordDefinition);
directory.mkdirs();
final String fileName = getFileName(recordDefinition);
final File file = new File(directory, fileName + this.nameSuffix + "." + this.fileExtension);
final PathResource resource = new PathResource(file);
writer = RecordWriter.newRecordWriter(recordDefinition, resource);
if (writer == null) {
throw new IllegalArgumentException("Unable to create writer for " + resource);
} else {
final Map<String, Object> properties = getProperties();
writer.setProperties(properties);
final Geometry geometry = record.getGeometry();
if (geometry != null) {
final GeometryFactory geometryFactory = geometry.getGeometryFactory();
setProperty(IoConstants.GEOMETRY_FACTORY, geometryFactory);
}
this.writers.put(path, writer);
RecordDefinition writerRecordDefinition = recordDefinition;
if (writer instanceof AbstractRecordWriter) {
final AbstractRecordWriter recordWriter = (AbstractRecordWriter) writer;
writerRecordDefinition = recordWriter.getRecordDefinition();
if (writerRecordDefinition == null) {
writerRecordDefinition = recordDefinition;
}
}
this.recordDefinitionMap.put(path, writerRecordDefinition);
}
}
return writer;
}
use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class ShapefileGeometryUtil method writePolygon.
private List<LineString> writePolygon(final EndianOutput out, final Geometry geometry, final int shapeType, final int headerOverhead, final int wordsPerPoint) throws IOException {
int vertexCount = 0;
final List<LineString> rings = new ArrayList<>();
for (int i = 0; i < geometry.getGeometryCount(); i++) {
final Geometry part = geometry.getGeometry(i);
if (part instanceof Polygon) {
final Polygon polygon = (Polygon) part;
LineString shell = polygon.getShell();
shell = shell.toClockwise();
rings.add(shell);
vertexCount += shell.getVertexCount();
final int numHoles = polygon.getHoleCount();
for (int j = 0; j < numHoles; j++) {
LineString hole = polygon.getHole(j);
hole = hole.toCounterClockwise();
rings.add(hole);
vertexCount += hole.getVertexCount();
}
} else {
throw new IllegalArgumentException("Expecting " + Polygon.class + " geometry got " + part.getClass());
}
}
final int numParts = rings.size();
if (this.writeLength) {
final int recordLength = 22 + headerOverhead + 2 * numParts + wordsPerPoint * vertexCount;
out.writeInt(recordLength);
}
out.writeLEInt(shapeType);
final BoundingBox envelope = geometry.getBoundingBox();
writeEnvelope(out, envelope);
out.writeLEInt(numParts);
out.writeLEInt(vertexCount);
int partIndex = 0;
for (final LineString ring : rings) {
out.writeLEInt(partIndex);
partIndex += ring.getVertexCount();
}
for (final LineString ring : rings) {
writeXYCoordinates(out, ring);
}
return rings;
}
use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class ShapefileDirectoryWriter method getWriter.
private Writer<Record> getWriter(final Record object) {
final RecordDefinition recordDefinition = object.getRecordDefinition();
final String path = recordDefinition.getPath();
Writer<Record> writer = this.writers.get(path);
if (writer == null) {
final File directory = getDirectory(recordDefinition);
directory.mkdirs();
final File file = new File(directory, getFileName(recordDefinition) + this.nameSuffix + ".shp");
writer = RecordWriter.newRecordWriter(recordDefinition, new PathResource(file));
((XbaseRecordWriter) writer).setUseZeroForNull(this.useZeroForNull);
final Geometry geometry = object.getGeometry();
if (geometry != null) {
setProperty(IoConstants.GEOMETRY_FACTORY, geometry.getGeometryFactory());
}
this.writers.put(path, writer);
this.recordDefinitionMap.put(path, ((ShapefileRecordWriter) writer).getRecordDefinition());
}
return writer;
}
use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class TextOnCurveConverter method read.
@Override
public Object read(final OsnIterator iterator) {
final List<Point> points = new ArrayList<>();
String fieldName = iterator.nextFieldName();
while (fieldName != null) {
if (fieldName.equals("characters")) {
while (iterator.next() != OsnIterator.END_LIST) {
final String objectName = iterator.nextObjectName();
final OsnConverter osnConverter = this.converters.getConverter(objectName);
if (osnConverter == null) {
iterator.throwParseError("No Geometry Converter for " + objectName);
}
points.add((TextLinePoint) osnConverter.read(iterator));
}
}
fieldName = iterator.nextFieldName();
}
final Geometry geometry = new TextOnCurve(this.geometryFactory, points);
return geometry;
}
Aggregations