/** * Calculates the pixels per meter ratio based on a scale denominator. * * @param scaleDenominator The scale denominator value. * @param hints The hints used in calculation. if "dpi" key is present, it uses it's Integer * value as the dpi of the current device. if not it uses 90 that is the OGC default value. * @return The pixels per meter ratio for the given scale denominator. */ public static double calculatePixelsPerMeterRatio(double scaleDenominator, Map hints) { if (scaleDenominator <= 0.0) throw new IllegalArgumentException("The scale denominator must be positive."); double scale = 1.0 / scaleDenominator; return scale * (getDpi(hints) / 0.0254); }
/** * This method performs the computation using the methods suggested by the OGC SLD * specification, page 26. * * @param CRS the coordinate reference system. Used to check if we are operating in degrees or * meters. * @param worldToScreen the transformation mapping world coordinates to screen coordinates. * Might specify a rotation in addition to translation and scaling. * @return */ public static double calculateOGCScaleAffine( CoordinateReferenceSystem crs, AffineTransform worldToScreen, Map hints) { double scale = XAffineTransform.getScale(worldToScreen); // if it's geodetic, we're dealing with lat/lon unit measures if (crs instanceof GeographicCRS) { return (OGC_DEGREE_TO_METERS * getDpi(hints)) / (scale * 0.0254); } else { return (getDpi(hints)) / (scale * 0.0254); } }
/** * First searches the hints for the scale denominator hint otherwise calls {@link * #calculateScale(Envelope, CoordinateReferenceSystem, int, int, double)}. If the hints * contains a DPI then that DPI is used otherwise 90 is used (the OGS default). */ public static double calculateScale( ReferencedEnvelope envelope, int imageWidth, int imageHeight, Map hints) throws TransformException, FactoryException { if (hints != null && hints.containsKey("declaredScaleDenominator")) { Double scale = (Double) hints.get("declaredScaleDenominator"); if (scale.doubleValue() <= 0) throw new IllegalArgumentException( "the declaredScaleDenominator must be greater than 0, was: " + scale.doubleValue()); return scale.doubleValue(); } return calculateScale(envelope, imageWidth, imageHeight, getDpi(hints)); }
/** * This method performs the computation using the methods suggested by the OGC SLD * specification, page 26. * * <p>In GeoTools 12 this method started to take into account units of measure, if this is not * desirable in your application you can set the system variable * "org.geotoools.render.lite.scale.unitCompensation" to false. * * @param envelope * @param imageWidth * @return */ public static double calculateOGCScale(ReferencedEnvelope envelope, int imageWidth, Map hints) { // if it's geodetic, we're dealing with lat/lon unit measures CoordinateReferenceSystem crs = envelope.getCoordinateReferenceSystem(); double width = envelope.getWidth(); double widthMeters = toMeters(width, crs); return widthMeters / (imageWidth / getDpi(hints) * 0.0254); }
/** * Applies Unit Of Measure rescaling against all symbolizers, the result will be symbolizers * that operate purely in pixels * * @param lfts */ void applyUnitRescale(final ArrayList<LiteFeatureTypeStyle> lfts) { // apply dpi rescale double dpi = RendererUtilities.getDpi(getRendererHints()); double standardDpi = RendererUtilities.getDpi(Collections.emptyMap()); if (dpi != standardDpi) { double scaleFactor = dpi / standardDpi; DpiRescaleStyleVisitor dpiVisitor = new GraphicsAwareDpiRescaleStyleVisitor(scaleFactor); for (LiteFeatureTypeStyle fts : lfts) { rescaleFeatureTypeStyle(fts, dpiVisitor); } } // apply UOM rescaling double pixelsPerMeters = RendererUtilities.calculatePixelsPerMeterRatio(scaleDenominator, rendererHints); UomRescaleStyleVisitor rescaleVisitor = new UomRescaleStyleVisitor(pixelsPerMeters); for (LiteFeatureTypeStyle fts : lfts) { rescaleFeatureTypeStyle(fts, rescaleVisitor); } }
/** * Calculates the pixels per meter ratio based on a scale denominator. * * @param scaleDenominator * The scale denominator value. * @param hints * The hints used in calculation. if "dpi" key is present, it * uses it's Integer value as the dpi of the current device. if * not it uses 90 that is the OGC default value. * @return The pixels per meter ratio for the given scale denominator. */ public static double calculatePixelsPerMeterRatio(double scaleDenominator, Map hints) { if (scaleDenominator <= 0.0) throw new IllegalArgumentException("The scale denominator must be positive."); double scale = 1.0 / scaleDenominator; return scale * (getDpi(hints) / 0.0254); }
/** * This method performs the computation using the methods suggested by the OGC SLD specification, page 26. * @param CRS the coordinate reference system. Used to check if we are operating in degrees or * meters. * @param worldToScreen the transformation mapping world coordinates to screen coordinates. Might * specify a rotation in addition to translation and scaling. * @return */ public static double calculateOGCScaleAffine(CoordinateReferenceSystem crs,AffineTransform worldToScreen, Map hints) { double scale = XAffineTransform.getScale(worldToScreen); // if it's geodetic, we're dealing with lat/lon unit measures if(crs instanceof GeographicCRS) { return (OGC_DEGREE_TO_METERS * getDpi(hints))/(scale * 0.0254); } else { return (getDpi(hints))/(scale * 0.0254); } }
/** * First searches the hints for the scale denominator hint otherwise calls * {@link #calculateScale(Envelope, CoordinateReferenceSystem, int, int, double)}. If * the hints contains a DPI then that DPI is used otherwise 90 is used (the OGS default). */ public static double calculateScale(ReferencedEnvelope envelope, int imageWidth,int imageHeight, Map hints ) throws TransformException, FactoryException { if( hints!=null && hints.containsKey("declaredScaleDenominator")){ Double scale=(Double) hints.get("declaredScaleDenominator"); if( scale.doubleValue()<=0 ) throw new IllegalArgumentException("the declaredScaleDenominator must be greater than 0, was: "+scale.doubleValue()); return scale.doubleValue(); } return calculateScale(envelope, imageWidth, imageHeight, getDpi(hints)); }
/** * First searches the hints for the scale denominator hint otherwise calls * {@link #calculateScale(Envelope, CoordinateReferenceSystem, int, int, double)}. If * the hints contains a DPI then that DPI is used otherwise 90 is used (the OGS default). */ public static double calculateScale(ReferencedEnvelope envelope, int imageWidth,int imageHeight, Map hints ) throws TransformException, FactoryException { if( hints!=null && hints.containsKey("declaredScaleDenominator")){ Double scale=(Double) hints.get("declaredScaleDenominator"); if( scale.doubleValue()<=0 ) throw new IllegalArgumentException("the declaredScaleDenominator must be greater than 0, was: "+scale.doubleValue()); return scale.doubleValue(); } return calculateScale(envelope, imageWidth, imageHeight, getDpi(hints)); }
/** * This method performs the computation using the methods suggested by the OGC SLD specification, page 26. * @param envelope * @param imageWidth * @return */ public static double calculateOGCScale(ReferencedEnvelope envelope, int imageWidth, Map hints) { // if it's geodetic, we're dealing with lat/lon unit measures if(envelope.getCoordinateReferenceSystem() instanceof GeographicCRS) { return (envelope.getWidth() * OGC_DEGREE_TO_METERS) / (imageWidth / getDpi(hints) * 0.0254); } else { return envelope.getWidth() / (imageWidth / getDpi(hints) * 0.0254); } }
/** * This method performs the computation using the methods suggested by the OGC SLD specification, page 26. * @param envelope * @param imageWidth * @return */ public static double calculateOGCScale(ReferencedEnvelope envelope, int imageWidth, Map hints) { // if it's geodetic, we're dealing with lat/lon unit measures if(envelope.getCoordinateReferenceSystem() instanceof GeographicCRS) { return (envelope.getWidth() * OGC_DEGREE_TO_METERS) / (imageWidth / getDpi(hints) * 0.0254); } else { return envelope.getWidth() / (imageWidth / getDpi(hints) * 0.0254); } }
@Override protected void onBeforeRender(StreamingRenderer renderer) { // disable antialiasing, numbers signify ids, we cannot have "half tints" renderer.getJava2DHints() .put( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); Map hints = renderer.getRendererHints(); double dpi = RendererUtilities.getDpi(hints); dpi = dpi / DEFAULT_UTFRESOLUTION; hints.put(StreamingRenderer.DPI_KEY, dpi); } };
/** * Applies Unit Of Measure rescaling against all symbolizers, the result will be symbolizers * that operate purely in pixels * @param lfts */ void applyUnitRescale(final ArrayList<LiteFeatureTypeStyle> lfts) { // apply dpi rescale double dpi = RendererUtilities.getDpi(getRendererHints()); double standardDpi = RendererUtilities.getDpi(Collections.emptyMap()); if(dpi != standardDpi) { double scaleFactor = dpi / standardDpi; DpiRescaleStyleVisitor dpiVisitor = new DpiRescaleStyleVisitor(scaleFactor); for(LiteFeatureTypeStyle fts : lfts) { rescaleFeatureTypeStyle(fts, dpiVisitor); } } // apply UOM rescaling double pixelsPerMeters = RendererUtilities.calculatePixelsPerMeterRatio(scaleDenominator, rendererHints); UomRescaleStyleVisitor rescaleVisitor = new UomRescaleStyleVisitor(pixelsPerMeters); for(LiteFeatureTypeStyle fts : lfts) { rescaleFeatureTypeStyle(fts, rescaleVisitor); } }
private void rescaleRules(List<Rule> rules, FeatureInfoRequestParameters params) { Map<Object, Object> rendererParams = new HashMap<Object, Object>(); Integer requestedDpi = ((Integer) params.getGetMapRequest().getFormatOptions().get("dpi")); if (requestedDpi != null) { rendererParams.put(StreamingRenderer.DPI_KEY, requestedDpi); } // apply dpi rescale if necessary double standardDpi = RendererUtilities.getDpi(rendererParams); if (requestedDpi != null && standardDpi != requestedDpi) { double scaleFactor = requestedDpi / standardDpi; DpiRescaleStyleVisitor dpiVisitor = new GraphicsAwareDpiRescaleStyleVisitor(scaleFactor); for (int i = 0; i < rules.size(); i++) { rules.get(i).accept(dpiVisitor); Rule rescaled = (Rule) dpiVisitor.getCopy(); rules.set(i, rescaled); } } // apply UOM rescaling double pixelsPerMeters = RendererUtilities.calculatePixelsPerMeterRatio( params.getScaleDenominator(), rendererParams); UomRescaleStyleVisitor uomVisitor = new UomRescaleStyleVisitor(pixelsPerMeters); for (int i = 0; i < rules.size(); i++) { rules.get(i).accept(uomVisitor); Rule rescaled = (Rule) uomVisitor.getCopy(); rules.set(i, rescaled); } }
public Dimension findOptimalSize(Graphics2D g2d, WMSMapContent mapContext) { double scaleDenominator = mapContext.getScaleDenominator(true); double dpi = RendererUtilities.getDpi(mapContext.getRequest().getFormatOptions()); double standardDpi = RendererUtilities.getDpi(Collections.emptyMap()); double scaleFactor = dpi / standardDpi;