def main(argv):
    args_extensions = set([os.path.splitext(p)[1] for p in sys.argv[1:]])
    if len(argv) != 3 or (args_extensions != set([".osm"]) and args_extensions != set([".zip"])):
        command_line_error("arguments invalides", HELP_MESSAGE)
    inputfile, outputfile = argv[1:3]
    if inputfile.endswith(".zip"):
        osm_zip_remove_associatedstreet(inputfile, outputfile)
    else:
        osm_file_remove_associatedstreet(inputfile, outputfile)
def cadastre_center(argv):
  if ("-h" in argv) or ("-.help" in argv):
      print(HELP_MESSAGE)
  else:
      cadastre = command_line_open_cadastre_website(argv)
      if type(cadastre) in (str,unicode):
        command_line_error(website, HELP_MESSAGE)
      elif cadastre != None:
        lon,lat = getCenter(cadastre)
        print("%f,%f" % (lat, lon))
Beispiel #3
0
def main(argv):
    if len(argv) <= 1: 
        command_line_error(u"pas asser d'argument", HELP_MESSAGE)
    elif argv[1] in ["-h", "-help","--help"]:
        print_help()
    else:
        pdf_filename_list = sys.argv[1:]
        for f in pdf_filename_list:
            if not f.endswith(".pdf"):
                command_line_error(u"l'argument n'est pas un fichier .pdf: " + f)
                return
        pdfs_2_svgs(pdf_filename_list)
Beispiel #4
0
def main(argv):
    if (len(argv) < 2): 
        command_line_error(u"fichier .bbox non spécifié", HELP_MESSAGE)
    bbox_filename_list = sys.argv[1:]
    if bbox_filename_list[-1].endswith(".osm"):
        osm_output = open(bbox_filename_list.pop(),"w")
    else:
        osm_output = sys.stdout
    for f in bbox_filename_list:
        if not f.endswith(".bbox"):
            args_fatal_error("l'argument n'est pas un fichier .bbox: " + f)
        if not os.path.exists(f):
            args_fatal_error("fichier non trouvé: " + f)
    bbox_2_osm_box(bbox_filename_list, osm_output)
def cadastre_2_pdfs(argv):
  i = 1
  ratio=PDF_DOWNLOAD_PIXELS_RATIO
  mode=PDF_DOWNLOAD_SPLIT_MODE
  nb=PDF_DOWNLOAD_SPLIT_NB
  size=PDF_DOWNLOAD_SPLIT_SIZE
  wait=PDF_DOWNALOD_WAIT_SECONDS
  bbox=None
  while i < len(argv):
      if argv[i].startswith("-"):
          if argv[i] in ["-h", "-help","--help"]:
              command_line_error(None, HELP_MESSAGE)
          elif argv[i] in ["-r", "-ratio","--ratio"]:
              ratio = float(argv[i+1])
              del(argv[i:i+2])
          elif argv[i] in ["-s", "-size","--size"]:
              size = int(argv[i+1])
              mode = "SIZE"
              del(argv[i:i+2])
          elif argv[i] in ["-n", "-nb","--nb"]:
              nb = int(argv[i+1])
              mode = "NB"
              del(argv[i:i+2])
          elif argv[i] in ["-w", "-wait","--wait"]:
              wait = float(argv[i+1])
              del(argv[i:i+2])
          elif argv[i] in ["-b", "-bbox","--bbox"]:
              bbox = argv[i+1]
              if not BBOX_OPTION_FORMAT.match(bbox):
                command_line_error(u"paramètre bbox invalide: " + bbox, HELP_MESSAGE)
                return
              bbox = map(float,bbox.split(","))
              del(argv[i:i+2])
          else:
              command_line_error(u"option invalide: " + argv[i], HELP_MESSAGE)
              return
      else:
          i = i + 1
  else:
      cadastreWebsite = command_line_open_cadastre_website(argv)
      if type(cadastreWebsite) in [str, unicode]:
          command_line_error(cadastreWebsite, HELP_MESSAGE)
      elif cadastreWebsite != None:
          code_departement = cadastreWebsite.code_departement
          code_commune = cadastreWebsite.code_commune
          nom_commune = cadastreWebsite.communes[code_commune]
          sys.stderr.write((u"Teléchargement des PDFs de la commune " + code_commune + " : " + nom_commune + "\n").encode("utf-8"))
          sys.stderr.flush()
          write_string_to_file("", code_commune + "-" + nom_commune + ".txt")
          result = []
          for f in download_pdfs(cadastreWebsite, code_departement, code_commune,mode=mode,size=size,nb=nb,ratio=ratio,wait=wait,force_bbox=bbox):
              sys.stdout.write(f)
              sys.stdout.write("\n")
              sys.stdout.flush()
              result.append(f)
          return result
def main(argv):
  args = argv[1:]
  global VERBOSE
  i = 0
  while i < (len(args) - 1):
    if args[i] == "-v":
      VERBOSE=True
      del(args[i])
    else:
      i = i + 1
  if len(args) == 0 or len(args) > 2 or any([arg.startswith("-") for arg in args]):
      command_line_error("wrong argument", HELP_MESSAGE)
  else:
    input_filename = args[0]
    if len(args) > 1:
      output_filename = args[1]
    else:
      name,ext = os.path.splitext(input_filename)
      output_filename = name + "-prediction_segmente" + ext

    if VERBOSE: print "load " + input_filename + " ..."

    osm = OsmParser().parse(input_filename)
    #simplify(osm, 0.2, 0.2, 0.1)

    if VERBOSE: print "transform..."
    inputTransform, outputTransform = get_centered_metric_equirectangular_transformation_from_osm(osm)
    compute_transformed_position_and_annotate(osm, inputTransform)

    if VERBOSE: print "detect..."
    classifier, scaler = load_classifier_and_scaler()
    buildings = get_predicted_segmented_buildings(classifier, scaler, osm)
    if VERBOSE: print " -> ", len(buildings), "cas"

    output_osm = filter_buildings_junction(osm, buildings)
    
    if len(output_osm.nodes) > 0:
        if VERBOSE: print "save ", output_filename 
        OsmWriter(output_osm).write_to_file(output_filename)
    else:
        print "Nothing detected"

    return 0
def main(argv):
    osm_args = [f for f in argv[1:] if os.path.splitext(f)[1] in (".zip", ".osm")]
    other_args = [f for f in argv[1:] if os.path.splitext(f)[1] not in (".zip", ".osm")]
    if len(other_args) != 0:
        command_line_error("invalid argument: " + str(other_args[0]), HELP_MESSAGE)
    if len(osm_args) == 0:
        command_line_error(u"not enough file.osm args", HELP_MESSAGE)

    all_data = []
    all_result = []

    for name, stream in open_zip_and_files_with_extension(osm_args, ".osm"):
        print("load " + name)
        osm = OsmParser().parse_stream(stream)
        inputTransform, outputTransform = get_centered_metric_equirectangular_transformation_from_osm(osm)
        compute_transformed_position_and_annotate(osm, inputTransform)

        data, result = get_segmented_buildings_data(osm)

        print(" -> {0} cas, dont {1} positifs".format(len(result), result.count(1)))
        all_data.extend(data)
        all_result.extend(result)

    scaler, classifier = train(all_data, all_result)
    ext = pickle_extension()
    with open("classifier" + ext, "wb") as f:
        pickle.dump(classifier, f)
    with open("scaler" + ext, "wb") as f:
        pickle.dump(scaler, f)

    #for positive_weight in 1,2,5:
    #    print "-------------------------------------------------------------"
    #    print "Train with scoring for positive segemented building weighted %d over non segmented ones" % positive_weight
    #    scaler, classifier = train(all_data, all_result, weighted_scoring([1,positive_weight]))
    #    with open("classifier_%d.txt" % positive_weight, "w") as f:
    #        f.write(str(classifier))
    #        f.write("\n")
    #    with open("classifier_%d.pickle" % positive_weight, "w") as f:
    #        pickle.dump(classifier, f)
    #    with open("scaler_%d.pickle" % positive_weight, "w") as f:
    #        pickle.dump(scaler, f)

    return 0
def main(argv):
    if len(argv) == 2 and len(argv[1]) == 5:
        prefix = argv[1]
        if os.path.exists(prefix + "-houses-simplifie.osm"):
            segmented_osm_file = prefix + "-houses-simplifie.osm"
        elif os.path.exists(prefix + "-houses.osm"):
            segmented_osm_file = prefix + "-houses.osm"
        else:
            command_line_error("no prefix-houses.osm file found", HELP_MESSAGE)
        if os.path.exists(prefix + "-buildings.osm"):
            corrected_osm_file = prefix + "-buildings.osm"
        else:
            command_line_error("no prefix-buildings.osm file found", HELP_MESSAGE)
        other_args = []
    else:
        osm_args = [f for f in argv[1:] if os.path.splitext(f)[1] == ".osm"]
        if len(osm_args) == 2:
            segmented_osm_file,  corrected_osm_file  = osm_args 
        elif len(osm_args) < 2:
            command_line_error("not enough .osm arguments", HELP_MESSAGE)
        else:
            command_line_error("too many .osm arguments", HELP_MESSAGE)
        other_args = [f for f in argv[1:] if os.path.splitext(f)[1] not in (".osm")]
        if len(other_args) != 0:
            command_line_error("invalid argument: " + other_args[0], HELP_MESSAGE)
        prefix = os.path.commonprefix(osm_args)
    print "load " + segmented_osm_file
    segmented_osm = OsmParser().parse(segmented_osm_file)
    print "load " + corrected_osm_file
    corrected_osm = OsmParser().parse(corrected_osm_file)
    print "find joined buildings"
    joined, unmodified = find_joined_and_unmodified_buildings(segmented_osm, corrected_osm, TOLERANCE)
    #joined_osm     = osm_filter_items(segmented_osm, itertools.chain(*joined))
    #unmodified_osm = osm_filter_items(segmented_osm, unmodified)
    #OsmWriter(joined_osm).write_to_file(os.path.splitext(corrected_osm_file)[0] + "-joined.osm")
    #OsmWriter(unmodified_osm).write_to_file(os.path.splitext(corrected_osm_file)[0] + "-unmodified.osm")
    output_file = os.path.splitext(segmented_osm_file)[0] + "-joined.osm"
    print "save " + output_file
    OsmWriter(segmented_osm).write_to_file(output_file)
    return 0
def main(argv):
    global VERBOSE
    VERBOSE = True
    osm_args = [f for f in argv[1:] if os.path.splitext(f)[1] in (".zip", ".osm")]
    other_args = [f for f in argv[1:] if os.path.splitext(f)[1] not in (".zip", ".osm")]
    if len(other_args) != 0:
        command_line_error("invalid argument: " + other_args[0], HELP_MESSAGE)
    if len(osm_args) == 0:
        command_line_error("not enough file.osm args", HELP_MESSAGE)

    classifier, scaler = load_classifier_and_scaler()

    score = 0

    for name, stream in open_zip_and_files_with_extension(osm_args, ".osm"):
        if VERBOSE: print "load " + name
        input_osm = OsmParser().parse_stream(stream)
        inputTransform, outputTransform = get_centered_metric_equirectangular_transformation_from_osm(input_osm)
        compute_transformed_position_and_annotate(input_osm, inputTransform)

        nb_ok, nb_missed, nb_false, missed_osm, false_osm = test_classifier(classifier, scaler, input_osm)

        if VERBOSE: print nb_ok, "correctly found"

        if len(missed_osm.ways) or nb_missed:
            missed_name = os.path.splitext(name)[0] + "-missed.osm"
            if VERBOSE: print nb_missed, " missed detections, write file", missed_name
            OsmWriter(missed_osm).write_to_file(missed_name)
        if len(false_osm.ways) or nb_false:
            false_name = os.path.splitext(name)[0] + "-false.osm"
            if VERBOSE: print nb_false, " false positives, write file", false_name
            OsmWriter(false_osm).write_to_file(false_name)
        score  += nb_ok * 2 - nb_missed - nb_false*10

    if VERBOSE: print "TOTAL SCORE (ok*3 - missed - false*10):"
    print score
    return 0
def main(argv):
    if (len(argv) < 2): 
        command_line_error(u"fichier .pdf non spécifié", HELP_MESSAGE)
    pdf_filename_list = sys.argv[1:]
    if pdf_filename_list[-1].endswith(".osm"):
        osm_output = open(pdf_filename_list.pop(),"w")
    else:
        osm_output = sys.stdout
    for f in pdf_filename_list:
        if (not f.endswith(".svg")) and (not f.endswith(".pdf")):
            command_line_error(u"l'argument n'est pas un fichier .pdf ou .svg: " + f)
        if not os.path.exists(f):
            command_line_error("fichier non trouvé: " + f)
        bboxfile = f[:-4] + ".bbox"
        if not os.path.exists(bboxfile):
            command_line_error(u"fichier .bbox correspondant non trouvé: " + bboxfile)
    pdf_2_osm_housenumbers(pdf_filename_list, osm_output)
def main(argv):
    if (len(sys.argv) < 2): 
        command_line_error(u"fichier .osm non spécifié", HELP_MESSAGE)
    input_filename = sys.argv[1]
    input_basename = os.path.splitext(os.path.basename(input_filename))[0]
    if len(sys.argv) < 3:
      size = 50
    elif not (sys.argv[2].isdigit()): 
        command_line_error(u"invalid size format", HELP_MESSAGE)
    else:
      size = int(sys.argv[2])
    if len(sys.argv) >= 4:
      output_filename = sys.argv[3]
    else:
      output_filename = os.path.splitext(input_filename)[0] + ("-partition%d.zip" % size)
    if len(sys.argv) > 4:
        command_line_error(u"trop d'arguments", HELP_MESSAGE)
    print "Lecture de " + input_filename
    input_osm = OsmParser().parse(input_filename)
    input_bbox = input_osm.bbox()
    if len(input_osm.ways) > 0 or len(input_osm.relations) > 0:
      command_line_error(u"le fichier %s ne contient pas que des noeuds" % input_filename, HELP_MESSAGE)
    print u"Partitionnement..."
    if (len(input_osm.nodes) > size):
      partitions = partition_osm_nodes(input_osm.nodes.values(), size)
    else:
      partitions = [(input_osm.nodes.values(), input_bbox),]
    print " -> %d partitions" % (len(partitions))
    print "Écriture de " + output_filename
    zip_output = zipfile.ZipFile(output_filename,"w", zipfile.ZIP_DEFLATED)
    index_size = int(math.ceil(math.log10(len(partitions))))
    bboxes = {}
    for i in xrange(len(partitions)):
      nodes, bbox = partitions[i]
      p_name = ("partition_%%0%dd" % index_size) % i
      bboxes[p_name] = BoundingBox(*bbox)
      p_osm = Osm(input_osm.attrs.copy())
      map(p_osm.add_node, nodes)
      s = StringIO()
      OsmWriter(p_osm).write_to_stream(s)
      zip_output.writestr(input_basename + "-" + p_name + ".osm", s.getvalue())
    s = StringIO()
    bbox_2_osm.write_osm_for_boxes(s, BoundingBox(*input_bbox), bboxes)
    zip_output.writestr(input_basename + "-index.osm", s.getvalue())
    zip_output.close()
def main(argv):
  download = True
  merge_addresses = True
  bis = True
  use_external_data = True
  split_result = True
  i = 1
  while i < len(argv):
      if argv[i].startswith("-"):
          if argv[i] in ["-h", "-help","--help"]:
              command_line_error(None, HELP_MESSAGE)
          elif argv[i] in ["-nobis"]:
              bis = False
              del(argv[i:i+1])
          elif argv[i] in ["-nd", "-nodownload"]:
              download = False
              del(argv[i:i+1])
          elif argv[i] in ["-data"]:
              merge_addresses = False
              del(argv[i:i+1])
          elif argv[i] in ["-ne"]:
              use_external_data = False
              del(argv[i:i+1])
          elif argv[i] in ["-nzip"]:
              split_result = False
              del(argv[i:i+1])
          else:
              command_line_error(u"option invalide: " + argv[i], HELP_MESSAGE)
              return
      else:
          i = i + 1
  if len(argv) <= 1:
      command_line_open_cadastre_website(argv)
      return
  elif len(argv) == 2:
      error = command_line_open_cadastre_website(argv)
      if error: command_line_error(error, HELP_MESSAGE)
  elif len(argv) > 3:
      command_line_error(u"trop d'arguments", HELP_MESSAGE)
  else:
      try:
          cadastreWebsite = command_line_open_cadastre_website(argv)
          if type(cadastreWebsite) in [str, unicode]:
              command_line_error(cadastreWebsite)
              return
          else:
              code_departement = cadastreWebsite.code_departement
              code_commune = cadastreWebsite.code_commune
              nom_commune = cadastreWebsite.communes[code_commune]
              write_string_to_file("", code_commune + "-" + nom_commune + ".txt")
      except urllib2.URLError:
          if download:
              command_line_error(u"problème de connexion au site du cadastre", HELP_MESSAGE)
              return
          else:
              sys.stdout.write(u"problème de connexion au site du cadastre\n".encode("utf-8"));
              code_departement = argv[1]
              code_commune = argv[2]
              nom_commune = "inconnu"
      cadastre_2_osm_addresses(cadastreWebsite, code_departement, code_commune,  nom_commune, download, bis, merge_addresses, use_external_data, split_result)