2

I would like to create one-sided buffer geometries around linestrings. I found this ST_SingleSidedBuffer SpatialLite function that I would like to use in my Python script.

When I run the function below, the bufferFeature is empty without throwing any error. Is this because I am using an incorrect syntax or because the ST_functions cannot be run without setting up a database? I am accessing my data with OGR/GDAL functions.

I couldn't find complete examples online to compare my syntax with, only small snippets from GDAL on spatialite SQL functions, as well as further ones that seem to require a database connection: stack exchange: How to use SpatiaLite functions in a Python script?

def createBuffer(self, datasource, layer, bufferDistance, side): 
 [...]
    for feature in layer:
        geometry = feature.GetGeometryRef()

        sqlQuerry = "SELECT ST_SingleSidedBuffer(%s, %.2f , %i) * FROM %s" \
                    % (geometry, bufferDistance, side, layer.GetName())

        bufferFeature = datasource.ExecuteSQL(sqlQuerry, None, 'SQLite')
        #syntax: ExecuteSQL(statement, [spatialFiler], [dialect])
2

Here is the correct syntax with which I was able to create a buffered layer:

def createBuffer(self, datasource, layer, bufferDistance, side): 
 [...]
    for feature in layer:
        geometry = feature.GetGeometryRef()

        bufferLayer = datasource.ExecuteSQL(
        "SELECT ST_SingleSidedBuffer(ST_GeomFromText('%s'), %.2f , %i)" 
        % (geometry, bufferDistance, side), dialect='SQLite')

Thanks @user30184 for pointing out the website in your comment. It seems, I was missing the ST_GeomFromText function, while the FROM statement is not required here. Further, the SQL statement returns a layer not a feature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.