I would like to use the
ST_SingleSidedBuffer SpatiaLite SQL function to create one-sided buffers around all lines in a layer. The following functions works fine, until the 64rd iteration. Then the error
ERROR: Too many connections: max 64 occurs and the variable
bufferLayer is empty. Is there a workaround in order to be able to use the
ST_SingleSidedBuffer function more than 64 times?
I found this related thread that describes the SpatiaLite limitation in more detail.
def createBuffer(self, datasource, layer, bufferDistance, side): # Create memory layer memoryDriver = ogr.GetDriverByName('MEMORY') memoryDatasource = memoryDriver.CreateDataSource('memoryData') memoryLayer = memoryDatasource.CreateLayer('memoryLayer') # Create ID field in memory layer AttributeCalculation.createField(None, memoryLayer, "ID", ogr.OFTInteger, 10, None) # Loop over each feature in input layer for feature in layer: # Read ID and geometry from input feature geometry = feature.GetGeometryRef() IDValue = int(feature.GetField('ID')) # SQL query to create single sided buffers bufferLayer = datasource.ExecuteSQL("SELECT ST_SingleSidedBuffer(ST_GeomFromText('%s'), %.2f , %i)" % (geometry, bufferDistance, side), dialect = 'SQLite') # Add buffer feature to memory layer outFeature = ogr.Feature(memoryLayer.GetLayerDefn()) bufferFeature = bufferLayer.GetFeature(0) bufferGeometry = bufferFeature.GetGeometryRef() outFeature.SetGeometry(bufferGeometry) outFeature.SetField('ID', IDValue) memoryLayer.CreateFeature(outFeature) return memoryLayer