Пример #1
0
def convertFile(tilename, inputfolder, outputfolder, filetype):

    inputfile = os.path.join(inputfolder,
                             '{0}.{1}'.format(tilename,
                                              filetype)).replace('\\', '/')
    temp_outputfile = os.path.join(outputfolder,
                                   '{0}.{1}'.format(tilename,
                                                    'las')).replace('\\', '/')
    outputfile = os.path.join(outputfolder,
                              '{0}.{1}'.format(tilename,
                                               filetype)).replace('\\', '/')

    try:
        inFile = File(inputfile, mode='r')

        header = inFile.header

        outfile = File(
            temp_outputfile,
            mode="w",
            header=header,
        )

        outfile.header.offset = [0.0, 0.0, 0.0]

        tic = time.perf_counter()
        X = inFile.get_x_scaled()
        Y = inFile.get_y_scaled()
        Z = inFile.get_z_scaled()
        E, N = transGDA94_to_ArgyleGrid(X, Y)

        outfile.points = inFile.points
        outfile.set_x_scaled(E)
        outfile.set_y_scaled(N)

        print(E, N, Z)

        toc = time.perf_counter()

        outfile.close()

        subprocessargs = [
            'C:/LAStools/bin/las2las.exe', '-i', temp_outputfile, '-olaz',
            '-o', outputfile
        ]
        subprocessargs = list(map(str, subprocessargs))
        p = subprocess.run(subprocessargs,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT,
                           shell=False,
                           check=True,
                           universal_newlines=True)

        log = f"{tilename} : Convertion completed in {toc - tic:0.4f}s"
        print(log)

        if os.path.isfile(outputfile):
            os.remove(temp_outputfile)

        return (True, outputfile, log)

    except:

        log = f"{tilename} : Convertion Failed"
        print(log)
        outfile.close()
        return (False, tilename, log)
def convertFile(tilename, inputfolder, outputfolder, filetype, Xorigin,
                Yorigin, Xoffset, Yoffset, costheta, sintheta):

    inputfile = os.path.join(inputfolder,
                             '{0}.{1}'.format(tilename,
                                              filetype)).replace('\\', '/')
    temp_outputfile = os.path.join(outputfolder,
                                   '{0}.{1}'.format(tilename,
                                                    'las')).replace('\\', '/')
    outputfile = os.path.join(outputfolder,
                              '{0}.{1}'.format(tilename,
                                               filetype)).replace('\\', '/')

    try:
        inFile = File(inputfile, mode='r')

        header = inFile.header
        outfile = File(
            temp_outputfile,
            mode="w",
            header=header,
        )

        tic = time.perf_counter()
        X = inFile.get_x_scaled()
        Y = inFile.get_y_scaled()

        X, Y = Translate(X, Y, -1 * Xorigin, -1 * Yorigin)
        X, Y = Rotate(X, Y, sintheta, costheta)
        X, Y = Translate(X, Y, Xorigin, Yorigin)
        X, Y = Translate(X, Y, Xoffset, Yoffset)

        outfile.points = inFile.points
        outfile.set_x_scaled(X)
        outfile.set_y_scaled(Y)

        toc = time.perf_counter()

        outfile.close()

        subprocessargs = [
            'C:/LAStools/bin/las2las.exe', '-i', temp_outputfile, '-olaz',
            '-o', outputfile
        ]
        subprocessargs = list(map(str, subprocessargs))
        p = subprocess.run(subprocessargs,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT,
                           shell=False,
                           check=True,
                           universal_newlines=True)

        log = f"{tilename} : Convertion completed in {toc - tic:0.4f}s"
        print(log)

        if os.path.isfile(outputfile):
            os.remove(temp_outputfile)

        return (True, outputfile, log)

    except:

        log = f"{tilename} : Convertion Failed"
        print(log)
        outfile.close()
        return (False, tilename, log)
Пример #3
0
def obfuscate_data(tile, inputfolder, originx, originy, rotation, xoffset,
                   yoffset, zoffset, toffset, outputfolder, filetype,
                   outtilename, buffer):
    """Rotate a point around a given point.
    x and y are numpy lists
    """
    tilename = tile.name
    input_file = os.path.join(outputfolder,
                              '{0}.{1}'.format(tilename,
                                               filetype)).replace('\\', '/')
    buffered_file = os.path.join(outputfolder,
                                 '{0}_buff.laz'.format(tilename)).replace(
                                     '\\', '/')
    temp_outputfile = os.path.join(outputfolder,
                                   '{0}.{1}'.format(outtilename,
                                                    'las')).replace('\\', '/')
    outputfile = os.path.join(outputfolder,
                              '{0}.{1}'.format(outtilename,
                                               filetype)).replace('\\', '/')
    log = ''
    try:
        neighbours = tile.getneighbours(buffer)
        neighbourfiles = []
        for fi in neighbours:
            nfi = os.path.join(inputfolder,
                               '{0}.{1}'.format(fi,
                                                filetype)).replace('\\', '/')
            if os.path.isfile(nfi):
                neighbourfiles.append(nfi)

        keep = '-keep_xy {0} {1} {2} {3}'.format(str(tile.xmin - buffer),
                                                 str(tile.ymin - buffer),
                                                 str(tile.xmax + buffer),
                                                 str(tile.ymax + buffer))
        keep = keep.split()

        subprocessargs = [
            'C:/LAStools/bin/las2las.exe', '-i'
        ] + neighbourfiles + ['-olaz', '-o', buffered_file, '-merged'] + keep
        subprocessargs = list(map(str, subprocessargs))
        p = subprocess.run(subprocessargs,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT,
                           shell=False,
                           check=True,
                           universal_newlines=True)

        infile = File(buffered_file, mode='r')

        xvalues = infile.get_x_scaled()
        yvalues = infile.get_y_scaled()
        zvalues = infile.get_z_scaled()
        tvalues = infile.get_gps_time()

        print(
            f"\ntilename={tilename:s} xoffset={xoffset:0.4f} yoffset={yoffset:0.4f} zoffset={zoffset:0.4f} rotation={rotation:0.4f}  toffset={toffset:0.4f}"
        )

        #rotate points
        xvalues, yvalues = rotate_about_origin(xvalues, yvalues,
                                               math.radians(rotation), originx,
                                               originy)
        #print(tilename,xvalues[0],yvalues[0],zvalues[0])
        #offset points
        newxvals = xvalues + xoffset
        newyvals = yvalues + yoffset
        newzvals = zvalues + zoffset
        newtvals = tvalues + toffset

        #print(tilename,newxvals[0],newyvals[0],newzvals[0])
        outfile = File(temp_outputfile, mode="w", header=infile.header)
        outfile.points = infile.points
        outfile.set_x_scaled(newxvals)
        outfile.set_y_scaled(newyvals)
        outfile.set_z_scaled(newzvals)
        outfile.set_gps_time(newtvals)

        outfile.close()
        infile.close()

        subprocessargs = [
            'C:/LAStools/bin/las2las.exe', '-i', temp_outputfile, '-olaz',
            '-o', outputfile
        ]
        subprocessargs = list(map(str, subprocessargs))
        p = subprocess.run(subprocessargs,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT,
                           shell=False,
                           check=True,
                           universal_newlines=True)

        if os.path.isfile(outputfile):
            log = f'Succesfully Obfuscated {tilename}'
            os.remove(temp_outputfile)
            os.remove(buffered_file)

            return (True, outputfile, log)

    except:

        log = f"{tilename} : Obfuscation Failed"
        print(log)
        #outfile.close()
        #infile.close()
        return (False, tilename, log)
Пример #4
0
def convertFile(tilename, inputfolder, xorigin, yorigin, scalar, xshift,
                yshift, outputfolder, filetype):

    inputfile = os.path.join(inputfolder,
                             '{0}.{1}'.format(tilename,
                                              filetype)).replace('\\', '/')
    temp_outputfile = os.path.join(outputfolder,
                                   '{0}.{1}'.format(tilename,
                                                    'las')).replace('\\', '/')
    outputfile = os.path.join(outputfolder,
                              '{0}.{1}'.format(tilename,
                                               filetype)).replace('\\', '/')

    try:
        inFile = File(inputfile, mode='r')

        header = inFile.header
        outfile = File(
            temp_outputfile,
            mode="w",
            header=header,
        )

        tic = time.perf_counter()
        xvalues = inFile.get_x_scaled()
        newxvals = shiftNscale(xvalues, xshift, xorigin, scalar)
        yvalues = inFile.get_y_scaled()
        newyvals = shiftNscale(yvalues, yshift, yorigin, scalar)

        outfile.points = inFile.points
        outfile.set_x_scaled(newxvals)
        outfile.set_y_scaled(newyvals)

        toc = time.perf_counter()

        outfile.close()

        subprocessargs = [
            'C:/LAStools/bin/las2las.exe', '-i', temp_outputfile, '-olaz',
            '-o', outputfile
        ]
        subprocessargs = list(map(str, subprocessargs))
        p = subprocess.run(subprocessargs,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT,
                           shell=False,
                           check=True,
                           universal_newlines=True)

        log = f"{tilename} : Convertion completed in {toc - tic:0.4f}s"
        print(log)

        if os.path.isfile(outputfile):
            os.remove(temp_outputfile)

        return (True, outputfile, log)

    except:

        log = f"{tilename} : Convertion Failed"
        print(log)
        outfile.close()
        return (False, tilename, log)