#!/usr/bin/env python
################################################################################
#    Created by <NAME>                                                 #
#    <EMAIL>                                                  #
################################################################################
import logging
from pointcloud import lasops
from pointcloud.oracle.AbstractLoader import AbstractLoader

# LAS2TXT + SQLLOADER all files to staging table. Then, create blocks globally with R-Tree blocking

class Loader(AbstractLoader):
    def initialize(self):
        # Check parameters for this loader
        if self.numProcessesLoad > 1:
            print 'WARNING: multi-core is not supported! Only used to get PC details. Rest is done with single-core'
        
        if self.blockMethod == 'hilbert':
            raise Exception('ERROR: Hilbert blocking is not supported!')
        
        if self.cUser:
            self.createUser()
        
        # Get the point cloud folder description
        logging.info('Getting files, extent and SRID from input folder ' + self.inputFolder)
        (self.inputFiles, _, _, _, boundingCube, _) = lasops.getPCFolderDetails(self.inputFolder, numProc = self.numProcessesLoad)
        (self.minX, self.minY, _, self.maxX, self.maxY, _) = boundingCube
        
        # Creates connection
        connection = self.getConnection()
        cursor = connection.cursor()
        
        self.flatTable = self.blockTable + '_STAGING'
        
        # Create the flat table
        self.createFlatTable(cursor, self.flatTable, self.tableSpace, self.columns)
        # Create blocks table and base table
        self.createBlocksTable(cursor, self.blockTable, self.tableSpace, self.compression, self.baseTable)
        
        connection.close()

    def process(self):
        logging.info('Starting data loading sequentially from ' + self.inputFolder + ' to ' + self.userName)
        return self.processSingle(self.inputFiles, self.loadFromFile)

    def loadFromFile(self,  index, fileAbsPath):
        self.las2txt_sqlldr(fileAbsPath, self.flatTable, self.columns)

    def close(self):
        connection = self.getConnection()
        cursor = connection.cursor()
        self.populateBlocks(cursor, self.srid, self.minX, self.minY, self.maxX, self.maxY, self.flatTable, self.blockTable, self.baseTable, self.blockSize, self.columns, self.tolerance, self.workTableSpace)
        self.createBlockIdIndex(cursor, self.blockTable, self.indexTableSpace)
        self.computeStatistics(cursor, self.blockTable)
        connection.close()
        
    def size(self):
        return self.sizeBlocks(self.blockTable, self.baseTable)
        
    def getNumPoints(self):
        return self.getNumPointsBlocks(self.blockTable)

#!/usr/bin/env python
################################################################################
#    Created by <NAME>                                                 #
#    <EMAIL>                                                  #
################################################################################
import logging
from pointcloud import lasops
from pointcloud.oracle.AbstractLoader import AbstractLoader

# LAS2TXT + SQLLOADER all files to staging table. Then, create blocks globally with R-Tree blocking

class Loader(AbstractLoader):
    def initialize(self):
        # Check parameters for this loader
        if self.numProcessesLoad > 1:
            print 'WARNING: multi-core is not supported! Only used to get PC details. Rest is done with single-core'
        
        if self.blockMethod == 'hilbert':
            raise Exception('ERROR: Hilbert blocking is not supported!')
        
        if self.cUser:
            self.createUser()
        
        # Get the point cloud folder description
        logging.info('Getting files, extent and SRID from input folder ' + self.inputFolder)
        (self.inputFiles, _, _, _, boundingCube, _) = lasops.getPCFolderDetails(self.inputFolder, numProc = self.numProcessesLoad)
        (self.minX, self.minY, _, self.maxX, self.maxY, _) = boundingCube
        
        # Creates connection
        connection = self.getConnection()
        cursor = connection.cursor()
        
        self.flatTable = self.blockTable + '_STAGING'
        
        # Create the flat table
        self.createFlatTable(cursor, self.flatTable, self.tableSpace, self.columns)
        # Create blocks table and base table
        self.createBlocksTable(cursor, self.blockTable, self.tableSpace, self.compression, self.baseTable)
        
        connection.close()

    def process(self):
        logging.info('Starting data loading sequentially from ' + self.inputFolder + ' to ' + self.userName)
        return self.processSingle(self.inputFiles, self.loadFromFile)

    def loadFromFile(self,  index, fileAbsPath):
        self.las2txt_sqlldr(fileAbsPath, self.flatTable, self.columns)

    def close(self):
        connection = self.getConnection()
        cursor = connection.cursor()
        self.populateBlocks(cursor, self.srid, self.minX, self.minY, self.maxX, self.maxY, self.flatTable, self.blockTable, self.baseTable, self.blockSize, self.columns, self.tolerance, self.workTableSpace)
        self.createBlockIdIndex(cursor, self.blockTable, self.indexTableSpace)
        self.computeStatistics(cursor, self.blockTable)
        connection.close()
        
    def size(self):
        return self.sizeBlocks(self.blockTable, self.baseTable)
        
    def getNumPoints(self):
        return self.getNumPointsBlocks(self.blockTable)

#!/usr/bin/env python ################################################################################ #    Created by <NAME>                                                 # #    <EMAIL>                                                  # ################################################################################ # LAS2TXT + SQLLOADER all files to staging table. Then, create blocks globally with R-Tree blocking # Check parameters for this loader # Get the point cloud folder description # Creates connection # Create the flat table # Create blocks table and base table