0

I have 2 shapefiles which I need to lap. The first one is city grid, and the second one representing borders of the city. Anyway, my code is:

extent = QgsRectangle()
layers = []
QgsProject.instance().addMapLayer(layerInput)
extent.combineExtentWith(layerInput)
layers.append(layerInput)
QgsProject.instance().addMapLayer(layerInputShape)
extent.combineExtentWith(layerInputShape)
layers.append(layerInputShape)
canvas.setExtent(extent)
canvas.setLayers(layers)

But for some reason it's not working, I didn't get the error message. :/

0

I figured it out! This is the solution. :)

extent = QgsRectangle()
layers = []
QgsProject.instance().addMapLayer(layerInputShape)
extent.combineExtentWith(layerInputShape.extent())
layers.append(layerInputShape)
QgsProject.instance().addMapLayer(layerInput)
extent.combineExtentWith(layerInput.extent())
layers.append(layerInput)

I forgot to call extent method. :/ I was looking for an hour to find the mistake and as soon as I posted this question, I realized what is the mistake. :D

| improve this answer | |

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.