File f = new File ( "world.shp" ); ShapefileDataStore dataStore = new ShapefileDataStore ( f.toURI ().toURL () ); FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore.getFeatureSource (); String geomAttrName = featureSource.getSchema () .getGeometryDescriptor ().getLocalName (); ResourceInfo resourceInfo = featureSource.getInfo (); CoordinateReferenceSystem crs = resourceInfo.getCRS (); Hints hints = GeoTools.getDefaultHints (); hints.put ( Hints.JTS_SRID, 4326 ); hints.put ( Hints.CRS, crs ); FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2 ( hints ); GeometryFactory gf = JTSFactoryFinder.getGeometryFactory ( hints ); Coordinate land = new Coordinate ( -122.0087, 47.54650 ); Point pointLand = gf.createPoint ( land ); Coordinate water = new Coordinate ( 0, 0 ); Point pointWater = gf.createPoint ( water ); Intersects filter = ff.intersects ( ff.property ( geomAttrName ), ff.literal ( pointLand ) ); FeatureCollection<SimpleFeatureType, SimpleFeature> features = featureSource .getFeatures ( filter ); filter = ff.intersects ( ff.property ( geomAttrName ), ff.literal ( pointWater ) ); features = featureSource.getFeatures ( filter );
/** * Sets the GRID_COVERAGE_PROCESSOR hint to the specified value. * This is used by {@link BufferedProcessor} only. */ final void setProcessor(final AbstractProcessor processor) { hints.put(Hints.GRID_COVERAGE_PROCESSOR, processor); }
/** * Constructs a default coverage processor. The {@link #scanForPlugins} method will be * automatically invoked the first time an operation is required. Additional operations * can be added by subclasses with the {@link #addOperation} method. Rendering hints will * be initialized with the following hints: * <p> * <ul> * <li>{@link JAI#KEY_REPLACE_INDEX_COLOR_MODEL} set to {@link Boolean#FALSE}.</li> * <li>{@link JAI#KEY_TRANSFORM_ON_COLORMAP} set to {@link Boolean#FALSE}.</li> * </ul> * * @param hints A set of additional rendering hints, or {@code null} if none. */ public DefaultProcessor(final RenderingHints hints) { registry = new FactoryRegistry(Collections.singleton(Operation.class)); this.hints = new Hints(hints); this.hints.put(JAI.KEY_REPLACE_INDEX_COLOR_MODEL, Boolean.FALSE); this.hints.put(JAI.KEY_TRANSFORM_ON_COLORMAP, Boolean.FALSE); this.hints.put(Hints.GRID_COVERAGE_PROCESSOR, this); // Must overwrites user setting. }
/** Just the defaults, use GeometryFactoryFinder for the rest */ public ComplexFactoryImpl( Hints hints ) { if (hints == null) { this.crs = DefaultGeographicCRS.WGS84; hints = GeoTools.getDefaultHints(); hints.put(Hints.CRS, crs ); } else { this.crs = (CoordinateReferenceSystem) hints.get( Hints.CRS ); if( crs == null ){ throw new NullPointerException("A CRS Hint is required in order to use ComplexFactoryImpl"); } } hintsWeCareAbout.put(Hints.CRS, crs ); }
/** * @param crs */ public PrimitiveFactoryImpl(CoordinateReferenceSystem crs, PositionFactory positionFactory) { this.crs = crs; if( crs == null ){ throw new NullPointerException("A non null crs is required in order to use PrimitiveFactoryImpl"); } if (positionFactory == null) { Hints hints = GeoTools.getDefaultHints(); hints.put(Hints.CRS, crs ); this.positionFactory = GeometryFactoryFinder.getPositionFactory(hints); } else { this.positionFactory = positionFactory; } geomValidate = true; hintsWeCareAbout.put(Hints.CRS, crs ); hintsWeCareAbout.put(Hints.POSITION_FACTORY, positionFactory ); hintsWeCareAbout.put(Hints.GEOMETRY_VALIDATE, geomValidate ); }
/** * Create a new FeatureTypeFactory with the given typeName. * * @param name The typeName of the feature to create. * * @return A new FeatureTypeFactory instance. * * @throws FactoryConfigurationError If there exists a configuration error. */ public static FeatureTypeFactory newInstance(String typeName) throws FactoryConfigurationError { // warning not sure if CommonFactoryFinder is going to cache the instance or not? // Hints hints = GeoTools.getDefaultHints(); if( hints == null ){ hints = new Hints( Hints.FEATURE_TYPE_FACTORY_NAME, typeName ); } else { hints.put( Hints.FEATURE_TYPE_FACTORY_NAME, typeName ); } hints.put( Hints.FEATURE_TYPE_FACTORY_NAME, typeName ); return CommonFactoryFinder.getFeatureTypeFactory( hints ); }
/** * Constructs a default coverage processor. The {@link #scanForPlugins} method will be * automatically invoked the first time an operation is required. Additional operations * can be added by subclasses with the {@link #addOperation} method. Rendering hints will * be initialized with the following hints: * <p> * <ul> * <li>{@link JAI#KEY_REPLACE_INDEX_COLOR_MODEL} set to {@link Boolean#FALSE}.</li> * <li>{@link JAI#KEY_TRANSFORM_ON_COLORMAP} set to {@link Boolean#FALSE}.</li> * </ul> * * @param hints A set of additional rendering hints, or {@code null} if none. */ public CoverageProcessor(final RenderingHints hints) { registry = new FactoryRegistry(Arrays.asList(new Class<?>[] { Operation.class })); this.hints = new Hints(); this.hints.put(JAI.KEY_REPLACE_INDEX_COLOR_MODEL, Boolean.FALSE); this.hints.put(JAI.KEY_TRANSFORM_ON_COLORMAP, Boolean.FALSE); // override with user hints if(hints!=null) this.hints.add(hints); }
/** Just the defaults, use GeometryFactoryFinder for the rest */ public GeometryFactoryImpl( Hints hints ) { if (hints == null) { this.crs = DefaultGeographicCRS.WGS84; hints = GeoTools.getDefaultHints(); hints.put(Hints.CRS, crs ); } else { this.crs = (CoordinateReferenceSystem) hints.get( Hints.CRS ); if( crs == null ){ throw new NullPointerException("A CRS Hint is required in order to use GeometryFactoryImpl"); } } this.positionFactory = GeometryFactoryFinder.getPositionFactory(hints); hintsWeCareAbout.put(Hints.CRS, crs ); hintsWeCareAbout.put(Hints.POSITION_FACTORY, positionFactory ); }
/** * Create a new FeatureTypeFactory with the given typeName. * * @param name The typeName of the feature to create. * * @return A new FeatureTypeFactory instance. * * @throws FactoryRegistryException If there exists a configuration error. */ public static FeatureTypeFactory newInstance(String typeName) throws FactoryRegistryException { // warning not sure if CommonFactoryFinder is going to cache the instance or not? // Hints hints = GeoTools.getDefaultHints(); if( hints == null ){ hints = new Hints( Hints.FEATURE_TYPE_FACTORY_NAME, typeName ); } else { hints.put( Hints.FEATURE_TYPE_FACTORY_NAME, typeName ); } hints.put( Hints.FEATURE_TYPE_FACTORY_NAME, typeName ); return new DefaultFeatureTypeFactory(); }
/** Just the defaults, use GeometryFactoryFinder for the rest */ public PrimitiveFactoryImpl( Hints hints ) { if (hints == null) { this.crs = DefaultGeographicCRS.WGS84; hints = GeoTools.getDefaultHints(); hints.put(Hints.CRS, crs ); geomValidate = true; hints.put(Hints.GEOMETRY_VALIDATE, geomValidate); } else { this.crs = (CoordinateReferenceSystem) hints.get( Hints.CRS ); if( crs == null ){ throw new NullPointerException("A CRS Hint is required in order to use PrimitiveFactoryImpl"); } geomValidate = (Boolean) hints.get( Hints.GEOMETRY_VALIDATE ); if (geomValidate == null) { geomValidate = true; } } this.positionFactory = GeometryFactoryFinder.getPositionFactory(hints); hintsWeCareAbout.put(Hints.CRS, crs ); hintsWeCareAbout.put(Hints.POSITION_FACTORY, positionFactory ); hintsWeCareAbout.put(Hints.GEOMETRY_VALIDATE, geomValidate ); }
/** * Creates a new instance of GeoTiffMetadata2CRSAdapter * * @param hints * a map of hints to locate the authority and object factories. * (can be null) */ public GeoTiffMetadata2CRSAdapter(Hints hints) { final Hints tempHints = hints != null ? new Hints(hints) : DEFAULT_HINTS; this.hints = (Hints) tempHints.clone(); allAuthoritiesFactory = hints != null ? new AllAuthoritiesFactory(this.hints): DEFAULT_ALLAUTHORITIES_FACTORY; // factory = new ThreadedEpsgFactory(hints); datumObjFactory = ReferencingFactoryFinder.getDatumFactory(this.hints); crsFactory = ReferencingFactoryFinder.getCRSFactory(this.hints); csFactory = ReferencingFactoryFinder.getCSFactory(this.hints); tempHints.put(Hints.DATUM_AUTHORITY_FACTORY, allAuthoritiesFactory); tempHints.put(Hints.CS_FACTORY, csFactory); tempHints.put(Hints.CRS_FACTORY, crsFactory); tempHints.put(Hints.MATH_TRANSFORM_FACTORY, mtFactory); factories = ReferencingFactoryContainer.instance(tempHints); }
public Query invertQuery( @DescribeParameter( name = "outputBBOX", description = "Georeferenced bounding box of the output") final ReferencedEnvelope argOutputEnv, @DescribeParameter( name = "outputWidth", description = "Width of the output raster") final Integer argOutputWidth, @DescribeParameter( name = "outputHeight", description = "Height of the output raster") final Integer argOutputHeight, @DescribeParameter( name = "pixelSize", description = "The pixel size to base subsampling on") final Double pixelSize, final Query targetQuery, final GridGeometry targetGridGeometry) throws ProcessException { // add to the query hints targetQuery.getHints().put(SUBSAMPLE_ENABLED, true); targetQuery.getHints().put(OUTPUT_WIDTH, argOutputWidth); targetQuery.getHints().put(OUTPUT_HEIGHT, argOutputHeight); targetQuery.getHints().put(OUTPUT_BBOX, argOutputEnv); if (pixelSize != null) { targetQuery.getHints().put(PIXEL_SIZE, pixelSize); } return targetQuery; } }
public Query invertQuery( @DescribeParameter( name = "outputBBOX", description = "Georeferenced bounding box of the output") final ReferencedEnvelope argOutputEnv, @DescribeParameter( name = "outputWidth", description = "Width of the output raster") final Integer argOutputWidth, @DescribeParameter( name = "outputHeight", description = "Height of the output raster") final Integer argOutputHeight, @DescribeParameter( name = "pixelSize", description = "The pixel size to decimate by") final Double pixelSize, final Query targetQuery, final GridGeometry targetGridGeometry) throws ProcessException { // add to the query hints targetQuery.getHints().put(OUTPUT_WIDTH, argOutputWidth); targetQuery.getHints().put(OUTPUT_HEIGHT, argOutputHeight); targetQuery.getHints().put(OUTPUT_BBOX, argOutputEnv); if (pixelSize != null) { targetQuery.getHints().put(PIXEL_SIZE, pixelSize); } return targetQuery; } }
/** * Adds a hint value to the set of {@linkplain GeoTools#getDefaultHints default hints}. * Default hints can be added by call to this {@code putDefaultHint} method, to the * {@link GeoTools#init} method or by {@linkplain System#getProperties system properties} * with keys defined by the {@link String} constants in the {@link GeoTools} class. * * @param key The hint key. * @param value The hint value. * @return The previous value of the specified key, or {@code null} if none. * @throws IllegalArgumentException If {@link Hints.Key#isCompatibleValue()} * returns {@code false} for the specified value. * * @since 2.4 */ public static Object putSystemDefault(final RenderingHints.Key key, final Object value) { final boolean changed; final Object old; synchronized (GLOBAL) { changed = ensureSystemDefaultLoaded(); old = GLOBAL.put(key, value); } if (changed || !Utilities.equals(value, old)) { GeoTools.fireConfigurationChanged(); } return old; }
/** * Adds a hint value to the set of {@linkplain GeoTools#getDefaultHints default hints}. * Default hints can be added by call to this {@code putDefaultHint} method, to the * {@link GeoTools#init} method or by {@linkplain System#getProperties system properties} * with keys defined by the {@link String} constants in the {@link GeoTools} class. * * @param key The hint key. * @param value The hint value. * @return The previous value of the specified key, or {@code null} if none. * @throws IllegalArgumentException If {@link Hints.Key#isCompatibleValue()} * returns {@code false} for the specified value. * * @since 2.4 */ public static Object putSystemDefault(final RenderingHints.Key key, final Object value) { final boolean changed; final Object old; synchronized (GLOBAL) { changed = ensureSystemDefaultLoaded(); old = GLOBAL.put(key, value); } if (changed || !Utilities.equals(value, old)) { GeoTools.fireConfigurationChanged(); } return old; }
adapted.getHints().put(GetRecords.KEY_BASEURL, request.getBaseUrl());
@Test public void testRespectsSuppliedGeometryFactory() throws Exception { SimpleFeatureSource source = this.linesSource; Query query = new Query(); GeometryFactory suppliedGeomFac = new GeometryFactory( new PrecisionModel(PrecisionModel.FLOATING_SINGLE)); query.getHints().put(Hints.JTS_GEOMETRY_FACTORY, suppliedGeomFac); SimpleFeature[] collection = (SimpleFeature[]) source.getFeatures(query).toArray(); assertEquals(3, collection.length); for (SimpleFeature f : collection) { Geometry g = (Geometry) f.getDefaultGeometry(); assertSame(suppliedGeomFac, g.getFactory()); } }
@Test public void testRespectsSuppliedGeometryFactory() throws Exception { SimpleFeatureSource source = this.linesSource; Query query = new Query(); GeometryFactory suppliedGeomFac = new GeometryFactory( new PrecisionModel(PrecisionModel.FLOATING_SINGLE)); query.getHints().put(Hints.JTS_GEOMETRY_FACTORY, suppliedGeomFac); SimpleFeature[] collection = (SimpleFeature[]) source.getFeatures(query).toArray(); assertEquals(3, collection.length); for (SimpleFeature f : collection) { Geometry g = (Geometry) f.getDefaultGeometry(); assertSame(suppliedGeomFac, g.getFactory()); } }
@Test public void testScreenMap() throws Exception { // Test a single point to make sure the feature tree itself (with the same bounds as the // point it contains) doesn't write to the ScreenMap deleteAndAdd(points2); deleteAndAdd(points3); geogig.command(CommitOp.class).setMessage("drop to 1 point").call(); Query query = new Query(pointsName); ScreenMap screenMap = new ScreenMap(-180, -90, 360, 180); screenMap.setSpans(1.0, 1.0); screenMap.setTransform(IdentityTransform.create(2)); query.getHints().put(Hints.SCREENMAP, screenMap); SimpleFeatureIterator iter = pointsSource.getFeatures(query).features(); assertTrue(iter.hasNext()); assertEquals(points1.getIdentifier().getID(), iter.next().getID()); assertTrue(screenMap.get(boundsOf(points1))); }
@Test public void testScreenMap() throws Exception { // Test a single point to make sure the feature tree itself (with the same bounds as the // point it contains) doesn't write to the ScreenMap deleteAndAdd(points2); deleteAndAdd(points3); geogig.command(CommitOp.class).setMessage("drop to 1 point").call(); Query query = new Query(pointsName); ScreenMap screenMap = new ScreenMap(-180, -90, 360, 180); screenMap.setSpans(1.0, 1.0); screenMap.setTransform(IdentityTransform.create(2)); query.getHints().put(Hints.SCREENMAP, screenMap); SimpleFeatureIterator iter = pointsSource.getFeatures(query).features(); assertTrue(iter.hasNext()); assertEquals(points1.getIdentifier().getID(), iter.next().getID()); assertTrue(screenMap.get(boundsOf(points1))); }