String typeName = inlineFeatureDatastore.getTypeNames()[0]; MemoryDataStore reTypedDS = new MemoryDataStore(new ForceCoordinateSystemFeatureReader(ilReader, crs));
public void testSameCRS() throws Exception { CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84; GeometryFactory fac = new GeometryFactory(); Point p = fac.createPoint(new Coordinate(10, 10)); SimpleFeatureCollection features = createTestFeatureCollection(crs, p); FeatureReader<SimpleFeatureType, SimpleFeature> original = DataUtilities.reader(features); // FeatureReader<SimpleFeatureType, SimpleFeature> original = new CollectionFeatureReader( // features, features.getSchema() ); try (ForceCoordinateSystemFeatureReader modified = new ForceCoordinateSystemFeatureReader(DataUtilities.reader(features), crs); ) { SimpleFeature f1 = original.next(); SimpleFeature f2 = modified.next(); assertEquals(f1, f2); assertFalse(original.hasNext()); assertFalse(modified.hasNext()); assertSame(modified.builder.getFeatureType(), original.getFeatureType()); } }
new ForceCoordinateSystemFeatureReader(DataUtilities.reader(features), destCRS); ) { SimpleFeature f1 = original.next(); SimpleFeature f2 = modified.next(); assertFalse(modified.hasNext());
protected FeatureReader<SimpleFeatureType, SimpleFeature> applyReprojectionDecorator( FeatureReader<SimpleFeatureType, SimpleFeature> reader, Query query, GetFeatureRequest request) { FeatureReader<SimpleFeatureType, SimpleFeature> tmp = reader; if (query.getCoordinateSystem() != null && !query.getCoordinateSystem() .equals(reader.getFeatureType().getCoordinateReferenceSystem())) { if (request.getSrsName() != null) { try { reader = new ForceCoordinateSystemFeatureReader( reader, query.getCoordinateSystem()); } catch (SchemaException e) { LOGGER.warning(e.toString()); reader = tmp; } } else { try { reader = new ReprojectFeatureReader(reader, query.getCoordinateSystem()); } catch (Exception e) { LOGGER.warning(e.toString()); reader = tmp; } } } return reader; }
public void testDifferentCRS() throws Exception { CoordinateReferenceSystem srcCRS = DefaultGeographicCRS.WGS84; GeometryFactory fac = new GeometryFactory(); Point p = fac.createPoint(new Coordinate(10, 10)); SimpleFeatureCollection features = createTestFeatureCollection(srcCRS, p); FeatureReader<SimpleFeatureType, SimpleFeature> original = DataUtilities.reader(features); CoordinateReferenceSystem destCRS = DefaultEngineeringCRS.CARTESIAN_2D; try (ForceCoordinateSystemFeatureReader modified = new ForceCoordinateSystemFeatureReader(DataUtilities.reader(features), destCRS); ) { SimpleFeature f1 = original.next(); SimpleFeature f2 = modified.next(); assertEquals( ((Geometry) f1.getDefaultGeometry()).getCoordinate(), ((Geometry) f2.getDefaultGeometry()).getCoordinate()); SimpleFeatureType f1Type = f1.getFeatureType(); SimpleFeatureType f2Type = f2.getFeatureType(); assertFalse( f1Type.getCoordinateReferenceSystem() .equals(f2Type.getCoordinateReferenceSystem())); assertEquals(srcCRS, f1Type.getCoordinateReferenceSystem()); assertEquals(srcCRS, f1Type.getGeometryDescriptor().getCoordinateReferenceSystem()); assertEquals(destCRS, f2Type.getCoordinateReferenceSystem()); assertEquals(destCRS, f2Type.getGeometryDescriptor().getCoordinateReferenceSystem()); assertFalse(original.hasNext()); assertFalse(modified.hasNext()); assertNotNull(modified.builder); } }
public void testNullDestination() throws Exception { CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84; GeometryFactory fac = new GeometryFactory(); Point p = fac.createPoint(new Coordinate(10, 10)); SimpleFeatureCollection features = createTestFeatureCollection(crs, p); try { new ForceCoordinateSystemFeatureReader( DataUtilities.reader(features), (CoordinateReferenceSystem) null); fail(); // should throw a nullpointer exception. } catch (NullPointerException e) { // good } }
reader = new ForceCoordinateSystemFeatureReader(reader, sourceCRS); } catch (SchemaException e) { throw (IOException)
protected FeatureReader<SimpleFeatureType, SimpleFeature> applyReprojectionDecorator(FeatureReader <SimpleFeatureType, SimpleFeature> reader, Query query, CoordinateReferenceSystem dataCRS) { FeatureReader<SimpleFeatureType, SimpleFeature> tmp = reader; if (query.getCoordinateSystem() != null && !query.getCoordinateSystem().equals(reader.getFeatureType().getCoordinateReferenceSystem())) { try { reader = new ForceCoordinateSystemFeatureReader(reader, query.getCoordinateSystem()); } catch (SchemaException e) { WFS_1_0_0_DataStore.LOGGER.warning(e.toString()); reader = tmp; } } else { if (reader.getFeatureType().getGeometryDescriptor() != null && dataCRS != null && reader.getFeatureType().getCoordinateReferenceSystem() == null) { // set up crs try { reader = new ForceCoordinateSystemFeatureReader(reader, dataCRS); } catch (SchemaException e) { WFS_1_0_0_DataStore.LOGGER.warning(e.toString()); reader = tmp; } } } return reader; }
protected FeatureReader<SimpleFeatureType, SimpleFeature> applyReprojectionDecorator( FeatureReader<SimpleFeatureType, SimpleFeature> reader, Query query, GetFeatureRequest request) { FeatureReader<SimpleFeatureType, SimpleFeature> tmp = reader; if (query.getCoordinateSystem() != null && !query.getCoordinateSystem() .equals(reader.getFeatureType().getCoordinateReferenceSystem())) { if (request.getSrsName() != null) { try { reader = new ForceCoordinateSystemFeatureReader( reader, query.getCoordinateSystem()); } catch (SchemaException e) { LOGGER.warning(e.toString()); reader = tmp; } } else { try { reader = new ReprojectFeatureReader(reader, query.getCoordinateSystem()); } catch (Exception e) { LOGGER.warning(e.toString()); reader = tmp; } } } return reader; }
reader = new ForceCoordinateSystemFeatureReader(reader, CRS.decode(serverSrs)); } catch (Exception e) {
: getMapRequest.getCrs(); MemoryDataStore reTypedDS = new MemoryDataStore( new ForceCoordinateSystemFeatureReader(ilReader, crs)); currLayer.setFeature(new TemporaryFeatureTypeInfo(reTypedDS));
: getMapRequest.getCrs(); MemoryDataStore reTypedDS = new MemoryDataStore( new ForceCoordinateSystemFeatureReader(ilReader, crs)); currLayer.setFeature(new TemporaryFeatureTypeInfo(reTypedDS));
private static MapLayerInfo initializeInlineFeatureLayer( UserLayer ul, CoordinateReferenceSystem requestCrs) throws Exception { // SPECIAL CASE - we make the temporary version final DataStore inlineDatastore = ul.getInlineFeatureDatastore(); final SimpleFeatureSource source; // what if they didn't put an "srsName" on their geometry in their // inlinefeature? // I guess we should assume they mean their geometry to exist in the // output SRS of the // request they're making. if (ul.getInlineFeatureType().getCoordinateReferenceSystem() == null) { LOGGER.warning( "No CRS set on inline features default geometry. " + "Assuming the requestor has their inlinefeatures in the boundingbox CRS."); SimpleFeatureType currFt = ul.getInlineFeatureType(); Query q = new Query(currFt.getTypeName(), Filter.INCLUDE); FeatureReader<SimpleFeatureType, SimpleFeature> ilReader; ilReader = inlineDatastore.getFeatureReader(q, Transaction.AUTO_COMMIT); ForceCoordinateSystemFeatureReader reader = new ForceCoordinateSystemFeatureReader(ilReader, requestCrs); MemoryDataStore reTypedDS = new MemoryDataStore(reader); source = reTypedDS.getFeatureSource(reTypedDS.getTypeNames()[0]); } else { source = inlineDatastore.getFeatureSource(inlineDatastore.getTypeNames()[0]); } MapLayerInfo mapLayer = new MapLayerInfo(source); return mapLayer; }