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; |
|
import java.util.HashMap; |
|
47 |
import java.util.List; |
import java.util.List; |
48 |
import java.util.Map; |
import java.util.Map; |
|
import java.util.SortedMap; |
|
|
import java.util.TreeMap; |
|
49 |
|
|
50 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
51 |
import javax.swing.Box; |
import javax.swing.Box; |
60 |
import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader; |
import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader; |
61 |
import org.geotools.coverage.grid.io.AbstractGridFormat; |
import org.geotools.coverage.grid.io.AbstractGridFormat; |
62 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
|
import org.geotools.gce.imagepyramid.ImagePyramidReader; |
|
63 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
64 |
import org.geotools.map.DefaultMapLayer; |
import org.geotools.map.DefaultMapLayer; |
65 |
import org.geotools.map.MapLayer; |
import org.geotools.map.MapLayer; |
75 |
import org.jdom.Element; |
import org.jdom.Element; |
76 |
import org.jdom.input.SAXBuilder; |
import org.jdom.input.SAXBuilder; |
77 |
import org.jdom.output.XMLOutputter; |
import org.jdom.output.XMLOutputter; |
78 |
|
import org.opengis.feature.simple.SimpleFeature; |
79 |
import org.opengis.feature.simple.SimpleFeatureType; |
import org.opengis.feature.simple.SimpleFeatureType; |
80 |
import org.opengis.parameter.GeneralParameterValue; |
import org.opengis.parameter.GeneralParameterValue; |
81 |
|
|
82 |
import schmitzm.geotools.JTSUtil; |
import schmitzm.geotools.JTSUtil; |
83 |
|
import schmitzm.geotools.feature.FeatureUtil; |
84 |
import schmitzm.geotools.styling.StylingUtil; |
import schmitzm.geotools.styling.StylingUtil; |
85 |
import schmitzm.io.IOUtil; |
import schmitzm.io.IOUtil; |
86 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
242 |
* indicated whether the visible or invisible entries are |
* indicated whether the visible or invisible entries are |
243 |
* returned |
* returned |
244 |
*/ |
*/ |
245 |
public static SortedMap<Integer, AttributeMetaData> getVisibleAttributeMetaData( |
public static AttributeMetadataMap getVisibleAttributeMetaData( |
246 |
Map<Integer, AttributeMetaData> amdMap, boolean visible) { |
Map<Integer, AttributeMetaData> amdMap, boolean visible) { |
247 |
SortedMap<Integer, AttributeMetaData> filteredMap = new TreeMap<Integer, AttributeMetaData>(); |
AttributeMetadataMap filteredMap = new AttributeMetadataMap(); |
248 |
for (AttributeMetaData amd : amdMap.values()) |
for (AttributeMetaData amd : amdMap.values()) |
249 |
if (amd.isVisible()) |
if (amd.isVisible()) |
250 |
filteredMap.put(amd.getColIdx(), amd); |
filteredMap.put(amd.getColIdx(), amd); |
287 |
* @param element |
* @param element |
288 |
* {@link Element} to parse |
* {@link Element} to parse |
289 |
*/ |
*/ |
290 |
public static Map<Integer, AttributeMetaData> parseAttributeMetaDataMap( |
public static AttributeMetadataMap parseAttributeMetaDataMap( |
291 |
final Element element) { |
final Element element) { |
292 |
HashMap<Integer, AttributeMetaData> metaData = new HashMap<Integer, AttributeMetaData>(); |
AttributeMetadataMap metaData = new AttributeMetadataMap(); |
293 |
List<Element> attributesElements = element |
List<Element> attributesElements = element |
294 |
.getChildren(ELEM_NAME_ATTRIBUTE); |
.getChildren(ELEM_NAME_ATTRIBUTE); |
295 |
for (Element attibuteElement : attributesElements) { |
for (Element attibuteElement : attributesElements) { |
306 |
* {@link URL} to parse |
* {@link URL} to parse |
307 |
* @see #parseAttributeMetaData(Element) |
* @see #parseAttributeMetaData(Element) |
308 |
*/ |
*/ |
309 |
public static Map<Integer, AttributeMetaData> loadAttributeMetaDataMap( |
public static AttributeMetadataMap loadAttributeMetaDataMap( |
310 |
final URL documentUrl) throws Exception { |
final URL documentUrl) throws Exception { |
311 |
Document document = SAX_BUILDER.build(documentUrl); |
Document document = SAX_BUILDER.build(documentUrl); |
312 |
return parseAttributeMetaDataMap(document.getRootElement()); |
return parseAttributeMetaDataMap(document.getRootElement()); |
340 |
* map of attribute meta data |
* map of attribute meta data |
341 |
*/ |
*/ |
342 |
public static Element createAttributeMetaDataMapElement( |
public static Element createAttributeMetaDataMapElement( |
343 |
final Map<Integer, AttributeMetaData> amdMap) { |
final AttributeMetadataMap amdMap) { |
344 |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
345 |
for (AttributeMetaData amd : amdMap.values()) |
for (AttributeMetaData amd : amdMap.values()) |
346 |
element.addContent(createAttributeMetaDataElement(amd)); |
element.addContent(createAttributeMetaDataElement(amd)); |
356 |
* {@link URL} to store the XML |
* {@link URL} to store the XML |
357 |
*/ |
*/ |
358 |
public static void saveAttributeMetaDataMap( |
public static void saveAttributeMetaDataMap( |
359 |
final Map<Integer, AttributeMetaData> amdMap, final URL documentUrl) |
final AttributeMetadataMap amdMap, final URL documentUrl) |
360 |
throws Exception { |
throws Exception { |
361 |
// Create XML-Document |
// Create XML-Document |
362 |
final FileWriter out = new FileWriter(new File(documentUrl.toURI())); |
final FileWriter out = new FileWriter(new File(documentUrl.toURI())); |
623 |
} |
} |
624 |
if (styledObject instanceof StyledFeatureCollectionInterface |
if (styledObject instanceof StyledFeatureCollectionInterface |
625 |
&& (style.getMetaData() instanceof Map || style.getMetaData() == null)) { |
&& (style.getMetaData() instanceof Map || style.getMetaData() == null)) { |
626 |
Map<Integer, AttributeMetaData> sourceAmd = (Map<Integer, AttributeMetaData>) style |
AttributeMetadataMap sourceAmd = (AttributeMetadataMap) style |
627 |
.getMetaData(); |
.getMetaData(); |
628 |
Map<Integer, AttributeMetaData> destAmd = ((StyledFeatureCollectionInterface) styledObject) |
AttributeMetadataMap destAmd = ((StyledFeatureCollectionInterface) styledObject) |
629 |
.getAttributeMetaDataMap(); |
.getAttributeMetaDataMap(); |
630 |
if (destAmd != null && sourceAmd != null) { |
if (destAmd != null && sourceAmd != null) { |
631 |
destAmd.clear(); |
destAmd.clear(); |
851 |
// KOMPILIERBAR!! |
// KOMPILIERBAR!! |
852 |
} else if (metaData instanceof Map) { |
} else if (metaData instanceof Map) { |
853 |
saveAttributeMetaDataMap( |
saveAttributeMetaDataMap( |
854 |
(Map<Integer, AttributeMetaData>) metaData, IOUtil |
(AttributeMetadataMap) metaData, IOUtil |
855 |
.changeUrlExt(geoObjectURL, mdExt)); |
.changeUrlExt(geoObjectURL, mdExt)); |
856 |
} else |
} else |
857 |
throw new UnsupportedOperationException( |
throw new UnsupportedOperationException( |
1107 |
graphics.setColor(color); |
graphics.setColor(color); |
1108 |
graphics.fillRect(0, 0, ICON_SIZE.width, ICON_SIZE.height); |
graphics.fillRect(0, 0, ICON_SIZE.width, ICON_SIZE.height); |
1109 |
} catch (Exception e) { |
} catch (Exception e) { |
1110 |
LOGGER.debug("Dann nehmen wir halt den GridCoverageRenderer", e); |
LOGGER.debug( |
1111 |
|
"Dann nehmen wir halt den GridCoverageRenderer", e); |
1112 |
colorModel = null; |
colorModel = null; |
1113 |
} |
} |
1114 |
} |
} |
1187 |
* Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May |
* Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May |
1188 |
* return <code>null</code> if the geoobject can not be accessed. |
* return <code>null</code> if the geoobject can not be accessed. |
1189 |
*/ |
*/ |
1190 |
|
@SuppressWarnings("unchecked") |
1191 |
public static ColorModel getColorModel(StyledRasterInterface<?> styledGrid) { |
public static ColorModel getColorModel(StyledRasterInterface<?> styledGrid) { |
1192 |
ColorModel colorModel = null; |
ColorModel colorModel = null; |
1193 |
try { |
try { |
1204 |
styledGrid.getEnvelope(), styledGrid.getCrs()); |
styledGrid.getEnvelope(), styledGrid.getCrs()); |
1205 |
|
|
1206 |
readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope( |
readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope( |
1207 |
new Rectangle(0, 0, 10, 10)), mapExtend)); |
new Rectangle(0, 0, 1, 1)), mapExtend)); |
1208 |
|
|
1209 |
final AbstractGridCoverage2DReader aReader = (AbstractGridCoverage2DReader) geoObject; |
FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject; |
1210 |
|
|
1211 |
|
final AbstractGridCoverage2DReader aReader = (AbstractGridCoverage2DReader) FeatureUtil |
1212 |
|
.getWrappedGeoObject(rFc); |
1213 |
GridCoverage2D cov = (GridCoverage2D) aReader |
GridCoverage2D cov = (GridCoverage2D) aReader |
1214 |
.read(new GeneralParameterValue[] { readGG }); |
.read(new GeneralParameterValue[] { readGG }); |
1215 |
colorModel = cov.getRenderedImage().getColorModel(); |
colorModel = cov.getRenderedImage().getColorModel(); |
1216 |
} |
} |
1217 |
} catch (Exception e) { |
} catch (Exception e) { |
1218 |
LOGGER.error("Error reading the colormodel from " + styledGrid); |
LOGGER.error("Error reading the colormodel from " + styledGrid, e); |
1219 |
return null; |
return null; |
1220 |
} |
} |
1221 |
return colorModel; |
return colorModel; |