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; |
63 |
|
import org.geotools.feature.NameImpl; |
64 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
65 |
import org.geotools.map.DefaultMapLayer; |
import org.geotools.map.DefaultMapLayer; |
66 |
import org.geotools.map.MapLayer; |
import org.geotools.map.MapLayer; |
78 |
import org.jdom.output.XMLOutputter; |
import org.jdom.output.XMLOutputter; |
79 |
import org.opengis.feature.simple.SimpleFeature; |
import org.opengis.feature.simple.SimpleFeature; |
80 |
import org.opengis.feature.simple.SimpleFeatureType; |
import org.opengis.feature.simple.SimpleFeatureType; |
81 |
|
import org.opengis.feature.type.Name; |
82 |
import org.opengis.parameter.GeneralParameterValue; |
import org.opengis.parameter.GeneralParameterValue; |
83 |
|
|
84 |
import schmitzm.geotools.JTSUtil; |
import schmitzm.geotools.JTSUtil; |
87 |
import schmitzm.io.IOUtil; |
import schmitzm.io.IOUtil; |
88 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
89 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
90 |
import skrueger.AttributeMetaData; |
import skrueger.AttributeMetadata; |
91 |
import skrueger.RasterLegendData; |
import skrueger.RasterLegendData; |
92 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
93 |
|
|
245 |
* returned |
* returned |
246 |
*/ |
*/ |
247 |
public static AttributeMetadataMap getVisibleAttributeMetaData( |
public static AttributeMetadataMap getVisibleAttributeMetaData( |
248 |
Map<Integer, AttributeMetaData> amdMap, boolean visible) { |
AttributeMetadataMap amdMap, boolean visible) { |
249 |
|
|
250 |
AttributeMetadataMap filteredMap = new AttributeMetadataMap(); |
AttributeMetadataMap filteredMap = new AttributeMetadataMap(); |
251 |
for (AttributeMetaData amd : amdMap.values()) |
for (AttributeMetadata amd : amdMap.values()) |
252 |
if (amd.isVisible()) |
if (amd.isVisible() == visible) |
253 |
filteredMap.put(amd.getColIdx(), amd); |
filteredMap.put(amd.getName(), amd); |
254 |
|
|
255 |
return filteredMap; |
return filteredMap; |
256 |
} |
} |
257 |
|
|
258 |
/** |
/** |
259 |
* Parses a {@link AttributeMetaData} object from an JDOM-{@link Element}. |
* Parses a {@link AttributeMetadata} object from an JDOM-{@link Element}. |
260 |
* This method works like {@link |
* This method works like {@link |
261 |
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM. |
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM. |
262 |
* |
* |
263 |
* @param element |
* @param element |
264 |
* {@link Element} to parse |
* {@link Element} to parse |
265 |
*/ |
*/ |
266 |
public static AttributeMetaData parseAttributeMetaData(final Element element) { |
public static AttributeMetadata parseAttributeMetaData(final Element element) { |
267 |
final Integer col = Integer.valueOf(element.getAttributeValue("col")); |
final String namespace = String.valueOf(element.getAttributeValue("namespace")); |
268 |
|
final String localname = String.valueOf(element.getAttributeValue("localname")); |
269 |
|
final Name aName= new NameImpl(namespace,localname); |
270 |
final Boolean visible = Boolean.valueOf(element |
final Boolean visible = Boolean.valueOf(element |
271 |
.getAttributeValue("visible")); |
.getAttributeValue("visible")); |
272 |
final String unit = element.getAttributeValue("unit"); |
final String unit = element.getAttributeValue("unit"); |
282 |
else if (childElement.getName().equals("desc")) |
else if (childElement.getName().equals("desc")) |
283 |
desc = parseTranslation(childElement); |
desc = parseTranslation(childElement); |
284 |
} |
} |
285 |
return new AttributeMetaData(col, visible, name, desc, unit); |
return new AttributeMetadata(aName, visible, name, desc, unit); |
286 |
} |
} |
287 |
|
|
288 |
/** |
/** |
289 |
* Parses a {@link AttributeMetaData} map from an JDOM-{@link Element} with |
* Parses a {@link AttributeMetadata} map from an JDOM-{@link Element} with |
290 |
* {@code <attribute>}-childs. |
* {@code <attribute>}-childs. |
291 |
* |
* |
292 |
* @param element |
* @param element |
298 |
List<Element> attributesElements = element |
List<Element> attributesElements = element |
299 |
.getChildren(ELEM_NAME_ATTRIBUTE); |
.getChildren(ELEM_NAME_ATTRIBUTE); |
300 |
for (Element attibuteElement : attributesElements) { |
for (Element attibuteElement : attributesElements) { |
301 |
AttributeMetaData attrMetaData = parseAttributeMetaData(attibuteElement); |
AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement); |
302 |
metaData.put(attrMetaData.getColIdx(), attrMetaData); |
metaData.put(attrMetaData.getName(), attrMetaData); |
303 |
} |
} |
304 |
return metaData; |
return metaData; |
305 |
} |
} |
306 |
|
|
307 |
/** |
/** |
308 |
* Loads a {@link AttributeMetaData} object from an URL. |
* Loads a {@link AttributeMetadata} object from an URL. |
309 |
* |
* |
310 |
* @param documentUrl |
* @param documentUrl |
311 |
* {@link URL} to parse |
* {@link URL} to parse |
318 |
} |
} |
319 |
|
|
320 |
/** |
/** |
321 |
* Creates an JDOM {@link Element} for the given {@link AttributeMetaData} |
* Creates an JDOM {@link Element} for the given {@link AttributeMetadata} |
322 |
* object. |
* object. |
323 |
* |
* |
324 |
* @param amd |
* @param amd |
325 |
* meta data for one attribute |
* meta data for one attribute |
326 |
*/ |
*/ |
327 |
public static Element createAttributeMetaDataElement( |
public static Element createAttributeMetaDataElement( |
328 |
final AttributeMetaData amd) { |
final AttributeMetadata amd) { |
329 |
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI); |
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI); |
330 |
element.setAttribute("col", String.valueOf(amd.getColIdx())); |
element.setAttribute("namespace", String.valueOf(amd.getName().getNamespaceURI())); |
331 |
|
element.setAttribute("localname", String.valueOf(amd.getLocalName())); |
332 |
element.setAttribute("visible", String.valueOf(amd.isVisible())); |
element.setAttribute("visible", String.valueOf(amd.isVisible())); |
333 |
element.setAttribute("unit", amd.getUnit()); |
element.setAttribute("unit", amd.getUnit()); |
334 |
// Creating a aml:name tag... |
// Creating a aml:name tag... |
339 |
} |
} |
340 |
|
|
341 |
/** |
/** |
342 |
* Creates an JDOM {@link Element} for the given {@link AttributeMetaData} |
* Creates an JDOM {@link Element} for the given {@link AttributeMetadata} |
343 |
* map. |
* map. |
344 |
* |
* |
345 |
* @param amdMap |
* @param amdMap |
348 |
public static Element createAttributeMetaDataMapElement( |
public static Element createAttributeMetaDataMapElement( |
349 |
final AttributeMetadataMap amdMap) { |
final AttributeMetadataMap amdMap) { |
350 |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
351 |
for (AttributeMetaData amd : amdMap.values()) |
for (AttributeMetadata amd : amdMap.values()) |
352 |
element.addContent(createAttributeMetaDataElement(amd)); |
element.addContent(createAttributeMetaDataElement(amd)); |
353 |
return element; |
return element; |
354 |
} |
} |
355 |
|
|
356 |
/** |
/** |
357 |
* Saves a {@link AttributeMetaData AttributeMetaData-Map} to an URL. |
* Saves a {@link AttributeMetadata AttributeMetaData-Map} to an URL. |
358 |
* |
* |
359 |
* @param amdMap |
* @param amdMap |
360 |
* map of {@link AttributeMetaData} |
* map of {@link AttributeMetadata} |
361 |
* @param documentUrl |
* @param documentUrl |
362 |
* {@link URL} to store the XML |
* {@link URL} to store the XML |
363 |
*/ |
*/ |
692 |
* @param styledFC |
* @param styledFC |
693 |
* a styled feature collection |
* a styled feature collection |
694 |
*/ |
*/ |
695 |
public static StyledLayerStyle<Map<Integer, AttributeMetaData>> getStyledLayerStyle( |
public static StyledLayerStyle<AttributeMetadataMap> getStyledLayerStyle( |
696 |
StyledFeatureCollectionInterface styledFC) { |
StyledFeatureCollectionInterface styledFC) { |
697 |
return new StyledLayerStyle<Map<Integer, AttributeMetaData>>(styledFC |
return new StyledLayerStyle<AttributeMetadataMap>(styledFC |
698 |
.getStyle(), styledFC.getAttributeMetaDataMap()); |
.getStyle(), styledFC.getAttributeMetaDataMap()); |
699 |
} |
} |
700 |
|
|
761 |
} |
} |
762 |
|
|
763 |
/** |
/** |
764 |
* Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetaData |
* Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetadata |
765 |
* AttributeMetaData-Map} for a given geo-object (feature) source. The SLD |
* AttributeMetaData-Map} for a given geo-object (feature) source. The SLD |
766 |
* file must be present. A missing attribute meta-data file is tolerated. |
* file must be present. A missing attribute meta-data file is tolerated. |
767 |
* |
* |
773 |
* file extention for the raster legend-data file |
* file extention for the raster legend-data file |
774 |
* @return {@code null} in case of any error |
* @return {@code null} in case of any error |
775 |
*/ |
*/ |
776 |
public static StyledLayerStyle<Map<Integer, AttributeMetaData>> loadStyledFeatureStyle( |
public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle( |
777 |
URL geoObjectURL, String sldExt, String rldExt) { |
URL geoObjectURL, String sldExt, String rldExt) { |
778 |
Map<Integer, AttributeMetaData> metaData = null; |
AttributeMetadataMap metaData = null; |
779 |
Style sldStyle = null; |
Style sldStyle = null; |
780 |
try { |
try { |
781 |
Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt( |
Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt( |
801 |
return null; |
return null; |
802 |
} |
} |
803 |
|
|
804 |
return new StyledLayerStyle<Map<Integer, AttributeMetaData>>(sldStyle, |
return new StyledLayerStyle<AttributeMetadataMap>(sldStyle, |
805 |
metaData); |
metaData); |
806 |
} |
} |
807 |
|
|
808 |
/** |
/** |
809 |
* Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and |
* Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and |
810 |
* {@linkplain AttributeMetaData AttributeMetaData-Map} from a {@code .amd} |
* {@linkplain AttributeMetadata AttributeMetaData-Map} from a {@code .amd} |
811 |
* file for a given geo-object (feature) source. The SLD file must be |
* file for a given geo-object (feature) source. The SLD file must be |
812 |
* present. A missing attribute meta-data file is tolerated. |
* present. A missing attribute meta-data file is tolerated. |
813 |
* |
* |
819 |
* file extention for the raster legend-data file |
* file extention for the raster legend-data file |
820 |
* @return {@code null} in case of any error |
* @return {@code null} in case of any error |
821 |
*/ |
*/ |
822 |
public static StyledLayerStyle<Map<Integer, AttributeMetaData>> loadStyledFeatureStyle( |
public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle( |
823 |
URL geoObjectURL) { |
URL geoObjectURL) { |
824 |
return loadStyledFeatureStyle(geoObjectURL, "sld", "amd"); |
return loadStyledFeatureStyle(geoObjectURL, "sld", "amd"); |
825 |
} |
} |
868 |
|
|
869 |
/** |
/** |
870 |
* 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 |
871 |
* meta data ({@link RasterLegendData} or {@link AttributeMetaData}) to a |
* meta data ({@link RasterLegendData} or {@link AttributeMetadata}) to a |
872 |
* {@code .rld} or {@code .amd} file. for a given geo-object source. |
* {@code .rld} or {@code .amd} file. for a given geo-object source. |
873 |
* |
* |
874 |
* @param style |
* @param style |