I am writing a simple plugin that finds buffer. My gui has 2 combo box and 1 Line edit. The first combo box will have a drop down of values from column 'States' and 2nd combo will have a drop down of values from column 'Cities'. Note that the Cities will be filtered in the combo box depending on the states selected. And 3rd Lineedit gets a distance from the user. As a result, I want buffer for the cities (from the 2nd combo box) with the user specified 'distance value' given in the lineedit box.I tried QgsGeometryAnalyzer().buffer() function in QGIS API. But the first argument is a layer for the above mentioned function. Instead i want my gui to take value from the city combo and lineedit and find buffer. How to accomplish. Sorry for the lengthy post.
Answer
I think this can help you:
# Get buffer distance and selected city
dist = float( myLineEdit.text() )
city = myComboBo.currentText()
# Get the feature corresponding to the selected city
expr = QgsExpression('"Cities" = \'' + city + '\'' )
it = myLayer.getFeatures( QgsFeatureRequest( expr ) )
feature = it.next()
# Perform a buffer on the feature geometry
myBufferPolygon = feature.geometry().buffer(dist, 50)
Then you could use the myBufferPolygon
to create a new feature and store it in another vector layer or something like that.
No comments:
Post a Comment