/** * Use the CRS's defined bounds to populate the LayerGroup bounds. * * <p>If the CRS has no bounds then the layer group bounds are set to null instead * * @param crs */ public void calculateBoundsFromCRS(CoordinateReferenceSystem crs) { Envelope crsEnvelope = CRS.getEnvelope(crs); if (crsEnvelope != null) { ReferencedEnvelope refEnvelope = new ReferencedEnvelope(crsEnvelope); this.group.setBounds(refEnvelope); } else { this.group.setBounds(null); } }
Envelope crsEnvelope = CRS.getEnvelope(crs); if (crsEnvelope != null) { crsReferencedEnvelope = new ReferencedEnvelope(crsEnvelope);
@Test public void testUseCRSBounds() throws NoSuchAuthorityCodeException, FactoryException { // this test is almost trivial since the code itself is trivial CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326"); LayerGroupHelper helper = new LayerGroupHelper(nested); helper.calculateBoundsFromCRS(targetCRS); // layer group bounds should now match target CRS bounds assertEquals(nested.getBounds(), new ReferencedEnvelope(CRS.getEnvelope(targetCRS))); // null CRS should get null bounds helper.calculateBoundsFromCRS(null); assertEquals(nested.getBounds(), null); }
@Test public void testGetBoundsFromCRS() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); CoordinateReferenceSystem resourceCRS = fti.getCRS(); assertNotNull(resourceCRS); // make sure the srs is as expected, otherwise the rest of the tests don't make sense assertEquals("EPSG:32615", fti.getSRS()); ReferencedEnvelope crsBounds = cb.getBoundsFromCRS(fti); assertNotNull(crsBounds); CoordinateReferenceSystem exptectedCRS = CRS.decode("EPSG:32615"); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // if we change the srs when there's no reproject policy, should still be the same bounding // box fti.setSRS("EPSG:4326"); fti.setProjectionPolicy(ProjectionPolicy.NONE); crsBounds = cb.getBoundsFromCRS(fti); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // if we use reproject policy, bounds should now be different fti.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED); crsBounds = cb.getBoundsFromCRS(fti); assertNotEquals(new ReferencedEnvelope(CRS.getEnvelope(exptectedCRS)), crsBounds); // should now be 4326 bounds CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326"); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds); fti.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED); assertEquals(new ReferencedEnvelope(CRS.getEnvelope(crs4326)), crsBounds); }
/** * Returns the bounding box for the coverage domain in {@linkplain #getCoordinateReferenceSystem * coordinate reference system} coordinates. May be {@code null} if this coverage has no * associated coordinate reference system. For grid coverages, the grid cells are centered on * each grid coordinate. The envelope for a 2-D grid coverage includes the following corner * positions. * * <blockquote> * * <pre> * (Minimum row - 0.5, Minimum column - 0.5) for the minimum coordinates * (Maximum row - 0.5, Maximum column - 0.5) for the maximum coordinates * </pre> * * </blockquote> * * The default implementation returns the domain of validity of the CRS, if there is one. * * @return The bounding box for the coverage domain in coordinate system coordinates. */ public Envelope getEnvelope() { return CRS.getEnvelope(crs); }
private static org.opengis.geometry.Envelope getCRSEnvelope(CoordinateReferenceSystem targetCRS) throws FactoryException, NoSuchAuthorityCodeException { if (targetCRS.getDomainOfValidity() == null) { Integer code = CRS.lookupEpsgCode(targetCRS, true); if (code != null) { CRS.decode("EPSG:" + code, CRS.getAxisOrder(targetCRS) != AxisOrder.NORTH_EAST); } } org.opengis.geometry.Envelope envelope = CRS.getEnvelope(targetCRS); return envelope; }
/** * Examines the map extent and tries to determine the number of digits that will be needed in * the display. If a coordinate reference system with valid extent defined, it is used to * determine coordinate limits; otherwise the extent of the envelope is used directly. If all * else fails, a default number of digits is set. * * @param env the map extent (may be {@code null}) */ private void setIntegerLen(Envelope env) { int len = -1; if (env != null) { // Try to get a valid extent for the CRS and use this to // determine num coordinate digits CoordinateReferenceSystem crs = env.getCoordinateReferenceSystem(); if (crs != null) { Envelope validExtent = CRS.getEnvelope(crs); if (validExtent != null) { len = getMaxIntegerLen(validExtent); } } if (len < 0) { // Use map extent directly len = getMaxIntegerLen(env); } } else { // Nothing to go on: use an arbitrary length len = DEFAULT_NUM_INTEGER_DIGITS; } intLen = len; }
/** * Returns a copy of current envelope. If no envelope has been {@linkplain #setEnvelope * explicitly defined}, then the default is inferred from the CRS (by default a geographic * envelope from 180°W to 180°E and 90°S to 90°N). */ public Envelope getEnvelope() { if (envelope != null) { return envelope.clone(); } else { final CoordinateReferenceSystem crs = getCoordinateReferenceSystem(); Envelope candidate = CRS.getEnvelope(crs); if (candidate == null) { final GeneralEnvelope copy = new GeneralEnvelope(crs); copy.setToNull(); candidate = copy; } return candidate; } }
/** * Sets the coordinate reference system to the specified value. If an {@linkplain #setEnvelope * envelope was previously defined}, it will be reprojected to the new CRS. * * @throws IllegalArgumentException if the CRS is illegal for the {@linkplain #getEnvelope * current envelope}. */ public void setCoordinateReferenceSystem(final CoordinateReferenceSystem crs) throws IllegalArgumentException { if (envelope == null) { if (crs != null) { envelope = wrap(CRS.getEnvelope(crs)); if (envelope == null) { envelope = new GeneralEnvelope(crs); envelope.setToNull(); } } } else try { envelope = wrap(CRS.transform(envelope, crs)); } catch (TransformException exception) { throw new IllegalArgumentException( Errors.format(ErrorKeys.ILLEGAL_COORDINATE_REFERENCE_SYSTEM), exception); } coverage = null; }
if (crs != null) { Envelope envelope = CRS.getEnvelope(crs); if (envelope != null) { return new ReferencedEnvelope(envelope); // nice!
CoordinateReferenceSystem crs = getCRS(e.getSrid()); if (crs != null) { org.opengis.geometry.Envelope env = CRS.getEnvelope(crs); if (env != null) { minx = env.getMinimum(0);
/** * Returns the bounding box for the coverage domain in * {@linkplain #getCoordinateReferenceSystem coordinate reference system} coordinates. May * be {@code null} if this coverage has no associated coordinate reference system. For grid * coverages, the grid cells are centered on each grid coordinate. The envelope for a 2-D * grid coverage includes the following corner positions. * * <blockquote><pre> * (Minimum row - 0.5, Minimum column - 0.5) for the minimum coordinates * (Maximum row - 0.5, Maximum column - 0.5) for the maximum coordinates * </pre></blockquote> * * The default implementation returns the domain of validity of the CRS, if there is one. * * @return The bounding box for the coverage domain in coordinate system coordinates. */ public Envelope getEnvelope() { return CRS.getEnvelope(crs); }
/** * Returns the bounding box for the coverage domain in * {@linkplain #getCoordinateReferenceSystem coordinate reference system} coordinates. May * be {@code null} if this coverage has no associated coordinate reference system. For grid * coverages, the grid cells are centered on each grid coordinate. The envelope for a 2-D * grid coverage includes the following corner positions. * * <blockquote><pre> * (Minimum row - 0.5, Minimum column - 0.5) for the minimum coordinates * (Maximum row - 0.5, Maximum column - 0.5) for the maximum coordinates * </pre></blockquote> * * The default implementation returns the domain of validity of the CRS, if there is one. * * @return The bounding box for the coverage domain in coordinate system coordinates. */ public Envelope getEnvelope() { return CRS.getEnvelope(crs); }
final Envelope domain = CRS.getEnvelope(crs); if (domain != null) { final CoordinateReferenceSystem domainCRS =
Envelope validExtent = CRS.getEnvelope(crs); if (validExtent != null) { len = getMaxIntegerLen(validExtent);
/** * Returns a copy of current envelope. If no envelope has been {@linkplain #setEnvelope * explicitly defined}, then the default is inferred from the CRS (by default a geographic * envelope from 180°W to 180°E and 90°S to 90°N). */ public Envelope getEnvelope() { if (envelope != null) { return envelope.clone(); } else { final CoordinateReferenceSystem crs = getCoordinateReferenceSystem(); Envelope candidate = CRS.getEnvelope(crs); if (candidate == null) { final GeneralEnvelope copy = new GeneralEnvelope(crs); copy.setToNull(); candidate = copy; } return candidate; } }
@Override protected void onAfterSubmit(AjaxRequestTarget target, Form<?> form) { super.onAfterSubmit(target, form); try { CoordinateReferenceSystem crs = envelopePanel.getCoordinateReferenceSystem(); if (crs == null) return; ReferencedEnvelope refEnv = new ReferencedEnvelope(CRS.getEnvelope(crs)); envelopePanel.setModelObject(refEnv); envelopePanel.modelChanged(); target.add(envelopePanel); } catch (Exception e) { throw new WicketRuntimeException(e); } }
/** * Sets the coordinate reference system to the specified value. If an * {@linkplain #setEnvelope envelope was previously defined}, it will * be reprojected to the new CRS. * * @throws IllegalArgumentException if the CRS is illegal for the * {@linkplain #getEnvelope current envelope}. */ public void setCoordinateReferenceSystem(final CoordinateReferenceSystem crs) throws IllegalArgumentException { if (envelope == null) { if (crs != null) { envelope = wrap(CRS.getEnvelope(crs)); if (envelope == null) { envelope = new GeneralEnvelope(crs); envelope.setToNull(); } } } else try { envelope = wrap(CRS.transform(envelope, crs)); } catch (TransformException exception) { throw new IllegalArgumentException(Errors.format( ErrorKeys.ILLEGAL_COORDINATE_REFERENCE_SYSTEM), exception); } coverage = null; }
/** * Creates an initially empty table model using the specified coordinate reference system. */ public CoordinateTableModel(final CoordinateReferenceSystem crs) { this.crs = crs; final CoordinateSystem cs = crs.getCoordinateSystem(); columnNames = new String[cs.getDimension()]; for (int i=0; i<columnNames.length; i++){ columnNames[i] = crs.getCoordinateSystem().getAxis(i).getName().getCode(); } validArea = new GeneralEnvelope(CRS.getEnvelope(crs)); }
StaticRasterReader(Object source) { coverageFactory = new GridCoverageFactory(); crs = DefaultGeographicCRS.WGS84; // instantiate the bounds based on the default CRS originalEnvelope = new GeneralEnvelope(CRS.getEnvelope(crs)); originalEnvelope.setCoordinateReferenceSystem(crs); originalGridRange = new GeneralGridEnvelope(originalEnvelope, PixelInCell.CELL_CENTER); // create a default layout based on the static image setlayout(new ImageLayout(STATIC_IMAGE)); }