Jody Garnett ha scritto:
On 17/06/2010, at 10:36 PM, Andrea Aime wrote:
Let's say the renderer would become... more aware of dpi.
It's actually already considering the dpi hint when it comes to compute
the scale.
The rescale visitor would not go, that's actually the bit of code I
want to use to perform dpi rescaling (just as the uom rescale visitor,
sitting right in the same package as yours, it visible to everybody,
and used internally in the renderer)
Got it; we may need to offer a bit more fine grain control over time; but if
you can use it as is more the better.
Here is a simple patch for rescaling.
This is a first WMS image, no dpi rescaling:
http://sigma.openplans.org/~aaime/base.png
It was obtained with the following request:
http://localhost:8080/geoserver/wms?HEIGHT=300&WIDTH=300&LAYERS=tiger%3Atiger_roads&STYLES=&SRS=EPSG%3A4326&FORMAT=image%2Fpng8&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&BBOX=-73.989983894288,40.740286695315,-73.975778059328,40.754492530275
And then one with mapserver like rescaling, the image this time
has been asked as 900x900 but with 300 dpi in the format_options:
http://sigma.openplans.org/~aaime/rescaled.png
and the request:
http://localhost:8080/geoserver/wms?HEIGHT=900&WIDTH=900&LAYERS=tiger%3Atiger_roads&STYLES=&SRS=EPSG%3A4326&FORMAT=image%2Fpng8&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&BBOX=-73.989983894288,40.740286695315,-73.975778059328,40.754492530275&format_options=dpi:300
The result is actually not exactly the same... and I think I know the
reasons: there has been no rescaling on the text symbolizer format
options, in particular the space around factor.
I guess I'll have to modify the rescaler code to take that into account
as well.
Besides that I guess I'm getting the expected result. Is this what
you were expecting as well?
Cheers
Andrea
--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.
diff --git a/modules/library/render/src/main/java/org/geotools/renderer/lite/RendererUtilities.java b/modules/library/render/src/main/java/org/geotools/renderer/lite/RendererUtilities.java
index a03637a..005fcf9 100644
--- a/modules/library/render/src/main/java/org/geotools/renderer/lite/RendererUtilities.java
+++ b/modules/library/render/src/main/java/org/geotools/renderer/lite/RendererUtilities.java
@@ -468,7 +468,7 @@ public final class RendererUtilities {
* @param hints
* @return DPI as doubles, to avoid issues with integer trunking in scale computation expression
*/
- private static double getDpi(Map hints) {
+ public static double getDpi(Map hints) {
if( hints!=null && hints.containsKey("dpi") ){
return ((Integer)hints.get("dpi")).intValue();
}else{
diff --git a/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java b/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java
index dbc612a..0e04e09 100644
--- a/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java
+++ b/modules/library/render/src/main/java/org/geotools/renderer/lite/StreamingRenderer.java
@@ -88,6 +88,8 @@ import org.geotools.styling.Rule;
import org.geotools.styling.StyleAttributeExtractor;
import org.geotools.styling.Symbolizer;
import org.geotools.styling.TextSymbolizer;
+import org.geotools.styling.visitor.DuplicatingStyleVisitor;
+import org.geotools.styling.visitor.RescaleStyleVisitor;
import org.geotools.styling.visitor.UomRescaleStyleVisitor;
import org.geotools.util.NumberRange;
import org.geotools.util.Range;
@@ -1809,15 +1811,35 @@ public final class StreamingRenderer implements GTRenderer {
double pixelsPerMeters = RendererUtilities.calculatePixelsPerMeterRatio(scaleDenominator, rendererHints);
UomRescaleStyleVisitor rescaleVisitor = new UomRescaleStyleVisitor(pixelsPerMeters);
for(LiteFeatureTypeStyle fts : lfts) {
- for (int i = 0; i < fts.ruleList.length; i++) {
- rescaleVisitor.visit(fts.ruleList[i]);
- fts.ruleList[i] = (Rule) rescaleVisitor.getCopy();
+ rescaleFeatureTypeStyle(fts, rescaleVisitor);
+ }
+
+ // apply dpi rescale
+ double dpi = RendererUtilities.getDpi(getRendererHints());
+ double standardDpi = RendererUtilities.getDpi(Collections.emptyMap());
+ if(dpi != standardDpi) {
+ double scaleFactor = dpi / standardDpi;
+ RescaleStyleVisitor dpiVisitor = new RescaleStyleVisitor(scaleFactor);
+ for(LiteFeatureTypeStyle fts : lfts) {
+ rescaleFeatureTypeStyle(fts, dpiVisitor);
}
- if(fts.elseRules != null) {
- for (int i = 0; i < fts.elseRules.length; i++) {
- rescaleVisitor.visit(fts.elseRules[i]);
- fts.elseRules[i] = (Rule) rescaleVisitor.getCopy();
- }
+ }
+ }
+
+ /**
+ * Utility method to apply the two rescale visitors without duplicating code
+ * @param fts
+ * @param visitor
+ */
+ void rescaleFeatureTypeStyle(LiteFeatureTypeStyle fts, DuplicatingStyleVisitor visitor) {
+ for (int i = 0; i < fts.ruleList.length; i++) {
+ visitor.visit(fts.ruleList[i]);
+ fts.ruleList[i] = (Rule) visitor.getCopy();
+ }
+ if(fts.elseRules != null) {
+ for (int i = 0; i < fts.elseRules.length; i++) {
+ visitor.visit(fts.elseRules[i]);
+ fts.elseRules[i] = (Rule) visitor.getCopy();
}
}
}
diff --git a/modules/unsupported/shapefile-renderer/src/main/java/org/geotools/renderer/shape/ShapefileRenderer.java b/modules/unsupported/shapefile-renderer/src/main/java/org/geotools/renderer/shape/ShapefileRenderer.java
index 67a0679..c91df60 100644
--- a/modules/unsupported/shapefile-renderer/src/main/java/org/geotools/renderer/shape/ShapefileRenderer.java
+++ b/modules/unsupported/shapefile-renderer/src/main/java/org/geotools/renderer/shape/ShapefileRenderer.java
@@ -100,6 +100,7 @@ import org.geotools.styling.StyleAttributeExtractor;
import org.geotools.styling.Symbolizer;
import org.geotools.styling.TextSymbolizer;
import org.geotools.styling.visitor.DuplicatingStyleVisitor;
+import org.geotools.styling.visitor.RescaleStyleVisitor;
import org.geotools.styling.visitor.UomRescaleStyleVisitor;
import org.geotools.util.NumberRange;
import org.opengis.feature.simple.SimpleFeature;
@@ -376,6 +377,22 @@ public class ShapefileRenderer implements GTRenderer {
rescaleVisitor.visit(elseRuleList.get(j));
elseRuleList.set(j, (Rule) rescaleVisitor.getCopy());
}
+
+ // apply dpi rescale
+ double dpi = RendererUtilities.getDpi(getRendererHints());
+ double standardDpi = RendererUtilities.getDpi(Collections.emptyMap());
+ if(dpi != standardDpi) {
+ double scaleFactor = dpi / standardDpi;
+ RescaleStyleVisitor dpiVisitor = new RescaleStyleVisitor(scaleFactor);
+ for (int j = 0; j < ruleList.size(); j++) {
+ dpiVisitor.visit(ruleList.get(j));
+ ruleList.set(j, (Rule) dpiVisitor.getCopy());
+ }
+ for (int j = 0; j < elseRuleList.size(); j++) {
+ dpiVisitor.visit(elseRuleList.get(j));
+ elseRuleList.set(j, (Rule) dpiVisitor.getCopy());
+ }
+ }
// process the features according to the rules
// TODO: find a better way to declare the scale ranges so that
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel