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 |
|
|
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; |
47 |
import java.util.ArrayList; |
import java.util.ArrayList; |
48 |
import java.util.List; |
import java.util.List; |
49 |
import java.util.Map; |
import java.util.Map; |
50 |
|
import java.util.Set; |
51 |
|
|
52 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
53 |
import javax.swing.ImageIcon; |
import javax.swing.ImageIcon; |
93 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
94 |
import schmitzm.swing.JPanel; |
import schmitzm.swing.JPanel; |
95 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
96 |
import skrueger.AttributeMetadata; |
import skrueger.AttributeMetadataImpl; |
97 |
|
import skrueger.AttributeMetadataInterface; |
98 |
import skrueger.RasterLegendData; |
import skrueger.RasterLegendData; |
99 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
100 |
|
|
255 |
* TODO replace with |
* TODO replace with |
256 |
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
257 |
*/ |
*/ |
258 |
public static AttributeMetadataMap getVisibleAttributeMetaData( |
public static AttributeMetadataMap<? extends AttributeMetadataInterface> getVisibleAttributeMetaData( |
259 |
final AttributeMetadataMap amdMap, final boolean visible) { |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap, |
260 |
|
final boolean visible) { |
261 |
|
|
262 |
final AttributeMetadataMap filteredMap = new AttributeMetadataMap( |
final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap |
263 |
amdMap.getLanguages()); |
.clone(); |
264 |
for (final AttributeMetadata amd : amdMap.values()) |
if (filteredMap.size() > 0) { |
265 |
|
filteredMap.clear(); // Just in case the close copies the contents |
266 |
|
} |
267 |
|
|
268 |
|
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); |
271 |
|
|
273 |
} |
} |
274 |
|
|
275 |
/** |
/** |
276 |
* Parses a {@link AttributeMetadata} object from an JDOM-{@link Element}. |
* Parses a {@link AttributeMetadataImpl} object from an JDOM- |
277 |
* This method works like {@link |
* {@link Element}. This method works like {@link |
278 |
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM. |
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM. |
279 |
* |
* |
280 |
* TODO 20.11.2009, SK: There are some new attribute weight, functiona, |
* TODO 20.11.2009, SK: There are some new attribute weight, functiona, |
285 |
* @param element |
* @param element |
286 |
* {@link Element} to parse |
* {@link Element} to parse |
287 |
*/ |
*/ |
288 |
public static AttributeMetadata parseAttributeMetaData(final Element element) { |
public static AttributeMetadataImpl parseAttributeMetaData( |
289 |
final String namespace = String.valueOf(element |
final Element element) { |
290 |
.getAttributeValue("namespace")); |
final String namespace = element.getAttributeValue("namespace"); |
291 |
final String localname = String.valueOf(element |
final String localname = element.getAttributeValue("localname"); |
292 |
.getAttributeValue("localname")); |
final NameImpl aName = new NameImpl(namespace, localname); |
|
final Name aName = new NameImpl(namespace, localname); |
|
293 |
final Boolean visible = Boolean.valueOf(element |
final Boolean visible = Boolean.valueOf(element |
294 |
.getAttributeValue("visible")); |
.getAttributeValue("visible")); |
295 |
final String unit = element.getAttributeValue("unit"); |
final String unit = element.getAttributeValue("unit"); |
305 |
else if (childElement.getName().equals("desc")) |
else if (childElement.getName().equals("desc")) |
306 |
desc = parseTranslation(childElement); |
desc = parseTranslation(childElement); |
307 |
} |
} |
308 |
return new AttributeMetadata(aName, visible, name, desc, unit); |
return new AttributeMetadataImpl(aName, visible, name, desc, unit); |
309 |
} |
} |
310 |
|
|
311 |
/** |
/** |
312 |
* Parses a {@link AttributeMetadata} map from an JDOM-{@link Element} with |
* Parses a {@link AttributeMetadataImpl} map from an JDOM-{@link Element} |
313 |
* {@code <attribute>}-childs. |
* with {@code <attribute>}-childs. |
314 |
* |
* |
315 |
* @param element |
* @param element |
316 |
* {@link Element} to parse |
* {@link Element} to parse |
317 |
* |
* |
318 |
* TODO Since GP 1.3 the {@link AttributeMetadata} class has more |
* TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has |
319 |
* attributes which are not used by Xulu/ISDSS. GP |
* more attributes which are not used by Xulu/ISDSS. GP |
320 |
* exports/imports the AMD via AMLExporter and AMLImporter |
* exports/imports the AMD via AMLExporter and AMLImporter |
321 |
* classes. (SK, 3.2.2010) * |
* classes. (SK, 3.2.2010) * |
322 |
*/ |
*/ |
323 |
public static AttributeMetadataMap parseAttributeMetaDataMap( |
public static AttributeMetadataMap parseAttributeMetaDataMap( |
324 |
final Element element) { |
final Element element) { |
325 |
final AttributeMetadataMap metaData = new AttributeMetadataMap(); |
final AttributeMetadataMap metaData = new AttributeMetadataImplMap(); |
326 |
final List<Element> attributesElements = element |
final List<Element> attributesElements = element |
327 |
.getChildren(ELEM_NAME_ATTRIBUTE); |
.getChildren(ELEM_NAME_ATTRIBUTE); |
328 |
for (final Element attibuteElement : attributesElements) { |
for (final Element attibuteElement : attributesElements) { |
329 |
final AttributeMetadata attrMetaData = parseAttributeMetaData(attibuteElement); |
final AttributeMetadataImpl attrMetaData = parseAttributeMetaData(attibuteElement); |
330 |
metaData.put(attrMetaData.getName(), attrMetaData); |
metaData.put(attrMetaData.getName(), attrMetaData); |
331 |
} |
} |
332 |
return metaData; |
return metaData; |
333 |
} |
} |
334 |
|
|
335 |
/** |
/** |
336 |
* Loads a {@link AttributeMetadata} object from an URL. |
* Loads a {@link AttributeMetadataImpl} object from an URL. |
337 |
* |
* |
338 |
* @param documentUrl |
* @param documentUrl |
339 |
* {@link URL} to parse |
* {@link URL} to parse |
346 |
} |
} |
347 |
|
|
348 |
/** |
/** |
349 |
* Creates an JDOM {@link Element} for the given {@link AttributeMetadata} |
* Creates an JDOM {@link Element} for the given |
350 |
* object. |
* {@link AttributeMetadataImpl} object. |
351 |
* |
* |
352 |
* @param amd |
* @param amd |
353 |
* meta data for one attribute |
* meta data for one attribute |
354 |
* |
* |
355 |
* TODO Since GP 1.3 the {@link AttributeMetadata} class has more |
* TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has |
356 |
* attributes which are not used by Xulu/ISDSS. GP |
* more attributes which are not used by Xulu/ISDSS. GP |
357 |
* exports/imports the AMD via AMLExporter and AMLImporter |
* exports/imports the AMD via AMLExporter and AMLImporter |
358 |
* classes. (SK, 3.2.2010) |
* classes. (SK, 3.2.2010) |
359 |
*/ |
*/ |
360 |
public static Element createAttributeMetaDataElement( |
public static Element createAttributeMetaDataElement( |
361 |
final AttributeMetadata 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()); |
373 |
} |
} |
374 |
|
|
375 |
/** |
/** |
376 |
* Creates an JDOM {@link Element} for the given {@link AttributeMetadata} |
* Creates an JDOM {@link Element} for the given |
377 |
* map. |
* {@link AttributeMetadataImpl} map. |
378 |
* |
* |
379 |
* @param amdMap |
* @param amdMap |
380 |
* map of attribute meta data |
* map of attribute meta data |
381 |
*/ |
*/ |
382 |
public static Element createAttributeMetaDataMapElement( |
public static Element createAttributeMetaDataMapElement( |
383 |
final AttributeMetadataMap amdMap) { |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap) { |
384 |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
final Element element = new Element(ELEM_NAME_AMD, AMLURI); |
385 |
for (final AttributeMetadata amd : amdMap.values()) |
for (final AttributeMetadataInterface amd : amdMap.values()) |
386 |
element.addContent(createAttributeMetaDataElement(amd)); |
element.addContent(createAttributeMetaDataElement(amd)); |
387 |
return element; |
return element; |
388 |
} |
} |
389 |
|
|
390 |
/** |
/** |
391 |
* Saves a {@link AttributeMetadata AttributeMetaData-Map} to an URL. |
* Saves a {@link AttributeMetadataImpl AttributeMetaData-Map} to an URL. |
392 |
* |
* |
393 |
* @param amdMap |
* @param amdMap |
394 |
* map of {@link AttributeMetadata} |
* map of {@link AttributeMetadataImpl} |
395 |
* @param documentUrl |
* @param documentUrl |
396 |
* {@link URL} to store the XML |
* {@link URL} to store the XML |
397 |
*/ |
*/ |
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( |
798 |
} |
} |
799 |
|
|
800 |
/** |
/** |
801 |
* Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetadata |
* Loads a {@linkplain Style SLD-Style} and a |
802 |
* AttributeMetaData-Map} for a given geo-object (feature) source. The SLD |
* {@linkplain AttributeMetadataImpl AttributeMetaData-Map} for a given |
803 |
* file must be present. A missing attribute meta-data file is tolerated. |
* geo-object (feature) source. The SLD file must be present. A missing |
804 |
|
* attribute meta-data file is tolerated. |
805 |
* |
* |
806 |
* @param geoObjectURL |
* @param geoObjectURL |
807 |
* URL of the (already read) feature object |
* URL of the (already read) feature object |
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 AttributeMetadata AttributeMetaData-Map} from a {@code .amd} |
* {@linkplain AttributeMetadataImpl AttributeMetaData-Map} from a |
848 |
* 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!! |
905 |
|
|
906 |
/** |
/** |
907 |
* 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 |
908 |
* meta data ({@link RasterLegendData} or {@link AttributeMetadata}) to a |
* meta data ({@link RasterLegendData} or {@link AttributeMetadataImpl}) to |
909 |
* {@code .rld} or {@code .amd} file. for a given geo-object source. |
* a {@code .rld} or {@code .amd} file. for a given geo-object source. |
910 |
* |
* |
911 |
* @param style |
* @param style |
912 |
* style to save |
* style to save |
922 |
} |
} |
923 |
|
|
924 |
/** |
/** |
925 |
|
* *If appended to the name of a rule, this rule shall not be shown in the |
926 |
|
* legend |
927 |
|
*/ |
928 |
|
public final static String HIDE_IN_LAYER_LEGEND_HINT = "HIDE_IN_LEGEND"; |
929 |
|
|
930 |
|
/** |
931 |
* Creates a {@link JPanel} that shows a legend for a list of |
* Creates a {@link JPanel} that shows a legend for a list of |
932 |
* {@link FeatureTypeStyle}s and a targeted featureType |
* {@link FeatureTypeStyle}s and a targeted featureType |
933 |
* |
* |
934 |
|
* @param style |
935 |
|
* The Style to presented in this legend |
936 |
* @param featureType |
* @param featureType |
937 |
* 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 |
|
938 |
* |
* |
939 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a> |
|
* Krüger</a> |
|
940 |
*/ |
*/ |
941 |
public static JPanel createLegendPanel(Style style, |
public static JPanel createLegendSwingPanel(Style style, |
942 |
final SimpleFeatureType featureType, final int iconWidth, |
final SimpleFeatureType featureType, final int iconWidth, |
943 |
final int iconHeight) { |
final int iconHeight) { |
944 |
|
|
957 |
final List<Rule> rules = ftStyle.rules(); |
final List<Rule> rules = ftStyle.rules(); |
958 |
for (final Rule rule : rules) { |
for (final Rule rule : rules) { |
959 |
|
|
960 |
|
// Check if this RULE shall actually appear in the legend |
961 |
|
if (rule.getName() != null |
962 |
|
&& rule.getName().endsWith(HIDE_IN_LAYER_LEGEND_HINT)) |
963 |
|
continue; |
964 |
|
|
965 |
/** |
/** |
966 |
* Let's not create a hbox for Rules that only contain |
* Let's not create a hbox for Rules that only contain |
967 |
* TextSymbolizers |
* TextSymbolizers |
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 |
* rasterLayer and a given {@link Style}. |
* {@link StyledRasterInterface} and a given {@link Style}. |
1000 |
* |
* |
1001 |
* @param style |
* @param style |
1002 |
* if <code>null</code>, the default {@link Style} is extracetd |
* if <code>null</code>, the default {@link Style} is extracetd |
1003 |
* from the {@link StyledRasterInterface} |
* from the {@link StyledRasterInterface} |
1004 |
*/ |
*/ |
1005 |
public static JPanel createLegendPanel( |
public static JPanel createLegendSwingPanel( |
1006 |
final StyledRasterInterface<?> styledRaster, Style style, |
final StyledRasterInterface<?> styledRaster, Style style, |
1007 |
final int iconWidth, final int iconHeight) { |
final int iconWidth, final int iconHeight) { |
1008 |
|
|
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) { |
1147 |
if (geoObject instanceof GridCoverage2D) { |
if (geoObject instanceof GridCoverage2D) { |
1148 |
final GridCoverage2D cov = (GridCoverage2D) geoObject; |
final GridCoverage2D cov = (GridCoverage2D) geoObject; |
1149 |
colorModel = cov.getRenderedImage().getColorModel(); |
colorModel = cov.getRenderedImage().getColorModel(); |
1150 |
} else if (styledGrid instanceof StyledRasterPyramidInterface) { |
} else if (styledGrid instanceof StyledGridCoverageReaderInterface) { |
1151 |
|
|
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 |
|
|
1260 |
* After loading an atlas, the AttribteMetaData contains whatever is written |
* After loading an atlas, the AttribteMetaData contains whatever is written |
1261 |
* in the XML. But the DBF may have changed! |
* in the XML. But the DBF may have changed! |
1262 |
*/ |
*/ |
1263 |
public static void checkAttribMetaData(AttributeMetadataMap attributeMetaDataMap, |
public static void checkAttribMetaData( |
1264 |
|
AttributeMetadataMap<AttributeMetadataImpl> attributeMetaDataMap, |
1265 |
SimpleFeatureType schema) { |
SimpleFeatureType schema) { |
1266 |
|
|
1267 |
|
if (schema == null) |
1268 |
|
throw new IllegalArgumentException("schmema may not be null!"); |
1269 |
|
|
1270 |
ArrayList<Name> willRemove = new ArrayList<Name>(); |
ArrayList<Name> willRemove = new ArrayList<Name>(); |
1271 |
|
|
1272 |
// 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. |
1273 |
// maybe correct some upperCase/loweCase stuff |
// maybe correct some upperCase/loweCase stuff |
1274 |
|
|
1275 |
for (AttributeMetadata atm : attributeMetaDataMap.values()) { |
for (AttributeMetadataInterface atm : attributeMetaDataMap.values()) { |
1276 |
|
|
1277 |
AttributeDescriptor foundDescr = schema |
AttributeDescriptor foundDescr = schema |
1278 |
.getDescriptor(atm.getName()); |
.getDescriptor(atm.getName()); |
1279 |
if (foundDescr == null) { |
if (foundDescr == null) { |
1280 |
Name 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 |
1291 |
|
|
1292 |
// Remove the ones that were not findable in the schema |
// Remove the ones that were not findable in the schema |
1293 |
for (Name removeName : willRemove) { |
for (Name removeName : willRemove) { |
1294 |
if (attributeMetaDataMap.remove(removeName) == null){ |
if (attributeMetaDataMap.remove(removeName) == null) { |
1295 |
LOGGER.warn("removing the AMData didn't work"); |
LOGGER.warn("removing the AMData didn't work"); |
1296 |
} |
} |
1297 |
} |
} |
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(ad.getName(), new AttributeMetadata( |
attributeMetaDataMap.put(new NameImpl(ad.getName() |
1305 |
ad, schema.getAttributeDescriptors().indexOf(ad), attributeMetaDataMap |
.getNamespaceURI(), ad.getName().getLocalPart()), |
1306 |
.getLanguages())); |
new AttributeMetadataImpl(ad, schema |
1307 |
|
.getAttributeDescriptors().indexOf(ad), |
1308 |
|
attributeMetaDataMap.getLanguages())); |
1309 |
} |
} |
1310 |
} |
} |
1311 |
|
} |
1312 |
|
|
1313 |
|
/** |
1314 |
|
* Checks every attribute name in the {@link AttributeMetadataMap} for its |
1315 |
|
* binding type. It the type is textual, add the mrpty string as a NODATA |
1316 |
|
* value. |
1317 |
|
* |
1318 |
|
* @param attributeMetaDataMap |
1319 |
|
* @param schema |
1320 |
|
*/ |
1321 |
|
public static void addEmptyStringToAllTextualAttributes( |
1322 |
|
AttributeMetadataMap<? extends AttributeMetadataInterface> attributeMetaDataMap, |
1323 |
|
SimpleFeatureType schema) { |
1324 |
|
|
1325 |
|
for (Name name : attributeMetaDataMap.keySet()) { |
1326 |
|
if (String.class.isAssignableFrom(schema.getDescriptor(name) |
1327 |
|
.getType().getBinding())) { |
1328 |
|
attributeMetaDataMap.get(name).getNodataValues().add(""); |
1329 |
|
} |
1330 |
|
} |
1331 |
} |
} |
1332 |
|
|
1333 |
|
/** |
1334 |
|
* @return a nicely formatted String containing all NODATA values of any |
1335 |
|
* {@link AttributeMetadataInterface} object. Strings are quoted so |
1336 |
|
* that any empty {@link String} can be seen. |
1337 |
|
*/ |
1338 |
|
public static String formatNoDataValues(Set<Object> nodataValuesList) { |
1339 |
|
String nicelyFormatted = ""; |
1340 |
|
if (nodataValuesList != null) { |
1341 |
|
if (nodataValuesList.size() == 0) |
1342 |
|
nicelyFormatted = ""; |
1343 |
|
else { |
1344 |
|
for (Object ndo : nodataValuesList) { |
1345 |
|
if (ndo instanceof String) |
1346 |
|
nicelyFormatted += "\"" + ndo + "\""; |
1347 |
|
else |
1348 |
|
nicelyFormatted += ndo.toString(); |
1349 |
|
|
1350 |
|
nicelyFormatted += ","; |
1351 |
|
} |
1352 |
|
// Remove the extra comma |
1353 |
|
nicelyFormatted = nicelyFormatted.substring(0, |
1354 |
|
nicelyFormatted.length() - 1); |
1355 |
|
} |
1356 |
|
} |
1357 |
|
return nicelyFormatted; |
1358 |
|
} |
1359 |
} |
} |