Mercurial > mxd2map
comparison src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 340:dbfcb0b69a63
* contrib/installer/example/example/template.map: Switch to latin1 encoding
* contrib/installer/example/example/mapfile_header.include: Remove shapepath,
data is now referenced relative to the mapfile
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 09 Nov 2012 16:54:16 +0100 |
parents | ef1cac2854e3 |
children |
comparison
equal
deleted
inserted
replaced
339:ef1cac2854e3 | 340:dbfcb0b69a63 |
---|---|
117 String fontSetPath = map.getFontset().getFilename(); | 117 String fontSetPath = map.getFontset().getFilename(); |
118 File fonts = new File(fontSetPath); | 118 File fonts = new File(fontSetPath); |
119 String fontSet = fonts.getAbsolutePath(); | 119 String fontSet = fonts.getAbsolutePath(); |
120 fontSet = fontSet.replaceAll("\\\\", "/"); | 120 fontSet = fontSet.replaceAll("\\\\", "/"); |
121 map.setFontSet(fontSet); | 121 map.setFontSet(fontSet); |
122 | |
122 } | 123 } |
123 | 124 |
124 /** | 125 /** |
125 * Write the mapfile. | 126 * Write the mapfile. |
126 * @param doc The root document containin the map attributes. | 127 * @param doc The root document containin the map attributes. |
276 Element mapNode = (Element)XMLUtils.xpath( | 277 Element mapNode = (Element)XMLUtils.xpath( |
277 root, | 278 root, |
278 "/mxd/map", | 279 "/mxd/map", |
279 XPathConstants.NODE); | 280 XPathConstants.NODE); |
280 NodeList list = mapNode.getElementsByTagName("layer"); | 281 NodeList list = mapNode.getElementsByTagName("layer"); |
281 for(int i = 0; i < list.getLength(); i++) { | 282 for(int i = list.getLength() - 1; i >= 0; i--) { |
282 Element layerElement = (Element)list.item(i); | 283 Element layerElement = (Element)list.item(i); |
284 if (layerElement.getAttribute("type") == "annotation" && | |
285 layerElement.getElementsByTagName("feature").getLength() == 0) { | |
286 logger.debug("Ignoring empty annotation Layer."); | |
287 continue; | |
288 } | |
283 layerObj layer = new layerObj(map); | 289 layerObj layer = new layerObj(map); |
284 NodeList renderer = layerElement.getElementsByTagName("renderer"); | 290 NodeList renderer = layerElement.getElementsByTagName("renderer"); |
285 | 291 |
286 //The layer name. | 292 //The layer name. |
287 String group = ""; | 293 String group = ""; |
856 * @param isShapeFile true if shapefile attribute limits should be enforced | 862 * @param isShapeFile true if shapefile attribute limits should be enforced |
857 */ | 863 */ |
858 private String createExpression(Element ce, int index, String prefixToRemove, | 864 private String createExpression(Element ce, int index, String prefixToRemove, |
859 boolean isShapeFile) { | 865 boolean isShapeFile) { |
860 String expression = "("; | 866 String expression = "("; |
861 int count = 0; | 867 int field_count = 0; |
868 int value_count = 0; | |
862 try { | 869 try { |
863 count = Integer.parseInt(ce.getAttribute("field_count")); | 870 field_count = Integer.parseInt(ce.getAttribute("field_count")); |
864 } | 871 } |
865 catch(NumberFormatException nfe) { | 872 catch(NumberFormatException nfe) { |
866 return ""; | 873 return ""; |
867 } | 874 } |
868 | 875 try { |
869 if(count == 1) { | 876 value_count = Integer.parseInt(ce.getAttribute("value_count")); |
877 } | |
878 catch(NumberFormatException nfe) { | |
879 value_count = field_count; | |
880 } | |
881 | |
882 if(field_count == 1) { | |
870 //Create single field expression. | 883 //Create single field expression. |
871 try { | 884 try { |
872 //If no exception is thrown, the expression value is a number. | 885 //If no exception is thrown, the expression value is a number. |
873 Double.parseDouble(ce.getAttribute("value")); | 886 Double.parseDouble(ce.getAttribute("value")); |
874 expression += "[" + | 887 expression += "[" + |
901 e.printStackTrace(); | 914 e.printStackTrace(); |
902 } | 915 } |
903 } | 916 } |
904 else { | 917 else { |
905 //Create a multi field expression. | 918 //Create a multi field expression. |
906 for (int i = 0; i < count; i++) { | 919 for (int i = 0; i < field_count; i++) { |
907 try { | 920 try { |
908 //If no exception is thrown, the expression values are | 921 //If no exception is thrown, the expression values are |
909 //numbers. | 922 //numbers. |
923 | |
910 Double.parseDouble(ce.getAttribute("value_" + i)); | 924 Double.parseDouble(ce.getAttribute("value_" + i)); |
911 expression += "["; | 925 expression += "["; |
912 expression += sanitizeAttribute(ce.getAttribute("expression_field_" + i), | 926 expression += sanitizeAttribute(ce.getAttribute("expression_field_" + i), |
913 prefixToRemove, prefix, isShapeFile); | 927 prefixToRemove, prefix, isShapeFile); |
914 expression += "]"; | 928 expression += "]"; |
915 expression += " " + ce.getAttribute("expression_operator"); | 929 expression += " " + ce.getAttribute("expression_operator"); |
916 expression += " " + ce.getAttribute("value_" + i); | 930 expression += " " + ce.getAttribute("value_" + i); |
917 if (i < count - 1) { | 931 if (i < field_count - 1) { |
918 expression += " AND "; | 932 expression += " AND "; |
919 } | 933 } |
920 else { | 934 else { |
921 expression += ")"; | 935 expression += ")"; |
922 } | 936 } |
923 } | 937 } |
924 catch (NumberFormatException nfe) { | 938 catch (NumberFormatException nfe) { |
925 //The expression values are strings. | 939 //The expression values are strings. |
926 expression += "\"["; | 940 expression += "\"["; |
927 expression += sanitizeAttribute(ce.getAttribute("expression_field_" + i), | 941 expression += sanitizeAttribute(ce.getAttribute("expression_field_" + i), |
928 prefixToRemove, prefix, isShapeFile); | 942 prefixToRemove, prefix, isShapeFile); |
929 expression += "]\""; | 943 expression += "]\""; |
930 expression += " " + ce.getAttribute("expression_operator"); | 944 expression += " " + ce.getAttribute("expression_operator"); |
931 expression += " \"" + ce.getAttribute("value_" + i); | 945 expression += " \"" + ce.getAttribute("value_" + i); |
932 if (i < count - 1) { | 946 if (i < field_count - 1) { |
933 expression += "\" AND "; | 947 expression += "\" AND "; |
934 } | 948 } |
935 else { | 949 else { |
936 expression += "\")"; | 950 expression += "\")"; |
937 } | 951 } |
938 } | 952 } |
939 } | 953 } |
954 | |
940 } | 955 } |
941 return expression; | 956 return expression; |
942 } | 957 } |
943 | 958 |
944 /** | 959 /** |