Search in sources :

Example 76 with GeometryFactory

use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.

the class OracleSdoGeometryFieldAdder method initialize.

@Override
public void initialize(final JdbcRecordStoreSchema schema) {
    try (final JdbcConnection connection = this.recordStore.getJdbcConnection()) {
        final String schemaName = schema.getDbName();
        final String sridSql = "select M.TABLE_NAME, M.COLUMN_NAME, M.SRID, M.DIMINFO, C.GEOMETRY_TYPE " + "from ALL_SDO_GEOM_METADATA M " + "LEFT OUTER JOIN ALL_GEOMETRY_COLUMNS C ON (M.OWNER = C.F_TABLE_SCHEMA AND M.TABLE_NAME = C.F_TABLE_NAME AND M.COLUMN_NAME = C.F_GEOMETRY_COLUMN) " + "where OWNER = ?";
        try (final PreparedStatement statement = connection.prepareStatement(sridSql)) {
            statement.setString(1, schemaName);
            try (final ResultSet resultSet = statement.executeQuery()) {
                while (resultSet.next()) {
                    final String tableName = resultSet.getString(1);
                    final String columnName = resultSet.getString(2);
                    final PathName typePath = schema.getPathName().newChild(tableName);
                    int srid = resultSet.getInt(3);
                    if (resultSet.wasNull() || srid < 0) {
                        srid = 0;
                    }
                    final Object[] dimInfo = (Object[]) resultSet.getArray("DIMINFO").getArray();
                    int axisCount = dimInfo.length;
                    setColumnProperty(schema, typePath, columnName, AXIS_COUNT, axisCount);
                    if (axisCount < 2) {
                        axisCount = 2;
                    } else if (axisCount > 4) {
                        axisCount = 4;
                    }
                    final double[] scales = new double[axisCount];
                    for (int i = 0; i < scales.length; i++) {
                        scales[i] = getScale(dimInfo, i);
                    }
                    final GeometryFactory geometryFactory = this.recordStore.getGeometryFactory(srid, axisCount, scales);
                    setColumnProperty(schema, typePath, columnName, GEOMETRY_FACTORY, geometryFactory);
                    setColumnProperty(schema, typePath, columnName, ORACLE_SRID, srid);
                    final int geometryType = resultSet.getInt(5);
                    DataType geometryDataType;
                    if (resultSet.wasNull()) {
                        geometryDataType = DataTypes.GEOMETRY;
                    } else {
                        geometryDataType = ID_TO_DATA_TYPE.get(geometryType);
                        if (geometryDataType == null) {
                            geometryDataType = DataTypes.GEOMETRY;
                        }
                    }
                    setColumnProperty(schema, typePath, columnName, GEOMETRY_TYPE, geometryDataType);
                }
            }
        } catch (final SQLException e) {
            Logs.error(this, "Unable to initialize", e);
        }
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) DataType(com.revolsys.datatype.DataType) JdbcConnection(com.revolsys.jdbc.JdbcConnection) PreparedStatement(java.sql.PreparedStatement) PathName(com.revolsys.io.PathName)

Example 77 with GeometryFactory

use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.

the class PackedGeometry method checkGeometry.

public static void checkGeometry(final Geometry geometry) {
    final GeometryFactory geometryFactory = geometry.getGeometryFactory();
    final Double xOffset = 0.0;
    final Double yOffset = 0.0;
    final Double xyScale = geometryFactory.getScaleXY();
    final Double zOffset = 0.0;
    final Double zScale = geometryFactory.getScaleZ();
    final boolean hasZ = zScale > 0;
    final boolean hasM = false;
    final Double mScale = null;
    final Double mOffset = null;
    final List<List<Geometry>> parts = ArcSdeStGeometryFieldDefinition.getParts(geometry);
    final int numPoints = PackedCoordinateUtil.getNumPoints(parts);
    final byte[] data = PackedCoordinateUtil.getPackedBytes(xOffset, yOffset, xyScale, hasZ, zOffset, zScale, hasM, mScale, mOffset, parts);
    final int geometryType = ArcSdeConstants.getStGeometryType(geometry);
    try {
        final Geometry geometry2 = PackedCoordinateUtil.getGeometry(data, geometryFactory, geometryType, numPoints, xOffset, yOffset, xyScale, zOffset, zScale, mOffset, mScale);
        System.out.println(WktWriter.toString(geometry));
        if (!DataTypes.GEOMETRY.equals(geometry, geometry2, Collections.<String>emptyList())) {
            System.err.println(WktWriter.toString(geometry2));
            throw new RuntimeException("Geometry not equal");
        }
    } catch (final IOException e) {
        throw Exceptions.wrap(e);
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) List(java.util.List) IOException(java.io.IOException)

Example 78 with GeometryFactory

use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.

the class OgrRecordStore method newLayerRecordDefinition.

protected RecordDefinitionImpl newLayerRecordDefinition(final RecordStoreSchema schema, final Layer layer) {
    final String layerName = layer.GetName();
    final PathName typePath = PathName.newPathName(layerName);
    /**
     * This primes the layer so that the fidColumn is loaded correctly.
     */
    layer.GetNextFeature();
    final RecordDefinitionImpl recordDefinition = new RecordDefinitionImpl(schema, typePath);
    String idFieldName = layer.GetFIDColumn();
    if (!Property.hasValue(idFieldName)) {
        idFieldName = "rowid";
    }
    this.idFieldNames.put(typePath.getUpperPath(), idFieldName);
    final FeatureDefn layerDefinition = layer.GetLayerDefn();
    if (SQLITE.equals(this.driverName) || GEO_PAKCAGE.equals(this.driverName)) {
        recordDefinition.addField(idFieldName, DataTypes.LONG, true);
        recordDefinition.setIdFieldName(idFieldName);
    }
    for (int fieldIndex = 0; fieldIndex < layerDefinition.GetFieldCount(); fieldIndex++) {
        final FieldDefn fieldDefinition = layerDefinition.GetFieldDefn(fieldIndex);
        final String fieldName = fieldDefinition.GetName();
        final int fieldType = fieldDefinition.GetFieldType();
        final int fieldWidth = fieldDefinition.GetWidth();
        final int fieldPrecision = fieldDefinition.GetPrecision();
        DataType fieldDataType;
        switch(fieldType) {
            case 0:
                fieldDataType = DataTypes.INT;
                break;
            case 2:
                fieldDataType = DataTypes.DOUBLE;
                break;
            case 4:
            case 6:
                fieldDataType = DataTypes.STRING;
                break;
            case 9:
                fieldDataType = DataTypes.DATE;
                break;
            case 11:
                fieldDataType = DataTypes.DATE_TIME;
                break;
            default:
                fieldDataType = DataTypes.STRING;
                final String fieldTypeName = fieldDefinition.GetFieldTypeName(fieldType);
                Logs.error(this, "Unsupported field type " + this.file + " " + fieldName + ": " + fieldTypeName);
                break;
        }
        final FieldDefinition field = new FieldDefinition(fieldName, fieldDataType, fieldWidth, fieldPrecision, false);
        recordDefinition.addField(field);
    }
    for (int fieldIndex = 0; fieldIndex < layerDefinition.GetGeomFieldCount(); fieldIndex++) {
        final GeomFieldDefn fieldDefinition = layerDefinition.GetGeomFieldDefn(fieldIndex);
        final String fieldName = fieldDefinition.GetName();
        final int geometryFieldType = fieldDefinition.GetFieldType();
        DataType geometryFieldDataType;
        int axisCount = 2;
        switch(geometryFieldType) {
            case 1:
                geometryFieldDataType = DataTypes.POINT;
                break;
            case 2:
                geometryFieldDataType = DataTypes.LINE_STRING;
                break;
            case 3:
                geometryFieldDataType = DataTypes.POLYGON;
                break;
            case 4:
                geometryFieldDataType = DataTypes.MULTI_POINT;
                break;
            case 5:
                geometryFieldDataType = DataTypes.MULTI_LINE_STRING;
                break;
            case 6:
                geometryFieldDataType = DataTypes.MULTI_POLYGON;
                break;
            case 7:
                geometryFieldDataType = DataTypes.GEOMETRY_COLLECTION;
                break;
            case 101:
                geometryFieldDataType = DataTypes.LINEAR_RING;
                break;
            case 0x80000000 + 1:
                geometryFieldDataType = DataTypes.POINT;
                axisCount = 3;
                break;
            case 0x80000000 + 2:
                geometryFieldDataType = DataTypes.LINE_STRING;
                axisCount = 3;
                break;
            case 0x80000000 + 3:
                geometryFieldDataType = DataTypes.POLYGON;
                axisCount = 3;
                break;
            case 0x80000000 + 4:
                geometryFieldDataType = DataTypes.MULTI_POINT;
                axisCount = 3;
                break;
            case 0x80000000 + 5:
                geometryFieldDataType = DataTypes.MULTI_LINE_STRING;
                axisCount = 3;
                break;
            case 0x80000000 + 6:
                geometryFieldDataType = DataTypes.MULTI_POLYGON;
                axisCount = 3;
                break;
            case 0x80000000 + 7:
                geometryFieldDataType = DataTypes.GEOMETRY_COLLECTION;
                axisCount = 3;
                break;
            default:
                geometryFieldDataType = DataTypes.GEOMETRY;
                break;
        }
        final SpatialReference spatialReference = fieldDefinition.GetSpatialRef();
        final GeometryFactory geometryFactory = Gdal.getGeometryFactory(spatialReference, axisCount);
        final FieldDefinition field = new FieldDefinition(fieldName, geometryFieldDataType, false);
        field.setProperty(FieldProperties.GEOMETRY_FACTORY, geometryFactory);
        recordDefinition.addField(field);
    }
    return recordDefinition;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FeatureDefn(org.gdal.ogr.FeatureDefn) GeomFieldDefn(org.gdal.ogr.GeomFieldDefn) FieldDefn(org.gdal.ogr.FieldDefn) FieldDefinition(com.revolsys.record.schema.FieldDefinition) GeomFieldDefn(org.gdal.ogr.GeomFieldDefn) SpatialReference(org.gdal.osr.SpatialReference) RecordDefinitionImpl(com.revolsys.record.schema.RecordDefinitionImpl) DataType(com.revolsys.datatype.DataType) PathName(com.revolsys.io.PathName)

Example 79 with GeometryFactory

use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.

the class OgrRecordStore method newLayerRecordDefinition.

private RecordDefinition newLayerRecordDefinition(final DataSource dataSource, final RecordDefinition sourceRecordDefinition) {
    final PathName typePath = sourceRecordDefinition.getPathName();
    final String name = typePath.getName();
    final PathName parentPath = typePath.getParent();
    final RecordStoreSchema schema = getSchema(parentPath);
    Layer layer;
    if (sourceRecordDefinition.hasGeometryField()) {
        final GeometryFactory geometryFactory = sourceRecordDefinition.getGeometryFactory();
        final FieldDefinition geometryField = sourceRecordDefinition.getGeometryField();
        final int geometryFieldType = getGeometryFieldType(geometryFactory, geometryField);
        final SpatialReference spatialReference = Gdal.getSpatialReference(geometryFactory);
        layer = dataSource.CreateLayer(typePath.getPath(), spatialReference, geometryFieldType);
    } else {
        layer = dataSource.CreateLayer(name);
    }
    if (dataSource.TestCapability(ogrConstants.ODsCCreateLayer) == false) {
        System.err.println("CreateLayer not supported by driver.");
    }
    return newLayerRecordDefinition(schema, layer);
}
Also used : RecordStoreSchema(com.revolsys.record.schema.RecordStoreSchema) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) SpatialReference(org.gdal.osr.SpatialReference) PathName(com.revolsys.io.PathName) Layer(org.gdal.ogr.Layer)

Example 80 with GeometryFactory

use of com.revolsys.geometry.model.GeometryFactory in project com.revolsys.open by revolsys.

the class OgrRecordWriter method setGeometries.

private void setGeometries(final FeatureDefn featureDefinition, final Record record, final Feature feature) {
    final RecordDefinition recordDefinition = record.getRecordDefinition();
    final int geometryFieldCount = featureDefinition.GetGeomFieldCount();
    for (int fieldIndex = 0; fieldIndex < geometryFieldCount; fieldIndex++) {
        final GeomFieldDefn fieldDefinition = featureDefinition.GetGeomFieldDefn(fieldIndex);
        final String name = fieldDefinition.GetName();
        Geometry geometry = record.getValue(name);
        if (geometry != null) {
            final FieldDefinition attribute = recordDefinition.getField(name);
            final GeometryFactory geometryFactory = attribute.getProperty(FieldProperties.GEOMETRY_FACTORY);
            geometry = geometry.convertGeometry(geometryFactory);
            final int geometryType = fieldDefinition.GetFieldType();
            final int axisCount = geometryFactory.getAxisCount();
            final org.gdal.ogr.Geometry ogrGeometry = toOgrGeometry(geometry, geometryType, axisCount);
            feature.SetGeomField(fieldIndex, ogrGeometry);
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) FieldDefinition(com.revolsys.record.schema.FieldDefinition) GeomFieldDefn(org.gdal.ogr.GeomFieldDefn) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

GeometryFactory (com.revolsys.geometry.model.GeometryFactory)360 Point (com.revolsys.geometry.model.Point)142 Geometry (com.revolsys.geometry.model.Geometry)72 BoundingBox (com.revolsys.geometry.model.BoundingBox)70 LineString (com.revolsys.geometry.model.LineString)61 ArrayList (java.util.ArrayList)45 DataType (com.revolsys.datatype.DataType)25 FieldDefinition (com.revolsys.record.schema.FieldDefinition)24 Polygon (com.revolsys.geometry.model.Polygon)22 List (java.util.List)18 RecordDefinition (com.revolsys.record.schema.RecordDefinition)17 Test (org.junit.Test)16 CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)15 Vertex (com.revolsys.geometry.model.vertex.Vertex)14 Record (com.revolsys.record.Record)14 IOException (java.io.IOException)13 PathName (com.revolsys.io.PathName)12 LinearRing (com.revolsys.geometry.model.LinearRing)10 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)10 QuadEdgeDelaunayTinBuilder (com.revolsys.elevation.tin.quadedge.QuadEdgeDelaunayTinBuilder)8