def initialize_las(path):
    h = header.Header()
    h.dataformat_id = 3
    h.major_version = 1
    h.minor_version = 3
    h.scale = [0.00001, 0.00001, 0.00001]
    f = file.File('pointcloud_classified.las', mode="w", header=h)

    # Classification by name of pcl in input
    for filename in glob.glob(os.path.join(path, '*.ply')):
        print(filename)
        name = filename.split("/")[-1]
        name = name.split(".")[0]
        pathfile = filename

        if name == "rgb":
            setClassification(f, pathfile, 1)
        if name == "ground":
            setClassification(f, pathfile, 2)
        if name == "vegetation":
            setClassification(f, pathfile, 3)
        if name == "road":
            setClassification(f, pathfile, 4)
        if name == "cables":
            setClassification(f, pathfile, 5)
        if name == "building":
            setClassification(f, pathfile, 6)
        if name == "poles":
            setClassification(f, pathfile, 7)
        if name == "anomalies":
            setClassification(f, pathfile, 8)
Ejemplo n.º 2
0
def toSphericalMercator(inputFile,outputFile):
	# Open the LAS file and reproject to Pseudo-Mercator
	# WGS 84 / Pseudo-Mercator -- Spherical Mercator, Google Maps, OpenStreetMap, Bing, ArcGIS, ESRI
	targetProjection = srs.SRS()
	targetProjection.set_userinput('epsg:3857') # Ending projection ( http://epsg.io/3857 )
	inf = file.File(inputFile, header=None, mode='r', in_srs=None , out_srs=targetProjection)
	inh = inf.header

	# If the height is in US Feets scale them into meters
	if (inh.srs.proj4.find('+units=us-ft')):
		scaleZ = 0.3048006096012192

	# Create the out put file. 
	outh = header.Header()
	outh.dataformat_id = 1
	outh.scale = [0.01,0.01,0.01]
	outh.offset = [0.0,0.0,-0.0]
	outsrs = srs.SRS()
	outsrs.set_userinput('epsg:3857')
	outh.srs = outsrs
	outh.schema = inh.schema

	# Open file
	outf = file.File(outputFile, mode='w', header=outh)
	
	# filter the outside the bBox (projected)
	for p in inf:
		p.z = p.z * scaleZ
		outf.write(p)
	outf.close();
Ejemplo n.º 3
0
    def __init__(self, onlybuildings, PlaneImage):
        only_building = file.File(onlybuildings, mode='r')

        # Get the value of bounding box
        height = width = 0
        oldlasnm = onlybuildings
        outputtxt = 'output.txt'

        fout = open(outputtxt, 'w')
        cmd = 'lasinfo ' + oldlasnm + '>' + outputtxt
        subprocess.check_output(cmd, shell=True)
        fout.close()

        rows = [i.split()[2:] for i in open(outputtxt, 'r') if "Bounding" in i]
        box = [i.strip(',') for i in rows[0]]
        minx = float(box[0])
        miny = float(box[1])
        maxx = float(box[2])
        maxy = float(box[3])
        height = int(ceil(maxy - miny))
        width = int(ceil(maxx - minx))
        print(height, width)

        h = header.Header()
        h.dataformat_id = 3
        # h = only_building.header
        print(h.min, h.max)

        lidar_list = [pnt for pnt in only_building]
        im = Image.new('RGB', (height, width))

        for i in range(0, len(lidar_list)):
            temp = lidar_list[i]
            temp.z = 0
            im.putpixel(
                [int(temp.x - minx), int(temp.y - miny)],
                (temp.color.red, temp.color.green, temp.color.blue))
            # im.append((temp.color.red, temp.color.green, temp.color.blue))
            # print(temp.color.red, temp.color.green, temp.color.blue)
            # fw.write(temp)

        # im.putdata([(i.color.red,i.color.green, i.color.blue)
        # for i in lidar_list])
        im.save(PlaneImage)

        print(len(lidar_list))
        # fw.close()
        only_building.close()
Ejemplo n.º 4
0
    def open_output(self):
        h = header.Header()

        prec = 10**-(self.options.precision - 1)
        h.scale = [prec, prec, prec]

        if self.options.offset:
            h.offset = [self.min.x, self.min.y, self.min.z]
            if self.options.verbose:
                print 'using minimum offsets', h.offset

        if self.srs:
            h.srs = self.srs

        output = lasfile.File(self.options.output, mode='w', header=h)
        return output
Ejemplo n.º 5
0
def write_file(version, format):
    h = header.Header()
    h.guid = g
    h.date = datetime.datetime.now()
    h.dataformat_id = format
    h.major_version = 1
    h.minor_version = version
    h.min = [p.x, p.y, p.z]
    h.max = [p.x, p.y, p.z]
    h.point_return_count = [0L, number_of_points, 0L, 0L, 0L, 0L, 0L, 0L]
    h.srs = s
    h.date = p.time

    f = file.File('1.%d_%d.las' % (version, format), mode='w', header=h)
    for i in xrange(number_of_points):
        f.write(p)
    f.close()
Ejemplo n.º 6
0
def cropTile(inputFile, x, y, z):

    # Get the edges of a tile
    south, west, north, east = tileEdges(x, y, z)
    scaleZ = 1.0

    # Open the LAS file and reproject to Pseudo-Mercator
    # WGS 84 / Pseudo-Mercator -- Spherical Mercator, Google Maps, OpenStreetMap, Bing, ArcGIS, ESRI
    targetProjection = srs.SRS()
    targetProjection.set_userinput(
        'epsg:3857')  # Ending projection ( http://epsg.io/3857 )
    inf = file.File(inputFile,
                    header=None,
                    mode='r',
                    in_srs=None,
                    out_srs=targetProjection)
    inh = inf.header

    # If the height is in US Feets scale them into meters
    if (inh.srs.proj4.find('+units=us-ft')):
        scaleZ = 0.3048006096012192

    # Create the out put file.
    outh = header.Header()
    outh.dataformat_id = 1
    outh.scale = [0.01, 0.01, 0.01]
    outh.offset = [0.0, 0.0, -0.0]
    outsrs = srs.SRS()
    outsrs.set_userinput('epsg:3857')
    outh.srs = outsrs
    outh.schema = inh.schema

    # Open file
    outf = file.File(str(int(x)) + '-' + str(int(y)) + '-' + str(int(z)) +
                     '.las',
                     mode='w',
                     header=outh)

    # filter the outside the bBox (projected)
    for p in inf:
        if west <= p.x <= east and south <= p.y <= north:
            p.z = p.z * scaleZ
            outf.write(p)
            print '%.2f,%.2f,%.2f' % (p.x, p.y, p.z)

    outf.close()
Ejemplo n.º 7
0
    def removevegetation(self, newlasfile, oldlasfile, NdviImage):
        h = header.Header()
        h.dataformat_id = 3
        h.minor_version = 1
        ###############################################
        '''get bounding box'''
        ##################################################
        outputtxt = './data/output.txt'

        fout = open(outputtxt, 'a')
        cmd = 'lasinfo ' + oldlasfile + '>' + outputtxt
        subprocess.check_output(cmd, shell=True)
        fout.close()

        rows = [i.split()[2:] for i in open(outputtxt, 'r') if "Bounding" in i]
        box = [i.strip(',') for i in rows[0]]
        minx = float(box[0])
        miny = float(box[1])
        maxx = float(box[2])
        maxy = float(box[3])

        ######################################################

        g = gdal.Open(NdviImage)
        lasfile = file.File(oldlasfile, mode='r')
        newlas = file.File(newlasfile, mode='w', header=h)
        #######################################################
        ndviband = g.ReadAsArray()
        ndviband = np.array(ndviband, dtype=float)
        m = len(ndviband)  # y axe len
        n = len(ndviband[0])  # x axe len

        #######################################################
        # print lastotif(2035311.686,525276.565,minx,miny,maxx,maxy,m,n)
        count = 0
        for p in lasfile:
            xy = self.lastotif(p.x, p.y, minx, miny, maxx, maxy, m, n)
            yval = xy[1]
            xval = xy[0]

            if yval <= m and xval <= n and ndviband[yval - 1][xval - 1] < 0.25:
                newlas.write(p)
                count += 1
        print count
        newlas.close()
Ejemplo n.º 8
0
    def open_output(self):
        self.header = header.Header()
        
        prec = 10**-(self.options.precision-1)
        self.header.scale = [prec, prec, prec]
        
        if self.options.offset:
            h.offset = [self.minx, self.miny, self.minz]
            if self.options.verbose:
                print 'using minimum offsets', h.offset

        self.header.compressed = self.options.compressed
 
        if self.srs:
            self.header.srs = self.srs
        
        self.header.data_format_id = 1
        output = lasfile.File(self.options.output,mode='w',header=self.header)
        return output
Ejemplo n.º 9
0
from liblas import header

h = header.Header()

h.dataformat_id = 1
Ejemplo n.º 10
0
#print panel
startTime = time()
xMin = panel[0] - 5
yMin = panel[1] - 5
zMin = panel[2] - 5
xMax = panel[3] + 5
yMax = panel[4] + 5
zMax = panel[5] + 5

dx = 0.5
dy = 0.5
print "Создание заголовка"
# Запись файла
#from liblas import header
h = header.Header()  # Формируем заголовок
### Support storing time values
h.major_version = 1
h.minor_version = 2
h.dataformat_id = 2
h.min = [xMin, yMin, zMin]
h.max = [xMax, yMax, zMax]
h.scale = [0.01, 0.01, 0.01]
h.offset = [0.0, 0.0, 0.0]
#h.point_records_count =  int(((xMax-xMin)/dx) * ((yMax-yMin)/dy))

#h.project_id =  "00000000-0000-0000-0000-000000000000"
#h.guid =  "00000000-0000-0000-0000-000000000000"
#s.proj4 = ''
print "Запись в файл LAS"
las_file = file.File(name_las + ".las", mode='w',