public void init(FilterConfig filterConfig) throws ServletException { CRS.cleanupThreadLocals(); } }
@Override public Object fromString(String str) { if (str.toUpperCase().startsWith("EPSG:")) { try { return CRS.decode(str); } catch (Exception e) { XStreamPersister.LOGGER.log(Level.WARNING, "Error decode epsg code: " + str, e); } } else { try { return CRS.parseWKT(str); } catch (FactoryException e) { XStreamPersister.LOGGER.log(Level.WARNING, "Error decode wkt: " + str, e); } } return null; } }
public CRSParameter (String name) { try { crs = CRS.decode(name, true); } catch (Exception e) { throw new WebApplicationException(onError(name, e)); } }
/** * Test method for {@link CoordinateOperationFactoryUsingWKT#createCoordinateOperation}. * * @throws TransformException */ @Test public void testCreateOperationFromCustomCodes() throws Exception { // Test CRSs CoordinateReferenceSystem source = CRS.decode(SOURCE_CRS); CoordinateReferenceSystem target = CRS.decode(TARGET_CRS); MathTransform mt = CRS.findMathTransform(source, target, true); // Test MathTransform double[] p = new double[2]; mt.transform(SRC_TEST_POINT, 0, p, 0, 1); assertEquals(p[0], DST_TEST_POINT[0], 1e-8); assertEquals(p[1], DST_TEST_POINT[1], 1e-8); }
@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); }
if (CRS.equalsIgnoreMetadata(sourceCRS, DefaultGeographicCRS.WGS84)) { return new GeneralEnvelope(envelope); if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { targetEnvelope = CRS.transform(envelope, targetCRS); } else { targetEnvelope = new GeneralEnvelope(envelope);
/** Helper method for transforming an envelope. */ private static ReferencedEnvelope transform(ReferencedEnvelope e, CoordinateReferenceSystem crs) throws TransformException, FactoryException { if (!CRS.equalsIgnoreMetadata(crs, e.getCoordinateReferenceSystem())) { return e.transform(crs, true); } return e; }
@Override public Object fromString(String str) { try { return CRS.parseWKT(str); } catch (Exception e) { try { return new SRSConverter().fromString(str); } catch (Exception e1) { } throw new RuntimeException(e); } } }
@Override public String toString(Object obj) { CoordinateReferenceSystem crs = (CoordinateReferenceSystem) obj; try { Integer epsg = CRS.lookupEpsgCode(crs, false); if (epsg != null) { return "EPSG:" + epsg; } } catch (FactoryException e) { XStreamPersister.LOGGER.warning( "Could not determine epsg code of crs, encoding as WKT"); } return new CRSConverter().toString(crs); }
/** * 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); } }
@Override protected void setUpTestData(SystemTestData testData) throws Exception { new File(testData.getDataDirectoryRoot(), "user_projections").mkdir(); testData.copyTo( OverrideCRSTest.class.getResourceAsStream("test_override_epsg.properties"), "user_projections/epsg_overrides.properties"); CRS.reset("all"); testData.setUpSecurity(); }
/** * Test method for {@link CoordinateOperationFactoryUsingWKT#createCoordinateOperation}. * * @throws TransformException */ @Test public void testOverrideEPSGOperation() throws Exception { // Test CRSs CoordinateReferenceSystem source = CRS.decode("EPSG:4269"); CoordinateReferenceSystem target = CRS.decode("EPSG:4326"); MathTransform mt = CRS.findMathTransform(source, target, true); // Test MathTransform double[] p = new double[2]; mt.transform(SRC_TEST_POINT, 0, p, 0, 1); assertEquals(p[0], DST_TEST_POINT[0], 1e-8); assertEquals(p[1], DST_TEST_POINT[1], 1e-8); }
public CoordinateReferenceSystem getCRS() { if (getSRS() == null) { return null; } // TODO: cache this try { return CRS.decode(getSRS()); } catch (Exception e) { throw new RuntimeException( "This is unexpected, the layer seems to be mis-configured", e); } }
@Test public void testSRSConverter() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:4901"); SRSConverter c = new SRSConverter(); assertEquals("EPSG:4901", c.toString(crs)); // definition with odd UOM that won't be matched to the EPSG one assertFalse( "EPSG:4901" .equals( c.toString( CRS.parseWKT( "GEOGCS[\"GCS_ATF_Paris\",DATUM[\"D_ATF\",SPHEROID[\"Plessis_1817\",6376523.0,308.64]],PRIMEM[\"Paris\",2.337229166666667],UNIT[\"Grad\",0.01570796326794897]]")))); }
public void destroy() { CRS.cleanupThreadLocals(); }
/** See if we can use the stgeorge grid shift files as the ESPG db would like us to */ @Test public void testNadCon() throws Exception { CoordinateReferenceSystem crs4138 = CRS.decode("EPSG:4138"); CoordinateReferenceSystem crs4326 = CRS.decode("EPSG:4326"); MathTransform mt = CRS.findMathTransform(crs4138, crs4326); assertTrue(mt.toWKT().contains("NADCON")); double[] src = new double[] {-169.625, 56.575}; double[] expected = new double[] {-169.62744, 56.576034}; double[] p = new double[2]; mt.transform(src, 0, p, 0, 1); assertEquals(expected[0], p[0], 1e-6); assertEquals(expected[1], p[1], 1e-6); } }
@Override public BoundingBox getBoundingBox(CoordinateReferenceSystem crs) { try { Envelope bounds = (Envelope) pedestrianIndex.getRoot().getBounds(); ReferencedEnvelope refEnv = new ReferencedEnvelope(bounds, CRS.decode("EPSG:4326", true)); return refEnv.toBounds(crs); } catch (Exception e) { LOG.error("error transforming graph bounding box to request CRS : {}", crs); return null; } }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { chain.doFilter(request, response); } finally { CRS.cleanupThreadLocals(); } }
@Override protected void setUpTestData(SystemTestData testData) throws Exception { testData.setUpRasterLayer(WATTEMP, "watertemp.zip", null, null, TestData.class); testData.setUpRasterLayer(S2REDUCED, "s2reduced.zip", null, null, TestData.class); testData.setUpRasterLayer(IR_RGB, "ir-rgb.zip", null, null, TestData.class); testData.setUpRasterLayer(BANDS_FLAGS, "bands-flags.zip", null, null, TestData.class); UTM32N = CRS.decode("EPSG:32632", true); }
void assertWMSLayer(WMSLayerInfo wmsLayer) throws Exception { assertEquals("states", wmsLayer.getName()); assertEquals("topp:states", wmsLayer.getNativeName()); assertEquals("EPSG:4326", wmsLayer.getSRS()); assertEquals("USA Population", wmsLayer.getTitle()); assertEquals("2000 census data for United States.", wmsLayer.getAbstract()); assertEquals(CRS.decode("EPSG:4326"), wmsLayer.getNativeCRS()); assertNotNull(wmsLayer.getNativeBoundingBox()); assertNotNull(wmsLayer.getLatLonBoundingBox()); assertFalse(wmsLayer.getKeywords().isEmpty()); }