use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class RecordIoTestSuite method addWriteReadTest.
public static void addWriteReadTest(final TestSuite suite, final String prefix, final String fileExtension) {
addGeometryTestSuites(suite, prefix, (geometryFactory, geometry, geometryDataType) -> {
final String geometryTypeString = geometryDataType.toString();
final File directory = new File("/tmp/revolsystest/io/" + fileExtension);
final File file = new File(directory, geometryTypeString + "_" + geometryFactory.getAxisCount() + "_" + geometry.getVertexCount() + "." + fileExtension);
file.delete();
file.getParentFile().mkdirs();
final PathResource resource = new PathResource(file);
final RecordWriterFactory recordWriterFactory = IoFactory.factory(RecordWriterFactory.class, resource);
final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(PathName.newPathName(geometryTypeString));
if (recordWriterFactory.isCustomFieldsSupported()) {
recordDefinition.addField("BOOLEAN", DataTypes.BOOLEAN, true);
recordDefinition.addField("BYTE", DataTypes.BYTE, true);
recordDefinition.addField("SHORT", DataTypes.SHORT, true);
recordDefinition.addField("INT", DataTypes.INT, true);
recordDefinition.addField("LONG", DataTypes.LONG, true);
recordDefinition.addField("FLOAT", DataTypes.FLOAT, 4, 3, true);
recordDefinition.addField("DOUBLE", DataTypes.DOUBLE, 10, 9, true);
recordDefinition.addField("STRING", DataTypes.STRING, true);
}
if (recordWriterFactory.isGeometrySupported()) {
recordDefinition.addField("GEOMETRY", geometryDataType, true);
}
recordDefinition.setGeometryFactory(geometryFactory);
final ArrayRecord record = new ArrayRecord(recordDefinition);
record.setValue("BOOLEAN", true);
record.setValue("BYTE", Byte.MAX_VALUE);
record.setValue("SHORT", Short.MAX_VALUE);
record.setValue("INT", Integer.MAX_VALUE);
record.setValue("LONG", 999999999999999999L);
record.setValue("FLOAT", 6.789);
record.setValue("DOUBLE", 1.234567890);
record.setValue("STRING", "test");
record.setGeometryValue(geometry);
doRecordWriteTest(resource, record);
doRecordReadTest(resource, record);
doGeometryReadTest(resource, record);
});
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class OgrRecordStore method refreshSchemaElements.
@Override
protected synchronized Map<PathName, ? extends RecordStoreSchemaElement> refreshSchemaElements(final RecordStoreSchema schema) {
final Map<PathName, RecordStoreSchemaElement> elementsByPath = new TreeMap<>();
if (!isClosed()) {
final DataSource dataSource = getDataSource();
if (dataSource != null) {
for (int layerIndex = 0; layerIndex < dataSource.GetLayerCount(); layerIndex++) {
final Layer layer = dataSource.GetLayer(layerIndex);
if (layer != null) {
try {
final RecordDefinitionImpl recordDefinition = newLayerRecordDefinition(schema, layer);
final PathName typePath = recordDefinition.getPathName();
final String layerName = layer.GetName();
this.layerNameToPathMap.put(layerName.toUpperCase(), typePath);
this.pathToLayerNameMap.put(typePath, layerName);
elementsByPath.put(typePath, recordDefinition);
} finally {
layer.delete();
}
}
}
}
}
return elementsByPath;
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class ShapefileRecordWriter method init.
@Override
protected void init() throws IOException {
super.init();
final RecordDefinitionImpl recordDefinition = (RecordDefinitionImpl) getRecordDefinition();
if (recordDefinition != null) {
this.geometryFieldName = recordDefinition.getGeometryFieldName();
if (this.geometryFieldName != null) {
this.out = new ResourceEndianOutput(this.resource);
writeHeader(this.out);
if (!hasField(this.geometryFieldName)) {
addFieldDefinition(this.geometryFieldName, XBaseFieldDefinition.OBJECT_TYPE, 0, 0);
}
final Resource indexResource = this.resource.newResourceChangeExtension("shx");
if (indexResource != null) {
this.indexOut = new ResourceEndianOutput(indexResource);
writeHeader(this.indexOut);
}
this.geometryFactory = getProperty(IoConstants.GEOMETRY_FACTORY);
final Object geometryType = getProperty(IoConstants.GEOMETRY_TYPE);
if (geometryType != null) {
this.geometryDataType = DataTypes.getDataType(geometryType.toString());
}
}
}
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class CreateObjectsWithinDistanceOfGeometry method getRecordDefinitionGeometries.
private final Map<RecordDefinition, Geometry> getRecordDefinitionGeometries(final RecordDefinition recordDefinition) {
Map<RecordDefinition, Geometry> recordDefinitionGeometries = this.recordDefinitionGeometryMap.get(recordDefinition);
if (recordDefinitionGeometries == null) {
recordDefinitionGeometries = new LinkedHashMap<>();
RecordDefinition newRecordDefinition;
Geometry preparedGeometry;
for (final Record record : this.geometryObjects) {
Geometry geometry = record.getGeometry();
if (geometry != null) {
final JexlContext context = new HashMapContext();
final Map<String, Object> vars = new HashMap<>(this.attributes);
vars.putAll(record);
vars.put("typePath", recordDefinition.getPath());
context.setVars(vars);
final String typePath = (String) JexlUtil.evaluateExpression(context, this.typePathTemplateExpression);
newRecordDefinition = new RecordDefinitionImpl(PathName.newPathName(typePath), recordDefinition.getFields());
if (this.distance > 0) {
geometry = geometry.buffer(this.distance, 1, LineCap.SQUARE, LineJoin.MITER, 1.0D);
}
geometry = DouglasPeuckerSimplifier.simplify(geometry, 2D);
preparedGeometry = geometry.prepare();
recordDefinitionGeometries.put(newRecordDefinition, preparedGeometry);
}
}
this.recordDefinitionGeometryMap.put(recordDefinition, recordDefinitionGeometries);
}
return recordDefinitionGeometries;
}
use of com.revolsys.record.schema.RecordDefinitionImpl in project com.revolsys.open by revolsys.
the class FeatureLayer method initialize.
@Override
protected void initialize(final MapEx properties) {
super.initialize(properties);
this.boundingBox = ArcGisResponse.newBoundingBox(properties, "extent");
final PathName pathName = getPathName();
final List<MapEx> fields = properties.getValue("fields");
if (fields != null) {
final RecordDefinitionImpl newRecordDefinition = new RecordDefinitionImpl(pathName);
newRecordDefinition.setPolygonRingDirection(ClockDirection.CLOCKWISE);
final String description = properties.getString("description");
newRecordDefinition.setDescription(description);
final String geometryType = properties.getString("geometryType");
for (final MapEx field : fields) {
addField(newRecordDefinition, geometryType, field);
}
if (Property.hasValue(geometryType)) {
if (!newRecordDefinition.hasGeometryField()) {
final DataType geometryDataType = getGeometryDataType(geometryType);
if (geometryDataType == null) {
throw new IllegalArgumentException("No geometryType specified for " + getServiceUrl());
} else {
newRecordDefinition.addField("GEOMETRY", geometryDataType);
}
}
}
if (this.boundingBox != null) {
final GeometryFactory geometryFactory = this.boundingBox.getGeometryFactory();
newRecordDefinition.setGeometryFactory(geometryFactory);
}
final FieldDefinition objectIdField = newRecordDefinition.getField("OBJECTID");
if (newRecordDefinition.getIdField() == null && objectIdField != null) {
final int fieldIndex = objectIdField.getIndex();
newRecordDefinition.setIdFieldIndex(fieldIndex);
objectIdField.setRequired(true);
}
this.recordDefinition = newRecordDefinition;
}
}
Aggregations