if (crs == null) { if (data != null) { crs = data.getSchema().getCoordinateReferenceSystem(); } else { crs = ftinfo.getFeatureType().getCoordinateReferenceSystem();
/** * Retreives the bounds for a feature source. * * <p>If the feautre source can calculate the bounds directly, those bounds are returned. * Otherwise, the underlying feature collection is retreived and asked to calculate bounds. If * that fails, an empty envelope is returned. * * @param fs The feature source. * @return The bounds. * @throws IOException Execption calculating bounds on feature source. */ public static ReferencedEnvelope getBoundingBoxEnvelope( FeatureSource<? extends FeatureType, ? extends Feature> fs) throws IOException { ReferencedEnvelope ev = fs.getBounds(); if ((ev == null) || ev.isNull()) { try { ev = fs.getFeatures().getBounds(); } catch (Throwable t) { LOGGER.log( Level.FINE, "Could not compute the data bounding box. Returning an empty envelope", t); ev = new ReferencedEnvelope(fs.getSchema().getCoordinateReferenceSystem()); } } return ev; } }
@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 testMetadataFromFeatueSource() throws Exception { CatalogBuilder cb = new CatalogBuilder(getCatalog()); cb.setStore(cb.buildDataStore("fooStore")); FeatureType ft = createMock(FeatureType.class); expect(ft.getName()).andReturn(new NameImpl("foo")).anyTimes(); expect(ft.getCoordinateReferenceSystem()).andReturn(null).anyTimes(); expect(ft.getGeometryDescriptor()).andReturn(null).anyTimes(); replay(ft); ResourceInfo rInfo = createMock(ResourceInfo.class); expect(rInfo.getTitle()).andReturn("foo title"); expect(rInfo.getDescription()).andReturn("foo description"); expect(rInfo.getKeywords()) .andReturn(new LinkedHashSet<String>(Arrays.asList("foo", "bar", "baz", ""))) .anyTimes(); replay(rInfo); FeatureSource fs = createMock(FeatureSource.class); expect(fs.getSchema()).andReturn(ft).anyTimes(); expect(fs.getInfo()).andReturn(rInfo).anyTimes(); expect(fs.getName()).andReturn(ft.getName()).anyTimes(); replay(fs); FeatureTypeInfo ftInfo = cb.buildFeatureType(fs); assertEquals("foo title", ftInfo.getTitle()); assertEquals("foo description", ftInfo.getDescription()); assertTrue(ftInfo.getKeywords().contains(new Keyword("foo"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("bar"))); assertTrue(ftInfo.getKeywords().contains(new Keyword("baz"))); }
@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()); }
@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()); }
@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()); }
CoordinateReferenceSystem crs = featureType.getCoordinateReferenceSystem(); if (crs == null && featureType.getGeometryDescriptor() != null) { crs = featureType.getGeometryDescriptor().getCoordinateReferenceSystem();
featureType.setNativeCRS(ft.getCoordinateReferenceSystem()); } catch (Exception e) { LOGGER.warning(
public CoordinateReferenceSystem getCRS() { return WFSContentComplexFeatureSource.this .getSchema() .getCoordinateReferenceSystem(); }
@Override public CoordinateReferenceSystem getCRS() { return fs.getSchema().getCoordinateReferenceSystem(); }
public CoordinateReferenceSystem getCoordinateReferenceSystem() { return ((FeatureType) getSubject()).getCoordinateReferenceSystem(); }
/** * Computes the declared SRS of a layer based on the layer schema and the EPSG forcing flag * * @param schema * @return * @throws FactoryException * @throws NoSuchAuthorityCodeException */ private CoordinateReferenceSystem getDeclaredSRS(FeatureType schema) throws FactoryException { // compute the default SRS of the feature source CoordinateReferenceSystem declaredCRS = schema.getCoordinateReferenceSystem(); if (isEPSGAxisOrderForced()) { Integer code = CRS.lookupEpsgCode(declaredCRS, false); if (code != null) { declaredCRS = CRS.decode("urn:ogc:def:crs:EPSG::" + code); } } return declaredCRS; }
/** * Get the total bounds of this feature which is calculated by doing a union of the bounds of * each geometry this feature is associated with. * * @return An Envelope containing the total bounds of this Feature. * @task REVISIT: what to return if there are no geometries in the feature? For now we'll return * a null envelope, make this part of interface? (IanS - by OGC standards, all Feature must * have geom) */ public BoundingBox getBounds() { ReferencedEnvelope bounds = new ReferencedEnvelope(getType().getCoordinateReferenceSystem()); for (Iterator itr = getValue().iterator(); itr.hasNext(); ) { Property property = (Property) itr.next(); if (property instanceof GeometryAttribute) { bounds.include(((GeometryAttribute) property).getBounds()); } } return bounds; }
public Object visit(Literal expression, Object extraData) { Object value = expression.getValue(); if (value instanceof Geometry) { value = reproject((Geometry) value, featureType.getCoordinateReferenceSystem()); } return getFactory(extraData).literal(value); }
CoordinateReferenceSystem contentCRS = content.getCoordinateReferenceSystem(); CoordinateReferenceSystem layerCRS = layer.getFeatureSource().getSchema().getCoordinateReferenceSystem();
Object transform(final BinarySpatialOperator filter, Object extraData) { // check working assumptions, first expression is a property final CoordinateReferenceSystem propertyCrs; if (filter.getExpression1() instanceof BoundedByFunction) { propertyCrs = featureType.getCoordinateReferenceSystem(); } else { if (!(filter.getExpression1() instanceof PropertyName)) { throw new IllegalArgumentException( "Binary geometry filter, but first expression " + "is not a property name? (it's a " + filter.getExpression1().getClass() + ")"); } propertyCrs = findPropertyCRS((PropertyName) filter.getExpression1()); } if (propertyCrs == null) return cloneFilter(filter, extraData); // "transformed" expressions Expression ex1 = (Expression) filter.getExpression1() .accept(ReprojectingFilterVisitor.this, extraData); Expression ex2 = reproject(filter.getExpression2(), propertyCrs, true); return cloneFilter(filter, extraData, ex1, ex2); }
try { CoordinateReferenceSystem crs = collection.getSchema().getCoordinateReferenceSystem(); ReferencedEnvelope bounds = new ReferencedEnvelope(crs);
getLayer().getFeatureSource().getSchema().getCoordinateReferenceSystem();
FeatureType featureType = (FeatureType) type; defaultGeom = featureType.getGeometryDescriptor().getType().getName(); crs = featureType.getCoordinateReferenceSystem();