@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; } }
/** * 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 testLatLonBounds() throws Exception { ReferencedEnvelope nativeBounds = new ReferencedEnvelope(700000, 800000, 4000000, 4100000, null); CoordinateReferenceSystem crs = CRS.decode("EPSG:32632", true); CatalogBuilder cb = new CatalogBuilder(getCatalog()); ReferencedEnvelope re = cb.getLatLonBounds(nativeBounds, crs); assertEquals(DefaultGeographicCRS.WGS84, re.getCoordinateReferenceSystem()); assertEquals(11.22, re.getMinX(), 0.01); assertEquals(36.1, re.getMinY(), 0.01); }
@Test public void testWgs84BoundsFromCompoundCRS() throws Exception { try { MapProjection.SKIP_SANITY_CHECKS = true; CatalogBuilder cb = new CatalogBuilder(getCatalog()); ReferencedEnvelope3D bounds = new ReferencedEnvelope3D( 142892, 470783, 16, 142900, 470790, 20, CRS.decode("EPSG:7415")); // used to throw an exception here ReferencedEnvelope latLonBounds = cb.getLatLonBounds(bounds, bounds.getCoordinateReferenceSystem()); assertTrue( CRS.equalsIgnoreMetadata( CRS.decode("EPSG:4326"), latLonBounds.getCoordinateReferenceSystem())); // System.out.println(latLonBounds); } finally { MapProjection.SKIP_SANITY_CHECKS = false; } }
/** * Test custom PADDING is being used when provided as Hint * * @throws Exception */ @Test public void testPadding() throws Exception { CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326", true); final double envWidth = 30; final double envHeight = 30; ReferencedEnvelope mapExtent = new ReferencedEnvelope(0, envWidth, 0, envHeight, wgs84); Rectangle screenSize = new Rectangle((int) envWidth, (int) envHeight); checkPadding(screenSize, mapExtent, 4); checkPadding(screenSize, mapExtent, 12); }
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()); }
/** * 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); }
@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 testCRSConverterInvalidWKT() throws Exception { CoordinateReferenceSystem crs = CRS.decode("EPSG:3575"); try { ((Formattable) crs).toWKT(2, true); fail("expected exception"); } catch (UnformattableObjectException e) { } String wkt = null; try { wkt = new CRSConverter().toString(crs); } catch (UnformattableObjectException e) { fail("Should have thrown exception"); } CoordinateReferenceSystem crs2 = (CoordinateReferenceSystem) new CRSConverter().fromString(wkt); assertTrue(CRS.equalsIgnoreMetadata(crs, crs2)); }
@Test public void testOutsideDefinitionArea() throws Exception { // setup a request that is outside of the coverage CoordinateReferenceSystem crs = CRS.decode("EPSG:3031", true); ReferencedEnvelope mapExtent = new ReferencedEnvelope(-1250000, 0, -13750000, -12500000, crs); // System.out.println(mapExtent.transform(DefaultGeographicCRS.WGS84, true)); GridCoverageReaderHelper helper = new GridCoverageReaderHelper( reader, new Rectangle(400, 200), mapExtent, Interpolation.getInstance(Interpolation.INTERP_NEAREST)); // read, nothing should come out ProjectionHandler handler = ProjectionHandlerFinder.getHandler( mapExtent, reader.getCoordinateReferenceSystem(), true); List<GridCoverage2D> coverages = helper.readCoverages(null, handler); assertTrue(coverages.isEmpty()); }
@BeforeClass public static void setupCRS() throws FactoryException { CRS.reset("all"); Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); // the following is only to make the test work in Eclipse, where the test // classpath is tainted by the test classpath of dependent modules (whilst in Maven it's // not) Set<CRSAuthorityFactory> factories = ReferencingFactoryFinder.getCRSAuthorityFactories(null); for (CRSAuthorityFactory factory : factories) { if (factory.getClass().getSimpleName().equals("EPSGCRSAuthorityFactory")) { ReferencingFactoryFinder.removeAuthorityFactory(factory); } } assertEquals( AxisOrder.NORTH_EAST, CRS.getAxisOrder(CRS.decode("urn:ogc:def:crs:EPSG::4326"))); }
@Override public void createIndividuals() { try { coverageCRS = CRS.decode(crsCode, true); } catch (Exception e) { LOG.error("error decoding coordinate reference system code.", e); return; } if (boundsFromGraph) { // autowire graph service or pass in } gridEnvelope = new GridEnvelope2D(0, 0, cols, rows); refEnvelope = new ReferencedEnvelope(left, right, bottom, top, coverageCRS); gridGeometry = new GridGeometry2D(gridEnvelope, refEnvelope); super.createIndividuals0(); }
/** * Check we are actually using the EPSG database for anything not in override * * @throws TransformException */ @Test public void testFallbackOnEPSGDatabaseStd() throws Exception { // Test CRSs CoordinateReferenceSystem source = CRS.decode("EPSG:3002"); CoordinateReferenceSystem target = CRS.decode("EPSG:4326"); CoordinateOperation co = CRS.getCoordinateOperationFactory(true).createOperation(source, target); ConcatenatedOperation cco = (ConcatenatedOperation) co; // the EPSG one only has two steps, the non EPSG one 4 assertEquals(2, cco.getOperations().size()); }
@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); }
@Test public void testReprojectLayerGroup() throws NoSuchAuthorityCodeException, FactoryException, Exception { Catalog catalog = getCatalog(); CatalogBuilder cb = new CatalogBuilder(catalog); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); LayerInfo l = catalog.getLayerByName(getLayerId(MockData.ROAD_SEGMENTS)); lg.getLayers().add(l); lg.getStyles().add(null); lg.setName("test-reproject"); // EPSG:4901 "equivalent" but different uom String wkt = "GEOGCS[\"GCS_ATF_Paris\",DATUM[\"D_ATF\",SPHEROID[\"Plessis_1817\",6376523.0,308.64]],PRIMEM[\"Paris\",2.337229166666667],UNIT[\"Grad\",0.01570796326794897]]"; CoordinateReferenceSystem lCrs = CRS.parseWKT(wkt); ((FeatureTypeInfo) l.getResource()).setSRS(null); ((FeatureTypeInfo) l.getResource()).setNativeCRS(lCrs); assertNull(CRS.lookupEpsgCode(lCrs, false)); // Use the real thing now CoordinateReferenceSystem lgCrs = CRS.decode("EPSG:4901"); assertNotNull(CRS.lookupEpsgCode(lgCrs, false)); // Reproject our layer group to EPSG:4901. We expect it to have an EPSG code. cb.calculateLayerGroupBounds(lg, lgCrs); assertNotNull(CRS.lookupEpsgCode(lg.getBounds().getCoordinateReferenceSystem(), false)); }
@Test public void testCutGeometryLambertConformal() throws Exception { // get a lambert conformal conic with ReferencedEnvelope wgs84South = new ReferencedEnvelope(-180, -90, -40, 0, WGS84); ReferencedEnvelope laeSouth = wgs84South.transform(CRS.decode("EPSG:2194"), true); ProjectionHandler handler = ProjectionHandlerFinder.getHandler(laeSouth, WGS84, true); // a Geometry that crosses the opposite of the central meridian Polygon geometry = JTS.toGeometry(new Envelope(5, 15, 0, 10)); Geometry preProcessed = handler.preProcess(geometry); assertTrue( "Should have sliced the geometry in two parts", preProcessed instanceof MultiPolygon); }
CoordinateReferenceSystem crs = srs != null ? CRS.decode(srs) : null; baseMap.put("baseMapEnvelope", new ReferencedEnvelope(x1, x2, y1, y2, crs));
/** 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); } }
@Test public void testQueryEnvelopeOnInvalidArea2() throws Exception { // and Envelope that does not make sense for EPSG:3003, too far away from central meridian ReferencedEnvelope re = new ReferencedEnvelope(-130, -120, -40, 30, DefaultGeographicCRS.WGS84); ReferencedEnvelope re3857 = re.transform(CRS.decode("EPSG:3857", true), true); ProjectionHandler ph = ProjectionHandlerFinder.getHandler(re3857, CRS.decode("EPSG:3003", true), true); List<ReferencedEnvelope> queryEnvelopes = ph.getQueryEnvelopes(); assertEquals(0, queryEnvelopes.size()); }
/** * Tests the {@code 42101} code. The purpose of this test is mostly to make sure that {@link * FactoryUsingWKT} is in the chain. * * @throws FactoryException If the CRS can't be created. */ @Test public void test42101() throws FactoryException { assertTrue(CRS.decode("EPSG:42101") instanceof ProjectedCRS); }