Search in sources :

Example 21 with RecordDefinitionImpl

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);
    });
}
Also used : ArrayRecord(com.revolsys.record.ArrayRecord) PathResource(com.revolsys.spring.resource.PathResource) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) RecordWriterFactory(com.revolsys.record.io.RecordWriterFactory) File(java.io.File)

Example 22 with RecordDefinitionImpl

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;
}
Also used : RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) PathName(com.revolsys.io.PathName) TreeMap(java.util.TreeMap) Layer(org.gdal.ogr.Layer) RecordStoreSchemaElement(com.revolsys.record.schema.RecordStoreSchemaElement) DataSource(org.gdal.ogr.DataSource)

Example 23 with RecordDefinitionImpl

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());
            }
        }
    }
}
Also used : ResourceEndianOutput(com.revolsys.io.endian.ResourceEndianOutput) Resource(com.revolsys.spring.resource.Resource) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl)

Example 24 with RecordDefinitionImpl

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;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) HashMapContext(org.apache.commons.jexl.context.HashMapContext) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JexlContext(org.apache.commons.jexl.JexlContext) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) Record(com.revolsys.record.Record) ArrayRecord(com.revolsys.record.ArrayRecord) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 25 with RecordDefinitionImpl

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;
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) MapEx(com.revolsys.collection.map.MapEx) FieldDefinition(com.revolsys.record.schema.FieldDefinition) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Aggregations

RecordDefinitionImpl (com.revolsys.record.schema.RecordDefinitionImpl)30 PathName (com.revolsys.io.PathName)14 DataType (com.revolsys.datatype.DataType)10 FieldDefinition (com.revolsys.record.schema.FieldDefinition)7 RecordDefinition (com.revolsys.record.schema.RecordDefinition)6 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)5 RecordStoreSchema (com.revolsys.record.schema.RecordStoreSchema)4 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Geometry (com.revolsys.geometry.model.Geometry)3 VectorOfWString (com.revolsys.gis.esri.gdb.file.capi.swig.VectorOfWString)3 ArrayRecord (com.revolsys.record.ArrayRecord)3 Record (com.revolsys.record.Record)3 DETable (com.revolsys.record.io.format.esri.gdb.xml.model.DETable)3 MapEx (com.revolsys.collection.map.MapEx)2 FileGdbRecordStore (com.revolsys.gis.esri.gdb.file.FileGdbRecordStore)2 FileGdbDomainCodeTable (com.revolsys.gis.esri.gdb.file.capi.FileGdbDomainCodeTable)2 CodeTable (com.revolsys.record.code.CodeTable)2 DEFeatureClass (com.revolsys.record.io.format.esri.gdb.xml.model.DEFeatureClass)2 Field (com.revolsys.record.io.format.esri.gdb.xml.model.Field)2