/*
	(c) Prof. Dr.-Ing. Franz-Josef Behr http://www.gis-news.de/.
 */

import java.io.*;
public class dfk2svg
{
  public static void transformDFKAngle2SVGAngle(double fangle)
  {
           fangle = fangle / 400 * 360;
           if (fangle < 90) {
              fangle = 360 - (90 - fangle);
           } else
             {
             if (fangle >= 90) {
                fangle = fangle - 90;
             }
           }
  }
  public static void write7Gruppe(PrintWriter svgfile, double x1, double y1, double dx, double dy, String sSymbol)
  {
     svgfile.println("<!-- " + sSymbol + " -->");
     svgfile.println("<g transform=\"translate(" + x1 + "," + y1 + ")\">");
     svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
     svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#" + sSymbol + "\" />");
     svgfile.println("</g></g>");
     svgfile.println("<g transform=\"translate(" + (x1 + dx) + "," + (y1 + dy) + ")\">");
     svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
     svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#" + sSymbol + "\" />");
     svgfile.println("</g></g>");
     svgfile.println("<g transform=\"translate(" + (x1 + dx) + "," + (y1 - dy) + ")\">");
     svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
     svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#" + sSymbol + "\" />");
     svgfile.println("</g></g>");
     svgfile.println("<g transform=\"translate(" + (x1 - dx) + "," + (y1 + dy) + ")\">");
     svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
     svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#" + sSymbol + "\" />");
     svgfile.println("</g></g>");
     svgfile.println("<g transform=\"translate(" + (x1 - dx) + "," + (y1 - dy) + ")\">");
     svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
     svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#" + sSymbol + "\" />");
     svgfile.println("</g></g>");
     svgfile.println("<g transform=\"translate(" + (x1 - dx*2) + "," + (y1 - 0.0) + ")\">");
     svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
     svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#" + sSymbol + "\" />");
     svgfile.println("</g></g>");
     svgfile.println("<g transform=\"translate(" + (x1 + dx*2) + "," + (y1 - 0.0) + ")\">");
     svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
     svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#" + sSymbol + "\" />");
     svgfile.println("</g></g>");

  }
  public static void writeOutputHeader(PrintWriter svgfile, double fxmax, double fymax)
  {
  svgfile.println("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
  svgfile.println("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20000303 Stylable//EN\"");
  //svgfile.println("\"http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd\">");
  svgfile.println("\"http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd\" [");
  //svgfile.println("<svg xml:space=\"preserve\" width=\"600\" height=\"405\" viewBox=\"0 0 " + fxmax - fxmin) + " " + (fymax - fymin) + "\">");
  svgfile.println("	<!ENTITY st0 \"fill:#FFF200;stroke:#101077;stroke-width:0.5;font-family:'Arial';\">");
  svgfile.println("	<!ENTITY st7 \"fill:none;stroke:#F0000;stroke-width:0.5;\">");
  svgfile.println("	<!ENTITY st3 \"fill:white;stroke:black;stroke-width:0.05;\">");
  svgfile.println("]>");
  svgfile.println("<svg xml:space=\"preserve\" width=\"600\" height=\"405\" viewBox=\"0 0 " + fxmax + " " + fymax + "\">");
  svgfile.println("<defs>");
  svgfile.println("<symbol id=\"Laubbaum\" viewBox=\"0 0 50 50\">");
  svgfile.println("<polyline style=\"fill:none; stroke:green; stroke-width:0.05cm\" points=\"");
  svgfile.println("32,25 34,23 35,21 36,18 35,15 35,13 33,10 31,8 29,7 26,6 24,6 21,7 19,8 17,10 15,13 15,15 14,18 15,21 16,23 18,25 \" />");
  svgfile.println("<polyline style=\"fill:none; stroke:green; stroke-width:0.05cm\" points=\"");
  svgfile.println("32,25 42,25 \" />");
  svgfile.println("</symbol>");
  svgfile.println("<symbol id=\"Nadelbaum\" viewBox=\"0 0 50 50\">");
  svgfile.println("<polyline style=\"fill:none; stroke:green; stroke-width:0.05cm\" points=\"");
  svgfile.println("20,25 25,7 30,25 35,25 \" />");
  svgfile.println("</symbol>");
 
  svgfile.println("<symbol id=\"Gruenland\" viewBox=\"0 0 50 50\">");
  svgfile.println("<polyline style=\"fill:none; stroke:green; stroke-width:0.05cm\" points=\"");
  svgfile.println("21,31 21,19 \" />");
  svgfile.println("<polyline style=\"fill:none; stroke:green; stroke-width:0.05cm\" points=\"");
  svgfile.println("29,19 29,31 \" />");
  svgfile.println("</symbol>");

  svgfile.println("<symbol id=\"HSP_Mast\" viewBox=\"0 0 50 50\">");
  svgfile.println("<circle cx=\"25\" cy=\"50\" r=\"7\" style=\"fill:none; stroke:black; stroke-width:0.05cm\"/>");
  svgfile.println("<polyline style=\"fill:none; stroke:black; stroke-width:0.05cm\" points=\"");
  svgfile.println("25,43 25,10 45,10 40,7 40,13 45,10 \" />");
  svgfile.println("<polyline style=\"fill:none; stroke:black; stroke-width:0.05cm\" points=\"");
  svgfile.println("25,10 5,10 10,7 10,13 5,10 \" />");
  svgfile.println("</symbol>");
  svgfile.println("</defs>");
  }
  public static void main(String args[])
  {
      PrintWriter svgfile;
      double sum = 0.0;
      int nenner;
      BufferedReader dfkfile;
      String line;
      //String sDFKFileName = "e:\\progproj\\DFK Bayern\\muster2.dfk";//20125008.dfk";//20114712.dfk";//20125008.dfk
      String sDFKFileName = "muster.dfk";//20125008.dfk";//20114712.dfk";//20125008.dfk
      //String sDFKFileName = "Kopie von muster2.dfk";//20125008.dfk";//20114712.dfk";//20125008.dfk
      //String sDFKFileName = "20125008.dfk";//20114712.dfk";//20125008.dfk
      double pxarray[] = new double[4000], pyarray[] = new double[4000];
      long pnarray[] = new long[4000];
      long pnabmarkungsarray[] = new long[4000];
      int ipoints, npoints = 0;
      int iSymbId = 0;
      String sStyle = "";
      double fangle = 0, fangledfk = 0;
      double dx = 0, dy = 0;
      String sPnr = "", sNumber = "", sText = "";
      boolean lMinus1Found = false;
      
  try {
  dfkfile = new BufferedReader(new FileReader(sDFKFileName));
  line = dfkfile.readLine();
  System.out.println(line);

  try {
  svgfile = new PrintWriter(new BufferedWriter(new FileWriter("zwei.svg")));
  System.out.println(line.substring(27,36));
  System.out.println(line.substring(37,46));
  System.out.println(line.substring(47,56));
  System.out.println(line.substring(57,66));
  double fxmin = (new Double(line.substring(28,36))).doubleValue() / 100;
  double fymin = (new Double(line.substring(38,46))).doubleValue() / 100;
  double fxmax = (new Double(line.substring(48,56))).doubleValue() / 100;
  double fymax = (new Double(line.substring(58,66))).doubleValue() / 100;
  writeOutputHeader(svgfile, fxmax - fxmin, fymax - fymin);
  
  while (line.length() < 1) {
    line = dfkfile.readLine();
  }
  while ((line = dfkfile.readLine()) != null && !lMinus1Found) {
    //System.out.println(line);
  while (line.length() < 1) {
    line = dfkfile.readLine();
  }
    if (line.substring(0,6).equals("+    1")){
       System.out.println("End of DFK-Data: " + line);
       lMinus1Found = true;
    }
    else {
    int iKenn = (new Long(line.substring(2,6))).intValue();
    //svgfile.println("iKenn: " + iKenn);
           double x1 = 0, y1 = 0, x2 = 0, y2 = 0;
    switch (iKenn) {
      case 9990:
           break;
      case 6000:
           sStyle = " style=\"fill:none;stroke:black;\" ";
           break;
      case 6002: // Flurstücksgrenze, nicht abgemarkt 
           sStyle = " style=\"fill:none;stroke:black;stroke-dasharray: 5 2;\" ";
           break;
      case 6020: // Gemeinde- und Gemarkungsgrenze
           sStyle = " style=\"fill:none;stroke:black;\" ";
           break;
      case 6030: // Gemarkungsgrenze
           sStyle = " style=\"fill:none;stroke:black;\" ";
           break;
      case 6050: // Gebäude
      case 6052: // Nebengebäude
           sStyle = " style=\"fill:none;stroke:red;stroke-width:0.2;\" ";
           break;
      case 6230: // Kirchenkreuz
           sStyle = " style=\"fill:none;stroke:black;stroke-width:0.2;\" ";
           break;
      case 6300:
           sStyle = " style=\"fill:none;stroke:green;\" ";
           break;
      case 6310:
           sStyle = " style=\"fill:none;stroke:blue;stroke-width:0.2;\" ";
           break;
      case 6400:
           sStyle = " style=\"fill:none;stroke:brown;stroke-width:0.2;\" ";
           break;
      case 6410: // Grube, Steg, ...
           sStyle = " style=\"fill:none;stroke:brown;stroke-width:0.3;\" ";
           break;

           // Font definitions
      case 4001: // Kl. See, ...
           sStyle = " style=\"font-family:Verdana; font-size:1.8;fill:red;\" ";
           break;
      case 4230: // Kl. See, ...
           sStyle = " style=\"font-family:Verdana; font-size:2.5;fill:blue;\" ";
           break;
      case 4410: // Kl. See, ...
           sStyle = " style=\"font-family:Verdana; font-size:3.5;fill:blue;\" ";
           break;
      case 4460: // Bahnlinie
           //sStyle = " style=\"fill:none;stroke:black;\" ";
           sStyle = " style=\"font-family:Verdana; font-size:3.5;fill:black;\" ";
           break;
      case 4350: // Strassennamen
           sStyle = " style=\"font-family:Verdana; font-size:3.5;fill:black;\" ";
           break;
      case 4800: // Gemeindenamen
           sStyle = " style=\"font-family:Verdana; font-size:5;fill:black;\" ";
           break;
      case 4900: // See, Fluß
           sStyle = " style=\"font-family:Verdana; font-size:5;fill:blue;\" ";
           break;
      case 4260: // Flurstücksnummer
      case 2298: // Flurstücksnummer
      case 4301: // Flurstücksnummer
           sStyle = " style=\"font-family:Verdana; font-size:1.8;fill:black;stroke:black;stroke-width:0.2;\" ";
           break;
    }
    switch (iKenn) {
      case 2500: // Kartenblattangaben
      case 4001: // Hausnummer
      case 4350: // Strassennamen
      case 4260: // Flurstücksnummer
      case 2298: // Flurstücksnummer
      case 4301: // Flurstücksnummer
      case 4460: // Bahnlinie
      case 4800: // Gemeindenamen
      case 4900: // See, Fluß
           x1 = (new Double(line.substring(16,25))).doubleValue() / 100;
           y1 = (new Double(line.substring(26,35))).doubleValue() / 100;
           fangle = (new Double(line.substring(50,57))).doubleValue();
           fangledfk = fangle;
           //transformDFKAngle2SVGAngle(fangle);
           fangle = fangle / 400 * 360;
           if (fangle < 90) {
              fangle = 360 - (90 - fangle);
           } else
             {
             if (fangle >= 90) {
                fangle = fangle - 90;
             }
           }

           sNumber = line.substring(37,42).trim();
           dx      = (new Double(sNumber)).doubleValue() / 100;
           if (line.substring(36,37).equals("-")){
              dx = - dx;
           }
           sNumber = line.substring(44,49).trim();
           dy      = (new Double(sNumber)).doubleValue() / 100;
           if (line.substring(43,44).equals("-")){
              dy = - dy;
           }
           svgfile.println("<!-- " + fangledfk + " | " + fangle + " " + dx + " " + dy + " -->");
           System.out.println(line.substring(58));
           x1 = x1 - fxmin; y1 = fymax - y1;
           
           sText = line.substring(58);
           if (iKenn==4301) {
              sText = sText.substring(sText.indexOf("-")+1);
           }
           //x1 = x1 + dx - fxmin; y1 = fymax + dy - y1;
           if (fangle != 0) {
              svgfile.println("<g transform=\"translate(" + x1 + "," + y1 + ")\">");
              svgfile.println("<g transform=\"rotate(" + fangle + ")\">");
              x1 = 0; y1 = 0;
           }
           svgfile.println("<text " + sStyle);//style=\"font-family:Verdana; font-size:3;fill:black;\"");
           svgfile.println(" x=\"" + x1 + "\" y=\"" + y1 + "\">" + sText + "</text>");
           if (fangle != 0) {
              svgfile.println("</g></g>");
           }
           break;
      case 4450: // Symbol
           //svgfile.println("    " + line.substring(16,25) + "\" cy=\"" + line.substring(26,35) + "\" r=\"50\"/>");
           if (line.length() < 61) {
              line = line + "  ";
           }
           x1 = (new Double(line.substring(16,25))).doubleValue();
           y1 = (new Double(line.substring(26,35))).doubleValue();
           fangle  = (new Double(line.substring(50,57))).doubleValue();
           String sTrim = line.substring(58,61).trim();
           iSymbId = (new   Long(sTrim)).intValue();
           svgfile.println("<!-- Symbol " + iSymbId  + " -->");
           x1 = x1/100 - fxmin; y1 = fymax - y1/100;
           switch (iSymbId) {
             case 220: // Nadelbaum, 7er Gruppe
                  write7Gruppe(svgfile, x1, y1, 3.5, 5.0, "Nadelbaum");
                  break;
             case 200: // Mischwald, 7er Gruppe
                  svgfile.println("<!-- Mischwald -->");
                  svgfile.println("<g transform=\"translate(" + x1 + "," + y1 + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Nadelbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 + 3.5) + "," + (y1 + 4.5) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 + 3.5) + "," + (y1 - 4.5) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 - 3.5) + "," + (y1 + 4.5) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 - 3.5) + "," + (y1 - 4.5) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 - 7) + "," + (y1 - 0.0) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Nadelbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 + 7) + "," + (y1 - 0.0) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Nadelbaum\" />");
                  svgfile.println("</g></g>");
             case 210: // Laubbaum, 7er Gruppe
                  svgfile.println("<!-- Laubbaum -->");
                  svgfile.println("<g transform=\"translate(" + x1 + "," + y1 + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 + 3.5) + "," + (y1 + 4.5) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 + 3.5) + "," + (y1 - 4.5) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 - 3.5) + "," + (y1 + 4.5) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 - 3.5) + "," + (y1 - 4.5) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 - 7) + "," + (y1 - 0.0) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 + 7) + "," + (y1 - 0.0) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  //svgfile.println("<use x=\"" + "3.5" + "\" y=\"" +  "4.5" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  //svgfile.println("<use x=\"" + "7.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  //svgfile.println("<use x=\"" + "3.5" + "\" y=\"" + "-4.5" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  //svgfile.println("<use x=\"" + "-3.5" + "\" y=\"" +  "4.5" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  //svgfile.println("<use x=\"" + "-3.5" + "\" y=\"" +  "-4.5" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  //svgfile.println("<use x=\"" + "-7.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  //svgfile.println("</g></g>");
                  break;
             case 211: // Laubbaum, 3er Gruppe
                  svgfile.println("<!-- Laubbaum -->");
                  svgfile.println("<g transform=\"translate(" + x1 + "," + (y1 + 2.12) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 + 3.5) + "," + (y1 - 2.37) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  svgfile.println("<g transform=\"translate(" + (x1 - 3.5) + "," + (y1 - 2.37) + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Laubbaum\" />");
                  svgfile.println("</g></g>");
                  break;
             case 110: // Grünland
                  svgfile.println("<g transform=\"translate(" + x1 + "," + y1 + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.2" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#Gruenland\" />");
                  svgfile.println("</g></g>");
                  break;
             case 309: // Hsp-Mast
                  svgfile.println("<g transform=\"translate(" + x1 + "," + y1 + ")\">");
                  svgfile.println("<g transform=\"scale(" + "0.1" + ")\">");
                  svgfile.println("<use x=\"" + "0.0" + "\" y=\"" +  "0.0" + "\" width=\"1.7cm\" height=\"1.7cm\" xlink:href=\"#HSP_Mast\" />");
                  svgfile.println("</g></g>");
                  break;
             default:
                  //svgfile.println("<circle style=\"fill:#A10000;stroke:blue;\"");
                  //svgfile.println("cx=\"" + x1 + "\" cy=\"" + y1 + "\" r=\"50\"/>");
           }
           break;
      case 9990:
           //svgfile.println("    " + line.substring(22,30) + "\" cy=\"" + line.substring(32,40) + "\" r=\"50\"/>");
           x1 = (new Double(line.substring(22,30))).doubleValue() / 100;
           y1 = (new Double(line.substring(32,40))).doubleValue() / 100;
           x1 = x1 - fxmin; y1 = fymax - y1;
           //svgfile.println("<circle style=\"fill:#F0000;stroke:red;\"");
           //svgfile.println("<circle style=\"&st3;\"");
           //svgfile.println("cx=\"" + x1 + "\" cy=\"" + y1 + "\" r=\"1\"/>");
           npoints = npoints + 1;
           pxarray[npoints] = (new Double(x1)).doubleValue();
           pyarray[npoints] = (new Double(y1)).doubleValue();
           sPnr = line.substring(16,20).trim();
           
           pnarray[npoints] = (new Long(line.substring(7,15))).longValue();
           pnarray[npoints] = pnarray[npoints]*10000 + (new Long(sPnr)).longValue();

           sPnr = line.substring(41,43).trim();
           pnabmarkungsarray[npoints]= (new Long(sPnr)).longValue();
           //System.out.println(" " + npoints + " " + pnarray[npoints] + " " + pxarray[npoints] + " " + pyarray[npoints]);
           //svgfile.println("<text style=\"font-family:Verdana; font-size:3;fill:black;\"");
           //svgfile.println(" x=\"" + (x1 +5) + "\" y=\"" + y1 + "\">" + sPnr + "</text>");
           break;
      case 6000:
      case 6002: // Flurstücksgrenze, nicht abgemarkt stroke-dasharray: 5 3 2
      case 6020: // Gemeinde- und Gemarkungsgrenze
      case 6030: // Gemarkungsgrenze
      case 6050: // Gebäude
      case 6052: // Nebengebäude
      case 6070:
      case 6072:
      case 6100: // genehmigtes Bauvorhaben
      case 6210:
      case 6230: // Kirchenkreuz
      case 6300:
      case 6310: // 
      case 6400:
      case 6450:
      case 6410: // Grube, Steg, ...
         //for (ipoints = 1; ipoints <= npoints; ipoints++) {
         //System.out.println(" " + ipoints + ": " + pnarray[ipoints] + " " + pxarray[ipoints] + " " + pyarray[ipoints]);
         //svgfile.println(" " + ipoints + ": " + pnarray[ipoints] + " " + pxarray[ipoints] + " " + pyarray[ipoints]);
         //}
         //System.out.println("Ende Punkte (" + npoints + ")");

         //long pn1 = (new Long(line.substring(7,15)  + sPnr)).longValue();
         System.out.println(line);
         svgfile.println(line);
  //try {
           long pn1 = (new Long(line.substring(7,15))).longValue();
           sPnr = line.substring(16,20).trim();
           //System.out.println(sPnr + " 16 - 20");
           pn1 = pn1*10000 + (new Long(sPnr)).longValue();
           //System.out.println("pn1: " + pn1 + " 7 - 15");
           sPnr = line.substring(30,34).trim();
           //System.out.println(sPnr + " 30 - 34");
           long pn2 = (new Long(line.substring(21,29))).longValue();
           pn2 = pn2*10000 + (new Long(sPnr)).longValue();
           //System.out.println("pn2: " + pn2 + " 21 - 29");
           //long pn1 = (new Long(line.substring(7,15) + line.substring(16,20))).longValue();
           //long pn2 = (new Long(line.substring(21,29) + line.substring(30,34))).longValue();
           boolean lNotFound = true;
           lNotFound = true;
           ipoints = 1;
           //System.out.println("pna1: " + pnarray[1]);
           while (ipoints <= npoints && lNotFound) {
             //System.out.println("Test iPoint " + ipoints);
             if (pn1 == pnarray[ipoints]) {
                x1 = pxarray[ipoints];
                y1 = pyarray[ipoints];
                lNotFound = false;
             }
             ipoints++;
           }
           if (lNotFound) {
           svgfile.println("<!--  Not found:  " + pn1 + " " + line + " -->");
           } else
           {
             //System.out.println("Found " + pnarray[ipoints]);
           }
           lNotFound = true;
           ipoints = 1;
           while (ipoints <= npoints && lNotFound) {
             if (pn2 == pnarray[ipoints]) {
                x2 = pxarray[ipoints];
                y2 = pyarray[ipoints];
                lNotFound = false;
             }
             ipoints++;
           }
           if (lNotFound) {
           svgfile.println("<!--  Not found:  " + pn2 + " " + line + " -->");
           } else
           {
             //System.out.println("Found " + pnarray[ipoints]);
           }
           svgfile.println("<path " + sStyle);
           svgfile.println("d=\"M " + x1 + " " + y1 + " L " + x2 + " " + y2 + "\"/>");
           //System.out.println("d=\"M " + x1 + " " + y1 + " L " + x2 + " " + y2 + "\"/>");
  //} catch (Exception e) {
  //  System.out.println("Fehler bei 6000  Lesen der Datei");
  //       svgfile.println(line);
  //}
           break;
      default:;
    }
    }
  } // while 
      svgfile.println("<g id=\"points\" style=\"display:inline;\" >");
      for (ipoints = 1; ipoints <= npoints; ipoints++) {
          if (pnabmarkungsarray[ipoints] == 0) {
             svgfile.println("<circle style=\"&st3;\"");
             svgfile.println("cx=\"" + pxarray[ipoints] + "\" cy=\"" + pyarray[ipoints] + "\" r=\"0.7\"/>");
          }  else {
             //svgfile.println("<! -- " + pnabmarkungsarray[ipoints] + " -->");
          }

         //System.out.println(" " + pnarray[ipoints] + " " + pxarray[ipoints] + " " + pyarray[ipoints]);
         //svgfile.println(" " + pnarray[ipoints] + " " + pxarray[ipoints] + " " + pyarray[ipoints]);
      }
      svgfile.println("</g> <!-- id=\"points\" -->");
  //svgfile.println();
  svgfile.println("</svg>");
  svgfile.close();
  } catch (IOException e) {
    System.out.println("Fehler beim Erstellen der Datei");
  }
  } catch (IOException e) {
    System.out.println("Fehler beim Lesen der Datei");
  }
   }
}


