New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GEOS-8034] Fix ysld color conversion master #1649
Merged
tbarsballe
merged 5 commits into
geotools:master
from
hwbllmnn:fix-ysld-color-conversion-master
Nov 15, 2017
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8adae77
[GEOS-8034] Fixed ysld color conversion
hwbllmnn 5d6c19f
Merge branch 'master' of github.com:geotools/geotools into fix-ysld-c…
hwbllmnn 27a7501
Revert "[GEOS-8034] Fixed ysld color conversion"
hwbllmnn ab77e3e
fixed ysdl encoder to allow for Color objects
hwbllmnn 98515c1
incorporate requested changes
hwbllmnn File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.awt.Color; | ||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.util.ArrayList; | ||
|
@@ -41,6 +42,7 @@ | |
import javax.measure.unit.NonSI; | ||
|
||
import org.geotools.factory.CommonFactoryFinder; | ||
import org.geotools.filter.FilterFactoryImpl; | ||
import org.geotools.styling.ColorMapEntry; | ||
import org.geotools.styling.FeatureTypeStyle; | ||
import org.geotools.styling.LabelPlacement; | ||
|
@@ -61,13 +63,13 @@ | |
import org.geotools.ysld.YamlMap; | ||
import org.geotools.ysld.YamlSeq; | ||
import org.geotools.ysld.Ysld; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.opengis.filter.FilterFactory; | ||
import org.opengis.filter.FilterFactory2; | ||
import org.opengis.filter.expression.Expression; | ||
import org.opengis.filter.expression.Function; | ||
import org.opengis.filter.expression.Literal; | ||
import org.opengis.style.ChannelSelection; | ||
import org.opengis.style.ContrastMethod; | ||
import org.opengis.style.Graphic; | ||
|
@@ -1320,4 +1322,12 @@ public void testSymbolizerUoMOther() throws Exception { | |
exception.expect(IllegalArgumentException.class); | ||
Ysld.encode(sld(fts), out); | ||
} | ||
|
||
@Test | ||
public void testColorObject() throws Exception { | ||
RasterSymbolizerEncoder encoder = new RasterSymbolizerEncoder(null); | ||
Literal literal = new FilterFactoryImpl().literal(Color.BLACK); | ||
Object obj = encoder.toObjOrNull(literal); | ||
assertEquals(obj.getClass(), Color.class); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the change suggested above, this test will no longer be valid. Something that tests a full style would probably be better anyway; something like this should work (using the style example reported in the ticket):
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems quite brittle.
Tracing through the existing YSLD logic, it looks like the only time this gets called with a Color an an argument is when it is called by
toColorOrNull
(line 170 of this class). Rather than risk breaking the behaviour of toObjOrNull, it would be better to modify that method to return the Color object instead.A simple check prior to calling this method should be sufficient (replace line 170 with the following):
(Additionally, this change violates the api defined in the javadocs for this method - it should return either a String or a Number; if you modify toColorOrNull instead you wont have that issue, as that method is expected to return a Color)