def __init__(self, arguments, options=None): self.connection = None self.output = None self.sql = None self.opts = options self.construct_parser() self.options, self.args = self.parser.parse_args(args=arguments) if self.args: self.options.connection = self.args[0] if not self.options.output: try: self.options.output = self.args[1] except IndexError: self.options.output = 'output.las' if not self.options.sql: try: self.options.sql = self.args[2] except IndexError: raise self.parser.error( "No SQL was provided to select the point cloud!") if self.options.output: self.options.output = os.path.abspath(self.options.output) if os.path.isdir(self.options.output): raise self.parser.error( "Output '%s' is a directory, not a file " % self.options.output) if os.path.exists(self.options.output): if not self.options.overwrite: raise self.parser.error( "Output file '%s' exists, but you have not selected the --overwrite option" % self.options.output) else: raise self.parser.error("No output was specified") try: self.options.precision = int(self.options.precision) if not self.options.precision: raise self.parser.error("Precision cannot be 0") except: raise self.parser.error("Precision was not an number") self.min = point.Point() self.max = point.Point() self.count = 0 self.first_point = True self.cloud_column = True if self.options.srs: self.srs = srs.SRS() self.srs.set_userinput(self.options.srs) print 'setting srs to %s' % self.srs.proj4 else: self.srs = None
def __init__(self): self.number_of_point_records = (0, ) * 8 self.number_of_returns_of_given_pulse = (0, ) * 8 self.classifications = (0, ) * 32 self.classification_synthetic = 0 self.classification_keypoint = 0 self.classification_withheld = 0 self.min = point.Point() self.max = point.Point()
def get_points(self, num_points, blob): points = [] for i in xrange(num_points): rng = ptsize * i, ptsize * (i + 1) d = struct.unpack(format, blob[ptsize * i:ptsize * (i + 1)]) x, y, z, blk_id, pt_id = d p = point.Point() p.x = x p.y = y p.z = z if self.first_point: self.min.x = p.x self.min.y = p.y self.max.x = p.x self.max.y = p.y self.min.z = p.z self.max.z = p.z self.first_point = False # cumulate min/max for the header self.min.x = min(self.min.x, p.x) self.max.x = max(self.max.x, p.x) self.min.y = min(self.min.y, p.y) self.max.y = max(self.max.y, p.y) self.min.z = min(self.min.z, p.z) self.max.z = max(self.max.z, p.z) self.count += 1 points.append(p) return points
def write_points(self, num_points, blob): # print 'writing block...', num_points if not self.points: for i in xrange(num_points): p = point.Point() p.header = self.header self.points.append(p) if (num_points > len(self.points)): for i in xrange(num_points-len(self.points)): p = point.Point() p.header = self.header self.points.append(p) for i in xrange(num_points): rng = ptsize*i,ptsize*(i+1) d = struct.unpack(format,blob[ptsize*i:ptsize*(i+1)]) x, y, z, time, classification, blk_id, pt_id = d p = self.points[i] p.x = x; p.y = y; p.z = z p.classification = int(classification) p.raw_time = time if self.first_point: self.minx = p.x self.miny = p.y self.maxx = p.x self.maxy = p.y self.minz = p.z self.maxz = p.z self.first_point = False # cumulate min/max for the header self.minx = min(self.minx, p.x) self.maxx = max(self.maxx, p.x) self.miny = min(self.miny, p.y) self.maxy = max(self.maxy, p.y) self.minz = min(self.minz, p.z) self.maxz = max(self.maxz, p.z) self.count += 1 self.output.write(p)
def setClassification(f, path, class_id): file_a = open(path, "r") for line in file_a: tmp = line.split(" ") if "comment" in tmp: continue else: if len(tmp) > 5: pt = point.Point() c = pt.color pt.x, pt.y, pt.z = (float(tmp[0]) * 100000, float(tmp[1]) * 100000, float(tmp[2]) * 100000) c.red, c.green, c.blue = (int(tmp[3]), int(tmp[4]), int(tmp[5])) pt.color = c # if tmp[3:6] == ["204", "153", "0"]: # pt.classification = 2 pt.classification = class_id f.write(pt)
def write_las_file(filePath,header,point): f = file.File('junk.las',mode='w', header= header) pt = point.Point() f.write(pt) f.close()
#!/usr/bin/env python from liblas import file from liblas import header from liblas import point from liblas import color from liblas import srs from liblas import guid import datetime p = point.Point() p.flightline_edge = 0 p.return_number = 1 p.classification = 0 p.scan_angle = -13 p.x = 470692.447538 p.y = 4602888.904642 p.z = 16.0 c = color.Color() c.red = 255 c.green = 12 c.blue = 234 p.color = c p.time = datetime.datetime(2008, 3, 19) p.classification = 2 p.return_number = 2 s = srs.SRS() s.proj4 = '+proj=utm +zone=15 +ellps=NAD83 +datum=NAD83 +units=m +no_defs '
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', header=h) # Открыли файл на запись с заголовком x = xMin cnt = 0 while x <= xMax: y = yMin while y <= yMax: z = GetZ(x, y) #print [x,y,z] pt = point.Point() pt.x = x pt.y = y pt.z = z las_file.write(pt) # write point to las cnt = cnt + 1 y = y + dy #print cnt x = x + dx las_file.close() print "Создали файл LAS за ", time() - startTime, "сек. Число точек = ", cnt