Search in sources :

Example 41 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class OracleRecordStore method getCoordinateSystem.

public synchronized CoordinateSystem getCoordinateSystem(final int oracleSrid) {
    CoordinateSystem coordinateSystem = this.oracleCoordinateSystems.get(oracleSrid);
    if (coordinateSystem == null) {
        try {
            final Map<String, Object> result = JdbcUtils.selectMap(this, "SELECT * FROM MDSYS.SDO_CS_SRS WHERE SRID = ?", oracleSrid);
            if (result == null) {
                coordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(oracleSrid);
            } else {
                final String wkt = (String) result.get("WKTEXT");
                coordinateSystem = WktCsParser.read(wkt);
                coordinateSystem = EpsgCoordinateSystems.getCoordinateSystem(coordinateSystem);
            }
        } catch (final Throwable e) {
            Logs.error(this, "Unable to load coordinate system: " + oracleSrid, e);
            return null;
        }
        this.oracleCoordinateSystems.put(oracleSrid, coordinateSystem);
    }
    return coordinateSystem;
}
Also used : CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem)

Example 42 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class PostgreSQLDdlWriter method writeAddGeometryColumn.

public void writeAddGeometryColumn(final RecordDefinition recordDefinition) {
    final PrintWriter out = getOut();
    final String typePath = recordDefinition.getPath();
    String schemaName = JdbcUtils.getSchemaName(typePath);
    if (schemaName.length() == 0) {
        schemaName = "public";
    }
    final String tableName = PathUtil.getName(typePath);
    final FieldDefinition geometryField = recordDefinition.getGeometryField();
    if (geometryField != null) {
        final GeometryFactory geometryFactory = geometryField.getProperty(FieldProperties.GEOMETRY_FACTORY);
        final String name = geometryField.getName();
        String geometryType = "GEOMETRY";
        final DataType dataType = geometryField.getDataType();
        if (dataType == DataTypes.POINT) {
            geometryType = "POINT";
        } else if (dataType == DataTypes.LINE_STRING) {
            geometryType = "LINESTRING";
        } else if (dataType == DataTypes.POLYGON) {
            geometryType = "POLYGON";
        } else if (dataType == DataTypes.MULTI_POINT) {
            geometryType = "MULTIPOINT";
        } else if (dataType == DataTypes.MULTI_LINE_STRING) {
            geometryType = "MULTILINESTRING";
        } else if (dataType == DataTypes.MULTI_POLYGON) {
            geometryType = "MULTIPOLYGON";
        }
        out.print("select addgeometrycolumn('");
        out.print(schemaName.toLowerCase());
        out.print("', '");
        out.print(tableName.toLowerCase());
        out.print("','");
        out.print(name.toLowerCase());
        out.print("',");
        final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
        out.print(coordinateSystem.getCoordinateSystemId());
        out.print(",'");
        out.print(geometryType);
        out.print("', ");
        out.print(geometryFactory.getAxisCount());
        out.println(");");
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) PrintWriter(java.io.PrintWriter)

Example 43 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class PostgreSQLDdlWriter method writeGeometryRecordDefinition.

@Override
public void writeGeometryRecordDefinition(final RecordDefinition recordDefinition) {
    final PrintWriter out = getOut();
    final String typePath = recordDefinition.getPath();
    String schemaName = JdbcUtils.getSchemaName(typePath);
    if (schemaName.length() == 0) {
        schemaName = "public";
    }
    final String tableName = PathUtil.getName(typePath);
    final FieldDefinition geometryField = recordDefinition.getGeometryField();
    if (geometryField != null) {
        final GeometryFactory geometryFactory = geometryField.getProperty(FieldProperties.GEOMETRY_FACTORY);
        final String name = geometryField.getName();
        String geometryType = "GEOMETRY";
        final DataType dataType = geometryField.getDataType();
        if (dataType == DataTypes.POINT) {
            geometryType = "POINT";
        } else if (dataType == DataTypes.LINE_STRING) {
            geometryType = "LINESTRING";
        } else if (dataType == DataTypes.POLYGON) {
            geometryType = "POLYGON";
        } else if (dataType == DataTypes.MULTI_POINT) {
            geometryType = "MULTIPOINT";
        } else if (dataType == DataTypes.MULTI_LINE_STRING) {
            geometryType = "MULTILINESTRING";
        } else if (dataType == DataTypes.MULTI_POLYGON) {
            geometryType = "MULTIPOLYGON";
        }
        out.print("INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, \"type\") VALUES ('','");
        out.print(schemaName.toLowerCase());
        out.print("', '");
        out.print(tableName.toLowerCase());
        out.print("','");
        out.print(name.toLowerCase());
        out.print("', ");
        out.print(geometryFactory.getAxisCount());
        out.print(",");
        final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
        out.print(coordinateSystem.getCoordinateSystemId());
        out.print(",'");
        out.print(geometryType);
        out.println("');");
    }
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) FieldDefinition(com.revolsys.record.schema.FieldDefinition) DataType(com.revolsys.datatype.DataType) PrintWriter(java.io.PrintWriter)

Example 44 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class EpsgCoordinateSystemsLoader method validateEsri.

private void validateEsri() {
    EsriCoordinateSystems.getCoordinateSystem(0);
    for (final CoordinateSystem coordinateSytstem : EpsgCoordinateSystems.getCoordinateSystems()) {
        if (coordinateSytstem instanceof GeographicCoordinateSystem) {
            final GeographicCoordinateSystem geoCs = (GeographicCoordinateSystem) coordinateSytstem;
            final int id = coordinateSytstem.getCoordinateSystemId();
            final GeographicCoordinateSystem esri = EsriCoordinateSystems.getCoordinateSystem(id);
            if (esri != null && !geoCs.equalsExact(esri)) {
            // System.out.println(id + coordinateSytstem.getCoordinateSystemName());
            }
        } else if (coordinateSytstem instanceof ProjectedCoordinateSystem) {
            final ProjectedCoordinateSystem projectedCs = (ProjectedCoordinateSystem) coordinateSytstem;
            final int id = coordinateSytstem.getCoordinateSystemId();
            final String wkt = new UrlResource("http://spatialreference.org/ref/epsg/" + id + "/esriwkt/").contentsAsString();
            final ProjectedCoordinateSystem esri = GeometryFactory.floating2d(wkt).getCoordinateSystem();
            final CoordinateOperationMethod coordinateOperationMethod = esri.getCoordinateOperationMethod();
            if (esri != null && !projectedCs.equals(esri) && coordinateOperationMethod != null && Property.hasValue(coordinateOperationMethod.getName()) && !projectedCs.isDeprecated()) {
                final Map<ParameterName, Object> p1 = projectedCs.getParameters();
                final Map<ParameterName, Object> p2 = esri.getParameters();
                final Set<ParameterName> n1 = p1.keySet();
                final Set<ParameterName> n2 = p2.keySet();
                if (!n1.equals(n2)) {
                    final TreeSet<ParameterName> nm1 = new TreeSet<>(n1);
                    nm1.removeAll(n2);
                    final TreeSet<ParameterName> nm2 = new TreeSet<>(n2);
                    nm2.removeAll(n1);
                    final String m = id + "\t" + coordinateSytstem.getCoordinateSystemName() + "\t" + nm1 + "\t" + nm2;
                // System.out.println(m);
                }
            }
        }
    }
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) UrlResource(com.revolsys.spring.resource.UrlResource) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) TreeSet(java.util.TreeSet) ProjectedCoordinateSystem(com.revolsys.geometry.cs.ProjectedCoordinateSystem) CoordinateOperationMethod(com.revolsys.geometry.cs.CoordinateOperationMethod) GeographicCoordinateSystem(com.revolsys.geometry.cs.GeographicCoordinateSystem) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 45 with CoordinateSystem

use of com.revolsys.geometry.cs.CoordinateSystem in project com.revolsys.open by revolsys.

the class AbstractLayer method newPropertiesTabCoordinateSystem.

protected JPanel newPropertiesTabCoordinateSystem(final TabbedValuePanel tabPanel) {
    final GeometryFactory geometryFactory = getGeometryFactory();
    if (geometryFactory != null) {
        final JPanel panel = new JPanel(new VerticalLayout(5));
        tabPanel.addTab("Spatial", "world", panel);
        final JPanel extentPanel = Panels.titledTransparent("Extent");
        extentPanel.setLayout(new BorderLayout());
        final BoundingBox boundingBox = getBoundingBox();
        if (boundingBox == null || boundingBox.isEmpty()) {
            extentPanel.add(new JLabel("Unknown"), BorderLayout.CENTER);
        } else {
            final JLabel extentLabel = new JLabel("<html><table cellspacing=\"3\" style=\"margin:0px\">" + "<tr><td>&nbsp;</td><th style=\"text-align:left\">Top:</th><td style=\"text-align:right\">" + DataTypes.toString(boundingBox.getMaximum(1)) + "</td><td>&nbsp;</td></tr><tr>" + "<td><b>Left</b>: " + DataTypes.toString(boundingBox.getMinimum(0)) + "</td><td>&nbsp;</td><td>&nbsp;</td>" + "<td><b>Right</b>: " + DataTypes.toString(boundingBox.getMaximum(0)) + "</td></tr>" + "<tr><td>&nbsp;</td><th>Bottom:</th><td style=\"text-align:right\">" + DataTypes.toString(boundingBox.getMinimum(1)) + "</td><td>&nbsp;</td></tr><tr>" + "</tr></table></html>");
            extentLabel.setFont(SwingUtil.FONT);
            extentPanel.add(extentLabel, BorderLayout.CENTER);
            final int boundingBoxAxisCount = boundingBox.getAxisCount();
            final DefaultTableModel boundingBoxTableModel = new DefaultTableModel(new Object[] { "AXIS", "MIN", "MAX" }, 0);
            boundingBoxTableModel.addRow(new Object[] { "X", boundingBox.getMinX(), boundingBox.getMaxY() });
            boundingBoxTableModel.addRow(new Object[] { "Y", boundingBox.getMinY(), boundingBox.getMaxY() });
            if (boundingBoxAxisCount > 2) {
                boundingBoxTableModel.addRow(new Object[] { "Z", boundingBox.getMinZ(), boundingBox.getMaxZ() });
            }
            final JXTable boundingBoxTable = new JXTable(boundingBoxTableModel);
            boundingBoxTable.setVisibleRowCount(3);
            boundingBoxTable.setDefaultEditor(Object.class, null);
            boundingBoxTable.setDefaultRenderer(Object.class, new NumberTableCellRenderer());
            final JScrollPane boundingBoxScroll = new JScrollPane(boundingBoxTable);
            extentPanel.add(boundingBoxScroll, BorderLayout.EAST);
            boundingBoxTable.getColumnExt(0).setMaxWidth(31);
        }
        panel.add(extentPanel);
        final JPanel coordinateSystemPanel = Panels.titledTransparent("Coordinate System");
        final CoordinateSystem coordinateSystem = geometryFactory.getCoordinateSystem();
        if (coordinateSystem == null) {
            coordinateSystemPanel.add(new JLabel("Unknown"));
        } else {
            final int axisCount = geometryFactory.getAxisCount();
            SwingUtil.addLabelledReadOnlyTextField(coordinateSystemPanel, "ID", coordinateSystem.getCoordinateSystemId(), 10);
            SwingUtil.addLabelledReadOnlyTextField(coordinateSystemPanel, "axisCount", axisCount, 10);
            final double scaleX = geometryFactory.getScaleX();
            if (scaleX > 0) {
                SwingUtil.addLabelledReadOnlyTextField(coordinateSystemPanel, "scaleX", scaleX, 10);
            } else {
                SwingUtil.addLabelledReadOnlyTextField(coordinateSystemPanel, "scaleX", "Floating", 10);
            }
            final double scaleY = geometryFactory.getScaleXY();
            if (scaleY > 0) {
                SwingUtil.addLabelledReadOnlyTextField(coordinateSystemPanel, "scaleY", scaleY, 10);
            } else {
                SwingUtil.addLabelledReadOnlyTextField(coordinateSystemPanel, "scaleY", "Floating", 10);
            }
            if (axisCount > 2) {
                final double scaleZ = geometryFactory.getScaleZ();
                if (scaleZ > 0) {
                    SwingUtil.addLabelledReadOnlyTextField(coordinateSystemPanel, "scaleZ", scaleZ, 10);
                } else {
                    SwingUtil.addLabelledReadOnlyTextField(coordinateSystemPanel, "scaleZ", "Floating", 10);
                }
            }
            SwingUtil.addLabel(coordinateSystemPanel, "ESRI WKT");
            final String wktFormatted = geometryFactory.toWktCsFormatted();
            final TextArea wktTextArea = new TextArea(wktFormatted, 10, 80);
            wktTextArea.setEditable(false);
            wktTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 11));
            coordinateSystemPanel.add(wktTextArea);
            GroupLayouts.makeColumns(coordinateSystemPanel, 2, true);
        }
        panel.add(coordinateSystemPanel);
        return panel;
    }
    return null;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) JXTable(org.jdesktop.swingx.JXTable) TextArea(java.awt.TextArea) CoordinateSystem(com.revolsys.geometry.cs.CoordinateSystem) DefaultTableModel(javax.swing.table.DefaultTableModel) JLabel(javax.swing.JLabel) ScrollableSizeHint(org.jdesktop.swingx.ScrollableSizeHint) Font(java.awt.Font) BorderLayout(java.awt.BorderLayout) BoundingBox(com.revolsys.geometry.model.BoundingBox) VerticalLayout(org.jdesktop.swingx.VerticalLayout) NumberTableCellRenderer(com.revolsys.swing.table.NumberTableCellRenderer)

Aggregations

CoordinateSystem (com.revolsys.geometry.cs.CoordinateSystem)51 ProjectedCoordinateSystem (com.revolsys.geometry.cs.ProjectedCoordinateSystem)28 GeographicCoordinateSystem (com.revolsys.geometry.cs.GeographicCoordinateSystem)25 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)14 BoundingBox (com.revolsys.geometry.model.BoundingBox)11 Point (com.revolsys.geometry.model.Point)8 CompoundCoordinateSystem (com.revolsys.geometry.cs.CompoundCoordinateSystem)7 EngineeringCoordinateSystem (com.revolsys.geometry.cs.EngineeringCoordinateSystem)7 GeocentricCoordinateSystem (com.revolsys.geometry.cs.GeocentricCoordinateSystem)7 VerticalCoordinateSystem (com.revolsys.geometry.cs.VerticalCoordinateSystem)7 ArrayList (java.util.ArrayList)6 CoordinateOperationMethod (com.revolsys.geometry.cs.CoordinateOperationMethod)5 Map (java.util.Map)5 DataType (com.revolsys.datatype.DataType)4 LinearUnit (com.revolsys.geometry.cs.unit.LinearUnit)4 Record (com.revolsys.record.Record)4 FieldDefinition (com.revolsys.record.schema.FieldDefinition)4 PrintWriter (java.io.PrintWriter)4 IntHashMap (com.revolsys.collection.map.IntHashMap)3 ParameterValueString (com.revolsys.geometry.cs.ParameterValueString)3