Converting QgsRaster object to arrayHow to fully load a raster into a numpy array?Converting Matplotlib contour objects to Shapely objectsUsing QgsRasterCalculatorhow to transfer a geotif with WGS84 to a mercator array for ploting it with matplotlib.basemapRendering shapefiles (.shp) to TIF with labels?Render QgsRasterLayer without adding to legendOverriding method of qgis object does not workImporting numpy array into QGIS?GDAL raster calculator does not create NDVI using PyQGIS?Convert floats array to rasterPython Scripting in QGIS to add features and select them?
Why doesn't H₄O²⁺ exist?
Important Resources for Dark Age Civilizations?
A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?
Theorems that impeded progress
How is it possible to have an ability score that is less than 3?
Why is Minecraft giving an OpenGL error?
How old can references or sources in a thesis be?
Why can't I see bouncing of switch on oscilloscope screen?
Revoked SSL certificate
How much of data wrangling is a data scientist's job?
Languages that we cannot (dis)prove to be Context-Free
Why doesn't a class having private constructor prevent inheriting from this class? How to control which classes can inherit from a certain base?
A case of the sniffles
What typically incentivizes a professor to change jobs to a lower ranking university?
meaning of に in 本当に?
Why is consensus so controversial in Britain?
how to check a propriety using r studio
What would happen to a modern skyscraper if it rains micro blackholes?
How to format long polynomial?
What is the word for reserving something for yourself before others do?
Replacing matching entries in one column of a file by another column from a different file
Does detail obscure or enhance action?
Why are electrically insulating heatsinks so rare? Is it just cost?
High voltage LED indicator 40-1000 VDC without additional power supply
Converting QgsRaster object to array
How to fully load a raster into a numpy array?Converting Matplotlib contour objects to Shapely objectsUsing QgsRasterCalculatorhow to transfer a geotif with WGS84 to a mercator array for ploting it with matplotlib.basemapRendering shapefiles (.shp) to TIF with labels?Render QgsRasterLayer without adding to legendOverriding method of qgis object does not workImporting numpy array into QGIS?GDAL raster calculator does not create NDVI using PyQGIS?Convert floats array to rasterPython Scripting in QGIS to add features and select them?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
So I'm a newbie, so sorry if this is an idiot question.
I'm trying to write a plugin for QGIS3 for my organisation, and I'd like to output a standalone figure (i.e. not in the QGIS window) as the final output. This way I can show rasters, line plots and vectors, in multiple subplots in a single figure and the user can save the figure directly if they want to.
I'm using Matplotlib as that's already available in pyQGIS, so I want to stick with that for logistic reasons.
My problem is that I have some nice QgsRasterLayer rasters (and QgsVectorLayer vectors too) that I'd like to display as some of the subplots but I don't know how to convert them into a form suitable display in Matplotlib. I can display them into the main QGIS window but that's not what I'm after. I need to plot them with Matplotlib.
Can anyone give me some suggestions? It's probably really obvious, but I'm just not finding the solution as my python experience is limited.
pyqgis matplotlib
New contributor
SJJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
So I'm a newbie, so sorry if this is an idiot question.
I'm trying to write a plugin for QGIS3 for my organisation, and I'd like to output a standalone figure (i.e. not in the QGIS window) as the final output. This way I can show rasters, line plots and vectors, in multiple subplots in a single figure and the user can save the figure directly if they want to.
I'm using Matplotlib as that's already available in pyQGIS, so I want to stick with that for logistic reasons.
My problem is that I have some nice QgsRasterLayer rasters (and QgsVectorLayer vectors too) that I'd like to display as some of the subplots but I don't know how to convert them into a form suitable display in Matplotlib. I can display them into the main QGIS window but that's not what I'm after. I need to plot them with Matplotlib.
Can anyone give me some suggestions? It's probably really obvious, but I'm just not finding the solution as my python experience is limited.
pyqgis matplotlib
New contributor
SJJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Is it possible for you to use gdal or rasterio? I found some answers here: gis.stackexchange.com/questions/32995/…. This exports the data to a numpy array, which matplotlib understands.
– Andreas Müller
2 days ago
Thanks - yes GDAL is possible, but I need the rasters in a QgsRasterLayer and display them in the main QGIS interface. That part is all ok. But if I took a GDAL approach I assume I'd have to open them a second time, which seems inelegant. Or have I got that wrong? I suspect the answer lies somewhere in QgsRasterLayer.dataProvider.block but so far it's still escaping me.
– SJJ
2 days ago
add a comment |
So I'm a newbie, so sorry if this is an idiot question.
I'm trying to write a plugin for QGIS3 for my organisation, and I'd like to output a standalone figure (i.e. not in the QGIS window) as the final output. This way I can show rasters, line plots and vectors, in multiple subplots in a single figure and the user can save the figure directly if they want to.
I'm using Matplotlib as that's already available in pyQGIS, so I want to stick with that for logistic reasons.
My problem is that I have some nice QgsRasterLayer rasters (and QgsVectorLayer vectors too) that I'd like to display as some of the subplots but I don't know how to convert them into a form suitable display in Matplotlib. I can display them into the main QGIS window but that's not what I'm after. I need to plot them with Matplotlib.
Can anyone give me some suggestions? It's probably really obvious, but I'm just not finding the solution as my python experience is limited.
pyqgis matplotlib
New contributor
SJJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
So I'm a newbie, so sorry if this is an idiot question.
I'm trying to write a plugin for QGIS3 for my organisation, and I'd like to output a standalone figure (i.e. not in the QGIS window) as the final output. This way I can show rasters, line plots and vectors, in multiple subplots in a single figure and the user can save the figure directly if they want to.
I'm using Matplotlib as that's already available in pyQGIS, so I want to stick with that for logistic reasons.
My problem is that I have some nice QgsRasterLayer rasters (and QgsVectorLayer vectors too) that I'd like to display as some of the subplots but I don't know how to convert them into a form suitable display in Matplotlib. I can display them into the main QGIS window but that's not what I'm after. I need to plot them with Matplotlib.
Can anyone give me some suggestions? It's probably really obvious, but I'm just not finding the solution as my python experience is limited.
pyqgis matplotlib
pyqgis matplotlib
New contributor
SJJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SJJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Apr 2 at 11:13
J. Monticolo
1,397217
1,397217
New contributor
SJJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Apr 2 at 9:24
SJJSJJ
62
62
New contributor
SJJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
SJJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
SJJ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Is it possible for you to use gdal or rasterio? I found some answers here: gis.stackexchange.com/questions/32995/…. This exports the data to a numpy array, which matplotlib understands.
– Andreas Müller
2 days ago
Thanks - yes GDAL is possible, but I need the rasters in a QgsRasterLayer and display them in the main QGIS interface. That part is all ok. But if I took a GDAL approach I assume I'd have to open them a second time, which seems inelegant. Or have I got that wrong? I suspect the answer lies somewhere in QgsRasterLayer.dataProvider.block but so far it's still escaping me.
– SJJ
2 days ago
add a comment |
Is it possible for you to use gdal or rasterio? I found some answers here: gis.stackexchange.com/questions/32995/…. This exports the data to a numpy array, which matplotlib understands.
– Andreas Müller
2 days ago
Thanks - yes GDAL is possible, but I need the rasters in a QgsRasterLayer and display them in the main QGIS interface. That part is all ok. But if I took a GDAL approach I assume I'd have to open them a second time, which seems inelegant. Or have I got that wrong? I suspect the answer lies somewhere in QgsRasterLayer.dataProvider.block but so far it's still escaping me.
– SJJ
2 days ago
Is it possible for you to use gdal or rasterio? I found some answers here: gis.stackexchange.com/questions/32995/…. This exports the data to a numpy array, which matplotlib understands.
– Andreas Müller
2 days ago
Is it possible for you to use gdal or rasterio? I found some answers here: gis.stackexchange.com/questions/32995/…. This exports the data to a numpy array, which matplotlib understands.
– Andreas Müller
2 days ago
Thanks - yes GDAL is possible, but I need the rasters in a QgsRasterLayer and display them in the main QGIS interface. That part is all ok. But if I took a GDAL approach I assume I'd have to open them a second time, which seems inelegant. Or have I got that wrong? I suspect the answer lies somewhere in QgsRasterLayer.dataProvider.block but so far it's still escaping me.
– SJJ
2 days ago
Thanks - yes GDAL is possible, but I need the rasters in a QgsRasterLayer and display them in the main QGIS interface. That part is all ok. But if I took a GDAL approach I assume I'd have to open them a second time, which seems inelegant. Or have I got that wrong? I suspect the answer lies somewhere in QgsRasterLayer.dataProvider.block but so far it's still escaping me.
– SJJ
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
Barry Rowlingson build an plugin for QGIS2 called "Rasterlang" (https://www.maths.lancs.ac.uk/~rowlings/Software/Qgis/Plugins/rasterlang/), inside there is a modul named layers.py with a function called layerAsArray():
def layerAsArray(layer):
""" read the data from a single-band layer into a numpy/Numeric array.
Only works for gdal layers!
"""
gd = gdal.Open(str(layer.source()))
array = gd.ReadAsArray()
return array
Like you I was concerned about loading data twice, but didn't see a way through QgsRasterLayer. Provider seems to be always gdal, but you can't "cast" it back and use ReadAsArray() on the provider.
Ok thanks - am re-assured that others have struggled with the same problem. It's not just me then. As some of my rasters are large I am concerned about the time and memory implications of loading twice. But if its the only route, then it's the one I will take although I remain open to other suggestions. Thank you for your kind help. Sarj
– SJJ
2 days ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
SJJ is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317464%2fconverting-qgsraster-object-to-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Barry Rowlingson build an plugin for QGIS2 called "Rasterlang" (https://www.maths.lancs.ac.uk/~rowlings/Software/Qgis/Plugins/rasterlang/), inside there is a modul named layers.py with a function called layerAsArray():
def layerAsArray(layer):
""" read the data from a single-band layer into a numpy/Numeric array.
Only works for gdal layers!
"""
gd = gdal.Open(str(layer.source()))
array = gd.ReadAsArray()
return array
Like you I was concerned about loading data twice, but didn't see a way through QgsRasterLayer. Provider seems to be always gdal, but you can't "cast" it back and use ReadAsArray() on the provider.
Ok thanks - am re-assured that others have struggled with the same problem. It's not just me then. As some of my rasters are large I am concerned about the time and memory implications of loading twice. But if its the only route, then it's the one I will take although I remain open to other suggestions. Thank you for your kind help. Sarj
– SJJ
2 days ago
add a comment |
Barry Rowlingson build an plugin for QGIS2 called "Rasterlang" (https://www.maths.lancs.ac.uk/~rowlings/Software/Qgis/Plugins/rasterlang/), inside there is a modul named layers.py with a function called layerAsArray():
def layerAsArray(layer):
""" read the data from a single-band layer into a numpy/Numeric array.
Only works for gdal layers!
"""
gd = gdal.Open(str(layer.source()))
array = gd.ReadAsArray()
return array
Like you I was concerned about loading data twice, but didn't see a way through QgsRasterLayer. Provider seems to be always gdal, but you can't "cast" it back and use ReadAsArray() on the provider.
Ok thanks - am re-assured that others have struggled with the same problem. It's not just me then. As some of my rasters are large I am concerned about the time and memory implications of loading twice. But if its the only route, then it's the one I will take although I remain open to other suggestions. Thank you for your kind help. Sarj
– SJJ
2 days ago
add a comment |
Barry Rowlingson build an plugin for QGIS2 called "Rasterlang" (https://www.maths.lancs.ac.uk/~rowlings/Software/Qgis/Plugins/rasterlang/), inside there is a modul named layers.py with a function called layerAsArray():
def layerAsArray(layer):
""" read the data from a single-band layer into a numpy/Numeric array.
Only works for gdal layers!
"""
gd = gdal.Open(str(layer.source()))
array = gd.ReadAsArray()
return array
Like you I was concerned about loading data twice, but didn't see a way through QgsRasterLayer. Provider seems to be always gdal, but you can't "cast" it back and use ReadAsArray() on the provider.
Barry Rowlingson build an plugin for QGIS2 called "Rasterlang" (https://www.maths.lancs.ac.uk/~rowlings/Software/Qgis/Plugins/rasterlang/), inside there is a modul named layers.py with a function called layerAsArray():
def layerAsArray(layer):
""" read the data from a single-band layer into a numpy/Numeric array.
Only works for gdal layers!
"""
gd = gdal.Open(str(layer.source()))
array = gd.ReadAsArray()
return array
Like you I was concerned about loading data twice, but didn't see a way through QgsRasterLayer. Provider seems to be always gdal, but you can't "cast" it back and use ReadAsArray() on the provider.
answered 2 days ago
Andreas MüllerAndreas Müller
1,633613
1,633613
Ok thanks - am re-assured that others have struggled with the same problem. It's not just me then. As some of my rasters are large I am concerned about the time and memory implications of loading twice. But if its the only route, then it's the one I will take although I remain open to other suggestions. Thank you for your kind help. Sarj
– SJJ
2 days ago
add a comment |
Ok thanks - am re-assured that others have struggled with the same problem. It's not just me then. As some of my rasters are large I am concerned about the time and memory implications of loading twice. But if its the only route, then it's the one I will take although I remain open to other suggestions. Thank you for your kind help. Sarj
– SJJ
2 days ago
Ok thanks - am re-assured that others have struggled with the same problem. It's not just me then. As some of my rasters are large I am concerned about the time and memory implications of loading twice. But if its the only route, then it's the one I will take although I remain open to other suggestions. Thank you for your kind help. Sarj
– SJJ
2 days ago
Ok thanks - am re-assured that others have struggled with the same problem. It's not just me then. As some of my rasters are large I am concerned about the time and memory implications of loading twice. But if its the only route, then it's the one I will take although I remain open to other suggestions. Thank you for your kind help. Sarj
– SJJ
2 days ago
add a comment |
SJJ is a new contributor. Be nice, and check out our Code of Conduct.
SJJ is a new contributor. Be nice, and check out our Code of Conduct.
SJJ is a new contributor. Be nice, and check out our Code of Conduct.
SJJ is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f317464%2fconverting-qgsraster-object-to-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is it possible for you to use gdal or rasterio? I found some answers here: gis.stackexchange.com/questions/32995/…. This exports the data to a numpy array, which matplotlib understands.
– Andreas Müller
2 days ago
Thanks - yes GDAL is possible, but I need the rasters in a QgsRasterLayer and display them in the main QGIS interface. That part is all ok. But if I took a GDAL approach I assume I'd have to open them a second time, which seems inelegant. Or have I got that wrong? I suspect the answer lies somewhere in QgsRasterLayer.dataProvider.block but so far it's still escaping me.
– SJJ
2 days ago