public static MathTransform getMathTransform( CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem destCRS) { try { return CRS.findMathTransform(sourceCRS, destCRS, true); } catch (OperationNotFoundException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } catch (FactoryException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } return null; }
public void setBoundsStr(String boundsStr) { if (boundsStr == null) { setBounds(null); } else { Matcher matcherEnvelope = patternEnvelope.matcher(boundsStr); if (!matcherEnvelope.matches()) { throw new IllegalArgumentException( "Envelope not in correct format: minx,miny,maxx,maxy"); } double minx = Double.parseDouble(matcherEnvelope.group(1)); double miny = Double.parseDouble(matcherEnvelope.group(2)); double maxx = Double.parseDouble(matcherEnvelope.group(3)); double maxy = Double.parseDouble(matcherEnvelope.group(4)); try { setBounds( new ReferencedEnvelope( minx, maxx, miny, maxy, CRS.decode("EPSG:4326", true))); } catch (FactoryException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } } }
stmt.setInt(1, Integer.parseInt(code)); final ResultSet result = stmt.executeQuery(); int i = 0; while (result.next()) { final String axisCode = getString(result, 1, code); if (i < axis.length) { result.close(); if (i != axis.length) { throw new FactoryException( Errors.format(ErrorKeys.MISMATCHED_DIMENSION_$2, axis.length, i));
/** * Set the data source for the EPSG database. If an other EPSG database was already in use, it * will be disconnected. Users should not invoke this method on the factory returned by {@link * ReferencingFactoryFinder}, since it could have a system-wide effect. * * @param datasource The new datasource. * @throws SQLException if an error occured. */ public synchronized void setDataSource(final DataSource datasource) throws SQLException { if (datasource != this.datasource) { try { dispose(); } catch (FactoryException exception) { final Throwable cause = exception.getCause(); if (cause instanceof SQLException) { throw (SQLException) cause; } if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } // Not really an SQL exception, but we should not reach this point anyway. final SQLException e = new SQLException(exception.getLocalizedMessage()); e.initCause(exception); // TODO: inline when we will be allowed to target Java 6. throw e; } this.datasource = datasource; } }
.createCoordinateSystemAxis(map, axisName, direction, unit); } catch (FactoryException e) { throw new FactoryException(e.getLocalizedMessage());
stmt.setString(1, code); final ResultSet result = stmt.executeQuery(); int i = 0; while (result.next()) { final String axisCode = getString(result, 1, code); if (i < axis.length) { result.close(); if (i != axis.length) { throw new FactoryException( Errors.format(ErrorKeys.MISMATCHED_DIMENSION_$2, axis.length, i));
+ " FROM [Ellipsoid]" + " WHERE ELLIPSOID_CODE = ?"); stmt.setString(1, primaryKey); final ResultSet result = stmt.executeQuery(); while (result.next()) { final String name = getString(result, 2, code); final double semiMajorAxis = getDouble(result, 3, code); final double inverseFlattening = result.getDouble(4); final double semiMinorAxis = result.getDouble(5); final String unitCode = getString(result, 6, code); final String remarks = result.getString(7); final String column = result.getMetaData().getColumnName(3); result.close(); throw new FactoryException( Errors.format(ErrorKeys.NULL_VALUE_IN_TABLE_$3, code, column)); } else {
+ " AND CV.COORD_OP_CODE = ?" + " ORDER BY CU.SORT_ORDER"); stmt.setString(1, method); stmt.setString(2, operation); final ResultSet result = stmt.executeQuery(); while (result.next()) { final String name = getString(result, 1, operation); final double value = result.getDouble(2); final Unit unit; Object reference; if (result.wasNull()) { throw new FactoryException( Errors.format(ErrorKeys.CANT_SET_PARAMETER_VALUE_$1, name), exception);
+ " FROM [Ellipsoid]" + " WHERE ELLIPSOID_CODE = ?"); stmt.setInt(1, Integer.parseInt(primaryKey)); final ResultSet result = stmt.executeQuery(); while (result.next()) { final String name = getString(result, 2, code); final double semiMajorAxis = getDouble(result, 3, code); final double inverseFlattening = result.getDouble(4); final double semiMinorAxis = result.getDouble(5); final String unitCode = getString(result, 6, code); final String remarks = result.getString(7); final String column = result.getMetaData().getColumnName(3); result.close(); throw new FactoryException( Errors.format(ErrorKeys.NULL_VALUE_IN_TABLE_$3, code, column)); } else {
+ " AND CV.COORD_OP_CODE = ?" + " ORDER BY CU.SORT_ORDER"); stmt.setInt(1, Integer.parseInt(method)); stmt.setInt(2, Integer.parseInt(operation)); final ResultSet result = stmt.executeQuery(); while (result.next()) { final String name = getString(result, 1, operation); final double value = result.getDouble(2); final Unit unit; Object reference; if (result.wasNull()) { throw new FactoryException( Errors.format(ErrorKeys.CANT_SET_PARAMETER_VALUE_$1, name), exception);
/** * Make sure that the last result was non-null. Used for {@code getString}, {@code getDouble} * and {@code getInt} methods only. */ private static void ensureNonNull( final ResultSet result, final int columnIndex, final String code) throws SQLException, FactoryException { if (result.wasNull()) { final ResultSetMetaData metadata = result.getMetaData(); final String column = metadata.getColumnName(columnIndex); final String table = metadata.getTableName(columnIndex); result.close(); throw new FactoryException( Errors.format(ErrorKeys.NULL_VALUE_IN_TABLE_$3, code, column, table)); } }
stmt.setString(1, epsg); try (final ResultSet result = stmt.executeQuery()) { final boolean present = result.next(); if (present) { if (index >= 0) { throw new FactoryException( Errors.format(ErrorKeys.DUPLICATED_VALUES_$1, code)); stmt.close(); } catch (SQLException exception) { throw databaseFailure(IdentifiedObject.class, code, exception);
isClosed = connection.isClosed(); for (final Iterator it = statements.values().iterator(); it.hasNext(); ) { ((PreparedStatement) it.next()).close(); it.remove(); throw new FactoryException(exception);
requestCRS = CRS.getHorizontalCRS(requestedBBox.getCoordinateReferenceSystem()); try { if (!CRS.equalsIgnoreMetadata( requestCRS, rasterManager.spatialDomainManager.coverageCRS2D)) destinationToSourceTransform = CRS.findMathTransform( requestCRS, rasterManager.spatialDomainManager.coverageCRS2D, true); if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, te.getLocalizedMessage(), te); } catch (FactoryException fe) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, fe.getLocalizedMessage(), fe); if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, te.getLocalizedMessage(), te); } catch (FactoryException fe) { if (LOGGER.isLoggable(Level.FINE)) LOGGER.log(Level.FINE, fe.getLocalizedMessage(), fe);
LOGGER.fine("request CRS decoding" + srs); requestCRS = CRS.decode(srs); LOGGER.log(Level.FINER, e.getMessage(), e); if (CRS.equalsIgnoreMetadata(requestCRS, matrixCRS)) { // matching SRS if (links.containsKey((matrixSet.getIdentifier()))) { // and available for
private static void forceSRS(GetMapRequest getMap, String srs) { getMap.setSRS(srs); try { getMap.setCrs(CRS.decode(srs)); } catch (NoSuchAuthorityCodeException e) { e.printStackTrace(); } catch (FactoryException e) { e.printStackTrace(); } }
public CrsGeoCoding getCrsGeoCoding () { Coordinate2D coordUpperLeft = getUpperLeft(); CrsGeoCoding crsGeoCoding = null; String EPSG = getEPSG(); try { crsGeoCoding = new CrsGeoCoding(CRS.decode("EPSG:" + EPSG), getRasterWidth(), getRasterHeight(), coordUpperLeft.x, coordUpperLeft.y, getBestResolution(), getBestResolution(), 0.0, 0.0); } catch (FactoryException e) { e.printStackTrace(); } catch (TransformException e) { e.printStackTrace(); } return crsGeoCoding; }
final CoordinateReferenceSystem sourceCRS = source.getCoordinateReferenceSystem(); final CoordinateReferenceSystem targetCRS; if (CRS.equalsIgnoreMetadata(crs2D, srcCrs2D)) { crs2D.getName().getCode()), components); } catch (FactoryException exception) { throw new CannotReprojectException(exception.getLocalizedMessage(), exception); final MathTransform toSource = geometry.getGridToCRS(); MathTransform toTarget; if (CRS.equalsIgnoreMetadata(gridToCrs2D, toSource2D)) { toTarget = toSource; } else { throw new CannotReprojectException(Errors.format(ErrorKeys.CANT_REPROJECT_$1, source.getName()), exception);
/** * Read the {@link CoordinateReferenceSystem crs} from the location. * * @return the crs of the location containing the map. * @throws Exception */ public CoordinateReferenceSystem getCoordinateReferenceSystem() throws Exception { File projWtkFile = getPROJ_WKT(); if (projWtkFile.exists()) { BufferedReader crsReader = new BufferedReader(new FileReader(projWtkFile)); StringBuffer wtkString = new StringBuffer(); try { String line = null; while ((line = crsReader.readLine()) != null) { wtkString.append(line.trim()); } } finally { crsReader.close(); } CoordinateReferenceSystem readCrs = null; try { readCrs = CRS.parseWKT(wtkString.toString()); } catch (FactoryException e) { throw new IOException(e.getLocalizedMessage()); } return readCrs; } else { return null; } }
private Point transformPoint(Point point) { CoordinateReferenceSystem sourceCRS = CRSUtils.getCRS(point.getSRID()); CoordinateReferenceSystem targetCRS = crs; try { MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS); return CRSUtils.transformPoint(point, transform); } catch (FactoryException e) { e.printStackTrace(); return null; } } /**