Esempio n. 1
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();
Esempio n. 2
0
    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.minx = None
        self.miny = None
        self.minz = None
        self.maxx = None
        self.maxy = None
        self.maxz = None
        self.count = 0
        self.first_point = True
        self.cloud_column = True
        self.header = None
        self.points = []
        
        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
Esempio n. 3
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()
Esempio n. 4
0
 def get_srid(self, srid):
     cur = self.con.cursor()
     if not srid: return ''
     cur.execute('SELECT WKTEXT,WKTEXT3D from MDSYS.CS_SRS where srid=%d'%(int(srid)))
     res = cur.fetchall()
     for wkt in res:
         text = wkt[0]
         text3d = wkt[1]
         s = srs.SRS()
         if text3d:
             s.wkt = text3d
         else:
             s.wkt = text
         return s
Esempio n. 5
0
def las2ply(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 )
    inFile = file.File(inputFile,
                       header=None,
                       mode='r',
                       in_srs=None,
                       out_srs=targetProjection)

    # Clear file
    open(outputFile, 'w').close()

    plyHeader = '''ply
format ascii 1.0
element vertex ''' + str(inHeader.count) + '''
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
end_header
'''
    newLine = ''
    newFile = open(outputFile, 'w')
    for p in inFile:
        newline = '%.2f %.2f %.2f %i %i %i' % (p.x, p.y, p.z, p.intensity,
                                               p.intensity, p.intensity)
        newFile.write(newline + "\n")
    newFile.close()

    line_prepend(outputFile, plyHeader)
Esempio n. 6
0
    def process(self):
        self.print_options()
        self.connect()

        self.cur = self.con.cursor()
#        self.cur.execute(self.options.sql)
#        clouds = []
#
#        res = self.cur.fetchall()

#        for row in res:
#            for column in row:
#                try:
#                    column.BASE_TABLE_COL
#                    clouds.append(column)
#                except AttributeError:
#                    # This column isn't a cloud
#                    pass

#        points = []
        
        # write an actual cloud column
#        for cloud in clouds:
#            cur2 = self.con.cursor()
#
#            cur2.execute('SELECT NUM_POINTS, POINTS, BLK_EXTENT FROM %s'% cloud.BLK_TABLE)
            
            
#            for num_points, blob, extent in cur2:
#                # set the SRS from the first geometry
#                if not self.srs:
#                    self.srs = self.get_srid(extent.SDO_SRID)
                    
#                b = blob.read()
#                points.append(self.get_points(num_points,b))
        
#        num_pts_index, blob_index = self.get_block_indexes(self.cur)
        
        # if we don't have a cloud object, we'll assume that NUM_POINTS and 
        # the POINTS blob exist in our already queried cursor
        clouds = None
        points = []
        print 'have srs?: %s' % bool(self.srs)

        self.output = self.open_output()

        if not clouds:
            cur = self.cur.execute(self.options.sql)
            num_pts_index, blob_index = self.get_block_indexes(cur)
            for row in cur:
                num_points = row[num_pts_index]
                blob = row[blob_index].read()
                self.write_points(num_points, blob)
                # try to set the SRS
                if not self.srs:
                    for col in row:
                        try:
                            col.SDO_SRID
                            self.srs = self.get_srid(col.SDO_SRID)
                            break
                        except AttributeError:
                            continue
                    
                    # if we still haven't been able to set an SRS, don't try 
                    # to anymore
                    if not self.srs:
                        self.srs = srs.SRS()

        
        self.rewrite_header()
Esempio n. 7
0
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 '

g = guid.GUID(key='8388f1b8-aa1b-4108-bca3-6bc68e7b062e')
number_of_points = 1


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]
Esempio n. 8
0
    def __init__(self, arguments, options=None):
        self.las = None
        self.image = None
        self.output = None
        self.sql = None

        self.opts = options
        self.construct_parser()
        self.options, self.args = self.parser.parse_args(args=arguments)

        if not self.options.image:
            try:
                self.options.image = self.args[1]
                self.options.image = gdal.Open(self.options.image)
            except IndexError:
                raise self.parser.error(
                    "No input image was selected to use for color values!")
            except Exception as inst:
                raise self.parser.error("Unable to open GDAL image: %s" %
                                        inst.args[0])

        if not self.options.bands:
            self.options.bands = (1, 2, 3)
        else:
            self.options.bands = [
                int(i) for i in self.options.bands.split(',')
            ]

        if not self.options.output:
            try:
                self.options.output = self.args[2]
            except IndexError:
                self.options.output = 'output.las'

        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")

        if self.options.target_srs:
            s = srs.SRS()
            s.set_userinput(self.options.target_srs)
            self.options.target_srs = s

        if self.options.assign_srs:
            s = srs.SRS()
            s.set_userinput(self.options.assign_srs)
            self.options.assign_srs = s

        if self.args:
            self.options.las = self.args[0]
            try:
                f = self.options.las
                self.options.las = lasfile.File(f, mode='r')
                if self.options.assign_srs:
                    # if we're assigning an SRS, take the header from the
                    # file, grab it, and then stick our SRS on it and use it
                    # to read the file
                    h = self.options.las.header
                    h.srs = self.options.assign_srs

                    self.options.las = lasfile.File(f, header=h)
            except Exception as inst:
                raise self.parser.error("Unable to open input LAS file: %s" %
                                        inst.args[0])