31 |
|
|
32 |
import java.awt.Color; |
import java.awt.Color; |
33 |
import java.awt.Dimension; |
import java.awt.Dimension; |
|
import java.awt.Graphics; |
|
34 |
import java.awt.Graphics2D; |
import java.awt.Graphics2D; |
35 |
import java.awt.Rectangle; |
import java.awt.Rectangle; |
36 |
import java.awt.geom.AffineTransform; |
import java.awt.geom.AffineTransform; |
47 |
import java.util.Map; |
import java.util.Map; |
48 |
|
|
49 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
|
import javax.swing.Box; |
|
|
import javax.swing.BoxLayout; |
|
50 |
import javax.swing.ImageIcon; |
import javax.swing.ImageIcon; |
51 |
|
import javax.swing.JComponent; |
52 |
import javax.swing.JLabel; |
import javax.swing.JLabel; |
53 |
|
|
54 |
|
import net.miginfocom.swing.MigLayout; |
55 |
|
|
56 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
57 |
import org.geotools.coverage.grid.GeneralGridEnvelope; |
import org.geotools.coverage.grid.GeneralGridEnvelope; |
58 |
import org.geotools.coverage.grid.GridCoverage2D; |
import org.geotools.coverage.grid.GridCoverage2D; |
86 |
import schmitzm.geotools.styling.StylingUtil; |
import schmitzm.geotools.styling.StylingUtil; |
87 |
import schmitzm.io.IOUtil; |
import schmitzm.io.IOUtil; |
88 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
89 |
|
import schmitzm.swing.JPanel; |
90 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
91 |
import skrueger.AttributeMetadata; |
import skrueger.AttributeMetadata; |
92 |
import skrueger.RasterLegendData; |
import skrueger.RasterLegendData; |
132 |
* if {@code null} is given as object or an error occurs |
* if {@code null} is given as object or an error occurs |
133 |
* during layer creation |
* during layer creation |
134 |
*/ |
*/ |
135 |
public static MapLayer createMapLayer(Object object) throws Exception { |
public static MapLayer createMapLayer(final Object object) throws Exception { |
136 |
return createMapLayer(object, null); |
return createMapLayer(object, null); |
137 |
} |
} |
138 |
|
|
151 |
* if {@code null} is given as object or an error occurs |
* if {@code null} is given as object or an error occurs |
152 |
* during layer creation |
* during layer creation |
153 |
*/ |
*/ |
154 |
public static MapLayer createMapLayer(Object object, Style forcedStyle) |
public static MapLayer createMapLayer(Object object, final Style forcedStyle) |
155 |
throws Exception { |
throws Exception { |
156 |
MapLayer layer = null; |
MapLayer layer = null; |
157 |
Style style = null; |
Style style = null; |
192 |
* if {@code null} is given as object or an error occurs |
* if {@code null} is given as object or an error occurs |
193 |
* during creation |
* during creation |
194 |
*/ |
*/ |
195 |
public static StyledLayerInterface<?> createStyledLayer(Object object, |
public static StyledLayerInterface<?> createStyledLayer( |
196 |
String title) { |
final Object object, final String title) { |
197 |
return createStyledLayer(object, title, null); |
return createStyledLayer(object, title, null); |
198 |
} |
} |
199 |
|
|
212 |
* if {@code null} is given as object or an error occurs |
* if {@code null} is given as object or an error occurs |
213 |
* during creation |
* during creation |
214 |
*/ |
*/ |
215 |
public static StyledLayerInterface<?> createStyledLayer(Object object, |
public static StyledLayerInterface<?> createStyledLayer( |
216 |
String title, StyledLayerStyle style) { |
final Object object, final String title, |
217 |
|
final StyledLayerStyle style) { |
218 |
StyledLayerInterface<?> styledLayer = null; |
StyledLayerInterface<?> styledLayer = null; |
219 |
|
|
220 |
String id = (title != null) ? title : "defaultID"; |
final String id = (title != null) ? title : "defaultID"; |
221 |
|
|
222 |
if (object instanceof GridCoverage2D) |
if (object instanceof GridCoverage2D) |
223 |
styledLayer = new StyledGridCoverage((GridCoverage2D) object, id, |
styledLayer = new StyledGridCoverage((GridCoverage2D) object, id, |
247 |
* returned |
* returned |
248 |
*/ |
*/ |
249 |
public static AttributeMetadataMap getVisibleAttributeMetaData( |
public static AttributeMetadataMap getVisibleAttributeMetaData( |
250 |
AttributeMetadataMap amdMap, boolean visible) { |
final AttributeMetadataMap amdMap, final boolean visible) { |
251 |
|
|
252 |
AttributeMetadataMap filteredMap = new AttributeMetadataMap(); |
final AttributeMetadataMap filteredMap = new AttributeMetadataMap(); |
253 |
for (AttributeMetadata amd : amdMap.values()) |
for (final AttributeMetadata amd : amdMap.values()) |
254 |
if (amd.isVisible() == visible) |
if (amd.isVisible() == visible) |
255 |
filteredMap.put(amd.getName(), amd); |
filteredMap.put(amd.getName(), amd); |
256 |
|
|
266 |
* {@link Element} to parse |
* {@link Element} to parse |
267 |
*/ |
*/ |
268 |
public static AttributeMetadata parseAttributeMetaData(final Element element) { |
public static AttributeMetadata parseAttributeMetaData(final Element element) { |
269 |
final String namespace = String.valueOf(element.getAttributeValue("namespace")); |
final String namespace = String.valueOf(element |
270 |
final String localname = String.valueOf(element.getAttributeValue("localname")); |
.getAttributeValue("namespace")); |
271 |
final Name aName= new NameImpl(namespace,localname); |
final String localname = String.valueOf(element |
272 |
|
.getAttributeValue("localname")); |
273 |
|
final Name aName = new NameImpl(namespace, localname); |
274 |
final Boolean visible = Boolean.valueOf(element |
final Boolean visible = Boolean.valueOf(element |
275 |
.getAttributeValue("visible")); |
.getAttributeValue("visible")); |
276 |
final String unit = element.getAttributeValue("unit"); |
final String unit = element.getAttributeValue("unit"); |
298 |
*/ |
*/ |
299 |
public static AttributeMetadataMap parseAttributeMetaDataMap( |
public static AttributeMetadataMap parseAttributeMetaDataMap( |
300 |
final Element element) { |
final Element element) { |
301 |
AttributeMetadataMap metaData = new AttributeMetadataMap(); |
final AttributeMetadataMap metaData = new AttributeMetadataMap(); |
302 |
List<Element> attributesElements = element |
final List<Element> attributesElements = element |
303 |
.getChildren(ELEM_NAME_ATTRIBUTE); |
.getChildren(ELEM_NAME_ATTRIBUTE); |
304 |
for (Element attibuteElement : attributesElements) { |
for (final Element attibuteElement : attributesElements) { |
305 |
AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement); |
final AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement); |
306 |
metaData.put(attrMetaData.getName(), attrMetaData); |
metaData.put(attrMetaData.getName(), attrMetaData); |
307 |
} |
} |
308 |
return metaData; |
return metaData; |
317 |
*/ |
*/ |
318 |
public static AttributeMetadataMap loadAttributeMetaDataMap( |
public static AttributeMetadataMap loadAttributeMetaDataMap( |
319 |
final URL documentUrl) throws Exception { |
final URL documentUrl) throws Exception { |
320 |
Document document = SAX_BUILDER.build(documentUrl); |
final Document document = SAX_BUILDER.build(documentUrl); |
321 |
return parseAttributeMetaDataMap(document.getRootElement()); |
return parseAttributeMetaDataMap(document.getRootElement()); |
322 |
} |
} |
323 |
|
|
331 |
public static Element createAttributeMetaDataElement( |
public static Element createAttributeMetaDataElement( |
332 |
final AttributeMetadata amd) { |
final AttributeMetadata amd) { |
333 |
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI); |
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI); |
334 |
element.setAttribute("namespace", String.valueOf(amd.getName().getNamespaceURI())); |
element.setAttribute("namespace", String.valueOf(amd.getName() |
335 |
|
.getNamespaceURI())); |
336 |
element.setAttribute("localname", String.valueOf(amd.getLocalName())); |
element.setAttribute("localname", String.valueOf(amd.getLocalName())); |
337 |
element.setAttribute("visible", String.valueOf(amd.isVisible())); |
element.setAttribute("visible", String.valueOf(amd.isVisible())); |
338 |
element.setAttribute("unit", amd.getUnit()); |
element.setAttribute("unit", amd.getUnit()); |
353 |
public static Element createAttributeMetaDataMapElement( |
public static Element createAttributeMetaDataMapElement( |
354 |
final AttributeMetadataMap amdMap) { |
final AttributeMetadataMap amdMap) { |
355 |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
356 |
for (AttributeMetadata amd : amdMap.values()) |
for (final AttributeMetadata amd : amdMap.values()) |
357 |
element.addContent(createAttributeMetaDataElement(amd)); |
element.addContent(createAttributeMetaDataElement(amd)); |
358 |
return element; |
return element; |
359 |
} |
} |
384 |
* @param element |
* @param element |
385 |
* {@link Element} to parse |
* {@link Element} to parse |
386 |
*/ |
*/ |
387 |
public static RasterLegendData parseRasterLegendData(Element element) { |
public static RasterLegendData parseRasterLegendData(final Element element) { |
388 |
|
|
389 |
final boolean paintGaps = Boolean.valueOf(element |
final boolean paintGaps = Boolean.valueOf(element |
390 |
.getAttributeValue("paintGaps")); |
.getAttributeValue("paintGaps")); |
391 |
|
|
392 |
RasterLegendData rld = new RasterLegendData(paintGaps); |
final RasterLegendData rld = new RasterLegendData(paintGaps); |
393 |
|
|
394 |
for (Element childElement : (List<Element>) element.getChildren()) { |
for (final Element childElement : (List<Element>) element.getChildren()) { |
395 |
final String name = childElement.getName(); |
final String name = childElement.getName(); |
396 |
// Cancel if it's an attribute |
// Cancel if it's an attribute |
397 |
if (childElement.getChildren().size() == 0) |
if (childElement.getChildren().size() == 0) |
411 |
// id label element is missing, the translation is searched |
// id label element is missing, the translation is searched |
412 |
// directly |
// directly |
413 |
// as childs of the rasterLegendItem element |
// as childs of the rasterLegendItem element |
414 |
Translation label = parseTranslation(labelElement != null ? labelElement |
final Translation label = parseTranslation(labelElement != null ? labelElement |
415 |
: childElement); |
: childElement); |
416 |
rld.put(value, label); |
rld.put(value, label); |
417 |
} |
} |
429 |
*/ |
*/ |
430 |
public static RasterLegendData loadRasterLegendData(final URL documentUrl) |
public static RasterLegendData loadRasterLegendData(final URL documentUrl) |
431 |
throws Exception { |
throws Exception { |
432 |
Document document = SAX_BUILDER.build(documentUrl); |
final Document document = SAX_BUILDER.build(documentUrl); |
433 |
return parseRasterLegendData(document.getRootElement()); |
return parseRasterLegendData(document.getRootElement()); |
434 |
} |
} |
435 |
|
|
444 |
final RasterLegendData rld) { |
final RasterLegendData rld) { |
445 |
final Element element = new Element(ELEM_NAME_RLD, AMLURI); |
final Element element = new Element(ELEM_NAME_RLD, AMLURI); |
446 |
element.setAttribute("paintGaps", rld.isPaintGaps().toString()); |
element.setAttribute("paintGaps", rld.isPaintGaps().toString()); |
447 |
for (Double key : rld.getSortedKeys()) { |
for (final Double key : rld.getSortedKeys()) { |
448 |
Element item = new Element(ELEM_NAME_RASTERLEGEND, AMLURI); |
final Element item = new Element(ELEM_NAME_RASTERLEGEND, AMLURI); |
449 |
item.setAttribute("value", key.toString()); |
item.setAttribute("value", key.toString()); |
450 |
item.addContent(createTranslationElement("label", rld.get(key))); |
item.addContent(createTranslationElement("label", rld.get(key))); |
451 |
element.addContent(item); |
element.addContent(item); |
465 |
* rounded to (null means no round; >= 0 means digits after |
* rounded to (null means no round; >= 0 means digits after |
466 |
* comma; < 0 means digits before comma) |
* comma; < 0 means digits before comma) |
467 |
*/ |
*/ |
468 |
public static RasterLegendData generateRasterLegendData(ColorMap colorMap, |
public static RasterLegendData generateRasterLegendData( |
469 |
boolean paintGaps, Integer digits) { |
final ColorMap colorMap, final boolean paintGaps, |
470 |
DecimalFormat decFormat = digits != null ? new DecimalFormat(SwingUtil |
final Integer digits) { |
471 |
.getNumberFormatPattern(digits)) : null; |
final DecimalFormat decFormat = digits != null ? new DecimalFormat( |
472 |
RasterLegendData rld = new RasterLegendData(paintGaps); |
SwingUtil.getNumberFormatPattern(digits)) : null; |
473 |
for (ColorMapEntry cme : colorMap.getColorMapEntries()) { |
final RasterLegendData rld = new RasterLegendData(paintGaps); |
474 |
double value = StylingUtil.getQuantityFromColorMapEntry(cme); |
for (final ColorMapEntry cme : colorMap.getColorMapEntries()) { |
475 |
|
final double value = StylingUtil.getQuantityFromColorMapEntry(cme); |
476 |
String label = cme.getLabel(); |
String label = cme.getLabel(); |
477 |
// if no label is set (e.g. quantitative style), |
// if no label is set (e.g. quantitative style), |
478 |
// use the value as label |
// use the value as label |
498 |
* rounded to (null means no round; >= 0 means digits after |
* rounded to (null means no round; >= 0 means digits after |
499 |
* comma; < 0 means digits before comma) |
* comma; < 0 means digits before comma) |
500 |
*/ |
*/ |
501 |
public static RasterLegendData generateRasterLegendData(Style style, |
public static RasterLegendData generateRasterLegendData(final Style style, |
502 |
boolean paintGaps, Integer digits) { |
final boolean paintGaps, final Integer digits) { |
503 |
ColorMap colorMap = StylingUtil.getColorMapFromStyle(style); |
final ColorMap colorMap = StylingUtil.getColorMapFromStyle(style); |
504 |
if (colorMap == null) |
if (colorMap == null) |
505 |
throw new IllegalArgumentException( |
throw new IllegalArgumentException( |
506 |
"Color map can not be determined from style!"); |
"Color map can not be determined from style!"); |
533 |
* {@link Element} to parse |
* {@link Element} to parse |
534 |
*/ |
*/ |
535 |
public final static Translation parseTranslation(final Element element) { |
public final static Translation parseTranslation(final Element element) { |
536 |
Translation trans = new Translation(); |
final Translation trans = new Translation(); |
537 |
|
|
538 |
if (element == null) |
if (element == null) |
539 |
return trans; |
return trans; |
575 |
* @param translation |
* @param translation |
576 |
* Translation to store in the Element |
* Translation to store in the Element |
577 |
*/ |
*/ |
578 |
public final static Element createTranslationElement(String tagname, |
public final static Element createTranslationElement(final String tagname, |
579 |
Translation translation) { |
final Translation translation) { |
580 |
Element element = new Element(tagname, AMLURI); |
final Element element = new Element(tagname, AMLURI); |
581 |
if (translation == null) |
if (translation == null) |
582 |
throw new UnsupportedOperationException( |
throw new UnsupportedOperationException( |
583 |
"Translation element can not be created from null!"); |
"Translation element can not be created from null!"); |
593 |
|
|
594 |
// add a <translation lang="..">..</tranlation> part to the element for |
// add a <translation lang="..">..</tranlation> part to the element for |
595 |
// all languages |
// all languages |
596 |
for (String lang : translation.keySet()) { |
for (final String lang : translation.keySet()) { |
597 |
Element translationElement = new Element(ELEM_NAME_TRANSLATION, |
final Element translationElement = new Element( |
598 |
AMLURI); |
ELEM_NAME_TRANSLATION, AMLURI); |
599 |
translationElement.setAttribute("lang", lang); |
translationElement.setAttribute("lang", lang); |
600 |
String translationString = translation.get(lang); |
String translationString = translation.get(lang); |
601 |
if (translationString == null) |
if (translationString == null) |
615 |
* @param style |
* @param style |
616 |
* a Style |
* a Style |
617 |
*/ |
*/ |
618 |
public static void setStyledLayerStyle(StyledLayerInterface styledObject, |
public static void setStyledLayerStyle( |
619 |
StyledLayerStyle<?> style) { |
final StyledLayerInterface styledObject, |
620 |
|
final StyledLayerStyle<?> style) { |
621 |
// set SLD style |
// set SLD style |
622 |
styledObject.setStyle(style.getGeoObjectStyle()); |
styledObject.setStyle(style.getGeoObjectStyle()); |
623 |
// set meta data |
// set meta data |
624 |
if (styledObject instanceof StyledGridCoverageInterface |
if (styledObject instanceof StyledGridCoverageInterface |
625 |
&& (style.getMetaData() instanceof RasterLegendData || style |
&& (style.getMetaData() instanceof RasterLegendData || style |
626 |
.getMetaData() == null)) { |
.getMetaData() == null)) { |
627 |
RasterLegendData sourceRld = (RasterLegendData) style.getMetaData(); |
final RasterLegendData sourceRld = (RasterLegendData) style |
628 |
RasterLegendData destRld = ((StyledGridCoverageInterface) styledObject) |
.getMetaData(); |
629 |
|
final RasterLegendData destRld = ((StyledGridCoverageInterface) styledObject) |
630 |
.getLegendMetaData(); |
.getLegendMetaData(); |
631 |
if (destRld != null && sourceRld != null) { |
if (destRld != null && sourceRld != null) { |
632 |
destRld.setPaintGaps(sourceRld.isPaintGaps()); |
destRld.setPaintGaps(sourceRld.isPaintGaps()); |
637 |
} |
} |
638 |
if (styledObject instanceof StyledFeatureCollectionInterface |
if (styledObject instanceof StyledFeatureCollectionInterface |
639 |
&& (style.getMetaData() instanceof Map || style.getMetaData() == null)) { |
&& (style.getMetaData() instanceof Map || style.getMetaData() == null)) { |
640 |
AttributeMetadataMap sourceAmd = (AttributeMetadataMap) style |
final AttributeMetadataMap sourceAmd = (AttributeMetadataMap) style |
641 |
.getMetaData(); |
.getMetaData(); |
642 |
AttributeMetadataMap destAmd = ((StyledFeatureCollectionInterface) styledObject) |
final AttributeMetadataMap destAmd = ((StyledFeatureCollectionInterface) styledObject) |
643 |
.getAttributeMetaDataMap(); |
.getAttributeMetaDataMap(); |
644 |
if (destAmd != null && sourceAmd != null) { |
if (destAmd != null && sourceAmd != null) { |
645 |
destAmd.clear(); |
destAmd.clear(); |
669 |
* {@link StyledFeatureCollectionInterface} |
* {@link StyledFeatureCollectionInterface} |
670 |
*/ |
*/ |
671 |
public static StyledLayerStyle<?> getStyledLayerStyle( |
public static StyledLayerStyle<?> getStyledLayerStyle( |
672 |
StyledLayerInterface styledObject) { |
final StyledLayerInterface styledObject) { |
673 |
if (styledObject instanceof StyledGridCoverageInterface) |
if (styledObject instanceof StyledGridCoverageInterface) |
674 |
return getStyledLayerStyle((StyledGridCoverageInterface) styledObject); |
return getStyledLayerStyle((StyledGridCoverageInterface) styledObject); |
675 |
if (styledObject instanceof StyledFeatureCollectionInterface) |
if (styledObject instanceof StyledFeatureCollectionInterface) |
688 |
* a styled grid coverage |
* a styled grid coverage |
689 |
*/ |
*/ |
690 |
public static StyledLayerStyle<RasterLegendData> getStyledLayerStyle( |
public static StyledLayerStyle<RasterLegendData> getStyledLayerStyle( |
691 |
StyledGridCoverageInterface styledGC) { |
final StyledGridCoverageInterface styledGC) { |
692 |
return new StyledLayerStyle<RasterLegendData>(styledGC.getStyle(), |
return new StyledLayerStyle<RasterLegendData>(styledGC.getStyle(), |
693 |
styledGC.getLegendMetaData()); |
styledGC.getLegendMetaData()); |
694 |
} |
} |
701 |
* a styled feature collection |
* a styled feature collection |
702 |
*/ |
*/ |
703 |
public static StyledLayerStyle<AttributeMetadataMap> getStyledLayerStyle( |
public static StyledLayerStyle<AttributeMetadataMap> getStyledLayerStyle( |
704 |
StyledFeatureCollectionInterface styledFC) { |
final StyledFeatureCollectionInterface styledFC) { |
705 |
return new StyledLayerStyle<AttributeMetadataMap>(styledFC |
return new StyledLayerStyle<AttributeMetadataMap>(styledFC.getStyle(), |
706 |
.getStyle(), styledFC.getAttributeMetaDataMap()); |
styledFC.getAttributeMetaDataMap()); |
707 |
} |
} |
708 |
|
|
709 |
/** |
/** |
720 |
* @return {@code null} in case of any error |
* @return {@code null} in case of any error |
721 |
*/ |
*/ |
722 |
public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle( |
public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle( |
723 |
URL geoObjectURL, String sldExt, String rldExt) { |
final URL geoObjectURL, final String sldExt, final String rldExt) { |
724 |
RasterLegendData metaData = null; |
RasterLegendData metaData = null; |
725 |
Style sldStyle = null; |
Style sldStyle = null; |
726 |
try { |
try { |
727 |
Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt( |
final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt( |
728 |
geoObjectURL, sldExt)); |
geoObjectURL, sldExt)); |
729 |
// SLD must be present |
// SLD must be present |
730 |
if (styles == null || styles.length == 0) |
if (styles == null || styles.length == 0) |
731 |
return null; |
return null; |
732 |
sldStyle = styles[0]; |
sldStyle = styles[0]; |
733 |
} catch (Exception err) { |
} catch (final Exception err) { |
734 |
// SLD must be present |
// SLD must be present |
735 |
LangUtil.logDebugError(LOGGER, err); |
LangUtil.logDebugError(LOGGER, err); |
736 |
return null; |
return null; |
739 |
try { |
try { |
740 |
metaData = StyledLayerUtil.loadRasterLegendData(IOUtil |
metaData = StyledLayerUtil.loadRasterLegendData(IOUtil |
741 |
.changeUrlExt(geoObjectURL, rldExt)); |
.changeUrlExt(geoObjectURL, rldExt)); |
742 |
} catch (FileNotFoundException err) { |
} catch (final FileNotFoundException err) { |
743 |
// ignore missing raster legend data |
// ignore missing raster legend data |
744 |
} catch (Exception err) { |
} catch (final Exception err) { |
745 |
// any other error during legend data creation leads to error |
// any other error during legend data creation leads to error |
746 |
LangUtil.logDebugError(LOGGER, err); |
LangUtil.logDebugError(LOGGER, err); |
747 |
return null; |
return null; |
764 |
* @return {@code null} in case of any error |
* @return {@code null} in case of any error |
765 |
*/ |
*/ |
766 |
public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle( |
public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle( |
767 |
URL geoObjectURL) { |
final URL geoObjectURL) { |
768 |
return loadStyledRasterStyle(geoObjectURL, "sld", "rld"); |
return loadStyledRasterStyle(geoObjectURL, "sld", "rld"); |
769 |
} |
} |
770 |
|
|
782 |
* @return {@code null} in case of any error |
* @return {@code null} in case of any error |
783 |
*/ |
*/ |
784 |
public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle( |
public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle( |
785 |
URL geoObjectURL, String sldExt, String rldExt) { |
final URL geoObjectURL, final String sldExt, final String rldExt) { |
786 |
AttributeMetadataMap metaData = null; |
AttributeMetadataMap metaData = null; |
787 |
Style sldStyle = null; |
Style sldStyle = null; |
788 |
try { |
try { |
789 |
Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt( |
final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt( |
790 |
geoObjectURL, sldExt)); |
geoObjectURL, sldExt)); |
791 |
// SLD must be present |
// SLD must be present |
792 |
if (styles == null || styles.length == 0) |
if (styles == null || styles.length == 0) |
793 |
return null; |
return null; |
794 |
sldStyle = styles[0]; |
sldStyle = styles[0]; |
795 |
} catch (Exception err) { |
} catch (final Exception err) { |
796 |
// SLD must be present |
// SLD must be present |
797 |
LangUtil.logDebugError(LOGGER, err); |
LangUtil.logDebugError(LOGGER, err); |
798 |
return null; |
return null; |
801 |
try { |
try { |
802 |
metaData = StyledLayerUtil.loadAttributeMetaDataMap(IOUtil |
metaData = StyledLayerUtil.loadAttributeMetaDataMap(IOUtil |
803 |
.changeUrlExt(geoObjectURL, rldExt)); |
.changeUrlExt(geoObjectURL, rldExt)); |
804 |
} catch (FileNotFoundException err) { |
} catch (final FileNotFoundException err) { |
805 |
// ignore missing attribute meta data |
// ignore missing attribute meta data |
806 |
} catch (Exception err) { |
} catch (final Exception err) { |
807 |
// any other error during meta data creation leads to error |
// any other error during meta data creation leads to error |
808 |
LangUtil.logDebugError(LOGGER, err); |
LangUtil.logDebugError(LOGGER, err); |
809 |
return null; |
return null; |
810 |
} |
} |
811 |
|
|
812 |
return new StyledLayerStyle<AttributeMetadataMap>(sldStyle, |
return new StyledLayerStyle<AttributeMetadataMap>(sldStyle, metaData); |
|
metaData); |
|
813 |
} |
} |
814 |
|
|
815 |
/** |
/** |
827 |
* @return {@code null} in case of any error |
* @return {@code null} in case of any error |
828 |
*/ |
*/ |
829 |
public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle( |
public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle( |
830 |
URL geoObjectURL) { |
final URL geoObjectURL) { |
831 |
return loadStyledFeatureStyle(geoObjectURL, "sld", "amd"); |
return loadStyledFeatureStyle(geoObjectURL, "sld", "amd"); |
832 |
} |
} |
833 |
|
|
844 |
* @param mdExt |
* @param mdExt |
845 |
* file extention for the meta-data file |
* file extention for the meta-data file |
846 |
*/ |
*/ |
847 |
public static <T> void saveStyledLayerStyle(StyledLayerStyle<T> style, |
public static <T> void saveStyledLayerStyle( |
848 |
URL geoObjectURL, String sldExt, String mdExt) throws Exception { |
final StyledLayerStyle<T> style, final URL geoObjectURL, |
849 |
|
final String sldExt, final String mdExt) throws Exception { |
850 |
// Store the SLD |
// Store the SLD |
851 |
Style sldStyle = style.getGeoObjectStyle(); |
final Style sldStyle = style.getGeoObjectStyle(); |
852 |
if (sldStyle != null) { |
if (sldStyle != null) { |
853 |
StylingUtil.saveStyleToSLD(sldStyle, IOUtil.changeFileExt(new File( |
StylingUtil.saveStyleToSLD(sldStyle, IOUtil.changeFileExt(new File( |
854 |
geoObjectURL.toURI()), sldExt)); |
geoObjectURL.toURI()), sldExt)); |
855 |
} |
} |
856 |
|
|
857 |
// Store the meta data |
// Store the meta data |
858 |
T metaData = style.getMetaData(); |
final T metaData = style.getMetaData(); |
859 |
if (metaData != null) { |
if (metaData != null) { |
860 |
if (metaData instanceof RasterLegendData) { |
if (metaData instanceof RasterLegendData) { |
861 |
saveRasterLegendData((RasterLegendData) metaData, IOUtil |
saveRasterLegendData((RasterLegendData) metaData, IOUtil |
864 |
// Map<Integer,AttributeMetaData> ) { // LEIDER NICHT |
// Map<Integer,AttributeMetaData> ) { // LEIDER NICHT |
865 |
// KOMPILIERBAR!! |
// KOMPILIERBAR!! |
866 |
} else if (metaData instanceof Map) { |
} else if (metaData instanceof Map) { |
867 |
saveAttributeMetaDataMap( |
saveAttributeMetaDataMap((AttributeMetadataMap) metaData, |
868 |
(AttributeMetadataMap) metaData, IOUtil |
IOUtil.changeUrlExt(geoObjectURL, mdExt)); |
|
.changeUrlExt(geoObjectURL, mdExt)); |
|
869 |
} else |
} else |
870 |
throw new UnsupportedOperationException( |
throw new UnsupportedOperationException( |
871 |
"Export for meta data not yet supported: " |
"Export for meta data not yet supported: " |
883 |
* @param geoObjectURL |
* @param geoObjectURL |
884 |
* URL of the (already read) raster object |
* URL of the (already read) raster object |
885 |
*/ |
*/ |
886 |
public static void saveStyledLayerStyle(StyledLayerStyle<?> style, |
public static void saveStyledLayerStyle(final StyledLayerStyle<?> style, |
887 |
URL geoObjectURL) throws Exception { |
final URL geoObjectURL) throws Exception { |
888 |
if (style.getMetaData() instanceof RasterLegendData) |
if (style.getMetaData() instanceof RasterLegendData) |
889 |
saveStyledLayerStyle(style, geoObjectURL, "sld", "rld"); |
saveStyledLayerStyle(style, geoObjectURL, "sld", "rld"); |
890 |
else |
else |
892 |
} |
} |
893 |
|
|
894 |
/** |
/** |
895 |
* Creates a {@link Box} that shows a legend for a list of |
* Creates a {@link JPanel} that shows a legend for a list of |
896 |
* {@link FeatureTypeStyle}s and a targeted featureType |
* {@link FeatureTypeStyle}s and a targeted featureType |
897 |
* |
* |
898 |
* @param featureType |
* @param featureType |
903 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
904 |
* Krüger</a> |
* Krüger</a> |
905 |
*/ |
*/ |
906 |
public static Box createLegendPanel(List<FeatureTypeStyle> list, |
public static JPanel createLegendPanel(Style style, |
907 |
SimpleFeatureType featureType, int iconWidth, int iconHeight) { |
final SimpleFeatureType featureType, final int iconWidth, |
908 |
|
final int iconHeight) { |
909 |
|
|
910 |
Box box = new Box(BoxLayout.Y_AXIS) { |
final List<FeatureTypeStyle> list = style.featureTypeStyles(); |
911 |
|
|
912 |
/** |
final JPanel panel = new JPanel(new MigLayout("wrap 2","[]:3:[]")); |
|
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot |
|
|
* gemacht wird) wird. Dann werden wird der Hintergrund auf WEISS |
|
|
* gesetzt. |
|
|
* |
|
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
|
|
* Krüger</a> |
|
|
*/ |
|
|
@Override |
|
|
public void print(Graphics g) { |
|
|
final Color orig = getBackground(); |
|
|
setBackground(Color.WHITE); |
|
|
// wrap in try/finally so that we always restore the state |
|
|
try { |
|
|
super.print(g); |
|
|
} finally { |
|
|
setBackground(orig); |
|
|
} |
|
|
} |
|
|
}; |
|
913 |
|
|
914 |
for (FeatureTypeStyle ftStyle : list) { |
if (style == null) { |
915 |
|
// No Style => no legend |
916 |
|
return panel; |
917 |
|
} |
918 |
|
|
919 |
|
for (final FeatureTypeStyle ftStyle : list) { |
920 |
|
|
921 |
// One child-node for every rule |
// One child-node for every rule |
922 |
List<Rule> rules = ftStyle.rules(); |
final List<Rule> rules = ftStyle.rules(); |
923 |
for (Rule rule : rules) { |
for (final Rule rule : rules) { |
924 |
|
|
925 |
/** |
/** |
926 |
* Let's not create a hbox for Rules that only contain |
* Let's not create a hbox for Rules that only contain |
930 |
.size() == rule.getSymbolizers().length) |
.size() == rule.getSymbolizers().length) |
931 |
continue; |
continue; |
932 |
|
|
|
Box hbox = new Box(BoxLayout.X_AXIS) { |
|
|
|
|
|
/** |
|
|
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein |
|
|
* Screenshot gemacht wird) wird. Dann werden wird der |
|
|
* Hintergrund auf WEISS gesetzt. |
|
|
*/ |
|
|
@Override |
|
|
public void print(Graphics g) { |
|
|
final Color orig = getBackground(); |
|
|
setBackground(Color.WHITE); |
|
|
// wrap in try/finally so that we always restore the |
|
|
// state |
|
|
try { |
|
|
super.print(g); |
|
|
} finally { |
|
|
setBackground(orig); |
|
|
} |
|
|
} |
|
|
}; |
|
|
|
|
|
/** |
|
|
* The size of the legend Symbol is dependent on the size of the |
|
|
* font. |
|
|
*/ |
|
|
final int fontHeight = new JLabel().getFontMetrics( |
|
|
new JLabel().getFont()).getHeight(); |
|
|
|
|
|
final Dimension ICON_SIZE = new Dimension(iconWidth, |
|
|
fontHeight > 5 ? fontHeight : iconHeight); |
|
|
|
|
|
// **************************************************************************** |
|
|
// Create the actual icon |
|
|
// **************************************************************************** |
|
933 |
final BufferedImage imageForRule = LegendIconFeatureRenderer |
final BufferedImage imageForRule = LegendIconFeatureRenderer |
934 |
.getInstance().createImageForRule(rule, featureType, |
.getInstance().createImageForRule(rule, featureType, |
935 |
ICON_SIZE); |
new Dimension(iconWidth, iconHeight)); |
|
|
|
|
// LOGGER.debug("Creating a new Legend Image for RUle name = |
|
|
// "+rule.getName()); |
|
936 |
|
|
937 |
ImageIcon legendIcon = new ImageIcon(imageForRule); |
final ImageIcon legendIcon = new ImageIcon(imageForRule); |
938 |
|
|
939 |
final JLabel iconLabel = new JLabel(legendIcon); |
final JLabel iconLabel = new JLabel(legendIcon); |
940 |
hbox.setAlignmentX(0f); |
panel.add(iconLabel,"sgx1"); |
941 |
hbox.add(iconLabel); |
// hbox.setAlignmentX(0f); |
942 |
hbox.add(Box.createHorizontalStrut(3)); |
// hbox.add(iconLabel); |
943 |
|
// hbox.add(Box.createHorizontalStrut(3)); |
944 |
|
|
945 |
Translation labelT = new Translation(); |
final Translation labelT = new Translation(); |
946 |
labelT.fromOneLine(rule.getDescription().getTitle()); |
labelT.fromOneLine(rule.getDescription().getTitle()); |
|
|
|
947 |
final JLabel classTitleLabel = new JLabel(labelT.toString()); |
final JLabel classTitleLabel = new JLabel(labelT.toString()); |
948 |
hbox.add(classTitleLabel); |
|
949 |
|
panel.add(classTitleLabel,"sgx2"); |
950 |
classTitleLabel.setLabelFor(iconLabel); |
classTitleLabel.setLabelFor(iconLabel); |
|
|
|
|
box.add(hbox); |
|
|
|
|
951 |
} |
} |
952 |
} |
} |
953 |
|
|
954 |
return box; |
return panel; |
955 |
} |
} |
956 |
|
|
957 |
/** |
/** |
958 |
* Creates a |
* Creates a {@link JComponent} that contains a legend for a given |
959 |
|
* rasterLayer and a given {@link Style}. |
960 |
* |
* |
961 |
* @param styledRaster |
* @param style |
962 |
* @param iconHeight |
* if <code>null</code>, the default {@link Style} is extracetd |
963 |
* @param iconWidth |
* from the {@link StyledRasterInterface} |
|
* @return |
|
964 |
*/ |
*/ |
965 |
public static Box createLegendPanel(StyledRasterInterface<?> styledRaster, |
public static JPanel createLegendPanel( |
966 |
int iconWidth, int iconHeight) { |
final StyledRasterInterface<?> styledRaster, Style style, |
967 |
|
final int iconWidth, final int iconHeight) { |
968 |
|
|
969 |
|
// If no style is given, we use the default style for this layer |
970 |
|
if (style == null) |
971 |
|
style = styledRaster.getStyle(); |
972 |
|
|
973 |
/** |
/** |
974 |
* Determine whether a Style is responsible for the coloring |
* Determine whether a Style is responsible for the coloring |
975 |
*/ |
*/ |
976 |
ColorModel colorModel = null; |
ColorModel colorModel = null; |
977 |
if (!isStyleable(styledRaster) |
if (!isStyleable(styledRaster) |
978 |
|| (isStyleable(styledRaster) && styledRaster.getStyle() == null)) { |
|| (isStyleable(styledRaster) && style == null)) { |
979 |
colorModel = getColorModel(styledRaster); |
colorModel = getColorModel(styledRaster); |
980 |
} |
} |
981 |
|
|
982 |
RasterLegendData rasterLegendData = styledRaster.getLegendMetaData(); |
final RasterLegendData rasterLegendData = styledRaster |
983 |
List<Double> legendRasterValues = rasterLegendData.getSortedKeys(); |
.getLegendMetaData(); |
984 |
Map<Double, GridCoverage2D> sampleRasters = rasterLegendData |
final List<Double> legendRasterValues = rasterLegendData |
985 |
|
.getSortedKeys(); |
986 |
|
final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData |
987 |
.createSampleRasters(); |
.createSampleRasters(); |
988 |
|
|
989 |
Box box = new Box(BoxLayout.Y_AXIS) { |
final JPanel panel = new JPanel(new MigLayout("wrap 2")); |
|
|
|
|
/** |
|
|
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot |
|
|
* gemacht wird) wird. Dann werden wird der Hintergrund auf WEISS |
|
|
* gesetzt. |
|
|
*/ |
|
|
@Override |
|
|
public void print(Graphics g) { |
|
|
final Color orig = getBackground(); |
|
|
setBackground(Color.WHITE); |
|
|
// wrap in try/finally so that we always restore the state |
|
|
try { |
|
|
super.print(g); |
|
|
} finally { |
|
|
setBackground(orig); |
|
|
} |
|
|
} |
|
|
}; |
|
990 |
|
|
991 |
for (Double rValue : legendRasterValues) { |
for (final Double rValue : legendRasterValues) { |
992 |
|
|
993 |
/** |
// final Dimension ICON_SIZE = new Dimension(iconWidth, |
994 |
* |
// new JLabel().getFontMetrics(new JLabel().getFont()) |
995 |
*/ |
// .getHeight() > 5 ? new JLabel().getFontMetrics( |
996 |
Box hbox = new Box(BoxLayout.X_AXIS) { |
// new JLabel().getFont()).getHeight() : iconHeight); |
|
|
|
|
/** |
|
|
* Nuetzlich wenn die Componente gedruckt (z.B. wenn ein |
|
|
* Screenshot gemacht wird) wird. Dann werden wird der |
|
|
* Hintergrund auf WEISS gesetzt. |
|
|
*/ |
|
|
@Override |
|
|
public void print(Graphics g) { |
|
|
final Color orig = getBackground(); |
|
|
setBackground(Color.WHITE); |
|
|
// wrap in try/finally so that we always restore the |
|
|
// state |
|
|
try { |
|
|
super.print(g); |
|
|
} finally { |
|
|
setBackground(orig); |
|
|
} |
|
|
} |
|
|
}; |
|
|
|
|
|
final Dimension ICON_SIZE = new Dimension(iconWidth, |
|
|
new JLabel().getFontMetrics(new JLabel().getFont()) |
|
|
.getHeight() > 5 ? new JLabel().getFontMetrics( |
|
|
new JLabel().getFont()).getHeight() : iconHeight); |
|
997 |
|
|
998 |
// **************************************************************************** |
// **************************************************************************** |
999 |
// Create the actual icon |
// Create the actual icon |
1000 |
// **************************************************************************** |
// **************************************************************************** |
1001 |
BufferedImage buffImage = new BufferedImage(ICON_SIZE.width, |
final BufferedImage buffImage = new BufferedImage(iconWidth, |
1002 |
ICON_SIZE.height, BufferedImage.TYPE_INT_ARGB); |
iconHeight, BufferedImage.TYPE_INT_ARGB); |
1003 |
Graphics2D graphics = buffImage.createGraphics(); |
|
1004 |
|
final Graphics2D graphics = buffImage.createGraphics(); |
1005 |
|
|
1006 |
if (colorModel != null) { |
if (colorModel != null) { |
1007 |
|
// The colors come from the ColorModel! |
1008 |
|
|
1009 |
try { |
try { |
1010 |
Object inData = null; |
Object inData = null; |
1011 |
switch (colorModel.getTransferType()) { |
switch (colorModel.getTransferType()) { |
1033 |
final Color color = new Color(colorModel.getRGB(inData)); |
final Color color = new Color(colorModel.getRGB(inData)); |
1034 |
graphics.setBackground(color); |
graphics.setBackground(color); |
1035 |
graphics.setColor(color); |
graphics.setColor(color); |
1036 |
graphics.fillRect(0, 0, ICON_SIZE.width, ICON_SIZE.height); |
graphics.fillRect(0, 0, iconWidth, iconHeight); |
1037 |
} catch (Exception e) { |
} catch (final Exception e) { |
1038 |
LOGGER.debug( |
LOGGER.info( |
1039 |
"Dann nehmen wir halt den GridCoverageRenderer", e); |
"Dann nehmen wir halt den GridCoverageRenderer", e); |
1040 |
colorModel = null; |
colorModel = null; |
1041 |
} |
} |
1042 |
} |
} else { |
1043 |
|
// The colors come from the Style |
|
if (colorModel == null) { |
|
1044 |
|
|
1045 |
/** |
/** |
1046 |
* The coverage contains only one value of value rValue |
* The coverage contains only one value of value rValue |
1047 |
*/ |
*/ |
1048 |
GridCoverage2D sampleCov = sampleRasters.get(rValue); |
final GridCoverage2D sampleCov = sampleRasters.get(rValue); |
1049 |
GridCoverageRenderer renderer; |
GridCoverageRenderer renderer; |
1050 |
try { |
try { |
1051 |
renderer = new GridCoverageRenderer(sampleCov |
renderer = new GridCoverageRenderer(sampleCov |
1053 |
.createEnvelope(sampleCov.getEnvelope()), |
.createEnvelope(sampleCov.getEnvelope()), |
1054 |
new Rectangle(iconWidth, iconHeight), |
new Rectangle(iconWidth, iconHeight), |
1055 |
(AffineTransform) null); |
(AffineTransform) null); |
1056 |
} catch (Exception e1) { |
} catch (final Exception e1) { |
1057 |
throw new RuntimeException( |
throw new RuntimeException( |
1058 |
"Creating the GridCoverageRenderer:", e1); |
"Creating a GridCoverageRenderer failed:", e1); |
1059 |
} |
} |
1060 |
|
|
1061 |
/** |
/** |
1062 |
* Iterate over all FeatureTypeStyles. |
* Iterate over all FeatureTypeStyles. |
1063 |
*/ |
*/ |
1064 |
// for (FeatureTypeStyle ftStyle : styledGrid.getStyle() |
final List<RasterSymbolizer> rSymbols = StylingUtil |
|
// .featureTypeStyles()) { |
|
|
// One child-node for every rule |
|
|
// List<Rule> rules = ftStyle.rules(); |
|
|
// for (Rule rule : rules) { |
|
|
final Style style = styledRaster.getStyle(); |
|
|
List<RasterSymbolizer> rSymbols = StylingUtil |
|
1065 |
.getRasterSymbolizers(style); |
.getRasterSymbolizers(style); |
1066 |
|
|
1067 |
for (RasterSymbolizer symbolizer : rSymbols) { |
for (final RasterSymbolizer symbolizer : rSymbols) { |
|
// LOGGER.debug("Creating a new Legend Image for RUle |
|
|
// name = |
|
|
// "+rule.getName()); |
|
1068 |
try { |
try { |
1069 |
renderer.paint(graphics, sampleCov, symbolizer); |
renderer.paint(graphics, sampleCov, symbolizer); |
1070 |
} catch (Exception ee) { |
} catch (final Exception ee) { |
1071 |
LOGGER.error("Unable to paint " + symbolizer |
LOGGER.error("Unable to paint " + symbolizer |
1072 |
+ " into the legend image", ee); |
+ " into the legend image", ee); |
1073 |
} |
} |
|
// } |
|
|
// } |
|
1074 |
} |
} |
1075 |
} |
} |
1076 |
|
|
1077 |
ImageIcon legendIcon = new ImageIcon(buffImage); |
final JLabel iconLabel = new JLabel(new ImageIcon(buffImage)); |
1078 |
|
// hbox.setAlignmentX(0f); |
1079 |
final JLabel iconLabel = new JLabel(legendIcon); |
panel.add(iconLabel,"sgx1"); |
1080 |
hbox.setAlignmentX(0f); |
// hbox.add(Box.createHorizontalStrut(3)); |
|
hbox.add(iconLabel); |
|
|
hbox.add(Box.createHorizontalStrut(3)); |
|
1081 |
|
|
1082 |
Translation labelT = rasterLegendData.get(rValue); |
final Translation labelT = rasterLegendData.get(rValue); |
1083 |
final JLabel classTitleLabel = new JLabel(labelT.toString()); |
final JLabel classTitleLabel = new JLabel(labelT.toString()); |
1084 |
hbox.add(classTitleLabel); |
panel.add(classTitleLabel,"sgx2" + (rasterLegendData.getPaintGaps()? ", gapy 0 3":"")); |
1085 |
classTitleLabel.setLabelFor(iconLabel); |
classTitleLabel.setLabelFor(iconLabel); |
1086 |
|
|
1087 |
box.add(hbox); |
// box.add(hbox); |
1088 |
|
|
1089 |
if (rasterLegendData.getPaintGaps()) { |
if (rasterLegendData.getPaintGaps()) { |
1090 |
iconLabel |
iconLabel |
1091 |
.setBorder(BorderFactory.createLineBorder(Color.black)); |
.setBorder(BorderFactory.createLineBorder(Color.black)); |
|
box.add(Box.createVerticalStrut(3)); |
|
1092 |
} |
} |
1093 |
|
|
1094 |
} |
} |
1095 |
|
|
1096 |
return box; |
return panel; |
1097 |
} |
} |
1098 |
|
|
1099 |
/** |
/** |
1101 |
* return <code>null</code> if the geoobject can not be accessed. |
* return <code>null</code> if the geoobject can not be accessed. |
1102 |
*/ |
*/ |
1103 |
@SuppressWarnings("unchecked") |
@SuppressWarnings("unchecked") |
1104 |
public static ColorModel getColorModel(StyledRasterInterface<?> styledGrid) { |
public static ColorModel getColorModel( |
1105 |
|
final StyledRasterInterface<?> styledGrid) { |
1106 |
ColorModel colorModel = null; |
ColorModel colorModel = null; |
1107 |
try { |
try { |
1108 |
Object geoObject = styledGrid.getGeoObject(); |
final Object geoObject = styledGrid.getGeoObject(); |
1109 |
if (geoObject instanceof GridCoverage2D) { |
if (geoObject instanceof GridCoverage2D) { |
1110 |
GridCoverage2D cov = (GridCoverage2D) geoObject; |
final GridCoverage2D cov = (GridCoverage2D) geoObject; |
1111 |
colorModel = cov.getRenderedImage().getColorModel(); |
colorModel = cov.getRenderedImage().getColorModel(); |
1112 |
} else if (styledGrid instanceof StyledRasterPyramidInterface) { |
} else if (styledGrid instanceof StyledRasterPyramidInterface) { |
1113 |
|
|
1114 |
Parameter readGG = new Parameter( |
final Parameter readGG = new Parameter( |
1115 |
AbstractGridFormat.READ_GRIDGEOMETRY2D); |
AbstractGridFormat.READ_GRIDGEOMETRY2D); |
1116 |
|
|
1117 |
ReferencedEnvelope mapExtend = new org.geotools.geometry.jts.ReferencedEnvelope( |
final ReferencedEnvelope mapExtend = new org.geotools.geometry.jts.ReferencedEnvelope( |
1118 |
styledGrid.getEnvelope(), styledGrid.getCrs()); |
styledGrid.getEnvelope(), styledGrid.getCrs()); |
1119 |
|
|
1120 |
readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope( |
readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope( |
1121 |
new Rectangle(0, 0, 1, 1)), mapExtend)); |
new Rectangle(0, 0, 1, 1)), mapExtend)); |
1122 |
|
|
1123 |
FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject; |
final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject; |
1124 |
|
|
1125 |
final AbstractGridCoverage2DReader aReader = (AbstractGridCoverage2DReader) FeatureUtil |
final AbstractGridCoverage2DReader aReader = (AbstractGridCoverage2DReader) FeatureUtil |
1126 |
.getWrappedGeoObject(rFc); |
.getWrappedGeoObject(rFc); |
1127 |
GridCoverage2D cov = (GridCoverage2D) aReader |
final GridCoverage2D cov = (GridCoverage2D) aReader |
1128 |
.read(new GeneralParameterValue[] { readGG }); |
.read(new GeneralParameterValue[] { readGG }); |
1129 |
colorModel = cov.getRenderedImage().getColorModel(); |
colorModel = cov.getRenderedImage().getColorModel(); |
1130 |
} |
} |
1131 |
} catch (Exception e) { |
} catch (final Exception e) { |
1132 |
LOGGER.error("Error reading the colormodel from " + styledGrid, e); |
LOGGER.error("Error reading the colormodel from " + styledGrid, e); |
1133 |
return null; |
return null; |
1134 |
} |
} |
1141 |
* with their own {@link ColorModel} and will ignore any |
* with their own {@link ColorModel} and will ignore any |
1142 |
* {@link RasterSymbolizer} = SLD. |
* {@link RasterSymbolizer} = SLD. |
1143 |
*/ |
*/ |
1144 |
public static boolean isStyleable(StyledRasterInterface<?> styledRaster) { |
public static boolean isStyleable( |
1145 |
ColorModel colorModel = getColorModel(styledRaster); |
final StyledRasterInterface<?> styledRaster) { |
1146 |
|
final ColorModel colorModel = getColorModel(styledRaster); |
1147 |
|
|
1148 |
LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is " |
LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is " |
1149 |
+ colorModel.getClass().getSimpleName()); |
+ colorModel.getClass().getSimpleName()); |