GDAL/OGR to extract pixel valuesRunning a Python script to extract raster data in QGISGetting pixel value of GDAL raster under OGR point without NumPy?Determining if shapefile and raster overlap in Python using OGR/GDAL?Extract raster values gdal looping rastersCreate new shapefile based on values ranges in existing shapefile using gdal/ogr/pythonProblem intersecting shapefiles with OGR in PythonGDAL/OGR ogr.Layer.Intersection fails when producing mixed geometry resultsCreate ShapeFile from CSV Using OGR and PythonRasterizing Shapefile with attribute value as pixel value with GDAL in PythonExtract raster values within shapefile with pygeoprocessing or gdalCut shapefile to raster in Python using GDAL/OGR
Anagram holiday
Stopping power of mountain vs road bike
Why do I get two different answers for this counting problem?
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
CEO ridiculed me with gay jokes and grabbed me and wouldn't let go - now getting pushed out of company
Brothers & sisters
Do I have a twin with permutated remainders?
Is the Joker left-handed?
Is it legal for company to use my work email to pretend I still work there?
How could indestructible materials be used in power generation?
Would Slavery Reparations be considered Bills of Attainder and hence Illegal?
1960's book about a plague that kills all white people
What is a clear way to write a bar that has an extra beat?
Why are electrically insulating heatsinks so rare? Is it just cost?
What is the most common color to indicate the input-field is disabled?
Assassin's bullet with mercury
Why is Collection not simply treated as Collection<?>
What about the virus in 12 Monkeys?
Were any external disk drives stacked vertically?
Did Shadowfax go to Valinor?
Forgetting the musical notes while performing in concert
90's TV series where a boy goes to another dimension through portal near power lines
Why doesn't using multiple commands with a || or && conditional work?
What is the word for reserving something for yourself before others do?
GDAL/OGR to extract pixel values
Running a Python script to extract raster data in QGISGetting pixel value of GDAL raster under OGR point without NumPy?Determining if shapefile and raster overlap in Python using OGR/GDAL?Extract raster values gdal looping rastersCreate new shapefile based on values ranges in existing shapefile using gdal/ogr/pythonProblem intersecting shapefiles with OGR in PythonGDAL/OGR ogr.Layer.Intersection fails when producing mixed geometry resultsCreate ShapeFile from CSV Using OGR and PythonRasterizing Shapefile with attribute value as pixel value with GDAL in PythonExtract raster values within shapefile with pygeoprocessing or gdalCut shapefile to raster in Python using GDAL/OGR
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to use GDAL/OGR to extract pixel values from a raster file. The extraction should be based on polygons, stored in a shapefile. My thought was to iterate over the features in the shapefile, extract the pixel values of those pixels that have there center point within the polygon and calculate a percentile from those values. When this is done I want to write the calculated percentile back to the polygon and go on with the next polygon.
Iterating over the polygons is easy, but what I do not get is how to extract the pixel values from the pixels, covered by the polygon.
I'm using Python.
Could somebody help me at this point?
python gdal ogr
|
show 1 more comment
I want to use GDAL/OGR to extract pixel values from a raster file. The extraction should be based on polygons, stored in a shapefile. My thought was to iterate over the features in the shapefile, extract the pixel values of those pixels that have there center point within the polygon and calculate a percentile from those values. When this is done I want to write the calculated percentile back to the polygon and go on with the next polygon.
Iterating over the polygons is easy, but what I do not get is how to extract the pixel values from the pixels, covered by the polygon.
I'm using Python.
Could somebody help me at this point?
python gdal ogr
If I iterate over the features and while one is 'selected', can I call the GetExtent function of the shapefile layer and will the returned extent only represent the extent of the current feature?
– Thomas Becker
Aug 13 '13 at 11:37
1
It sounds as though you are wanting to do zonal statistics. Have a look at gis.stackexchange.com/questions/43748/…"
– MappaGnosis
Aug 13 '13 at 11:56
@MappaGnosis That version of zonal stats appears extremely limited; I see no evidence from the documentation that it computes percentiles. Do you know of a zonal stats solution for QGIS that does compute specified percentiles by zone?
– whuber♦
Aug 13 '13 at 15:13
1
alright, the percentile is no problem for me since I had to define a function for it anyway. My issue goes with the Python coding using GDAL/OGR... I'm used to do the stuff using ArcGIS and their Python classes. However, it takes ages and in the end the script is crashing. So, I'm on my way to re-write the script without arcpy. Can anybody point me to some code snippet where I can learn on how to do the stuff?
– Thomas Becker
Aug 13 '13 at 16:04
1
@WHuber Offhand I don't know of a more extensive Zonal Stats Plugin for QGIS. However, my link was meant to point to the programmed Python + GDAL solution in my reply in that thread. My example there is just looking at getting the minimum value, but being a programmed solution, it shouldn't be too hard to extend it a bit to calculate percentiles of the zone data. Instead of going for the 'easy statistics' options there is also a scipy.ndimage.filters.percentile_filter function available.
– MappaGnosis
Aug 14 '13 at 15:07
|
show 1 more comment
I want to use GDAL/OGR to extract pixel values from a raster file. The extraction should be based on polygons, stored in a shapefile. My thought was to iterate over the features in the shapefile, extract the pixel values of those pixels that have there center point within the polygon and calculate a percentile from those values. When this is done I want to write the calculated percentile back to the polygon and go on with the next polygon.
Iterating over the polygons is easy, but what I do not get is how to extract the pixel values from the pixels, covered by the polygon.
I'm using Python.
Could somebody help me at this point?
python gdal ogr
I want to use GDAL/OGR to extract pixel values from a raster file. The extraction should be based on polygons, stored in a shapefile. My thought was to iterate over the features in the shapefile, extract the pixel values of those pixels that have there center point within the polygon and calculate a percentile from those values. When this is done I want to write the calculated percentile back to the polygon and go on with the next polygon.
Iterating over the polygons is easy, but what I do not get is how to extract the pixel values from the pixels, covered by the polygon.
I'm using Python.
Could somebody help me at this point?
python gdal ogr
python gdal ogr
edited Jun 6 '16 at 2:44
PolyGeo♦
53.9k1781245
53.9k1781245
asked Aug 13 '13 at 10:57
Thomas BeckerThomas Becker
577719
577719
If I iterate over the features and while one is 'selected', can I call the GetExtent function of the shapefile layer and will the returned extent only represent the extent of the current feature?
– Thomas Becker
Aug 13 '13 at 11:37
1
It sounds as though you are wanting to do zonal statistics. Have a look at gis.stackexchange.com/questions/43748/…"
– MappaGnosis
Aug 13 '13 at 11:56
@MappaGnosis That version of zonal stats appears extremely limited; I see no evidence from the documentation that it computes percentiles. Do you know of a zonal stats solution for QGIS that does compute specified percentiles by zone?
– whuber♦
Aug 13 '13 at 15:13
1
alright, the percentile is no problem for me since I had to define a function for it anyway. My issue goes with the Python coding using GDAL/OGR... I'm used to do the stuff using ArcGIS and their Python classes. However, it takes ages and in the end the script is crashing. So, I'm on my way to re-write the script without arcpy. Can anybody point me to some code snippet where I can learn on how to do the stuff?
– Thomas Becker
Aug 13 '13 at 16:04
1
@WHuber Offhand I don't know of a more extensive Zonal Stats Plugin for QGIS. However, my link was meant to point to the programmed Python + GDAL solution in my reply in that thread. My example there is just looking at getting the minimum value, but being a programmed solution, it shouldn't be too hard to extend it a bit to calculate percentiles of the zone data. Instead of going for the 'easy statistics' options there is also a scipy.ndimage.filters.percentile_filter function available.
– MappaGnosis
Aug 14 '13 at 15:07
|
show 1 more comment
If I iterate over the features and while one is 'selected', can I call the GetExtent function of the shapefile layer and will the returned extent only represent the extent of the current feature?
– Thomas Becker
Aug 13 '13 at 11:37
1
It sounds as though you are wanting to do zonal statistics. Have a look at gis.stackexchange.com/questions/43748/…"
– MappaGnosis
Aug 13 '13 at 11:56
@MappaGnosis That version of zonal stats appears extremely limited; I see no evidence from the documentation that it computes percentiles. Do you know of a zonal stats solution for QGIS that does compute specified percentiles by zone?
– whuber♦
Aug 13 '13 at 15:13
1
alright, the percentile is no problem for me since I had to define a function for it anyway. My issue goes with the Python coding using GDAL/OGR... I'm used to do the stuff using ArcGIS and their Python classes. However, it takes ages and in the end the script is crashing. So, I'm on my way to re-write the script without arcpy. Can anybody point me to some code snippet where I can learn on how to do the stuff?
– Thomas Becker
Aug 13 '13 at 16:04
1
@WHuber Offhand I don't know of a more extensive Zonal Stats Plugin for QGIS. However, my link was meant to point to the programmed Python + GDAL solution in my reply in that thread. My example there is just looking at getting the minimum value, but being a programmed solution, it shouldn't be too hard to extend it a bit to calculate percentiles of the zone data. Instead of going for the 'easy statistics' options there is also a scipy.ndimage.filters.percentile_filter function available.
– MappaGnosis
Aug 14 '13 at 15:07
If I iterate over the features and while one is 'selected', can I call the GetExtent function of the shapefile layer and will the returned extent only represent the extent of the current feature?
– Thomas Becker
Aug 13 '13 at 11:37
If I iterate over the features and while one is 'selected', can I call the GetExtent function of the shapefile layer and will the returned extent only represent the extent of the current feature?
– Thomas Becker
Aug 13 '13 at 11:37
1
1
It sounds as though you are wanting to do zonal statistics. Have a look at gis.stackexchange.com/questions/43748/…"
– MappaGnosis
Aug 13 '13 at 11:56
It sounds as though you are wanting to do zonal statistics. Have a look at gis.stackexchange.com/questions/43748/…"
– MappaGnosis
Aug 13 '13 at 11:56
@MappaGnosis That version of zonal stats appears extremely limited; I see no evidence from the documentation that it computes percentiles. Do you know of a zonal stats solution for QGIS that does compute specified percentiles by zone?
– whuber♦
Aug 13 '13 at 15:13
@MappaGnosis That version of zonal stats appears extremely limited; I see no evidence from the documentation that it computes percentiles. Do you know of a zonal stats solution for QGIS that does compute specified percentiles by zone?
– whuber♦
Aug 13 '13 at 15:13
1
1
alright, the percentile is no problem for me since I had to define a function for it anyway. My issue goes with the Python coding using GDAL/OGR... I'm used to do the stuff using ArcGIS and their Python classes. However, it takes ages and in the end the script is crashing. So, I'm on my way to re-write the script without arcpy. Can anybody point me to some code snippet where I can learn on how to do the stuff?
– Thomas Becker
Aug 13 '13 at 16:04
alright, the percentile is no problem for me since I had to define a function for it anyway. My issue goes with the Python coding using GDAL/OGR... I'm used to do the stuff using ArcGIS and their Python classes. However, it takes ages and in the end the script is crashing. So, I'm on my way to re-write the script without arcpy. Can anybody point me to some code snippet where I can learn on how to do the stuff?
– Thomas Becker
Aug 13 '13 at 16:04
1
1
@WHuber Offhand I don't know of a more extensive Zonal Stats Plugin for QGIS. However, my link was meant to point to the programmed Python + GDAL solution in my reply in that thread. My example there is just looking at getting the minimum value, but being a programmed solution, it shouldn't be too hard to extend it a bit to calculate percentiles of the zone data. Instead of going for the 'easy statistics' options there is also a scipy.ndimage.filters.percentile_filter function available.
– MappaGnosis
Aug 14 '13 at 15:07
@WHuber Offhand I don't know of a more extensive Zonal Stats Plugin for QGIS. However, my link was meant to point to the programmed Python + GDAL solution in my reply in that thread. My example there is just looking at getting the minimum value, but being a programmed solution, it shouldn't be too hard to extend it a bit to calculate percentiles of the zone data. Instead of going for the 'easy statistics' options there is also a scipy.ndimage.filters.percentile_filter function available.
– MappaGnosis
Aug 14 '13 at 15:07
|
show 1 more comment
1 Answer
1
active
oldest
votes
Your question defines a complex process which is difficult to help with all of it. Here, I will suggest something that might help with the part getting the raster data using the vector.
Refer to this: http://machinalis8.rssing.com/chan-51920729/latest.php#item3
In that blog post I rasterize vector data to subset pixels from an image.
The idea there is that you convert the vector data into a raster, like a mask. Then, using numpy, you use that mask to filter or choose the pixels in the raster.
You may need to check the part about "the center of the pixel" fallin within the poligon: it will depend on GDAL's implementation of RasterizeLayer.
Next, you can do the rest of the calculations.
3
+1 Nice use of random forests in your example. It would be helpful to include an example on this site in the event that the link goes away.
– Aaron♦
Mar 15 '16 at 23:15
That link doesn't work anymore sadly
– Cam
Mar 28 at 12:45
1
@cam link fixed to an archive version
– Akhorus
Apr 1 at 21:21
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
);
);
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%2f68562%2fgdal-ogr-to-extract-pixel-values%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
Your question defines a complex process which is difficult to help with all of it. Here, I will suggest something that might help with the part getting the raster data using the vector.
Refer to this: http://machinalis8.rssing.com/chan-51920729/latest.php#item3
In that blog post I rasterize vector data to subset pixels from an image.
The idea there is that you convert the vector data into a raster, like a mask. Then, using numpy, you use that mask to filter or choose the pixels in the raster.
You may need to check the part about "the center of the pixel" fallin within the poligon: it will depend on GDAL's implementation of RasterizeLayer.
Next, you can do the rest of the calculations.
3
+1 Nice use of random forests in your example. It would be helpful to include an example on this site in the event that the link goes away.
– Aaron♦
Mar 15 '16 at 23:15
That link doesn't work anymore sadly
– Cam
Mar 28 at 12:45
1
@cam link fixed to an archive version
– Akhorus
Apr 1 at 21:21
add a comment |
Your question defines a complex process which is difficult to help with all of it. Here, I will suggest something that might help with the part getting the raster data using the vector.
Refer to this: http://machinalis8.rssing.com/chan-51920729/latest.php#item3
In that blog post I rasterize vector data to subset pixels from an image.
The idea there is that you convert the vector data into a raster, like a mask. Then, using numpy, you use that mask to filter or choose the pixels in the raster.
You may need to check the part about "the center of the pixel" fallin within the poligon: it will depend on GDAL's implementation of RasterizeLayer.
Next, you can do the rest of the calculations.
3
+1 Nice use of random forests in your example. It would be helpful to include an example on this site in the event that the link goes away.
– Aaron♦
Mar 15 '16 at 23:15
That link doesn't work anymore sadly
– Cam
Mar 28 at 12:45
1
@cam link fixed to an archive version
– Akhorus
Apr 1 at 21:21
add a comment |
Your question defines a complex process which is difficult to help with all of it. Here, I will suggest something that might help with the part getting the raster data using the vector.
Refer to this: http://machinalis8.rssing.com/chan-51920729/latest.php#item3
In that blog post I rasterize vector data to subset pixels from an image.
The idea there is that you convert the vector data into a raster, like a mask. Then, using numpy, you use that mask to filter or choose the pixels in the raster.
You may need to check the part about "the center of the pixel" fallin within the poligon: it will depend on GDAL's implementation of RasterizeLayer.
Next, you can do the rest of the calculations.
Your question defines a complex process which is difficult to help with all of it. Here, I will suggest something that might help with the part getting the raster data using the vector.
Refer to this: http://machinalis8.rssing.com/chan-51920729/latest.php#item3
In that blog post I rasterize vector data to subset pixels from an image.
The idea there is that you convert the vector data into a raster, like a mask. Then, using numpy, you use that mask to filter or choose the pixels in the raster.
You may need to check the part about "the center of the pixel" fallin within the poligon: it will depend on GDAL's implementation of RasterizeLayer.
Next, you can do the rest of the calculations.
edited Apr 1 at 21:20
answered Mar 15 '16 at 21:14
AkhorusAkhorus
311211
311211
3
+1 Nice use of random forests in your example. It would be helpful to include an example on this site in the event that the link goes away.
– Aaron♦
Mar 15 '16 at 23:15
That link doesn't work anymore sadly
– Cam
Mar 28 at 12:45
1
@cam link fixed to an archive version
– Akhorus
Apr 1 at 21:21
add a comment |
3
+1 Nice use of random forests in your example. It would be helpful to include an example on this site in the event that the link goes away.
– Aaron♦
Mar 15 '16 at 23:15
That link doesn't work anymore sadly
– Cam
Mar 28 at 12:45
1
@cam link fixed to an archive version
– Akhorus
Apr 1 at 21:21
3
3
+1 Nice use of random forests in your example. It would be helpful to include an example on this site in the event that the link goes away.
– Aaron♦
Mar 15 '16 at 23:15
+1 Nice use of random forests in your example. It would be helpful to include an example on this site in the event that the link goes away.
– Aaron♦
Mar 15 '16 at 23:15
That link doesn't work anymore sadly
– Cam
Mar 28 at 12:45
That link doesn't work anymore sadly
– Cam
Mar 28 at 12:45
1
1
@cam link fixed to an archive version
– Akhorus
Apr 1 at 21:21
@cam link fixed to an archive version
– Akhorus
Apr 1 at 21:21
add a comment |
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%2f68562%2fgdal-ogr-to-extract-pixel-values%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
If I iterate over the features and while one is 'selected', can I call the GetExtent function of the shapefile layer and will the returned extent only represent the extent of the current feature?
– Thomas Becker
Aug 13 '13 at 11:37
1
It sounds as though you are wanting to do zonal statistics. Have a look at gis.stackexchange.com/questions/43748/…"
– MappaGnosis
Aug 13 '13 at 11:56
@MappaGnosis That version of zonal stats appears extremely limited; I see no evidence from the documentation that it computes percentiles. Do you know of a zonal stats solution for QGIS that does compute specified percentiles by zone?
– whuber♦
Aug 13 '13 at 15:13
1
alright, the percentile is no problem for me since I had to define a function for it anyway. My issue goes with the Python coding using GDAL/OGR... I'm used to do the stuff using ArcGIS and their Python classes. However, it takes ages and in the end the script is crashing. So, I'm on my way to re-write the script without arcpy. Can anybody point me to some code snippet where I can learn on how to do the stuff?
– Thomas Becker
Aug 13 '13 at 16:04
1
@WHuber Offhand I don't know of a more extensive Zonal Stats Plugin for QGIS. However, my link was meant to point to the programmed Python + GDAL solution in my reply in that thread. My example there is just looking at getting the minimum value, but being a programmed solution, it shouldn't be too hard to extend it a bit to calculate percentiles of the zone data. Instead of going for the 'easy statistics' options there is also a scipy.ndimage.filters.percentile_filter function available.
– MappaGnosis
Aug 14 '13 at 15:07