25 |
* |
* |
26 |
* Contributors: |
* Contributors: |
27 |
* Martin O. J. Schmitz - initial API and implementation |
* Martin O. J. Schmitz - initial API and implementation |
28 |
* Stefan A. Krüger - additional utility classes |
* Stefan A. Tzeggai - additional utility classes |
29 |
******************************************************************************/ |
******************************************************************************/ |
30 |
package skrueger.geotools; |
package skrueger.geotools; |
31 |
|
|
38 |
import java.awt.image.ColorModel; |
import java.awt.image.ColorModel; |
39 |
import java.awt.image.ComponentColorModel; |
import java.awt.image.ComponentColorModel; |
40 |
import java.awt.image.DataBuffer; |
import java.awt.image.DataBuffer; |
41 |
|
import java.awt.image.IndexColorModel; |
42 |
import java.io.File; |
import java.io.File; |
43 |
import java.io.FileNotFoundException; |
import java.io.FileNotFoundException; |
44 |
import java.io.FileWriter; |
import java.io.FileWriter; |
45 |
import java.net.URL; |
import java.net.URL; |
46 |
import java.text.DecimalFormat; |
import java.text.DecimalFormat; |
47 |
|
import java.util.ArrayList; |
48 |
import java.util.List; |
import java.util.List; |
49 |
import java.util.Map; |
import java.util.Map; |
50 |
|
import java.util.Set; |
51 |
|
|
52 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
53 |
import javax.swing.ImageIcon; |
import javax.swing.ImageIcon; |
81 |
import org.jdom.output.XMLOutputter; |
import org.jdom.output.XMLOutputter; |
82 |
import org.opengis.feature.simple.SimpleFeature; |
import org.opengis.feature.simple.SimpleFeature; |
83 |
import org.opengis.feature.simple.SimpleFeatureType; |
import org.opengis.feature.simple.SimpleFeatureType; |
84 |
|
import org.opengis.feature.type.AttributeDescriptor; |
85 |
|
import org.opengis.feature.type.GeometryDescriptor; |
86 |
import org.opengis.feature.type.Name; |
import org.opengis.feature.type.Name; |
87 |
import org.opengis.parameter.GeneralParameterValue; |
import org.opengis.parameter.GeneralParameterValue; |
88 |
|
|
93 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
94 |
import schmitzm.swing.JPanel; |
import schmitzm.swing.JPanel; |
95 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
96 |
import skrueger.AttributeMetadata; |
import skrueger.AttributeMetadataImpl; |
97 |
|
import skrueger.AttributeMetadataInterface; |
98 |
import skrueger.RasterLegendData; |
import skrueger.RasterLegendData; |
99 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
100 |
|
|
251 |
* @param visible |
* @param visible |
252 |
* indicated whether the visible or invisible entries are |
* indicated whether the visible or invisible entries are |
253 |
* returned |
* returned |
254 |
|
* |
255 |
|
* TODO replace with |
256 |
|
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
257 |
*/ |
*/ |
258 |
public static AttributeMetadataMap getVisibleAttributeMetaData( |
public static AttributeMetadataMap<? extends AttributeMetadataInterface> getVisibleAttributeMetaData( |
259 |
final AttributeMetadataMap amdMap, final boolean visible) { |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap, |
260 |
|
final boolean visible) { |
261 |
|
|
262 |
|
final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap |
263 |
|
.clone(); |
264 |
|
if (filteredMap.size() > 0) { |
265 |
|
filteredMap.clear(); // Just in case the close copies the contents |
266 |
|
} |
267 |
|
|
268 |
final AttributeMetadataMap filteredMap = new AttributeMetadataMap(); |
for (final AttributeMetadataInterface amd : amdMap.values()) |
|
for (final AttributeMetadata amd : amdMap.values()) |
|
269 |
if (amd.isVisible() == visible) |
if (amd.isVisible() == visible) |
270 |
filteredMap.put(amd.getName(), amd); |
filteredMap.put(amd.getName(), amd); |
271 |
|
|
273 |
} |
} |
274 |
|
|
275 |
/** |
/** |
276 |
* Parses a {@link AttributeMetadata} object from an JDOM-{@link Element}. |
* Parses a {@link AttributeMetadataImpl} object from an JDOM- |
277 |
* This method works like {@link |
* {@link Element}. This method works like {@link |
278 |
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM. |
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM. |
279 |
* |
* |
280 |
|
* TODO 20.11.2009, SK: There are some new attribute weight, functiona, |
281 |
|
* functionX and nodata in AttributeMetaData that should be parsed/exported |
282 |
|
* too. but this method is only used by ISDSS, which is not supporting that |
283 |
|
* stuff anyways. |
284 |
|
* |
285 |
* @param element |
* @param element |
286 |
* {@link Element} to parse |
* {@link Element} to parse |
287 |
*/ |
*/ |
288 |
public static AttributeMetadata parseAttributeMetaData(final Element element) { |
public static AttributeMetadataImpl parseAttributeMetaData( |
289 |
final String namespace = String.valueOf(element |
final Element element) { |
290 |
.getAttributeValue("namespace")); |
final String namespace = element.getAttributeValue("namespace"); |
291 |
final String localname = String.valueOf(element |
final String localname = element.getAttributeValue("localname"); |
292 |
.getAttributeValue("localname")); |
final NameImpl aName = new NameImpl(namespace, localname); |
|
final Name aName = new NameImpl(namespace, localname); |
|
293 |
final Boolean visible = Boolean.valueOf(element |
final Boolean visible = Boolean.valueOf(element |
294 |
.getAttributeValue("visible")); |
.getAttributeValue("visible")); |
295 |
final String unit = element.getAttributeValue("unit"); |
final String unit = element.getAttributeValue("unit"); |
305 |
else if (childElement.getName().equals("desc")) |
else if (childElement.getName().equals("desc")) |
306 |
desc = parseTranslation(childElement); |
desc = parseTranslation(childElement); |
307 |
} |
} |
308 |
return new AttributeMetadata(aName, visible, name, desc, unit); |
return new AttributeMetadataImpl(aName, visible, name, desc, unit); |
309 |
} |
} |
310 |
|
|
311 |
/** |
/** |
312 |
* Parses a {@link AttributeMetadata} map from an JDOM-{@link Element} with |
* Parses a {@link AttributeMetadataImpl} map from an JDOM-{@link Element} |
313 |
* {@code <attribute>}-childs. |
* with {@code <attribute>}-childs. |
314 |
* |
* |
315 |
* @param element |
* @param element |
316 |
* {@link Element} to parse |
* {@link Element} to parse |
317 |
|
* |
318 |
|
* TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has |
319 |
|
* more attributes which are not used by Xulu/ISDSS. GP |
320 |
|
* exports/imports the AMD via AMLExporter and AMLImporter |
321 |
|
* classes. (SK, 3.2.2010) * |
322 |
*/ |
*/ |
323 |
public static AttributeMetadataMap parseAttributeMetaDataMap( |
public static AttributeMetadataMap parseAttributeMetaDataMap( |
324 |
final Element element) { |
final Element element) { |
325 |
final AttributeMetadataMap metaData = new AttributeMetadataMap(); |
final AttributeMetadataMap metaData = new AttributeMetadataImplMap(); |
326 |
final List<Element> attributesElements = element |
final List<Element> attributesElements = element |
327 |
.getChildren(ELEM_NAME_ATTRIBUTE); |
.getChildren(ELEM_NAME_ATTRIBUTE); |
328 |
for (final Element attibuteElement : attributesElements) { |
for (final Element attibuteElement : attributesElements) { |
329 |
final AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement); |
final AttributeMetadataImpl attrMetaData = parseAttributeMetaData(attibuteElement); |
330 |
metaData.put(attrMetaData.getName(), attrMetaData); |
metaData.put(attrMetaData.getName(), attrMetaData); |
331 |
} |
} |
332 |
return metaData; |
return metaData; |
333 |
} |
} |
334 |
|
|
335 |
/** |
/** |
336 |
* Loads a {@link AttributeMetadata} object from an URL. |
* Loads a {@link AttributeMetadataImpl} object from an URL. |
337 |
* |
* |
338 |
* @param documentUrl |
* @param documentUrl |
339 |
* {@link URL} to parse |
* {@link URL} to parse |
346 |
} |
} |
347 |
|
|
348 |
/** |
/** |
349 |
* Creates an JDOM {@link Element} for the given {@link AttributeMetadata} |
* Creates an JDOM {@link Element} for the given |
350 |
* object. |
* {@link AttributeMetadataImpl} object. |
351 |
* |
* |
352 |
* @param amd |
* @param amd |
353 |
* meta data for one attribute |
* meta data for one attribute |
354 |
|
* |
355 |
|
* TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has |
356 |
|
* more attributes which are not used by Xulu/ISDSS. GP |
357 |
|
* exports/imports the AMD via AMLExporter and AMLImporter |
358 |
|
* classes. (SK, 3.2.2010) |
359 |
*/ |
*/ |
360 |
public static Element createAttributeMetaDataElement( |
public static Element createAttributeMetaDataElement( |
361 |
final AttributeMetadata amd) { |
final AttributeMetadataInterface amd) { |
362 |
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI); |
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI); |
363 |
element.setAttribute("namespace", String.valueOf(amd.getName() |
element.setAttribute("namespace", |
364 |
.getNamespaceURI())); |
String.valueOf(amd.getName().getNamespaceURI())); |
365 |
element.setAttribute("localname", String.valueOf(amd.getLocalName())); |
element.setAttribute("localname", String.valueOf(amd.getLocalName())); |
366 |
element.setAttribute("visible", String.valueOf(amd.isVisible())); |
element.setAttribute("visible", String.valueOf(amd.isVisible())); |
367 |
element.setAttribute("unit", amd.getUnit()); |
element.setAttribute("unit", amd.getUnit()); |
373 |
} |
} |
374 |
|
|
375 |
/** |
/** |
376 |
* Creates an JDOM {@link Element} for the given {@link AttributeMetadata} |
* Creates an JDOM {@link Element} for the given |
377 |
* map. |
* {@link AttributeMetadataImpl} map. |
378 |
* |
* |
379 |
* @param amdMap |
* @param amdMap |
380 |
* map of attribute meta data |
* map of attribute meta data |
381 |
*/ |
*/ |
382 |
public static Element createAttributeMetaDataMapElement( |
public static Element createAttributeMetaDataMapElement( |
383 |
final AttributeMetadataMap amdMap) { |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap) { |
384 |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
385 |
for (final AttributeMetadata amd : amdMap.values()) |
for (final AttributeMetadataInterface amd : amdMap.values()) |
386 |
element.addContent(createAttributeMetaDataElement(amd)); |
element.addContent(createAttributeMetaDataElement(amd)); |
387 |
return element; |
return element; |
388 |
} |
} |
389 |
|
|
390 |
/** |
/** |
391 |
* Saves a {@link AttributeMetadata AttributeMetaData-Map} to an URL. |
* Saves a {@link AttributeMetadataImpl AttributeMetaData-Map} to an URL. |
392 |
* |
* |
393 |
* @param amdMap |
* @param amdMap |
394 |
* map of {@link AttributeMetadata} |
* map of {@link AttributeMetadataImpl} |
395 |
* @param documentUrl |
* @param documentUrl |
396 |
* {@link URL} to store the XML |
* {@link URL} to store the XML |
397 |
*/ |
*/ |
693 |
* @param styledObject |
* @param styledObject |
694 |
* a styled object |
* a styled object |
695 |
* @return {@code StyledLayerStyle<RasterLegendData>} for |
* @return {@code StyledLayerStyle<RasterLegendData>} for |
696 |
* {@link StyledGridCoverageInterface} or {@code |
* {@link StyledGridCoverageInterface} or |
697 |
* StyledLayerStyle<Map<Integer,AttributeMetaData>>} for |
* {@code StyledLayerStyle<Map<Integer,AttributeMetaData>>} for |
698 |
* {@link StyledFeatureCollectionInterface} |
* {@link StyledFeatureCollectionInterface} |
699 |
*/ |
*/ |
700 |
public static StyledLayerStyle<?> getStyledLayerStyle( |
public static StyledLayerStyle<?> getStyledLayerStyle( |
798 |
} |
} |
799 |
|
|
800 |
/** |
/** |
801 |
* Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetadata |
* Loads a {@linkplain Style SLD-Style} and a |
802 |
* AttributeMetaData-Map} for a given geo-object (feature) source. The SLD |
* {@linkplain AttributeMetadataImpl AttributeMetaData-Map} for a given |
803 |
* file must be present. A missing attribute meta-data file is tolerated. |
* geo-object (feature) source. The SLD file must be present. A missing |
804 |
|
* attribute meta-data file is tolerated. |
805 |
* |
* |
806 |
* @param geoObjectURL |
* @param geoObjectURL |
807 |
* URL of the (already read) feature object |
* URL of the (already read) feature object |
844 |
|
|
845 |
/** |
/** |
846 |
* Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and |
* Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and |
847 |
* {@linkplain AttributeMetadata AttributeMetaData-Map} from a {@code .amd} |
* {@linkplain AttributeMetadataImpl AttributeMetaData-Map} from a |
848 |
* file for a given geo-object (feature) source. The SLD file must be |
* {@code .amd} file for a given geo-object (feature) source. The SLD file |
849 |
* present. A missing attribute meta-data file is tolerated. |
* must be present. A missing attribute meta-data file is tolerated. |
850 |
* |
* |
851 |
* @param geoObjectURL |
* @param geoObjectURL |
852 |
* URL of the (already read) feature object |
* URL of the (already read) feature object |
880 |
// Store the SLD |
// Store the SLD |
881 |
final Style sldStyle = style.getGeoObjectStyle(); |
final Style sldStyle = style.getGeoObjectStyle(); |
882 |
if (sldStyle != null) { |
if (sldStyle != null) { |
883 |
StylingUtil.saveStyleToSLD(sldStyle, IOUtil.changeFileExt(new File( |
StylingUtil.saveStyleToSld(sldStyle, IOUtil.changeFileExt(new File( |
884 |
geoObjectURL.toURI()), sldExt)); |
geoObjectURL.toURI()), sldExt)); |
885 |
} |
} |
886 |
|
|
888 |
final T metaData = style.getMetaData(); |
final T metaData = style.getMetaData(); |
889 |
if (metaData != null) { |
if (metaData != null) { |
890 |
if (metaData instanceof RasterLegendData) { |
if (metaData instanceof RasterLegendData) { |
891 |
saveRasterLegendData((RasterLegendData) metaData, IOUtil |
saveRasterLegendData((RasterLegendData) metaData, |
892 |
.changeUrlExt(geoObjectURL, mdExt)); |
IOUtil.changeUrlExt(geoObjectURL, mdExt)); |
893 |
// } else if ( metaData instanceof |
// } else if ( metaData instanceof |
894 |
// Map<Integer,AttributeMetaData> ) { // LEIDER NICHT |
// Map<Integer,AttributeMetaData> ) { // LEIDER NICHT |
895 |
// KOMPILIERBAR!! |
// KOMPILIERBAR!! |
905 |
|
|
906 |
/** |
/** |
907 |
* Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and the |
* Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and the |
908 |
* meta data ({@link RasterLegendData} or {@link AttributeMetadata}) to a |
* meta data ({@link RasterLegendData} or {@link AttributeMetadataImpl}) to |
909 |
* {@code .rld} or {@code .amd} file. for a given geo-object source. |
* a {@code .rld} or {@code .amd} file. for a given geo-object source. |
910 |
* |
* |
911 |
* @param style |
* @param style |
912 |
* style to save |
* style to save |
922 |
} |
} |
923 |
|
|
924 |
/** |
/** |
925 |
|
* *If appended to the name of a rule, this rule shall not be shown in the |
926 |
|
* legend |
927 |
|
*/ |
928 |
|
public final static String HIDE_IN_LAYER_LEGEND_HINT = "HIDE_IN_LEGEND"; |
929 |
|
|
930 |
|
/** |
931 |
* Creates a {@link JPanel} that shows a legend for a list of |
* Creates a {@link JPanel} that shows a legend for a list of |
932 |
* {@link FeatureTypeStyle}s and a targeted featureType |
* {@link FeatureTypeStyle}s and a targeted featureType |
933 |
* |
* |
934 |
|
* @param style |
935 |
|
* The Style to presented in this legend |
936 |
* @param featureType |
* @param featureType |
937 |
* If this a legend for Point, Polygon or Line? |
* If this a legend for Point, Polygon or Line? |
|
* @param list |
|
|
* The Styles to presented in this legend |
|
938 |
* |
* |
939 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a> |
|
* Krüger</a> |
|
940 |
*/ |
*/ |
941 |
public static JPanel createLegendPanel(Style style, |
public static JPanel createLegendSwingPanel(Style style, |
942 |
final SimpleFeatureType featureType, final int iconWidth, |
final SimpleFeatureType featureType, final int iconWidth, |
943 |
final int iconHeight) { |
final int iconHeight) { |
944 |
|
|
957 |
final List<Rule> rules = ftStyle.rules(); |
final List<Rule> rules = ftStyle.rules(); |
958 |
for (final Rule rule : rules) { |
for (final Rule rule : rules) { |
959 |
|
|
960 |
|
// Check if this RULE shall actually appear in the legend |
961 |
|
if (rule.getName() != null |
962 |
|
&& rule.getName().endsWith(HIDE_IN_LAYER_LEGEND_HINT)) |
963 |
|
continue; |
964 |
|
|
965 |
/** |
/** |
966 |
* Let's not create a hbox for Rules that only contain |
* Let's not create a hbox for Rules that only contain |
967 |
* TextSymbolizers |
* TextSymbolizers |
996 |
|
|
997 |
/** |
/** |
998 |
* Creates a {@link JComponent} that contains a legend for a given |
* Creates a {@link JComponent} that contains a legend for a given |
999 |
* rasterLayer and a given {@link Style}. |
* {@link StyledRasterInterface} and a given {@link Style}. |
1000 |
* |
* |
1001 |
* @param style |
* @param style |
1002 |
* if <code>null</code>, the default {@link Style} is extracetd |
* if <code>null</code>, the default {@link Style} is extracetd |
1003 |
* from the {@link StyledRasterInterface} |
* from the {@link StyledRasterInterface} |
1004 |
*/ |
*/ |
1005 |
public static JPanel createLegendPanel( |
public static JPanel createLegendSwingPanel( |
1006 |
final StyledRasterInterface<?> styledRaster, Style style, |
final StyledRasterInterface<?> styledRaster, Style style, |
1007 |
final int iconWidth, final int iconHeight) { |
final int iconWidth, final int iconHeight) { |
1008 |
|
|
1026 |
final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData |
final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData |
1027 |
.createSampleRasters(); |
.createSampleRasters(); |
1028 |
|
|
1029 |
final JPanel panel = new JPanel(new MigLayout("wrap 2")); |
final JPanel panel = new JPanel(new MigLayout("wrap 2, gapy 0")); |
1030 |
|
|
1031 |
for (final Double rValue : legendRasterValues) { |
for (final Double rValue : legendRasterValues) { |
1032 |
|
|
1088 |
final GridCoverage2D sampleCov = sampleRasters.get(rValue); |
final GridCoverage2D sampleCov = sampleRasters.get(rValue); |
1089 |
GridCoverageRenderer renderer; |
GridCoverageRenderer renderer; |
1090 |
try { |
try { |
1091 |
renderer = new GridCoverageRenderer(sampleCov |
renderer = new GridCoverageRenderer( |
1092 |
.getCoordinateReferenceSystem(), JTSUtil |
sampleCov.getCoordinateReferenceSystem(), |
1093 |
.createEnvelope(sampleCov.getEnvelope()), |
JTSUtil.createEnvelope(sampleCov.getEnvelope()), |
1094 |
new Rectangle(iconWidth, iconHeight), |
new Rectangle(iconWidth, iconHeight), |
1095 |
(AffineTransform) null); |
(AffineTransform) null); |
1096 |
} catch (final Exception e1) { |
} catch (final Exception e1) { |
1115 |
} |
} |
1116 |
|
|
1117 |
final JLabel iconLabel = new JLabel(new ImageIcon(buffImage)); |
final JLabel iconLabel = new JLabel(new ImageIcon(buffImage)); |
|
// hbox.setAlignmentX(0f); |
|
1118 |
panel.add(iconLabel, "sgx1"); |
panel.add(iconLabel, "sgx1"); |
|
// hbox.add(Box.createHorizontalStrut(3)); |
|
1119 |
|
|
1120 |
final Translation labelT = rasterLegendData.get(rValue); |
final Translation labelT = rasterLegendData.get(rValue); |
1121 |
final JLabel classTitleLabel = new JLabel(labelT.toString()); |
final JLabel classTitleLabel = new JLabel(labelT.toString()); |
1122 |
panel.add(classTitleLabel, "sgx2" |
panel.add(classTitleLabel, "sgx2" |
1123 |
+ (rasterLegendData.getPaintGaps() ? ", gapy 0 3" : "")); |
+ (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5" |
1124 |
|
: "")); |
1125 |
classTitleLabel.setLabelFor(iconLabel); |
classTitleLabel.setLabelFor(iconLabel); |
1126 |
|
|
1127 |
// box.add(hbox); |
if (rasterLegendData.isPaintGaps()) { |
|
|
|
|
if (rasterLegendData.getPaintGaps()) { |
|
1128 |
iconLabel |
iconLabel |
1129 |
.setBorder(BorderFactory.createLineBorder(Color.black)); |
.setBorder(BorderFactory.createLineBorder(Color.black)); |
1130 |
} |
} |
1147 |
if (geoObject instanceof GridCoverage2D) { |
if (geoObject instanceof GridCoverage2D) { |
1148 |
final GridCoverage2D cov = (GridCoverage2D) geoObject; |
final GridCoverage2D cov = (GridCoverage2D) geoObject; |
1149 |
colorModel = cov.getRenderedImage().getColorModel(); |
colorModel = cov.getRenderedImage().getColorModel(); |
1150 |
} else if (styledGrid instanceof StyledRasterPyramidInterface) { |
} else if (styledGrid instanceof StyledGridCoverageReaderInterface) { |
1151 |
|
|
1152 |
final Parameter readGG = new Parameter( |
final Parameter readGG = new Parameter( |
1153 |
AbstractGridFormat.READ_GRIDGEOMETRY2D); |
AbstractGridFormat.READ_GRIDGEOMETRY2D); |
1154 |
|
|
1155 |
final ReferencedEnvelope mapExtend = new org.geotools.geometry.jts.ReferencedEnvelope( |
final ReferencedEnvelope mapExtend = new ReferencedEnvelope( |
1156 |
styledGrid.getEnvelope(), styledGrid.getCrs()); |
styledGrid.getEnvelope(), styledGrid.getCrs()); |
1157 |
|
|
1158 |
readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope( |
readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope( |
1159 |
new Rectangle(0, 0, 1, 1)), mapExtend)); |
new Rectangle(0, 0, 1, 1)), mapExtend)); |
1160 |
|
|
1161 |
final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject; |
AbstractGridCoverage2DReader aReader; |
1162 |
|
if (geoObject instanceof FeatureCollection) { |
1163 |
|
final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject; |
1164 |
|
|
1165 |
|
aReader = (AbstractGridCoverage2DReader) FeatureUtil |
1166 |
|
.getWrappedGeoObject(rFc); |
1167 |
|
|
1168 |
|
} else if (geoObject instanceof AbstractGridCoverage2DReader) { |
1169 |
|
aReader = (AbstractGridCoverage2DReader) geoObject; |
1170 |
|
|
1171 |
|
} else |
1172 |
|
throw new RuntimeException("need a reader..."); |
1173 |
|
// |
1174 |
|
|
|
final AbstractGridCoverage2DReader aReader = (AbstractGridCoverage2DReader) FeatureUtil |
|
|
.getWrappedGeoObject(rFc); |
|
1175 |
final GridCoverage2D cov = (GridCoverage2D) aReader |
final GridCoverage2D cov = (GridCoverage2D) aReader |
1176 |
.read(new GeneralParameterValue[] { readGG }); |
.read(new GeneralParameterValue[] { readGG }); |
1177 |
colorModel = cov.getRenderedImage().getColorModel(); |
colorModel = cov.getRenderedImage().getColorModel(); |
1193 |
final StyledRasterInterface<?> styledRaster) { |
final StyledRasterInterface<?> styledRaster) { |
1194 |
final ColorModel colorModel = getColorModel(styledRaster); |
final ColorModel colorModel = getColorModel(styledRaster); |
1195 |
|
|
1196 |
LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is " |
// LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is " |
1197 |
+ colorModel.getClass().getSimpleName()); |
// + colorModel != null ? colorModel.getClass().getSimpleName() : |
1198 |
|
// "NULL"); |
1199 |
|
|
1200 |
if (colorModel == null) |
if (colorModel == null) |
1201 |
return true; |
return true; |
1202 |
if (colorModel instanceof ComponentColorModel) |
if (colorModel instanceof ComponentColorModel) |
1203 |
return true; |
return true; |
1204 |
|
if (colorModel instanceof IndexColorModel) |
1205 |
|
return true; |
1206 |
|
|
1207 |
return false; |
return false; |
1208 |
} |
} |
1209 |
|
|
1214 |
* Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a |
* Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a |
1215 |
* repaint, so only use it when needed. |
* repaint, so only use it when needed. |
1216 |
* |
* |
1217 |
* @return <code>true</code> if the {@link MapLayer}'s {@link Style} has been changed. |
* @return <code>true</code> if the {@link MapLayer}'s {@link Style} has |
1218 |
|
* been changed. |
1219 |
*/ |
*/ |
1220 |
public static boolean updateMapLayerStyleIfChangedAndKeepSelection(MapLayer mapLayer, |
public static boolean updateMapLayerStyleIfChangedAndKeepSelection( |
1221 |
Style style2) { |
MapLayer mapLayer, Style style2) { |
1222 |
|
|
1223 |
Style mapLayerStyleCleaned = StylingUtil |
Style mapLayerStyleCleaned = StylingUtil |
1224 |
.removeSelectionFeatureTypeStyle(mapLayer.getStyle()); |
.removeSelectionFeatureTypeStyle(mapLayer.getStyle()); |
1225 |
|
|
1226 |
Style newStyleCleaned = StylingUtil.removeSelectionFeatureTypeStyle(style2); |
Style newStyleCleaned = StylingUtil |
1227 |
|
.removeSelectionFeatureTypeStyle(style2); |
1228 |
if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned, |
|
1229 |
newStyleCleaned)) { |
if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned, newStyleCleaned)) { |
1230 |
|
|
1231 |
// They are different when compared without SELECTION FTS! |
// They are different when compared without SELECTION FTS! |
1232 |
|
|
1233 |
// Now let's copy any SELECTION FTS to the now style |
// Now let's copy any SELECTION FTS to the now style |
1234 |
FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil.getSelectionFeatureTypeStyle( mapLayer.getStyle() ); |
FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil |
1235 |
|
.getSelectionFeatureTypeStyle(mapLayer.getStyle()); |
1236 |
if (selectionFeatureTypeStyle != null) { |
if (selectionFeatureTypeStyle != null) { |
1237 |
newStyleCleaned.featureTypeStyles().add(selectionFeatureTypeStyle); |
newStyleCleaned.featureTypeStyles().add( |
1238 |
// newStyleCleaned is not so clean anymore... We just alled a selcetion FTS |
selectionFeatureTypeStyle); |
1239 |
} |
// newStyleCleaned is not so clean anymore... We just alled a |
1240 |
|
// selcetion FTS |
1241 |
|
} |
1242 |
|
|
1243 |
mapLayer.setStyle(newStyleCleaned); |
mapLayer.setStyle(newStyleCleaned); |
1244 |
|
|
1245 |
return true; |
return true; |
1246 |
|
|
1247 |
} else return false; |
} else { |
1248 |
|
return false; |
1249 |
|
} |
1250 |
|
} |
1251 |
|
|
1252 |
|
/** |
1253 |
|
* After loading an atlas, the AttribteMetaData contains whatever is written |
1254 |
|
* in the XML. But the DBF may have changed! This method checks an |
1255 |
|
* {@link AttributeMetadataMap} against a schema and also corrects |
1256 |
|
* upperCase/lowerCase problems. It will also remove any geometry column |
1257 |
|
* attribute metadata. |
1258 |
|
*/ |
1259 |
|
/** |
1260 |
|
* After loading an atlas, the AttribteMetaData contains whatever is written |
1261 |
|
* in the XML. But the DBF may have changed! |
1262 |
|
*/ |
1263 |
|
public static void checkAttribMetaData( |
1264 |
|
AttributeMetadataMap<AttributeMetadataImpl> attributeMetaDataMap, |
1265 |
|
SimpleFeatureType schema) { |
1266 |
|
|
1267 |
|
if (schema == null) |
1268 |
|
throw new IllegalArgumentException("schmema may not be null!"); |
1269 |
|
|
1270 |
|
ArrayList<Name> willRemove = new ArrayList<Name>(); |
1271 |
|
|
1272 |
|
// 1. Check.. all attributes in the atm should be in the schema as well. |
1273 |
|
// maybe correct some upperCase/loweCase stuff |
1274 |
|
|
1275 |
|
for (AttributeMetadataInterface atm : attributeMetaDataMap.values()) { |
1276 |
|
|
1277 |
|
AttributeDescriptor foundDescr = schema |
1278 |
|
.getDescriptor(atm.getName()); |
1279 |
|
if (foundDescr == null) { |
1280 |
|
NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute( |
1281 |
|
schema, atm.getLocalName()); |
1282 |
|
if (bestMatch == null) |
1283 |
|
willRemove.add(atm.getName()); |
1284 |
|
else |
1285 |
|
atm.setName(bestMatch); |
1286 |
|
} else if (foundDescr instanceof GeometryDescriptor) { |
1287 |
|
// We don't want GeometryColumns in here |
1288 |
|
willRemove.add(atm.getName()); |
1289 |
|
} |
1290 |
|
} |
1291 |
|
|
1292 |
|
// Remove the ones that were not findable in the schema |
1293 |
|
for (Name removeName : willRemove) { |
1294 |
|
if (attributeMetaDataMap.remove(removeName) == null) { |
1295 |
|
LOGGER.warn("removing the AMData didn't work"); |
1296 |
|
} |
1297 |
|
} |
1298 |
|
|
1299 |
|
// 2. check... all attributes from the schema must have an ATM |
1300 |
|
for (AttributeDescriptor ad : schema.getAttributeDescriptors()) { |
1301 |
|
if (ad instanceof GeometryDescriptor) |
1302 |
|
continue; |
1303 |
|
if (!attributeMetaDataMap.containsKey(ad.getName())) { |
1304 |
|
attributeMetaDataMap.put(new NameImpl(ad.getName() |
1305 |
|
.getNamespaceURI(), ad.getName().getLocalPart()), |
1306 |
|
new AttributeMetadataImpl(ad, schema |
1307 |
|
.getAttributeDescriptors().indexOf(ad), |
1308 |
|
attributeMetaDataMap.getLanguages())); |
1309 |
|
} |
1310 |
|
} |
1311 |
} |
} |
1312 |
|
|
1313 |
|
/** |
1314 |
|
* Checks every attribute name in the {@link AttributeMetadataMap} for its |
1315 |
|
* binding type. It the type is textual, add the mrpty string as a NODATA |
1316 |
|
* value. |
1317 |
|
* |
1318 |
|
* @param attributeMetaDataMap |
1319 |
|
* @param schema |
1320 |
|
*/ |
1321 |
|
public static void addEmptyStringToAllTextualAttributes( |
1322 |
|
AttributeMetadataMap<? extends AttributeMetadataInterface> attributeMetaDataMap, |
1323 |
|
SimpleFeatureType schema) { |
1324 |
|
|
1325 |
|
for (Name name : attributeMetaDataMap.keySet()) { |
1326 |
|
if (String.class.isAssignableFrom(schema.getDescriptor(name) |
1327 |
|
.getType().getBinding())) { |
1328 |
|
attributeMetaDataMap.get(name).getNodataValues().add(""); |
1329 |
|
} |
1330 |
|
} |
1331 |
|
} |
1332 |
|
|
1333 |
|
/** |
1334 |
|
* @return a nicely formatted String containing all NODATA values of any |
1335 |
|
* {@link AttributeMetadataInterface} object. Strings are quoted so |
1336 |
|
* that any empty {@link String} can be seen. |
1337 |
|
*/ |
1338 |
|
public static String formatNoDataValues(Set<Object> nodataValuesList) { |
1339 |
|
String nicelyFormatted = ""; |
1340 |
|
if (nodataValuesList != null) { |
1341 |
|
if (nodataValuesList.size() == 0) |
1342 |
|
nicelyFormatted = ""; |
1343 |
|
else { |
1344 |
|
for (Object ndo : nodataValuesList) { |
1345 |
|
if (ndo instanceof String) |
1346 |
|
nicelyFormatted += "\"" + ndo + "\""; |
1347 |
|
else |
1348 |
|
nicelyFormatted += ndo.toString(); |
1349 |
|
|
1350 |
|
nicelyFormatted += ","; |
1351 |
|
} |
1352 |
|
// Remove the extra comma |
1353 |
|
nicelyFormatted = nicelyFormatted.substring(0, |
1354 |
|
nicelyFormatted.length() - 1); |
1355 |
|
} |
1356 |
|
} |
1357 |
|
return nicelyFormatted; |
1358 |
|
} |
1359 |
} |
} |