43 |
import java.io.FileWriter; |
import java.io.FileWriter; |
44 |
import java.net.URL; |
import java.net.URL; |
45 |
import java.text.DecimalFormat; |
import java.text.DecimalFormat; |
46 |
|
import java.util.ArrayList; |
47 |
import java.util.List; |
import java.util.List; |
48 |
import java.util.Map; |
import java.util.Map; |
49 |
|
import java.util.Set; |
50 |
|
|
51 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
52 |
import javax.swing.ImageIcon; |
import javax.swing.ImageIcon; |
80 |
import org.jdom.output.XMLOutputter; |
import org.jdom.output.XMLOutputter; |
81 |
import org.opengis.feature.simple.SimpleFeature; |
import org.opengis.feature.simple.SimpleFeature; |
82 |
import org.opengis.feature.simple.SimpleFeatureType; |
import org.opengis.feature.simple.SimpleFeatureType; |
83 |
|
import org.opengis.feature.type.AttributeDescriptor; |
84 |
|
import org.opengis.feature.type.GeometryDescriptor; |
85 |
import org.opengis.feature.type.Name; |
import org.opengis.feature.type.Name; |
86 |
import org.opengis.parameter.GeneralParameterValue; |
import org.opengis.parameter.GeneralParameterValue; |
87 |
|
|
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; |
95 |
import skrueger.AttributeMetadata; |
import skrueger.AttributeMetadataImpl; |
96 |
|
import skrueger.AttributeMetadataInterface; |
97 |
import skrueger.RasterLegendData; |
import skrueger.RasterLegendData; |
98 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
99 |
|
|
250 |
* @param visible |
* @param visible |
251 |
* indicated whether the visible or invisible entries are |
* indicated whether the visible or invisible entries are |
252 |
* returned |
* returned |
253 |
* |
* |
254 |
* TODO replace with {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
* TODO replace with |
255 |
|
* {@link AttributeMetadataMap#sortedValuesVisibleOnly()} |
256 |
*/ |
*/ |
257 |
public static AttributeMetadataMap getVisibleAttributeMetaData( |
public static AttributeMetadataMap<? extends AttributeMetadataInterface > getVisibleAttributeMetaData( |
258 |
final AttributeMetadataMap amdMap, final boolean visible) { |
final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap, |
259 |
|
final boolean visible) { |
260 |
final AttributeMetadataMap filteredMap = new AttributeMetadataMap(amdMap.getLanguages()); |
|
261 |
for (final AttributeMetadata amd : amdMap.values()) |
final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap.clone(); |
262 |
|
if (filteredMap.size() > 0 ) { |
263 |
|
filteredMap.clear(); // Just in case the close copies the contents |
264 |
|
} |
265 |
|
|
266 |
|
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 |
|
|
271 |
} |
} |
272 |
|
|
273 |
/** |
/** |
274 |
* Parses a {@link AttributeMetadata} object from an JDOM-{@link Element}. |
* Parses a {@link AttributeMetadataImpl} object from an JDOM- |
275 |
* This method works like {@link |
* {@link Element}. This method works like {@link |
276 |
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM. |
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM. |
277 |
* |
* |
278 |
* TODO 20.11.2009, SK: There are some new attribute weight, functiona, |
* TODO 20.11.2009, SK: There are some new attribute weight, functiona, |
283 |
* @param element |
* @param element |
284 |
* {@link Element} to parse |
* {@link Element} to parse |
285 |
*/ |
*/ |
286 |
public static AttributeMetadata parseAttributeMetaData(final Element element) { |
public static AttributeMetadataImpl parseAttributeMetaData( |
287 |
|
final Element element) { |
288 |
final String namespace = String.valueOf(element |
final String namespace = String.valueOf(element |
289 |
.getAttributeValue("namespace")); |
.getAttributeValue("namespace")); |
290 |
final String localname = String.valueOf(element |
final String localname = String.valueOf(element |
291 |
.getAttributeValue("localname")); |
.getAttributeValue("localname")); |
292 |
final Name aName = new NameImpl(namespace, localname); |
final NameImpl 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 AttributeMetadataImpl} class has |
319 |
|
* more attributes which are not used by Xulu/ISDSS. GP |
320 |
|
* exports/imports the AMD via AMLExporter and AMLImporter |
321 |
|
* 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 AttributeMetadataImpl} class has |
356 |
|
* more attributes which are not used by Xulu/ISDSS. GP |
357 |
|
* exports/imports the AMD via AMLExporter and AMLImporter |
358 |
|
* 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", String.valueOf(amd.getName() |
364 |
.getNamespaceURI())); |
.getNamespaceURI())); |
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 |
*/ |
*/ |
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 {@code |
848 |
* file for a given geo-object (feature) source. The SLD file must be |
* .amd} file for a given geo-object (feature) source. The SLD file must be |
849 |
* present. A missing attribute meta-data file is tolerated. |
* present. A missing attribute meta-data file is tolerated. |
850 |
* |
* |
851 |
* @param geoObjectURL |
* @param geoObjectURL |
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 |
940 |
* Krüger</a> |
* Krüger</a> |
941 |
*/ |
*/ |
942 |
public static JPanel createLegendPanel(Style style, |
public static JPanel createLegendSwingPanel(Style style, |
943 |
final SimpleFeatureType featureType, final int iconWidth, |
final SimpleFeatureType featureType, final int iconWidth, |
944 |
final int iconHeight) { |
final int iconHeight) { |
945 |
|
|
958 |
final List<Rule> rules = ftStyle.rules(); |
final List<Rule> rules = ftStyle.rules(); |
959 |
for (final Rule rule : rules) { |
for (final Rule rule : rules) { |
960 |
|
|
961 |
|
// Check if this RULE shall actually appear in the legend |
962 |
|
if (rule.getName() != null |
963 |
|
&& rule.getName().endsWith(HIDE_IN_LAYER_LEGEND_HINT)) |
964 |
|
continue; |
965 |
|
|
966 |
/** |
/** |
967 |
* Let's not create a hbox for Rules that only contain |
* Let's not create a hbox for Rules that only contain |
968 |
* TextSymbolizers |
* TextSymbolizers |
995 |
return panel; |
return panel; |
996 |
} |
} |
997 |
|
|
998 |
|
|
999 |
|
|
1000 |
|
|
1001 |
/** |
/** |
1002 |
* Creates a {@link JComponent} that contains a legend for a given |
* Creates a {@link JComponent} that contains a legend for a given |
1003 |
* rasterLayer and a given {@link Style}. |
* {@link StyledRasterInterface} and a given {@link Style}. |
1004 |
* |
* |
1005 |
* @param style |
* @param style |
1006 |
* if <code>null</code>, the default {@link Style} is extracetd |
* if <code>null</code>, the default {@link Style} is extracetd |
1007 |
* from the {@link StyledRasterInterface} |
* from the {@link StyledRasterInterface} |
1008 |
*/ |
*/ |
1009 |
public static JPanel createLegendPanel( |
public static JPanel createLegendSwingPanel( |
1010 |
final StyledRasterInterface<?> styledRaster, Style style, |
final StyledRasterInterface<?> styledRaster, Style style, |
1011 |
final int iconWidth, final int iconHeight) { |
final int iconWidth, final int iconHeight) { |
1012 |
|
|
1030 |
final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData |
final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData |
1031 |
.createSampleRasters(); |
.createSampleRasters(); |
1032 |
|
|
1033 |
final JPanel panel = new JPanel(new MigLayout("wrap 2")); |
final JPanel panel = new JPanel(new MigLayout("wrap 2, gapy 0")); |
1034 |
|
|
1035 |
for (final Double rValue : legendRasterValues) { |
for (final Double rValue : legendRasterValues) { |
1036 |
|
|
1119 |
} |
} |
1120 |
|
|
1121 |
final JLabel iconLabel = new JLabel(new ImageIcon(buffImage)); |
final JLabel iconLabel = new JLabel(new ImageIcon(buffImage)); |
|
// hbox.setAlignmentX(0f); |
|
1122 |
panel.add(iconLabel, "sgx1"); |
panel.add(iconLabel, "sgx1"); |
|
// hbox.add(Box.createHorizontalStrut(3)); |
|
1123 |
|
|
1124 |
final Translation labelT = rasterLegendData.get(rValue); |
final Translation labelT = rasterLegendData.get(rValue); |
1125 |
final JLabel classTitleLabel = new JLabel(labelT.toString()); |
final JLabel classTitleLabel = new JLabel(labelT.toString()); |
1126 |
panel.add(classTitleLabel, "sgx2" |
panel.add(classTitleLabel, "sgx2" |
1127 |
+ (rasterLegendData.getPaintGaps() ? ", gapy 0 3" : "")); |
+ (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5" |
1128 |
|
: "")); |
1129 |
classTitleLabel.setLabelFor(iconLabel); |
classTitleLabel.setLabelFor(iconLabel); |
1130 |
|
|
1131 |
// box.add(hbox); |
if (rasterLegendData.isPaintGaps()) { |
|
|
|
|
if (rasterLegendData.getPaintGaps()) { |
|
1132 |
iconLabel |
iconLabel |
1133 |
.setBorder(BorderFactory.createLineBorder(Color.black)); |
.setBorder(BorderFactory.createLineBorder(Color.black)); |
1134 |
} |
} |
1137 |
|
|
1138 |
return panel; |
return panel; |
1139 |
} |
} |
1140 |
|
|
1141 |
|
|
1142 |
|
|
1143 |
/** |
/** |
1144 |
* Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May |
* Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May |
1188 |
public static boolean isStyleable( |
public static boolean isStyleable( |
1189 |
final StyledRasterInterface<?> styledRaster) { |
final StyledRasterInterface<?> styledRaster) { |
1190 |
final ColorModel colorModel = getColorModel(styledRaster); |
final ColorModel colorModel = getColorModel(styledRaster); |
1191 |
|
|
1192 |
// LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is " |
// LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is " |
1193 |
// + colorModel != null ? colorModel.getClass().getSimpleName() : "NULL"); |
// + colorModel != null ? colorModel.getClass().getSimpleName() : |
1194 |
|
// "NULL"); |
1195 |
|
|
1196 |
if (colorModel == null) |
if (colorModel == null) |
1197 |
return true; |
return true; |
1207 |
* Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a |
* Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a |
1208 |
* repaint, so only use it when needed. |
* repaint, so only use it when needed. |
1209 |
* |
* |
1210 |
* @return <code>true</code> if the {@link MapLayer}'s {@link Style} has been changed. |
* @return <code>true</code> if the {@link MapLayer}'s {@link Style} has |
1211 |
|
* been changed. |
1212 |
*/ |
*/ |
1213 |
public static boolean updateMapLayerStyleIfChangedAndKeepSelection(MapLayer mapLayer, |
public static boolean updateMapLayerStyleIfChangedAndKeepSelection( |
1214 |
Style style2) { |
MapLayer mapLayer, Style style2) { |
1215 |
|
|
1216 |
Style mapLayerStyleCleaned = StylingUtil |
Style mapLayerStyleCleaned = StylingUtil |
1217 |
.removeSelectionFeatureTypeStyle(mapLayer.getStyle()); |
.removeSelectionFeatureTypeStyle(mapLayer.getStyle()); |
1218 |
|
|
1219 |
Style newStyleCleaned = StylingUtil.removeSelectionFeatureTypeStyle(style2); |
Style newStyleCleaned = StylingUtil |
1220 |
|
.removeSelectionFeatureTypeStyle(style2); |
1221 |
if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned, |
|
1222 |
newStyleCleaned)) { |
if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned, newStyleCleaned)) { |
1223 |
|
|
1224 |
// They are different when compared without SELECTION FTS! |
// They are different when compared without SELECTION FTS! |
1225 |
|
|
1226 |
// Now let's copy any SELECTION FTS to the now style |
// Now let's copy any SELECTION FTS to the now style |
1227 |
FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil.getSelectionFeatureTypeStyle( mapLayer.getStyle() ); |
FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil |
1228 |
|
.getSelectionFeatureTypeStyle(mapLayer.getStyle()); |
1229 |
if (selectionFeatureTypeStyle != null) { |
if (selectionFeatureTypeStyle != null) { |
1230 |
newStyleCleaned.featureTypeStyles().add(selectionFeatureTypeStyle); |
newStyleCleaned.featureTypeStyles().add( |
1231 |
// newStyleCleaned is not so clean anymore... We just alled a selcetion FTS |
selectionFeatureTypeStyle); |
1232 |
} |
// newStyleCleaned is not so clean anymore... We just alled a |
1233 |
|
// selcetion FTS |
1234 |
|
} |
1235 |
|
|
1236 |
mapLayer.setStyle(newStyleCleaned); |
mapLayer.setStyle(newStyleCleaned); |
1237 |
|
|
1238 |
return true; |
return true; |
1239 |
|
|
1240 |
} else { |
} else { |
1241 |
return false; |
return false; |
1242 |
} |
} |
1243 |
} |
} |
1244 |
|
|
1245 |
|
/** |
1246 |
|
* After loading an atlas, the AttribteMetaData contains whatever is written |
1247 |
|
* in the XML. But the DBF may have changed! This method checks an |
1248 |
|
* {@link AttributeMetadataMap} against a schema and also corrects |
1249 |
|
* upperCase/lowerCase problems. It will also remove any geometry column |
1250 |
|
* attribute metadata. |
1251 |
|
*/ |
1252 |
|
/** |
1253 |
|
* After loading an atlas, the AttribteMetaData contains whatever is written |
1254 |
|
* in the XML. But the DBF may have changed! |
1255 |
|
*/ |
1256 |
|
public static void checkAttribMetaData( |
1257 |
|
AttributeMetadataMap<AttributeMetadataImpl> attributeMetaDataMap, |
1258 |
|
SimpleFeatureType schema) { |
1259 |
|
|
1260 |
|
if (schema == null) |
1261 |
|
throw new IllegalArgumentException("schmema may not be null!"); |
1262 |
|
|
1263 |
|
ArrayList<Name> willRemove = new ArrayList<Name>(); |
1264 |
|
|
1265 |
|
// 1. Check.. all attributes in the atm should be in the schema as well. |
1266 |
|
// maybe correct some upperCase/loweCase stuff |
1267 |
|
|
1268 |
|
for (AttributeMetadataInterface atm : attributeMetaDataMap.values()) { |
1269 |
|
|
1270 |
|
AttributeDescriptor foundDescr = schema |
1271 |
|
.getDescriptor(atm.getName()); |
1272 |
|
if (foundDescr == null) { |
1273 |
|
NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(schema, |
1274 |
|
atm.getLocalName()); |
1275 |
|
if (bestMatch == null) |
1276 |
|
willRemove.add(atm.getName()); |
1277 |
|
else |
1278 |
|
atm.setName(bestMatch); |
1279 |
|
} else if (foundDescr instanceof GeometryDescriptor) { |
1280 |
|
// We don't want GeometryColumns in here |
1281 |
|
willRemove.add(atm.getName()); |
1282 |
|
} |
1283 |
|
} |
1284 |
|
|
1285 |
|
// Remove the ones that were not findable in the schema |
1286 |
|
for (Name removeName : willRemove) { |
1287 |
|
if (attributeMetaDataMap.remove(removeName) == null) { |
1288 |
|
LOGGER.warn("removing the AMData didn't work"); |
1289 |
|
} |
1290 |
|
} |
1291 |
|
|
1292 |
|
// 2. check... all attributes from the schema must have an ATM |
1293 |
|
for (AttributeDescriptor ad : schema.getAttributeDescriptors()) { |
1294 |
|
if (ad instanceof GeometryDescriptor) |
1295 |
|
continue; |
1296 |
|
if (!attributeMetaDataMap.containsKey(ad.getName())) { |
1297 |
|
attributeMetaDataMap.put( new NameImpl(ad.getName().getNamespaceURI(), ad.getName().getLocalPart()), |
1298 |
|
new AttributeMetadataImpl(ad, schema |
1299 |
|
.getAttributeDescriptors().indexOf(ad), |
1300 |
|
attributeMetaDataMap.getLanguages())); |
1301 |
|
} |
1302 |
|
} |
1303 |
|
} |
1304 |
|
|
1305 |
|
/** |
1306 |
|
* Checks every attribute name in the {@link AttributeMetadataMap} for its |
1307 |
|
* binding type. It the type is textual, add the mrpty string as a NODATA |
1308 |
|
* value. |
1309 |
|
* |
1310 |
|
* @param attributeMetaDataMap |
1311 |
|
* @param schema |
1312 |
|
*/ |
1313 |
|
public static void addEmptyStringToAllTextualAttributes( |
1314 |
|
AttributeMetadataMap<? extends AttributeMetadataInterface> attributeMetaDataMap, |
1315 |
|
SimpleFeatureType schema) { |
1316 |
|
|
1317 |
|
for (Name name : attributeMetaDataMap.keySet()) { |
1318 |
|
if (String.class.isAssignableFrom(schema.getDescriptor(name) |
1319 |
|
.getType().getBinding())) { |
1320 |
|
attributeMetaDataMap.get(name).getNodataValues().add(""); |
1321 |
|
} |
1322 |
|
} |
1323 |
|
} |
1324 |
|
|
1325 |
|
/** |
1326 |
|
* @return a nicely formatted String containing all NODATA values of any |
1327 |
|
* {@link AttributeMetadataInterface} object. Strings are quoted so that any |
1328 |
|
* empty {@link String} can be seen. |
1329 |
|
*/ |
1330 |
|
public static String formatNoDataValues(Set<Object> nodataValuesList) { |
1331 |
|
String nicelyFormatted = ""; |
1332 |
|
if (nodataValuesList != null) { |
1333 |
|
if (nodataValuesList.size() == 0) |
1334 |
|
nicelyFormatted = ""; |
1335 |
|
else { |
1336 |
|
for (Object ndo : nodataValuesList) { |
1337 |
|
if (ndo instanceof String) |
1338 |
|
nicelyFormatted += "\"" + ndo + "\""; |
1339 |
|
else |
1340 |
|
nicelyFormatted += ndo.toString(); |
1341 |
|
|
1342 |
|
nicelyFormatted += ","; |
1343 |
|
} |
1344 |
|
// Remove the extra comma |
1345 |
|
nicelyFormatted = nicelyFormatted.substring(0, nicelyFormatted |
1346 |
|
.length() - 1); |
1347 |
|
} |
1348 |
|
} |
1349 |
|
return nicelyFormatted; |
1350 |
|
} |
1351 |
} |
} |