[Schmitzm-commits] r1215 - in trunk: src/skrueger/geotools src_junit/schmitzm/swing src_junit/skrueger/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Nov 3 12:06:22 CET 2010
Author: alfonx
Date: 2010-11-03 12:06:22 +0100 (Wed, 03 Nov 2010)
New Revision: 1215
Modified:
trunk/src/skrueger/geotools/StyledLayerUtil.java
trunk/src_junit/schmitzm/swing/TestingUtil.java
trunk/src_junit/skrueger/geotools/StyledLayerUtilTest.java
Log:
Modified: trunk/src/skrueger/geotools/StyledLayerUtil.java
===================================================================
--- trunk/src/skrueger/geotools/StyledLayerUtil.java 2010-11-03 10:55:16 UTC (rev 1214)
+++ trunk/src/skrueger/geotools/StyledLayerUtil.java 2010-11-03 11:06:22 UTC (rev 1215)
@@ -38,6 +38,7 @@
import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
+import java.awt.image.IndexColorModel;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
@@ -254,15 +255,16 @@
* TODO replace with
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
*/
- public static AttributeMetadataMap<? extends AttributeMetadataInterface > getVisibleAttributeMetaData(
+ public static AttributeMetadataMap<? extends AttributeMetadataInterface> getVisibleAttributeMetaData(
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap,
final boolean visible) {
- final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap.clone();
- if (filteredMap.size() > 0 ) {
+ final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap
+ .clone();
+ if (filteredMap.size() > 0) {
filteredMap.clear(); // Just in case the close copies the contents
}
-
+
for (final AttributeMetadataInterface amd : amdMap.values())
if (amd.isVisible() == visible)
filteredMap.put(amd.getName(), amd);
@@ -358,8 +360,8 @@
public static Element createAttributeMetaDataElement(
final AttributeMetadataInterface amd) {
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI);
- element.setAttribute("namespace", String.valueOf(amd.getName()
- .getNamespaceURI()));
+ element.setAttribute("namespace",
+ String.valueOf(amd.getName().getNamespaceURI()));
element.setAttribute("localname", String.valueOf(amd.getLocalName()));
element.setAttribute("visible", String.valueOf(amd.isVisible()));
element.setAttribute("unit", amd.getUnit());
@@ -691,8 +693,8 @@
* @param styledObject
* a styled object
* @return {@code StyledLayerStyle<RasterLegendData>} for
- * {@link StyledGridCoverageInterface} or {@code
- * StyledLayerStyle<Map<Integer,AttributeMetaData>>} for
+ * {@link StyledGridCoverageInterface} or
+ * {@code StyledLayerStyle<Map<Integer,AttributeMetaData>>} for
* {@link StyledFeatureCollectionInterface}
*/
public static StyledLayerStyle<?> getStyledLayerStyle(
@@ -842,9 +844,9 @@
/**
* Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
- * {@linkplain AttributeMetadataImpl AttributeMetaData-Map} from a {@code
- * .amd} file for a given geo-object (feature) source. The SLD file must be
- * present. A missing attribute meta-data file is tolerated.
+ * {@linkplain AttributeMetadataImpl AttributeMetaData-Map} from a
+ * {@code .amd} file for a given geo-object (feature) source. The SLD file
+ * must be present. A missing attribute meta-data file is tolerated.
*
* @param geoObjectURL
* URL of the (already read) feature object
@@ -886,8 +888,8 @@
final T metaData = style.getMetaData();
if (metaData != null) {
if (metaData instanceof RasterLegendData) {
- saveRasterLegendData((RasterLegendData) metaData, IOUtil
- .changeUrlExt(geoObjectURL, mdExt));
+ saveRasterLegendData((RasterLegendData) metaData,
+ IOUtil.changeUrlExt(geoObjectURL, mdExt));
// } else if ( metaData instanceof
// Map<Integer,AttributeMetaData> ) { // LEIDER NICHT
// KOMPILIERBAR!!
@@ -934,8 +936,7 @@
* @param featureType
* If this a legend for Point, Polygon or Line?
*
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public static JPanel createLegendSwingPanel(Style style,
final SimpleFeatureType featureType, final int iconWidth,
@@ -993,9 +994,6 @@
return panel;
}
-
-
-
/**
* Creates a {@link JComponent} that contains a legend for a given
* {@link StyledRasterInterface} and a given {@link Style}.
@@ -1090,9 +1088,9 @@
final GridCoverage2D sampleCov = sampleRasters.get(rValue);
GridCoverageRenderer renderer;
try {
- renderer = new GridCoverageRenderer(sampleCov
- .getCoordinateReferenceSystem(), JTSUtil
- .createEnvelope(sampleCov.getEnvelope()),
+ renderer = new GridCoverageRenderer(
+ sampleCov.getCoordinateReferenceSystem(),
+ JTSUtil.createEnvelope(sampleCov.getEnvelope()),
new Rectangle(iconWidth, iconHeight),
(AffineTransform) null);
} catch (final Exception e1) {
@@ -1135,8 +1133,6 @@
return panel;
}
-
-
/**
* Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May
@@ -1162,10 +1158,20 @@
readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(
new Rectangle(0, 0, 1, 1)), mapExtend));
- final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject;
+ AbstractGridCoverage2DReader aReader;
+ if (geoObject instanceof FeatureCollection) {
+ final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject;
- final AbstractGridCoverage2DReader aReader = (AbstractGridCoverage2DReader) FeatureUtil
- .getWrappedGeoObject(rFc);
+ aReader = (AbstractGridCoverage2DReader) FeatureUtil
+ .getWrappedGeoObject(rFc);
+
+ } else if (geoObject instanceof AbstractGridCoverage2DReader) {
+ aReader = (AbstractGridCoverage2DReader) geoObject;
+
+ } else
+ throw new RuntimeException("need a reader...");
+ //
+
final GridCoverage2D cov = (GridCoverage2D) aReader
.read(new GeneralParameterValue[] { readGG });
colorModel = cov.getRenderedImage().getColorModel();
@@ -1195,6 +1201,9 @@
return true;
if (colorModel instanceof ComponentColorModel)
return true;
+ if (colorModel instanceof IndexColorModel)
+ return true;
+
return false;
}
@@ -1268,8 +1277,8 @@
AttributeDescriptor foundDescr = schema
.getDescriptor(atm.getName());
if (foundDescr == null) {
- NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(schema,
- atm.getLocalName());
+ NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(
+ schema, atm.getLocalName());
if (bestMatch == null)
willRemove.add(atm.getName());
else
@@ -1292,7 +1301,8 @@
if (ad instanceof GeometryDescriptor)
continue;
if (!attributeMetaDataMap.containsKey(ad.getName())) {
- attributeMetaDataMap.put( new NameImpl(ad.getName().getNamespaceURI(), ad.getName().getLocalPart()),
+ attributeMetaDataMap.put(new NameImpl(ad.getName()
+ .getNamespaceURI(), ad.getName().getLocalPart()),
new AttributeMetadataImpl(ad, schema
.getAttributeDescriptors().indexOf(ad),
attributeMetaDataMap.getLanguages()));
@@ -1322,8 +1332,8 @@
/**
* @return a nicely formatted String containing all NODATA values of any
- * {@link AttributeMetadataInterface} object. Strings are quoted so that any
- * empty {@link String} can be seen.
+ * {@link AttributeMetadataInterface} object. Strings are quoted so
+ * that any empty {@link String} can be seen.
*/
public static String formatNoDataValues(Set<Object> nodataValuesList) {
String nicelyFormatted = "";
@@ -1340,8 +1350,8 @@
nicelyFormatted += ",";
}
// Remove the extra comma
- nicelyFormatted = nicelyFormatted.substring(0, nicelyFormatted
- .length() - 1);
+ nicelyFormatted = nicelyFormatted.substring(0,
+ nicelyFormatted.length() - 1);
}
}
return nicelyFormatted;
Modified: trunk/src_junit/schmitzm/swing/TestingUtil.java
===================================================================
--- trunk/src_junit/schmitzm/swing/TestingUtil.java 2010-11-03 10:55:16 UTC (rev 1214)
+++ trunk/src_junit/schmitzm/swing/TestingUtil.java 2010-11-03 11:06:22 UTC (rev 1215)
@@ -139,7 +139,7 @@
* List of available vector test datasets
*/
public static enum TestDatasetsRaster {
- geotiffWithSld("/rasters/rasterGeotiffWithSLD/geotiffwithsld.sld"), geotiffRGBWithoutSLD(
+ geotiffWithSld("/rasters/rasterGeotiffWithSLD/geotiffwithsld.tif"), geotiffRGBWithoutSLD(
"/rasters/rasterGeotiffRGBWithoutSLD/geotiff_rgb_ohnesld.tif"), arcAscii(
"/rasters/rasterASCIIWithSLDTransparency/asciiWithSldTransparency.asc");
Modified: trunk/src_junit/skrueger/geotools/StyledLayerUtilTest.java
===================================================================
--- trunk/src_junit/skrueger/geotools/StyledLayerUtilTest.java 2010-11-03 10:55:16 UTC (rev 1214)
+++ trunk/src_junit/skrueger/geotools/StyledLayerUtilTest.java 2010-11-03 11:06:22 UTC (rev 1215)
@@ -1,11 +1,17 @@
package skrueger.geotools;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import java.awt.image.ColorModel;
+import java.io.IOException;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import schmitzm.swing.TestingUtil;
+
public class StyledLayerUtilTest {
@Before
@@ -17,15 +23,18 @@
}
@Test
- public void testGetColorModel() {
-// TestingUtil.TestDatasetsRaster.
- //TODO
+ public void testGetColorModel() throws IOException {
+ StyledGridCoverageReader styled = TestingUtil.TestDatasetsRaster.geotiffWithSld
+ .getStyled();
+ ColorModel colorModel = StyledLayerUtil.getColorModel(styled);
+ assertNotNull(colorModel);
}
@Test
- public void testIsStyleable() {
- fail("Not yet implemented");
-
+ public void testIsStyleable() throws IOException {
+ StyledGridCoverageReader styled = TestingUtil.TestDatasetsRaster.geotiffWithSld
+ .getStyled();
+ assertTrue(StyledLayerUtil.isStyleable(styled));
}
}
More information about the Schmitzm-commits
mailing list