Skip to content

Instantly share code, notes, and snippets.

@breinbaas
Last active July 1, 2022 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save breinbaas/e0a6110ebf6b417387409f6ba485cfe2 to your computer and use it in GitHub Desktop.
Save breinbaas/e0a6110ebf6b417387409f6ba485cfe2 to your computer and use it in GitHub Desktop.

XML to GEF

I don't like the xml format but unfortunately some people thought it would be a great idea to use that as a CPT exchange format. Fortunately for us some people wrote code to read those xml files and I have used their code to write a XML to GEF convertor. That code can be found here. I've tested it on some xml files but since I don't have many of them there will probably be some possible errors. For the files that I've tested everything is just fine.

Check out these repo's that are actively working on XML readers;

Note that this code will only copy the most important parts of the cpt and not the full cpt information!

So here is the code, just copy and paste it as a function of the Cpt class of the gefxml_reader file in the https://github.com/Amsterdam/gefxml_viewer repo

def to_gef(self, output_file: str):
  # we only take u2 into account
  has_u2 = self.data["porePressureU2"].notnull().count() > 0

  f = open(output_file, "w")
  f.write("#GEFID= 1, 1, 0\n")
  if has_u2:
      f.write("COLUMN=6\n")
  else:
      f.write("COLUMN=5\n")
  f.write("#COLUMNINFO= 1, m (meter), sondeertrajectlengte, 1\n")
  f.write("#COLUMNINFO= 2, MPa (megaPascal), conusweerstand, 2\n")
  f.write("#COLUMNINFO= 3, m (meter), diepte, 11\n")
  f.write("#COLUMNINFO= 4, MPa (megaPascal), plaatselijke wrijving, 3\n")
  f.write("#COLUMNINFO= 5, % (procent; MPa/MPa), wrijvingsgetal, 4\n")
  if has_u2:
      f.write("#COLUMNINFO= 6, MPa (megaPascal), waterspanning u2, 6\n")
  f.write("#COLUMNSEPARATOR= ;\n")
  f.write("#COLUMNVOID= 1, 999\n")
  f.write("#COLUMNVOID= 2, 999\n")
  f.write("#COLUMNVOID= 3, 999\n")
  f.write("#COLUMNVOID= 4, 999\n")
  f.write("#COLUMNVOID= 5, 999\n")
  if has_u2:
      f.write("#COLUMNVOID= 6, 999\n")
  f.write("#COMPANYID= wordt niet automatisch geconverteerd, -\n")
  f.write(
      f"#FILEDATE= {self.date.year}, {self.date.month:02d}, {self.date.day:02d}\n"
  )
  f.write("#FILEOWNER= Basisregistratie Ondergrond\n")

  f.write(f"#LASTSCAN= {self.data.shape[0]}\n")

  f.write("#PROJECTID= BRO\n")
  f.write("#REPORTCODE= GEF-CPT-Report, 1, 1, 2\n")
  f.write(
      "#STARTDATE= {self.date.year}, {self.date.month:02d}, {self.date.day:02d}\n"
  )
  f.write("#STARTTIME= 12, 00, 00\n")
  f.write(f"#TESTID= {self.testid}\n")
  f.write(f"#XYID= 28992, {self.easting}, {self.northing}\n")
  f.write(f"#ZID= 31000, {self.groundlevel}\n")
  f.write("#EOH=\n")

  # 1 = penetrationLength
  # 2 = coneResistance
  # 3 = depth
  # 4 = localFriction
  # 5 = frictionRatio
  # 6 = optioneel porePressureU2
  for _, row in self.data.iterrows():
      pl = row["penetrationLength"]
      qc = row["coneResistance"]
      de = row["depth"]
      fs = row["localFriction"]
      fr = row["frictionRatio"]
      u2 = row["porePressureU2"]

      if np.isnan(pl):
          pl = 999
      if np.isnan(qc):
          qc = 999
      if np.isnan(de):
          de = 999
      if np.isnan(fs):
          fs = 999
      if np.isnan(fr):
          fr = 999
      if np.isnan(u2):
          u2 = 999

      s = f"{pl:.3f};{qc:.3f};{de:.3f};{fs:.3f};{fr:.1f}"

      if has_u2:
          s += f";{u2:.3f}"

      f.write(f"{s}\n")
  f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment