CoordinateReferenceSystem sourceCRS = featureSource.getInfo().getCRS(); Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints); CoordinateReferenceSystem worldCRS = factory .createCoordinateReferenceSystem("EPSG:4326"); Query query = new Query(); query.setCoordinateSystem(sourceCRS); query.setCoordinateSystemReproject(worldCRS);
/** * Hints constructor for FactoryRegistry */ public JTSAggregateFactory( Hints hints ){ this( (CoordinateReferenceSystem) hints.get( Hints.CRS ) ); } /**
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 );
/** * Adds all specified hints to the system hints. This * is for {@link GeoTools#init} implementation only. */ static void putSystemDefault(final RenderingHints hints) { synchronized (GLOBAL) { ensureSystemDefaultLoaded(); GLOBAL.add(hints); } GeoTools.fireConfigurationChanged(); }
sameCRS = CRS.equalsIgnoreMetadata(targetCRS, sourceCRS); if (sameGG && sameCRS) { return sourceCoverage; targetHints = new RenderingHints(hints); } else if (hints != null) { targetHints.add(hints); final Object property = (hints != null) ? hints.get(Hints.JAI_INSTANCE) : null; if (property instanceof JAI) { processor = (JAI) property; ReferencingFactoryFinder.getCoordinateOperationFactory(hints); final MathTransformFactory mtFactory = ReferencingFactoryFinder.getMathTransformFactory(hints); gridRange = CRS.transform(allSteps.inverse(), gridRange); targetGG = new GridGeometry2D(new GeneralGridRange(gridRange), step1, targetCRS); step3 = sourceGG.getGridToCRS().inverse(); sourceEnvelope = sourceCoverage.getEnvelope(); targetEnvelope = CRS.transform(step2.inverse(), sourceEnvelope); targetEnvelope.setCoordinateReferenceSystem(targetCRS); for (int i=gridRange.getDimension(); --i>=0;) { gridRange.setRange(i, gridRange.getMinimum(i) + 0.5,
if(!CRS.equalsIgnoreMetadata(targetCRS, targetGGCRS)&&!CRS.findMathTransform(targetCRS, targetGGCRS).isIdentity()){ throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$1,"TargetCRS must be compatible with TargetGG CRS")); if(hints.containsKey(JAI.KEY_INTERPOLATION)) interpolation=(Interpolation) hints.get(JAI.KEY_INTERPOLATION); hints.put(JAI.KEY_INTERPOLATION,interpolation); if (!hints.containsKey(JAI.KEY_BORDER_EXTENDER)) { hints.put(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY)); if (CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { targetEnvelope.setCoordinateReferenceSystem(targetCRS); targetHints.add(hints); ImageLayout layout = (ImageLayout) targetHints.get(JAI.KEY_IMAGE_LAYOUT); if (layout != null) { layout = (ImageLayout) layout.clone(); } else { layout = new ImageLayout(); final Rectangle targetBB = targetGG.getGridRange2D(); if (isBoundsUndefined(layout, false)) { layout.setMinX (targetBB.x); targetHints.put(JAI.KEY_IMAGE_LAYOUT, layout);
final MathTransform sourceCRSToDestinationCRSTransformation = CRS.findMathTransform(sourceCoverageCRS, destinationCRS, true); final MathTransform destinationCRSToSourceCRSTransformation = sourceCRSToDestinationCRSTransformation.inverse(); final boolean doReprojection = !sourceCRSToDestinationCRSTransformation.isIdentity(); destinationEnvelopeInSourceCRS = CRS.transform( destinationCRSToSourceCRSTransformation, destinationEnvelope); if (!CRS.equalsIgnoreMetadata(destinationCRS, DefaultGeographicCRS.WGS84)) { destinationEnvelope); destinationEnvelopeWGS84 .setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); } else { destinationEnvelopeWGS84 = new GeneralEnvelope( destinationEnvelope); destinationEnvelopeWGS84 = new GeneralEnvelope( destinationEnvelope); final Interpolation interpolation = (Interpolation) hints.get(JAI.KEY_INTERPOLATION); if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine("Using interpolation "+interpolation); final Hints localHints = this.hints.clone(); if(interpolation instanceof InterpolationNearest){ localHints.add(new RenderingHints(JAI.KEY_REPLACE_INDEX_COLOR_MODEL, Boolean.FALSE)); localHints.add(new RenderingHints(JAI.KEY_TRANSFORM_ON_COLORMAP, Boolean.TRUE));
final Rectangle sourceArea = CRS.transform(cropWorldToGrid, intersection).toRectangle2D().getBounds(); final ImageLayout layout = new ImageLayout(); layout.setTileHeight(tileDimensions.width).setTileWidth(tileDimensions.height); localHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT,layout)); } else { if (hints != null && hints.containsKey(JAI.KEY_IMAGE_LAYOUT)) { final Object layout = hints.get(JAI.KEY_IMAGE_LAYOUT); if (layout != null && layout instanceof ImageLayout) { localHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, ((ImageLayout) layout).clone())); if (hints != null && hints.containsKey(JAI.KEY_TILE_CACHE)){ final Object cache = hints.get(JAI.KEY_TILE_CACHE); if (cache != null && cache instanceof TileCache) localHints.add(new RenderingHints(JAI.KEY_TILE_CACHE, (TileCache) cache)); if (hints != null && hints.containsKey(JAI.KEY_TILE_SCHEDULER)){ final Object scheduler = hints.get(JAI.KEY_TILE_SCHEDULER); if (scheduler != null && scheduler instanceof TileScheduler) localHints.add(new RenderingHints(JAI.KEY_TILE_SCHEDULER, (TileScheduler) scheduler)); if (hints != null && hints.containsKey(JAI.KEY_BORDER_EXTENDER)) { final Object extender = hints.get(JAI.KEY_BORDER_EXTENDER); if (extender != null && extender instanceof BorderExtender) { localHints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER, (BorderExtender) extender));
public GeoToolsCoverageTransformer(String defaultSRS) { // create basic hints hints = new Hints(GeoTools.getDefaultHints()); if (defaultSRS != null) { try { final CoordinateReferenceSystem crs = CRS.decode(defaultSRS); hints.add(new RenderingHints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, crs)); } catch (Exception e) { LOGGER.log(Level.FINE, "Cannot parse CRS " + defaultSRS, new Exception()); hints = new Hints(GeoTools.getDefaultHints()); } } }
this.granuleDescriptor = granuleDescriptor; this.request=request; this.hints = new Hints(hints); if (request.getTileDimensions()!= null) { final Dimension tileDimension = request.getTileDimensions(); if (hints != null && hints.containsKey(JAI.KEY_IMAGE_LAYOUT)){ final Object layout = this.hints.get(JAI.KEY_IMAGE_LAYOUT); if (layout != null && layout instanceof ImageLayout){ final ImageLayout imageLayout = (ImageLayout) layout; imageLayout.setTileHeight(tileDimension.height); imageLayout.setTileWidth(tileDimension.width); final ImageLayout layout = new ImageLayout(); layout.setTileWidth(tileDimension.width).setTileHeight(tileDimension.height); this.hints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT,layout));
if (name.equals(AbstractGridFormat.READ_GRIDGEOMETRY2D.getName())) { final GridGeometry2D gg = (GridGeometry2D) param.getValue(); requestedEnvelope = new GeneralEnvelope((Envelope) gg.getEnvelope2D()); dim = gg.getGridRange2D().getBounds(); continue; newHints= (Hints) hints.clone(); final ImageLayout layout = new ImageLayout(); layout.setTileGridXOffset(0); layout.setTileGridYOffset(0); layout.setTileHeight(suggestedTileSize[1]); layout.setTileWidth(suggestedTileSize[0]); newHints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout));
final ImageLayout layout = new ImageLayout( rasterBounds.x, rasterBounds.y, layout.setTileHeight(tileDimensions.width).setTileWidth(tileDimensions.height); final RenderingHints localHints = new RenderingHints(JAI.KEY_IMAGE_LAYOUT,layout); if (hints != null && !hints.isEmpty()){ if (hints.containsKey(JAI.KEY_TILE_CACHE)){ final Object tc = hints.get(JAI.KEY_TILE_CACHE); if (tc != null && tc instanceof TileCache) localHints.add(new RenderingHints(JAI.KEY_TILE_CACHE, (TileCache) tc)); if (hints != null && hints.containsKey(JAI.KEY_BORDER_EXTENDER)){ final Object extender = hints.get(JAI.KEY_BORDER_EXTENDER); if (extender != null && extender instanceof BorderExtender) { localHints.add(new RenderingHints(JAI.KEY_BORDER_EXTENDER, (BorderExtender) extender)); localHints.add(ImageUtilities.BORDER_EXTENDER_HINTS); if (hints.containsKey(JAI.KEY_TILE_SCHEDULER)){ final Object ts = hints.get(JAI.KEY_TILE_SCHEDULER); if (ts != null && ts instanceof TileScheduler) localHints.add(new RenderingHints(JAI.KEY_TILE_SCHEDULER, (TileScheduler) ts));
final Hints hints = new Hints(getHints()); final ImageLayout layout = new ImageLayout(); final RenderedImage sourceRaster = source .getRenderedImage(); .getInstance(ColorSpace.CS_GRAY), false, false, Transparency.OPAQUE, oldSM.getDataType()); layout.setColorModel(cm); layout.setSampleModel(cm.createCompatibleSampleModel(oldSM .getWidth(), oldSM.getHeight())); hints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); output = (GridCoverage2D) new SelectSampleDimension() .doOperation(parameters, hints);
final Object tempCRS = this.hints.get(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM); if (tempCRS != null) { this.crs=(CoordinateReferenceSystem) tempCRS; this.crs=CRS.parseWKT(wkt); final Integer epsgCode = CRS.lookupEpsgCode(this.crs, true); this.crs=CRS.decode("EPSG:" + epsgCode); this.originalEnvelope=CRS.transform(ProjectiveTransform .create(tempTransform), new GeneralEnvelope( ((GridEnvelope2D) this.originalGridRange))); } catch (IllegalStateException e) {
if (!CRS.equalsIgnoreMetadata(sourceCRS, destinationCRS)) { throw new CannotCropException(Errors.format( ErrorKeys.MISMATCHED_ENVELOPE_CRS_$2, sourceCRS.getName() final GeneralEnvelope intersectionEnvelope = new GeneralEnvelope( (Envelope) destinationEnvelope); intersectionEnvelope.setCoordinateReferenceSystem(source .getCoordinateReferenceSystem()); intersectionEnvelope.intersect(sourceEnvelope); if (intersectionEnvelope.isEmpty()) throw new CannotCropException(Errors .create(parameters, (hints instanceof Hints) ? (Hints) hints : new Hints(hints), source, sourceGridToWorld, tolerance); } else {
final MathTransform sourceCRSToDestinationCRSTransformation = CRS.findMathTransform(sourceCoverageCRS, destinationCRS, true); final MathTransform destinationCRSToSourceCRSTransformation = sourceCRSToDestinationCRSTransformation.inverse(); final boolean doReprojection = !sourceCRSToDestinationCRSTransformation.isIdentity(); destinationEnvelopeInSourceCRS = CRS.transform( destinationCRSToSourceCRSTransformation, destinationEnvelope); if (!CRS.equalsIgnoreMetadata(destinationCRS, DefaultGeographicCRS.WGS84)) { destinationEnvelope); destinationEnvelopeWGS84 .setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); } else { destinationEnvelopeWGS84 = new GeneralEnvelope( destinationEnvelope); destinationEnvelopeWGS84 = new GeneralEnvelope( destinationEnvelope); .get(JAI.KEY_INTERPOLATION); if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine(new StringBuffer("Using interpolation ").append(
private FeatureReader<SimpleFeatureType, SimpleFeature> getReader(Query query) { GeometryFactory geometryFactory = (GeometryFactory) query.getHints() .get(Hints.JTS_GEOMETRY_FACTORY); Integer offset = query.getStartIndex(); Integer limit = query.isMaxFeaturesUnlimited() ? null : query.getMaxFeatures(); String[] propertyNames = query.getPropertyNames(); ScreenMap screenMap = (ScreenMap) query.getHints().get(Hints.SCREENMAP); SortBy[] sortBy = query.getSortBy(); reader = builder.filter(query.getFilter())// .geometryFactory(geometryFactory)// .offset(offset)// .limit(limit)// .propertyNames(propertyNames)// .screenMap(screenMap)// .sortBy(sortBy)// .build(); return reader; }
/** * Transform a geometry to EPSG:4326 format with lon/lat coordinate ordering. NOTE: This method * will perform the transform swapping coordinates even if the sourceCrsName is EPSG:4326 * * @param geometry - Geometry to transform * @param sourceCrsName - Source geometry's coordinate reference system * @return Geometry - Transformed geometry into EPSG:4326 lon/lat coordinate system */ public static Geometry transformToEPSG4326LonLatFormat(Geometry geometry, String sourceCrsName) throws GeoFormatException { if (geometry == null) { throw new GeoFormatException("Unable to convert null geometry"); } // If we don't have source CRS just return geometry as we can't transform without that // information if (sourceCrsName == null) { return geometry; } try { CoordinateReferenceSystem sourceCrs = CRS.decode(sourceCrsName); Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints); CoordinateReferenceSystem targetCRS = factory.createCoordinateReferenceSystem(EPSG_4326); MathTransform transform = CRS.findMathTransform(sourceCrs, targetCRS); return JTS.transform(geometry, transform); } catch (FactoryException | TransformException e) { throw new GeoFormatException("Unable to convert coordinate to " + EPSG_4326, e); } }
FilterFactory2 filterFac = CommonFactoryFinder.getFilterFactory2(GeoTools.getDefaultHints()); if ((requestedCRS != null) && !CRS.equalsIgnoreMetadata(dataCRS, requestedCRS)) { try { MathTransform transform = CRS.findMathTransform(requestedCRS, dataCRS, true); final CoverageInfo cinfo = requestedLayers[i].getCoverage(); final GridGeometry2D coverageGeometry=(GridGeometry2D) cinfo.getGrid(); final GeneralEnvelope requestedEnvelope=new GeneralEnvelope(new ReferencedEnvelope(bbox,requestedCRS)); final GridCoverage2D coverage=(GridCoverage2D) cinfo.getCoverage(requestedEnvelope, new Rectangle(0,0,width,height)); final DirectPosition position = new DirectPosition2D(requestedCRS, middle.x, middle.y); requestedCRS, targetCRS, new Hints( Hints.LENIENT_DATUM_SHIFT, Boolean.TRUE));
currentSourceCoverage.getRenderedImage() .getSampleModel().getDataType()); layout = new ImageLayout(); layout.setColorModel(cm); } else if (!gg.equals(gridGeometry)) throw new IllegalArgumentException(Errors.format( hints.add(new RenderingHints(JAI.KEY_IMAGE_LAYOUT, layout)); op = FormatDescriptor.create(op, Integer.valueOf(op.getSampleModel().getDataType()), hints); final GridSampleDimension [] sd= new GridSampleDimension[op.getSampleModel().getNumBands()];