Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Implementation for SE-1.1 PerpendicularOffset for LineSymbolizer (GEOT-3912) #1

Closed
wants to merge 2 commits into from

2 participants

Björn Harrtell Andrea Aime
Simone Giannecchini simboss referenced this pull request from a commit July 25, 2012
Simone Giannecchini #1: adding tests for h2 305d5b8
Simone Giannecchini simboss referenced this pull request from a commit July 26, 2012
Simone Giannecchini more work on #1 2b7e06b
Simone Giannecchini simboss referenced this pull request from a commit July 26, 2012
Simone Giannecchini more work on #1 143ff44
Simone Giannecchini simboss referenced this pull request from a commit August 08, 2012
Simone Giannecchini #1 ac11a90
Andrea Aime aaime closed this November 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Jul 02, 2012
Björn Harrtell Initial code and tests 4ad8dd0
Björn Harrtell Disable interactive testing
Note about bugged result
9fad4a5
This page is out of date. Refresh to see the latest.
6  modules/library/main/src/main/java/org/geotools/geometry/jts/LiteShape2.java
@@ -222,6 +222,12 @@ public void setGeometry(Geometry g) throws TransformException,
222 222
 			transformGeometry(geometry);
223 223
 		}
224 224
 	}
  225
+	
  226
+	public void setGeometry2(Geometry g){
  227
+		if (g != null) {
  228
+			this.geometry = g;
  229
+		}
  230
+	}
225 231
 
226 232
 	/**
227 233
 	 * Tests if the interior of the <code>Shape</code> entirely contains the
3  modules/library/main/src/main/java/org/geotools/styling/visitor/UomRescaleStyleVisitor.java
@@ -216,6 +216,9 @@ public void visit(LineSymbolizer line) {
216 216
         Stroke copyStroke = copy.getStroke();
217 217
         rescaleStroke(copyStroke, mapScale, copy.getUnitOfMeasure());
218 218
         copy.setUnitOfMeasure(NonSI.PIXEL);
  219
+        
  220
+        Expression copyPerpendicularOffset = copy.getPerpendicularOffset();
  221
+        rescale(copyPerpendicularOffset, mapScale, copy.getUnitOfMeasure());
219 222
     }
220 223
 
221 224
     @Override
22  modules/library/render/src/main/java/org/geotools/renderer/lite/StyledShapePainter.java
@@ -53,8 +53,11 @@
53 53
 import com.vividsolutions.jts.geom.Geometry;
54 54
 import com.vividsolutions.jts.geom.GeometryCollection;
55 55
 import com.vividsolutions.jts.geom.GeometryFactory;
  56
+import com.vividsolutions.jts.geom.LineString;
56 57
 import com.vividsolutions.jts.geom.MultiPolygon;
57 58
 import com.vividsolutions.jts.geom.Polygon;
  59
+import com.vividsolutions.jts.operation.buffer.BufferParameters;
  60
+import com.vividsolutions.jts.operation.buffer.OffsetCurveBuilder;
58 61
 
59 62
 /**
60 63
  * A simple class that knows how to paint a Shape object onto a Graphic given a
@@ -113,7 +116,7 @@ public void paint(final Graphics2D graphics, final LiteShape2 shape,
113 116
      * @throws FactoryException 
114 117
      * @throws TransformException 
115 118
      */
116  
-    public void paint(final Graphics2D graphics, final LiteShape2 shape,
  119
+    public void paint(final Graphics2D graphics, LiteShape2 shape,
117 120
             final Style2D style, final double scale, boolean isLabelObstacle) {
118 121
         if (style == null) {
119 122
             // TODO: what's going on? Should not be reached...
@@ -259,6 +262,23 @@ public void paint(final Graphics2D graphics, final LiteShape2 shape,
259 262
 
260 263
             if (style instanceof LineStyle2D) {
261 264
                 LineStyle2D ls2d = (LineStyle2D) style;
  265
+                
  266
+                double perpendicularOffset = ls2d.getPerpendicularOffset();
  267
+                if (Math.abs(perpendicularOffset) != 0){
  268
+                	GeometryFactory factory = new GeometryFactory();
  269
+            		LineString lineString = factory.createLineString(shape.getGeometry().getCoordinates());
  270
+            		BufferParameters bufParams = new BufferParameters();
  271
+            		bufParams.setQuadrantSegments(0);
  272
+            		bufParams.setJoinStyle(BufferParameters.CAP_FLAT);
  273
+            		OffsetCurveBuilder offsetCurveBuilder = new OffsetCurveBuilder(lineString.getPrecisionModel(), bufParams);
  274
+            		Coordinate[] coordinates = offsetCurveBuilder.getOffsetCurve(lineString.getCoordinates(), perpendicularOffset);
  275
+            		LineString offsetLineString = shape.getGeometry().getFactory().createLineString(coordinates);
  276
+            		try {
  277
+						shape = new LiteShape2(offsetLineString, null, null, false);
  278
+					} catch (TransformException e) {
  279
+					} catch (FactoryException e) {
  280
+					}
  281
+                }
262 282
 
263 283
                 if (ls2d.getStroke() != null) {
264 284
                     // see if a graphic stroke is to be used, the drawing method
9  modules/library/render/src/main/java/org/geotools/renderer/style/LineStyle2D.java
@@ -37,6 +37,7 @@
37 37
 public class LineStyle2D extends Style2D {
38 38
     protected Paint contour;
39 39
     protected Stroke stroke;
  40
+    protected double perpendicularOffset;
40 41
     protected Composite contourComposite;
41 42
 
42 43
     /** Holds value of property graphicStroke. */
@@ -61,6 +62,14 @@ public Stroke getStroke() {
61 62
     public void setStroke(Stroke stroke) {
62 63
         this.stroke = stroke;
63 64
     }
  65
+    
  66
+    public double getPerpendicularOffset() {
  67
+    	return perpendicularOffset;
  68
+    }
  69
+    
  70
+    public void setPerpendicularOffset(double perpendicularOffset) {
  71
+    	this.perpendicularOffset = perpendicularOffset;
  72
+    }
64 73
 
65 74
     /**
66 75
      * Returns the contour color for the {@linkplain org.geotools.renderer.geom.Polyline polyline}
1  modules/library/render/src/main/java/org/geotools/renderer/style/SLDStyleFactory.java
@@ -462,6 +462,7 @@ Style2D createLineStyle(Object feature, LineSymbolizer symbolizer,
462 462
 		LineStyle2D style = new LineStyle2D();
463 463
 		setScaleRange(style, scaleRange);
464 464
 		style.setStroke(getStroke(symbolizer.getStroke(), feature));
  465
+		style.setPerpendicularOffset(evalToDouble(symbolizer.getPerpendicularOffset(), feature, 0));
465 466
 		style.setGraphicStroke(getGraphicStroke(symbolizer.getStroke(),
466 467
 				feature, scaleRange));
467 468
 		style.setContour(getStrokePaint(symbolizer.getStroke(), feature));
79  modules/library/render/src/test/java/org/geotools/renderer/lite/PerpendicularOffsetTest.java
... ...
@@ -0,0 +1,79 @@
  1
+package org.geotools.renderer.lite;
  2
+
  3
+import java.io.File;
  4
+import java.io.IOException;
  5
+import java.net.URISyntaxException;
  6
+
  7
+import org.geotools.data.property.PropertyDataStore;
  8
+import org.geotools.data.simple.SimpleFeatureSource;
  9
+import org.geotools.geometry.jts.ReferencedEnvelope;
  10
+import org.geotools.map.FeatureLayer;
  11
+import org.geotools.map.Layer;
  12
+import org.geotools.map.MapContent;
  13
+import org.geotools.referencing.crs.DefaultGeographicCRS;
  14
+import org.geotools.styling.Style;
  15
+import org.geotools.test.TestData;
  16
+import org.junit.Before;
  17
+import org.junit.Test;
  18
+
  19
+public class PerpendicularOffsetTest {
  20
+
  21
+    private static final long TIME = 8000;
  22
+    
  23
+    StreamingRenderer renderer;
  24
+    ReferencedEnvelope bounds;
  25
+
  26
+    @Before
  27
+    public void initialize() throws Exception {
  28
+        renderer = new StreamingRenderer();
  29
+        bounds = new ReferencedEnvelope(0, 10, 0, 10, DefaultGeographicCRS.WGS84);
  30
+        
  31
+        //System.setProperty("org.geotools.test.interactive", "true");
  32
+    }
  33
+    
  34
+    SimpleFeatureSource getData(String name) throws IOException, URISyntaxException {
  35
+    	File property = new File(TestData.getResource(this, name + ".properties").toURI());
  36
+        PropertyDataStore ds = new PropertyDataStore(property.getParentFile());
  37
+        SimpleFeatureSource fs = ds.getFeatureSource(name);
  38
+        return fs;
  39
+    }
  40
+    
  41
+    void setupRenderer(String name, Style style) throws IOException, URISyntaxException {
  42
+    	MapContent mc = new MapContent();
  43
+        Layer layer = new FeatureLayer(getData(name), style);
  44
+        mc.addLayer(layer);
  45
+        renderer.setMapContent(mc);
  46
+    }
  47
+    
  48
+    @Test
  49
+    public void testDiagonalPerpendicularOffset() throws Exception {
  50
+        Style style = RendererBaseTest.loadStyle(this, "linePerpendicularOffset.sld");
  51
+        
  52
+        setupRenderer("diaglines", style);
  53
+        
  54
+        RendererBaseTest.showRender("Diagonal lines PerpendicularOffset", renderer, TIME, bounds);
  55
+    }
  56
+    
  57
+    @Test
  58
+    public void testCurvedPerpendicularOffset() throws Exception {
  59
+        Style style = RendererBaseTest.loadStyle(this, "linePerpendicularOffset.sld");
  60
+        
  61
+        setupRenderer("curvedline", style);
  62
+        
  63
+        RendererBaseTest.showRender("Curved line PerpendicularOffset", renderer, TIME, bounds);
  64
+    }
  65
+    
  66
+    /**
  67
+     * TODO: This test shows a case where the current PerpendicularOffset implementation does not produce a
  68
+     * valid result.
  69
+     */
  70
+    @Test
  71
+    public void testNarrowCurvedPerpendicularOffset() throws Exception {
  72
+        Style style = RendererBaseTest.loadStyle(this, "linePerpendicularOffsetWide.sld");
  73
+        
  74
+        setupRenderer("narrowcurvedline", style);
  75
+        
  76
+        RendererBaseTest.showRender("Narrow curved line wide PerpendicularOffset", renderer, TIME, bounds);
  77
+    }
  78
+    
  79
+}
2  modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/curvedline.properties
... ...
@@ -0,0 +1,2 @@
  1
+_=geom:LineString:4326
  2
+Line.1=LINESTRING(1 5, 4 8, 7 6, 6 3, 3 2)
35  modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/linePerpendicularOffset.sld
... ...
@@ -0,0 +1,35 @@
  1
+<?xml version="1.0" encoding="UTF-8"?>
  2
+<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld"
  3
+  xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4
+  xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  5
+  <NamedLayer>
  6
+
  7
+    <Name>GrayLines</Name>
  8
+    <UserStyle>
  9
+      <FeatureTypeStyle>
  10
+        <Rule>
  11
+          <LineSymbolizer>
  12
+            <Stroke>
  13
+              <CssParameter name="stroke">0x000000</CssParameter>
  14
+              <CssParameter name="stroke-width">1</CssParameter>
  15
+            </Stroke>
  16
+          </LineSymbolizer>
  17
+          <LineSymbolizer>
  18
+            <Stroke>
  19
+              <CssParameter name="stroke">0xff0000</CssParameter>
  20
+              <CssParameter name="stroke-width">1</CssParameter>
  21
+            </Stroke>
  22
+            <PerpendicularOffset>3</PerpendicularOffset>
  23
+          </LineSymbolizer>
  24
+          <LineSymbolizer>
  25
+            <Stroke>
  26
+              <CssParameter name="stroke">0x0000ff</CssParameter>
  27
+              <CssParameter name="stroke-width">1</CssParameter>
  28
+            </Stroke>
  29
+            <PerpendicularOffset>-3</PerpendicularOffset>
  30
+          </LineSymbolizer>
  31
+        </Rule>
  32
+      </FeatureTypeStyle>
  33
+    </UserStyle>
  34
+  </NamedLayer>
  35
+</StyledLayerDescriptor>
28  ...s/library/render/src/test/resources/org/geotools/renderer/lite/test-data/linePerpendicularOffsetWide.sld
... ...
@@ -0,0 +1,28 @@
  1
+<?xml version="1.0" encoding="UTF-8"?>
  2
+<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld"
  3
+  xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4
+  xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
  5
+  <NamedLayer>
  6
+
  7
+    <Name>GrayLines</Name>
  8
+    <UserStyle>
  9
+      <FeatureTypeStyle>
  10
+        <Rule>
  11
+          <LineSymbolizer>
  12
+            <Stroke>
  13
+              <CssParameter name="stroke">0x000000</CssParameter>
  14
+              <CssParameter name="stroke-width">1</CssParameter>
  15
+            </Stroke>
  16
+          </LineSymbolizer>
  17
+          <LineSymbolizer>
  18
+            <Stroke>
  19
+              <CssParameter name="stroke">0xff0000</CssParameter>
  20
+              <CssParameter name="stroke-width">1</CssParameter>
  21
+            </Stroke>
  22
+            <PerpendicularOffset>5</PerpendicularOffset>
  23
+          </LineSymbolizer>
  24
+        </Rule>
  25
+      </FeatureTypeStyle>
  26
+    </UserStyle>
  27
+  </NamedLayer>
  28
+</StyledLayerDescriptor>
2  modules/library/render/src/test/resources/org/geotools/renderer/lite/test-data/narrowcurvedline.properties
... ...
@@ -0,0 +1,2 @@
  1
+_=geom:LineString:4326
  2
+Line.1=LINESTRING(1 5, 4 8, 7 6, 5.5 6.9, 3 2)
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.