comparison src/java/de/intevation/mxd/writer/MapScriptWriter.java @ 311:c8b8f887ef80

Add write support for Fgdb layers and make it possible to remove a prefix from the expressions. The expressions returned by arcgis for Fgdb data contain the data source name as a prefix. Mapserver does not need it and does not match those expressions so they have to be removed
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 14 Sep 2012 11:54:03 +0200
parents 1c949a309940
children cd3cb1a7f35a
comparison
equal deleted inserted replaced
310:be441fa4bed0 311:c8b8f887ef80
525 layer.setType(MS_LAYER_TYPE.MS_LAYER_RASTER); 525 layer.setType(MS_LAYER_TYPE.MS_LAYER_RASTER);
526 layer.setConnection(layerElement.getAttribute("connection")); 526 layer.setConnection(layerElement.getAttribute("connection"));
527 layer.setConnectionType(MS_CONNECTION_TYPE.MS_WMS.swigValue(), ""); 527 layer.setConnectionType(MS_CONNECTION_TYPE.MS_WMS.swigValue(), "");
528 layer.setMetaData("wms_name", 528 layer.setMetaData("wms_name",
529 layerElement.getAttribute("wms_name")); 529 layerElement.getAttribute("wms_name"));
530 } else if(con_type.equals("ogr")) {
531 layer.setConnectionType(MS_CONNECTION_TYPE.MS_OGR.swigValue(), "");
532 layer.setConnection(layerElement.getAttribute("connection"));
533 layer.setData(layerElement.getAttribute("data_source"));
530 } 534 }
531 if(!type.equals("raster")) { 535 if(!type.equals("raster")) {
532 layer.setTemplate("PleaseInsertAValidTemplateForGFI"); 536 layer.setTemplate("PleaseInsertAValidTemplateForGFI");
533 } 537 }
534 538
542 if(labels.getLength() > 0) { 546 if(labels.getLength() > 0) {
543 Element label = (Element)labels.item(0); 547 Element label = (Element)labels.item(0);
544 String expr = label.getAttribute("expression"); 548 String expr = label.getAttribute("expression");
545 expr = expr.replaceAll("\\[", ""); 549 expr = expr.replaceAll("\\[", "");
546 expr = expr.replaceAll("\\]", ""); 550 expr = expr.replaceAll("\\]", "");
551 if (con_type == "ogr") {
552 // ogr expression fields come prefixed from arcgis
553 // the prefix has to be removed in order to work with
554 // mapserver
555 String unwantedPrefix = layerElement.getAttribute("data") + ".";
556 logger.debug("Removing expression Prefix: " + unwantedPrefix);
557 expr = expr.replace(unwantedPrefix, "");
558 }
547 if(!prefix.equals("")) { 559 if(!prefix.equals("")) {
548 expr = prefix + "." + expr; 560 expr = prefix + "." + expr;
549 } 561 }
550 layer.setLabelitem(expr.trim()); 562 layer.setLabelitem(expr.trim());
551 } 563 }
591 writeLabel(co, labelElement, layerType); 603 writeLabel(co, labelElement, layerType);
592 } 604 }
593 605
594 //Create definition expression. 606 //Create definition expression.
595 if(classElement.hasAttribute("field_count")) { 607 if(classElement.hasAttribute("field_count")) {
596 co.setExpression(createExpression(classElement, i)); 608 String unwantedPrefix = layerElement.getAttribute("data") + ".";
609 co.setExpression(createExpression(classElement, i, unwantedPrefix));
597 } 610 }
598 611
599 //Write symbols and styles. 612 //Write symbols and styles.
600 NodeList l = classElement.getChildNodes(); 613 NodeList l = classElement.getChildNodes();
601 for (int j = l.getLength() - 1; j >= 0; j--) { 614 for (int j = l.getLength() - 1; j >= 0; j--) {
699 /** 712 /**
700 * Create definition expression. 713 * Create definition expression.
701 * 714 *
702 * @param ce DOM elementcontaining the class expression information. 715 * @param ce DOM elementcontaining the class expression information.
703 * @param index Index to determine the correct expression operator. 716 * @param index Index to determine the correct expression operator.
704 */ 717 * @param prefixToRemove A string that will be removed from the start of
705 private String createExpression(Element ce, int index) { 718 * expression fields.
719 */
720 private String createExpression(Element ce, int index, String prefixToRemove) {
706 String expression = "("; 721 String expression = "(";
707 int count = 0; 722 int count = 0;
708 try { 723 try {
709 count = Integer.parseInt(ce.getAttribute("field_count")); 724 count = Integer.parseInt(ce.getAttribute("field_count"));
710 } 725 }
721 String pre = ""; 736 String pre = "";
722 if (!prefix.equals("") && !exp.startsWith(prefix)) { 737 if (!prefix.equals("") && !exp.startsWith(prefix)) {
723 pre = prefix + "."; 738 pre = prefix + ".";
724 } 739 }
725 expression += "[" + pre; 740 expression += "[" + pre;
726 expression += ce.getAttribute("expression_field_0") + "]"; 741 expression += ce.getAttribute("expression_field_0").replace(
742 prefixToRemove, "") + "]";
727 if(ce.hasAttribute("min_value")) { 743 if(ce.hasAttribute("min_value")) {
728 if(index == 0) { 744 if(index == 0) {
729 expression += " >= " + ce.getAttribute("min_value"); 745 expression += " >= " + ce.getAttribute("min_value");
730 } 746 }
731 else { 747 else {
732 expression += " > " + ce.getAttribute("min_value"); 748 expression += " > " + ce.getAttribute("min_value");
733 } 749 }
734 expression += " AND [" + pre; 750 expression += " AND [" + pre;
735 expression += ce.getAttribute("expression_field_0"); 751 expression += ce.getAttribute("expression_field_0").replace(
752 prefixToRemove, "");
736 expression += "]"; 753 expression += "]";
737 } 754 }
738 expression += " " + ce.getAttribute("expression_operator"); 755 expression += " " + ce.getAttribute("expression_operator");
739 expression += " " + ce.getAttribute("value") + ")"; 756 expression += " " + ce.getAttribute("value") + ")";
740 } 757 }
741 catch(NumberFormatException nfe) { 758 catch(NumberFormatException nfe) {
742 //The expression value is a strings. 759 //The expression value is a strings.
743 String exp = ce.getAttribute("expression_field_0"); 760 String exp = ce.getAttribute("expression_field_0").replace(
761 prefixToRemove, "");
744 String pre = ""; 762 String pre = "";
745 if (!prefix.equals("") && !exp.startsWith(prefix)) { 763 if (!prefix.equals("") && !exp.startsWith(prefix)) {
746 pre = prefix + "."; 764 pre = prefix + ".";
747 } 765 }
748 expression += "\"[" + pre; 766 expression += "\"[" + pre;
749 expression += ce.getAttribute("expression_field_0") + "]\""; 767 expression += ce.getAttribute("expression_field_0").replace(
768 prefixToRemove, "") + "]\"";
750 expression += " " + ce.getAttribute("expression_operator"); 769 expression += " " + ce.getAttribute("expression_operator");
751 expression += " \"" + ce.getAttribute("value") + "\")"; 770 expression += " \"" + ce.getAttribute("value") + "\")";
752 } 771 }
753 catch(Exception e) { 772 catch(Exception e) {
754 e.printStackTrace(); 773 e.printStackTrace();
759 for (int i = 0; i < count; i++) { 778 for (int i = 0; i < count; i++) {
760 try { 779 try {
761 //If no exception is thrown, the expression values are 780 //If no exception is thrown, the expression values are
762 //numbers. 781 //numbers.
763 Double.parseDouble(ce.getAttribute("value_" + i)); 782 Double.parseDouble(ce.getAttribute("value_" + i));
764 String exp = ce.getAttribute("expression_field_" + i); 783 String exp = ce.getAttribute("expression_field_" + i).replace(
784 prefixToRemove, "");
765 String pre = ""; 785 String pre = "";
766 if (!prefix.equals("") && !exp.startsWith(prefix)) { 786 if (!prefix.equals("") && !exp.startsWith(prefix)) {
767 pre = prefix + "."; 787 pre = prefix + ".";
768 } 788 }
769 expression += "[" + pre; 789 expression += "[" + pre;
770 expression += ce.getAttribute("expression_field_" + i); 790 expression += ce.getAttribute("expression_field_" + i).replace(
791 prefixToRemove, "");
771 expression += "]"; 792 expression += "]";
772 expression += " " + ce.getAttribute("expression_operator"); 793 expression += " " + ce.getAttribute("expression_operator");
773 expression += " " + ce.getAttribute("value_" + i); 794 expression += " " + ce.getAttribute("value_" + i);
774 if (i < count - 1) { 795 if (i < count - 1) {
775 expression += " AND "; 796 expression += " AND ";
778 expression += ")"; 799 expression += ")";
779 } 800 }
780 } 801 }
781 catch (NumberFormatException nfe) { 802 catch (NumberFormatException nfe) {
782 //The expression values are strings. 803 //The expression values are strings.
783 String exp = ce.getAttribute("expression_field_" + i); 804 String exp = ce.getAttribute("expression_field_" + i).replace(
805 prefixToRemove, "");
784 String pre = ""; 806 String pre = "";
785 if (!prefix.equals("") && !exp.startsWith(prefix)) { 807 if (!prefix.equals("") && !exp.startsWith(prefix)) {
786 pre = prefix + "."; 808 pre = prefix + ".";
787 } 809 }
788 expression += "\"[" + pre; 810 expression += "\"[" + pre;
789 expression += ce.getAttribute("expression_field_" + i); 811 expression += ce.getAttribute("expression_field_" + i).replace(
812 prefixToRemove, "");
790 expression += "]\""; 813 expression += "]\"";
791 expression += " " + ce.getAttribute("expression_operator"); 814 expression += " " + ce.getAttribute("expression_operator");
792 expression += " \"" + ce.getAttribute("value_" + i); 815 expression += " \"" + ce.getAttribute("value_" + i);
793 if (i < count - 1) { 816 if (i < count - 1) {
794 expression += "\" AND "; 817 expression += "\" AND ";
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)