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 |
|
|
92 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
93 |
import schmitzm.swing.JPanel; |
import schmitzm.swing.JPanel; |
94 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
|
import skrueger.AttributeMetadata; |
|
95 |
import skrueger.AttributeMetadataImpl; |
import skrueger.AttributeMetadataImpl; |
96 |
|
import skrueger.AttributeMetadataInterface; |
97 |
import skrueger.RasterLegendData; |
import skrueger.RasterLegendData; |
98 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
99 |
|
|
254 |
* TODO replace with |
* TODO replace with |
255 |
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
256 |
*/ |
*/ |
257 |
public static AttributeMetadataMap<? extends AttributeMetadata > getVisibleAttributeMetaData( |
public static AttributeMetadataMap<? extends AttributeMetadataInterface > getVisibleAttributeMetaData( |
258 |
final AttributeMetadataMap<? extends AttributeMetadata> amdMap, |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap, |
259 |
final boolean visible) { |
final boolean visible) { |
260 |
|
|
261 |
final AttributeMetadataMap<AttributeMetadata> filteredMap = (AttributeMetadataMap<AttributeMetadata>) amdMap.clone(); |
final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap.clone(); |
262 |
if (filteredMap.size() > 0 ) { |
if (filteredMap.size() > 0 ) { |
263 |
filteredMap.clear(); // Just in case the close copies the contents |
filteredMap.clear(); // Just in case the close copies the contents |
264 |
} |
} |
265 |
|
|
266 |
for (final AttributeMetadata amd : amdMap.values()) |
for (final AttributeMetadataInterface amd : amdMap.values()) |
267 |
if (amd.isVisible() == visible) |
if (amd.isVisible() == visible) |
268 |
filteredMap.put(amd.getName(), amd); |
filteredMap.put(amd.getName(), amd); |
269 |
|
|
285 |
*/ |
*/ |
286 |
public static AttributeMetadataImpl parseAttributeMetaData( |
public static AttributeMetadataImpl parseAttributeMetaData( |
287 |
final Element element) { |
final Element element) { |
288 |
final String namespace = String.valueOf(element |
final String namespace = element.getAttributeValue("namespace"); |
289 |
.getAttributeValue("namespace")); |
final String localname = element.getAttributeValue("localname"); |
|
final String localname = String.valueOf(element |
|
|
.getAttributeValue("localname")); |
|
290 |
final NameImpl aName = new NameImpl(namespace, localname); |
final NameImpl aName = new NameImpl(namespace, localname); |
291 |
final Boolean visible = Boolean.valueOf(element |
final Boolean visible = Boolean.valueOf(element |
292 |
.getAttributeValue("visible")); |
.getAttributeValue("visible")); |
356 |
* classes. (SK, 3.2.2010) |
* classes. (SK, 3.2.2010) |
357 |
*/ |
*/ |
358 |
public static Element createAttributeMetaDataElement( |
public static Element createAttributeMetaDataElement( |
359 |
final AttributeMetadata amd) { |
final AttributeMetadataInterface amd) { |
360 |
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI); |
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI); |
361 |
element.setAttribute("namespace", String.valueOf(amd.getName() |
element.setAttribute("namespace", String.valueOf(amd.getName() |
362 |
.getNamespaceURI())); |
.getNamespaceURI())); |
378 |
* map of attribute meta data |
* map of attribute meta data |
379 |
*/ |
*/ |
380 |
public static Element createAttributeMetaDataMapElement( |
public static Element createAttributeMetaDataMapElement( |
381 |
final AttributeMetadataMap<? extends AttributeMetadata> amdMap) { |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap) { |
382 |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
383 |
for (final AttributeMetadata amd : amdMap.values()) |
for (final AttributeMetadataInterface amd : amdMap.values()) |
384 |
element.addContent(createAttributeMetaDataElement(amd)); |
element.addContent(createAttributeMetaDataElement(amd)); |
385 |
return element; |
return element; |
386 |
} |
} |
878 |
// Store the SLD |
// Store the SLD |
879 |
final Style sldStyle = style.getGeoObjectStyle(); |
final Style sldStyle = style.getGeoObjectStyle(); |
880 |
if (sldStyle != null) { |
if (sldStyle != null) { |
881 |
StylingUtil.saveStyleToSLD(sldStyle, IOUtil.changeFileExt(new File( |
StylingUtil.saveStyleToSld(sldStyle, IOUtil.changeFileExt(new File( |
882 |
geoObjectURL.toURI()), sldExt)); |
geoObjectURL.toURI()), sldExt)); |
883 |
} |
} |
884 |
|
|
929 |
* Creates a {@link JPanel} that shows a legend for a list of |
* Creates a {@link JPanel} that shows a legend for a list of |
930 |
* {@link FeatureTypeStyle}s and a targeted featureType |
* {@link FeatureTypeStyle}s and a targeted featureType |
931 |
* |
* |
932 |
|
* @param style |
933 |
|
* The Style to presented in this legend |
934 |
* @param featureType |
* @param featureType |
935 |
* 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 |
|
936 |
* |
* |
937 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
938 |
* Krüger</a> |
* Tzeggai</a> |
939 |
*/ |
*/ |
940 |
public static JPanel createLegendPanel(Style style, |
public static JPanel createLegendSwingPanel(Style style, |
941 |
final SimpleFeatureType featureType, final int iconWidth, |
final SimpleFeatureType featureType, final int iconWidth, |
942 |
final int iconHeight) { |
final int iconHeight) { |
943 |
|
|
993 |
return panel; |
return panel; |
994 |
} |
} |
995 |
|
|
996 |
|
|
997 |
|
|
998 |
|
|
999 |
/** |
/** |
1000 |
* Creates a {@link JComponent} that contains a legend for a given |
* Creates a {@link JComponent} that contains a legend for a given |
1001 |
* rasterLayer and a given {@link Style}. |
* {@link StyledRasterInterface} and a given {@link Style}. |
1002 |
* |
* |
1003 |
* @param style |
* @param style |
1004 |
* if <code>null</code>, the default {@link Style} is extracetd |
* if <code>null</code>, the default {@link Style} is extracetd |
1005 |
* from the {@link StyledRasterInterface} |
* from the {@link StyledRasterInterface} |
1006 |
*/ |
*/ |
1007 |
public static JPanel createLegendPanel( |
public static JPanel createLegendSwingPanel( |
1008 |
final StyledRasterInterface<?> styledRaster, Style style, |
final StyledRasterInterface<?> styledRaster, Style style, |
1009 |
final int iconWidth, final int iconHeight) { |
final int iconWidth, final int iconHeight) { |
1010 |
|
|
1135 |
|
|
1136 |
return panel; |
return panel; |
1137 |
} |
} |
1138 |
|
|
1139 |
|
|
1140 |
|
|
1141 |
/** |
/** |
1142 |
* Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May |
* Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May |
1151 |
if (geoObject instanceof GridCoverage2D) { |
if (geoObject instanceof GridCoverage2D) { |
1152 |
final GridCoverage2D cov = (GridCoverage2D) geoObject; |
final GridCoverage2D cov = (GridCoverage2D) geoObject; |
1153 |
colorModel = cov.getRenderedImage().getColorModel(); |
colorModel = cov.getRenderedImage().getColorModel(); |
1154 |
} else if (styledGrid instanceof StyledRasterPyramidInterface) { |
} else if (styledGrid instanceof StyledGridCoverageReaderInterface) { |
1155 |
|
|
1156 |
final Parameter readGG = new Parameter( |
final Parameter readGG = new Parameter( |
1157 |
AbstractGridFormat.READ_GRIDGEOMETRY2D); |
AbstractGridFormat.READ_GRIDGEOMETRY2D); |
1158 |
|
|
1159 |
final ReferencedEnvelope mapExtend = new org.geotools.geometry.jts.ReferencedEnvelope( |
final ReferencedEnvelope mapExtend = new ReferencedEnvelope( |
1160 |
styledGrid.getEnvelope(), styledGrid.getCrs()); |
styledGrid.getEnvelope(), styledGrid.getCrs()); |
1161 |
|
|
1162 |
readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope( |
readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope( |
1263 |
// 1. Check.. all attributes in the atm should be in the schema as well. |
// 1. Check.. all attributes in the atm should be in the schema as well. |
1264 |
// maybe correct some upperCase/loweCase stuff |
// maybe correct some upperCase/loweCase stuff |
1265 |
|
|
1266 |
for (AttributeMetadata atm : attributeMetaDataMap.values()) { |
for (AttributeMetadataInterface atm : attributeMetaDataMap.values()) { |
1267 |
|
|
1268 |
AttributeDescriptor foundDescr = schema |
AttributeDescriptor foundDescr = schema |
1269 |
.getDescriptor(atm.getName()); |
.getDescriptor(atm.getName()); |
1309 |
* @param schema |
* @param schema |
1310 |
*/ |
*/ |
1311 |
public static void addEmptyStringToAllTextualAttributes( |
public static void addEmptyStringToAllTextualAttributes( |
1312 |
AttributeMetadataMap<? extends AttributeMetadata> attributeMetaDataMap, |
AttributeMetadataMap<? extends AttributeMetadataInterface> attributeMetaDataMap, |
1313 |
SimpleFeatureType schema) { |
SimpleFeatureType schema) { |
1314 |
|
|
1315 |
for (Name name : attributeMetaDataMap.keySet()) { |
for (Name name : attributeMetaDataMap.keySet()) { |
1322 |
|
|
1323 |
/** |
/** |
1324 |
* @return a nicely formatted String containing all NODATA values of any |
* @return a nicely formatted String containing all NODATA values of any |
1325 |
* {@link AttributeMetadata} object. Strings are quoted so that any |
* {@link AttributeMetadataInterface} object. Strings are quoted so that any |
1326 |
* empty {@link String} can be seen. |
* empty {@link String} can be seen. |
1327 |
*/ |
*/ |
1328 |
public static String formatNoDataValues(Set<Object> nodataValuesList) { |
public static String formatNoDataValues(Set<Object> nodataValuesList) { |