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; |
255 |
* TODO replace with |
* TODO replace with |
256 |
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
257 |
*/ |
*/ |
258 |
public static AttributeMetadataMap<? extends AttributeMetadataInterface > getVisibleAttributeMetaData( |
public static AttributeMetadataMap<? extends AttributeMetadataInterface> getVisibleAttributeMetaData( |
259 |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap, |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap, |
260 |
final boolean visible) { |
final boolean visible) { |
261 |
|
|
262 |
final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap.clone(); |
final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap |
263 |
if (filteredMap.size() > 0 ) { |
.clone(); |
264 |
|
if (filteredMap.size() > 0) { |
265 |
filteredMap.clear(); // Just in case the close copies the contents |
filteredMap.clear(); // Just in case the close copies the contents |
266 |
} |
} |
267 |
|
|
268 |
for (final AttributeMetadataInterface amd : amdMap.values()) |
for (final AttributeMetadataInterface amd : amdMap.values()) |
269 |
if (amd.isVisible() == visible) |
if (amd.isVisible() == visible) |
270 |
filteredMap.put(amd.getName(), amd); |
filteredMap.put(amd.getName(), amd); |
360 |
public static Element createAttributeMetaDataElement( |
public static Element createAttributeMetaDataElement( |
361 |
final AttributeMetadataInterface 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()); |
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( |
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 AttributeMetadataImpl AttributeMetaData-Map} from a {@code |
* {@linkplain AttributeMetadataImpl AttributeMetaData-Map} from a |
848 |
* .amd} 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!! |
936 |
* @param featureType |
* @param featureType |
937 |
* If this a legend for Point, Polygon or Line? |
* If this a legend for Point, Polygon or Line? |
938 |
* |
* |
939 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a> |
|
* Tzeggai</a> |
|
940 |
*/ |
*/ |
941 |
public static JPanel createLegendSwingPanel(Style style, |
public static JPanel createLegendSwingPanel(Style style, |
942 |
final SimpleFeatureType featureType, final int iconWidth, |
final SimpleFeatureType featureType, final int iconWidth, |
994 |
return panel; |
return panel; |
995 |
} |
} |
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 |
* {@link StyledRasterInterface} and a given {@link Style}. |
* {@link StyledRasterInterface} and a given {@link Style}. |
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) { |
1133 |
|
|
1134 |
return panel; |
return panel; |
1135 |
} |
} |
|
|
|
|
|
|
1136 |
|
|
1137 |
/** |
/** |
1138 |
* Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May |
* Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May |
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(); |
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 |
|
|
1277 |
AttributeDescriptor foundDescr = schema |
AttributeDescriptor foundDescr = schema |
1278 |
.getDescriptor(atm.getName()); |
.getDescriptor(atm.getName()); |
1279 |
if (foundDescr == null) { |
if (foundDescr == null) { |
1280 |
NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(schema, |
NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute( |
1281 |
atm.getLocalName()); |
schema, atm.getLocalName()); |
1282 |
if (bestMatch == null) |
if (bestMatch == null) |
1283 |
willRemove.add(atm.getName()); |
willRemove.add(atm.getName()); |
1284 |
else |
else |
1301 |
if (ad instanceof GeometryDescriptor) |
if (ad instanceof GeometryDescriptor) |
1302 |
continue; |
continue; |
1303 |
if (!attributeMetaDataMap.containsKey(ad.getName())) { |
if (!attributeMetaDataMap.containsKey(ad.getName())) { |
1304 |
attributeMetaDataMap.put( new NameImpl(ad.getName().getNamespaceURI(), ad.getName().getLocalPart()), |
attributeMetaDataMap.put(new NameImpl(ad.getName() |
1305 |
|
.getNamespaceURI(), ad.getName().getLocalPart()), |
1306 |
new AttributeMetadataImpl(ad, schema |
new AttributeMetadataImpl(ad, schema |
1307 |
.getAttributeDescriptors().indexOf(ad), |
.getAttributeDescriptors().indexOf(ad), |
1308 |
attributeMetaDataMap.getLanguages())); |
attributeMetaDataMap.getLanguages())); |
1332 |
|
|
1333 |
/** |
/** |
1334 |
* @return a nicely formatted String containing all NODATA values of any |
* @return a nicely formatted String containing all NODATA values of any |
1335 |
* {@link AttributeMetadataInterface} object. Strings are quoted so that any |
* {@link AttributeMetadataInterface} object. Strings are quoted so |
1336 |
* empty {@link String} can be seen. |
* that any empty {@link String} can be seen. |
1337 |
*/ |
*/ |
1338 |
public static String formatNoDataValues(Set<Object> nodataValuesList) { |
public static String formatNoDataValues(Set<Object> nodataValuesList) { |
1339 |
String nicelyFormatted = ""; |
String nicelyFormatted = ""; |
1350 |
nicelyFormatted += ","; |
nicelyFormatted += ","; |
1351 |
} |
} |
1352 |
// Remove the extra comma |
// Remove the extra comma |
1353 |
nicelyFormatted = nicelyFormatted.substring(0, nicelyFormatted |
nicelyFormatted = nicelyFormatted.substring(0, |
1354 |
.length() - 1); |
nicelyFormatted.length() - 1); |
1355 |
} |
} |
1356 |
} |
} |
1357 |
return nicelyFormatted; |
return nicelyFormatted; |