0

i'm used to writing in C for embedded systems, so python is somewhat new to me. I've built up this script in QGIS script editor following the template. However, when I run the script I get an Access Violation when I get to the output portion of the script.

    #get memory layer output (points in polygons)
    dlayer = resCount.get("OUTPUT")

    #make layer editable
    dlayer.startEditing()

    # build a request to filter the features based on an attribute
    request = QgsFeatureRequest().setFilterExpression('"NUMPOINTS" = 0')

    # we don't need attributes or geometry, skip them to minimize overhead.
    # these lines are not strictly required but improve performance
    request.setSubsetOfAttributes([])
    request.setFlags(QgsFeatureRequest.NoGeometry)

    # loop over the features and delete
    for f in dlayer.getFeatures(request):
        if feedback.isCanceled():
            break

        dlayer.deleteFeature(f.id())

    #commit the changes
    dlayer.commitChanges()

    feedback.pushInfo('Empty hexagons deleted')

    # Return the results of the algorithm. In this case our only result is
    # the feature sink which contains the processed features, but some
    # algorithms may return multiple feature sinks, calculated numeric
    # statistics, etc. These should all be included in the returned
    # dictionary, with keys matching the feature corresponding parameter
    # or output names.
    return {self.OUTPUT: dlayer}

i tried using with edit(dlayer), but i kept getting an "edit is not defined" error and couldn't figure out what i needed to import to make that work.

  • Welcome to GIS SE! As a new user, please be sure to take the short tour to learn about this site's focused Q&A format. I suggest you also edit your question to include a description of what you are trying to accomplish with your code. – Andy Jan 16 at 23:18

Your Answer

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

Browse other questions tagged or ask your own question.