public String getSRS() { return delegate.getSRS(); }
/** * As per GEOS-3513, make sure the old SRS codes are imported by adding the EPSG: prefix where * needed */ public void testCRSPrefix() throws Exception { MockData mockData = (MockData) getTestData(); mockData.getCoveragesDirectory().delete(); Catalog catalog = new CatalogImpl(); LegacyCatalogImporter importer = new LegacyCatalogImporter(catalog); File dataDirectoryRoot = mockData.getDataDirectoryRoot(); importer.imprt(dataDirectoryRoot); FeatureTypeInfo typeInfo = catalog.getFeatureTypeByName(typeName.getNamespaceURI(), typeName.getLocalPart()); assertEquals("EPSG:4326", typeInfo.getSRS()); } }
b.setCRS(getCRS(info.getSRS())); ad = b.buildDescriptor(old.getLocalName());
@Test public void testForce() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.BASIC_POLYGONS.getLocalPart()); assertEquals("EPSG:4269", fti.getSRS()); assertEquals(ProjectionPolicy.FORCE_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4269"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); fi.close(); assertEquals(CRS.decode("EPSG:4269"), f.getType().getCoordinateReferenceSystem()); }
@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 testLookupSRSDetached() throws Exception { Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); DataStoreInfo sf = cat.getDataStoreByName("sf"); FeatureSource fs = sf.getDataStore(null).getFeatureSource(toName(MockData.PRIMITIVEGEOFEATURE)); FeatureTypeInfo ft = cat.getFactory().createFeatureType(); ft.setNativeName("PrimitiveGeoFeature"); assertNull(ft.getSRS()); assertNull(ft.getCRS()); cb.lookupSRS(ft, fs, true); assertNotNull(ft.getSRS()); assertNotNull(ft.getCRS()); }
@Test public void testLeaveNative() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.LINES.getLocalPart()); assertEquals("EPSG:3004", fti.getSRS()); assertEquals(ProjectionPolicy.NONE, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:32615"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that the geometry was left in tact Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertTrue(g.equalsExact(WKT.read("LINESTRING(500125 500025,500175 500075)"))); fi.close(); assertEquals(CRS.decode("EPSG:32615"), f.getType().getCoordinateReferenceSystem()); }
/** Initializes a feature type object setting any info that has not been set. */ public void initFeatureType(FeatureTypeInfo featureType) throws Exception { if (featureType.getCatalog() == null) { featureType.setCatalog(catalog); } initResourceInfo(featureType); // setup the srs if missing if (featureType.getSRS() == null) { lookupSRS(featureType, true); } if (featureType.getProjectionPolicy() == null) { setupProjectionPolicy(featureType); } // deal with bounding boxes as possible CoordinateReferenceSystem crs = featureType.getCRS(); if (featureType.getLatLonBoundingBox() == null && featureType.getNativeBoundingBox() == null) { // both missing, we compute them setupBounds(featureType); } else if (featureType.getLatLonBoundingBox() == null) { // native available but geographic to be computed setupBounds(featureType); } else if (featureType.getNativeBoundingBox() == null && crs != null) { // we know the geographic and we can reproject back to native ReferencedEnvelope boundsLatLon = featureType.getLatLonBoundingBox(); featureType.setNativeBoundingBox(boundsLatLon.transform(crs, true)); } }
@Test public void testReproject() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.POLYGONS.getLocalPart()); assertEquals("EPSG:4326", fti.getSRS()); assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that geometry was actually reprojected Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertFalse( g.equalsExact( WKT.read( "POLYGON((500225 500025,500225 500075,500275 500050,500275 500025,500225 500025))"))); fi.close(); assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem()); }
@Test public void testWithRename() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName("MyPoints"); assertEquals("EPSG:4326", fti.getSRS()); assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that geometry was reprojected Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertFalse(g.equalsExact(WKT.read("POINT(500050 500050)"))); fi.close(); assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem()); }
resultCRS = nativeCRS; } else { resultCRS = getCRS(info.getSRS());
@Test public void testFeatureType() throws Exception { // build a feature type (it's already in the catalog, but we just want to // check it's built as expected // LINES is a feature type with a native SRS, so we want the bounds to be there Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.LINES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.LINES)); // perform basic checks assertEquals("EPSG:32615", fti.getSRS()); assertEquals(CRS.decode("EPSG:32615", true), fti.getCRS()); assertNull(fti.getNativeBoundingBox()); assertNull(fti.getLatLonBoundingBox()); // force bounds computation cb.setupBounds(fti); assertNotNull(fti.getNativeBoundingBox()); assertNotNull(fti.getNativeBoundingBox().getCoordinateReferenceSystem()); assertNotNull(fti.getLatLonBoundingBox()); }
@Test public void testFeatureTypeNoSRS() throws Exception { // build a feature type (it's already in the catalog, but we just want to // check it's built as expected // LINES is a feature type with a native SRS, so we want the bounds to be there Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.BRIDGES.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.BRIDGES)); // perform basic checks, this has no srs, so default one will be set assertEquals(CatalogBuilder.DEFAULT_SRS, fti.getSRS()); assertNull(fti.getNativeCRS()); assertNull(fti.getNativeBoundingBox()); assertNull(fti.getLatLonBoundingBox()); // force bounds computation cb.setupBounds(fti); assertNotNull(fti.getNativeBoundingBox()); assertNull(fti.getNativeBoundingBox().getCoordinateReferenceSystem()); assertNotNull(fti.getLatLonBoundingBox()); }
@Test public void testGeometryless() throws Exception { // build a feature type (it's already in the catalog, but we just want to // check it's built as expected // LINES is a feature type with a native SRS, so we want the bounds to be there Catalog cat = getCatalog(); CatalogBuilder cb = new CatalogBuilder(cat); cb.setStore(cat.getDataStoreByName(MockData.GEOMETRYLESS.getPrefix())); FeatureTypeInfo fti = cb.buildFeatureType(toName(MockData.GEOMETRYLESS)); LayerInfo layer = cb.buildLayer(fti); cb.setupBounds(fti); // perform basic checks assertEquals(CatalogBuilder.DEFAULT_SRS, fti.getSRS()); assertNotNull(fti.getNativeBoundingBox()); assertTrue(fti.getNativeBoundingBox().isEmpty()); assertNotNull(fti.getLatLonBoundingBox()); assertFalse(fti.getLatLonBoundingBox().isEmpty()); assertNull(layer.getDefaultStyle()); }
assertEquals(ds, ft.getStore()); assertEquals(ns, ft.getNamespace()); assertEquals("EPSG:4326", ft.getSRS()); assertEquals(new Measure(10, SI.METRE), ft.getLinearizationTolerance()); assertTrue(CRS.equalsIgnoreMetadata(CRS.decode("EPSG:4326"), ft.getNativeCRS()));
public DomainType getSrsParameter(WFSInfo wfs) { List<String> extraSRS = wfs.getSRS(); Set<String> srsParameterValues; GMLInfo gml = wfs.getGML().get(WFSInfo.Version.V_20); String prefix = gml.getSrsNameStyle().getPrefix(); Function<String, String> epsgMapper = srs -> qualifySRS(prefix, srs); if (extraSRS != null && !extraSRS.isEmpty()) { srsParameterValues = extraSRS.stream() .map(epsgMapper) .collect(Collectors.toCollection(LinkedHashSet::new)); } else { srsParameterValues = new LinkedHashSet<>(); } // add values from feature types gs.getCatalog() .getFeatureTypes() .forEach( ft -> { String srs = epsgMapper.apply(ft.getSRS()); srsParameterValues.add(srs); }); // build the parameter DomainType srsParameter = new DomainType("srsName", new ArrayList<>(srsParameterValues)); return srsParameter; }
XMLAssert.assertXpathExists(base, doc); boolean wgs84Native = "EPSG:4326".equals(ft.getSRS()); if (wgs84Native) { assertXpathEvaluatesTo("2", "count(" + base + "/wfs:OtherSRS)", doc);
assertEquals("EPSG:4326", fti.getSRS()); SimpleFeatureSource fs = (SimpleFeatureSource) fti.getFeatureSource(null, null); assertEquals(2, fs.getCount(Query.ALL));