PyQGIS: GDAL hillshade patchwork effect Planned maintenance scheduled April 23, 2019 at 23:30...

How much damage would a cupful of neutron star matter do to the Earth?

What does it mean that physics no longer uses mechanical models to describe phenomena?

Semigroups with no morphisms between them

Significance of Cersei's obsession with elephants?

Converted a Scalar function to a TVF function for parallel execution-Still running in Serial mode

Maximum summed subsequences with non-adjacent items

What is the chair depicted in Cesare Maccari's 1889 painting "Cicerone denuncia Catilina"?

AppleTVs create a chatty alternate WiFi network

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

Did any compiler fully use 80-bit floating point?

How can I prevent/balance waiting and turtling as a response to cooldown mechanics

What is the meaning of 'breadth' in breadth first search?

How did Fremen produce and carry enough thumpers to use Sandworms as de facto Ubers?

Do I really need to have a message in a novel to appeal to readers?

Strange behavior of Object.defineProperty() in JavaScript

Is multiple magic items in one inherently imbalanced?

Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?

Deconstruction is ambiguous

How do living politicians protect their readily obtainable signatures from misuse?

Why can't I install Tomboy in Ubuntu Mate 19.04?

Why do early math courses focus on the cross sections of a cone and not on other 3D objects?

How do I find out the mythology and history of my Fortress?

Is there hard evidence that the grant peer review system performs significantly better than random?

Would it be easier to apply for a UK visa if there is a host family to sponsor for you in going there?



PyQGIS: GDAL hillshade patchwork effect



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Understanding garbage hillshade output from ArcGIS for Desktop?Interaction with two variables as parameters, saving the raster properties output into a table (.dbf)Going from hillshade to percent shaded using gdaldem?gdaldem hillshade using command to calculate hillshade of whole folderHillshade effect not working when no data is on screenNo hillshade effect when no-data area is on screenGenerated ArcGIS tile cache ignores DEM hillshade effect?gdal hillshade problem in pythonHow can I get a blurred Hillshade effect in QGIS?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















I have used QGIS to batch import and visualise tiled elevation data. This is illuminated greyscale, with identical parameters used each time, so I would have expected the result to be seamless and the tile boundaries to be essentially invisible.



However, the result is a 'patchwork quilt' effect. The shading is not consistent from one tile to the next. I do not understand why not. This is the code used to apply the hillshading:



  def ShadeRaster(raster, pth):

import processing

parameters = {'INPUT': "",
'BAND': 1,
'COMPUTE_EDGES': False,
'ZEVENBERGEN': False,
'Z_FACTOR': 1.0,
'SCALE': 1.0,
'AZIMUTH': 315,
'COMBINED': False,
'ALTITUDE': 45,
'MULTIDIRECTIONAL': False,
'OUTPUT': ""}

parameters['INPUT'] =raster.name()
parameters['OUTPUT'] = pth + '/' + raster.name() + '.tif'

processing.runAndLoadResults('gdal:hillshade',parameters,feedback=feedback)
return QgsProject.instance().mapLayersByName('Hillshade')[0]


As you can see, the elevation and azimuth of the light source are always the same. But this is how it looks:



enter image description here



Why?










share|improve this question
















bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • What software are you viewing this in? Is each tile a unique file or is the hillshade a mosaic? It looks to me like the tiles are single images which have been stretched by default, if you mosaic or build a VRT of the hillshade tiles the contrast stretch should be applied over all the tiles the same.

    – Michael Stimson
    Nov 9 '18 at 0:08











  • It is viewed in QGIS. The code shown above generates a TIFF image for each tile, and it is at this point that the inconsistent shading occurs. Agreed, it does look as if the contrast is being stretched, but I am not sure why or how to prevent it. Once generated I dragged and dropped the images into QGIS with the result as shown.

    – wotnot
    Nov 9 '18 at 1:27











  • ArcMap does the same thing, I suggest creating a VRT with GDALBuildVRT (from the command line). A VRT is an XML file that points to your existing raster so is fast to create and takes up only a little space then add the VRT to your QGIS project. Your other option is to go to each hillshade tile layer and turn the stretching off in the layer properties, I think it's MIN-MAX or 'standard deviations' by default; because each tile has different statistics the stretched values do not match.

    – Michael Stimson
    Nov 9 '18 at 1:33













  • Thanks for the info ; I will investigate. First option wouldn't necessarily work since the hillshading is done within a plugin and should be fully automatic. Turning off stretching for each raster layer (before generating images) sounds like a better bet. I could presumably automate that.

    – wotnot
    Nov 9 '18 at 1:45






  • 1





    Seems I need to set the contrast enhancement for the raster layer to 'no enhancement' before running the hillshading.

    – wotnot
    Nov 9 '18 at 2:38


















2















I have used QGIS to batch import and visualise tiled elevation data. This is illuminated greyscale, with identical parameters used each time, so I would have expected the result to be seamless and the tile boundaries to be essentially invisible.



However, the result is a 'patchwork quilt' effect. The shading is not consistent from one tile to the next. I do not understand why not. This is the code used to apply the hillshading:



  def ShadeRaster(raster, pth):

import processing

parameters = {'INPUT': "",
'BAND': 1,
'COMPUTE_EDGES': False,
'ZEVENBERGEN': False,
'Z_FACTOR': 1.0,
'SCALE': 1.0,
'AZIMUTH': 315,
'COMBINED': False,
'ALTITUDE': 45,
'MULTIDIRECTIONAL': False,
'OUTPUT': ""}

parameters['INPUT'] =raster.name()
parameters['OUTPUT'] = pth + '/' + raster.name() + '.tif'

processing.runAndLoadResults('gdal:hillshade',parameters,feedback=feedback)
return QgsProject.instance().mapLayersByName('Hillshade')[0]


As you can see, the elevation and azimuth of the light source are always the same. But this is how it looks:



enter image description here



Why?










share|improve this question
















bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • What software are you viewing this in? Is each tile a unique file or is the hillshade a mosaic? It looks to me like the tiles are single images which have been stretched by default, if you mosaic or build a VRT of the hillshade tiles the contrast stretch should be applied over all the tiles the same.

    – Michael Stimson
    Nov 9 '18 at 0:08











  • It is viewed in QGIS. The code shown above generates a TIFF image for each tile, and it is at this point that the inconsistent shading occurs. Agreed, it does look as if the contrast is being stretched, but I am not sure why or how to prevent it. Once generated I dragged and dropped the images into QGIS with the result as shown.

    – wotnot
    Nov 9 '18 at 1:27











  • ArcMap does the same thing, I suggest creating a VRT with GDALBuildVRT (from the command line). A VRT is an XML file that points to your existing raster so is fast to create and takes up only a little space then add the VRT to your QGIS project. Your other option is to go to each hillshade tile layer and turn the stretching off in the layer properties, I think it's MIN-MAX or 'standard deviations' by default; because each tile has different statistics the stretched values do not match.

    – Michael Stimson
    Nov 9 '18 at 1:33













  • Thanks for the info ; I will investigate. First option wouldn't necessarily work since the hillshading is done within a plugin and should be fully automatic. Turning off stretching for each raster layer (before generating images) sounds like a better bet. I could presumably automate that.

    – wotnot
    Nov 9 '18 at 1:45






  • 1





    Seems I need to set the contrast enhancement for the raster layer to 'no enhancement' before running the hillshading.

    – wotnot
    Nov 9 '18 at 2:38














2












2








2








I have used QGIS to batch import and visualise tiled elevation data. This is illuminated greyscale, with identical parameters used each time, so I would have expected the result to be seamless and the tile boundaries to be essentially invisible.



However, the result is a 'patchwork quilt' effect. The shading is not consistent from one tile to the next. I do not understand why not. This is the code used to apply the hillshading:



  def ShadeRaster(raster, pth):

import processing

parameters = {'INPUT': "",
'BAND': 1,
'COMPUTE_EDGES': False,
'ZEVENBERGEN': False,
'Z_FACTOR': 1.0,
'SCALE': 1.0,
'AZIMUTH': 315,
'COMBINED': False,
'ALTITUDE': 45,
'MULTIDIRECTIONAL': False,
'OUTPUT': ""}

parameters['INPUT'] =raster.name()
parameters['OUTPUT'] = pth + '/' + raster.name() + '.tif'

processing.runAndLoadResults('gdal:hillshade',parameters,feedback=feedback)
return QgsProject.instance().mapLayersByName('Hillshade')[0]


As you can see, the elevation and azimuth of the light source are always the same. But this is how it looks:



enter image description here



Why?










share|improve this question
















I have used QGIS to batch import and visualise tiled elevation data. This is illuminated greyscale, with identical parameters used each time, so I would have expected the result to be seamless and the tile boundaries to be essentially invisible.



However, the result is a 'patchwork quilt' effect. The shading is not consistent from one tile to the next. I do not understand why not. This is the code used to apply the hillshading:



  def ShadeRaster(raster, pth):

import processing

parameters = {'INPUT': "",
'BAND': 1,
'COMPUTE_EDGES': False,
'ZEVENBERGEN': False,
'Z_FACTOR': 1.0,
'SCALE': 1.0,
'AZIMUTH': 315,
'COMBINED': False,
'ALTITUDE': 45,
'MULTIDIRECTIONAL': False,
'OUTPUT': ""}

parameters['INPUT'] =raster.name()
parameters['OUTPUT'] = pth + '/' + raster.name() + '.tif'

processing.runAndLoadResults('gdal:hillshade',parameters,feedback=feedback)
return QgsProject.instance().mapLayersByName('Hillshade')[0]


As you can see, the elevation and azimuth of the light source are always the same. But this is how it looks:



enter image description here



Why?







pyqgis gdal hillshade






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 '18 at 17:39







wotnot

















asked Nov 8 '18 at 15:57









wotnotwotnot

999




999





bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • What software are you viewing this in? Is each tile a unique file or is the hillshade a mosaic? It looks to me like the tiles are single images which have been stretched by default, if you mosaic or build a VRT of the hillshade tiles the contrast stretch should be applied over all the tiles the same.

    – Michael Stimson
    Nov 9 '18 at 0:08











  • It is viewed in QGIS. The code shown above generates a TIFF image for each tile, and it is at this point that the inconsistent shading occurs. Agreed, it does look as if the contrast is being stretched, but I am not sure why or how to prevent it. Once generated I dragged and dropped the images into QGIS with the result as shown.

    – wotnot
    Nov 9 '18 at 1:27











  • ArcMap does the same thing, I suggest creating a VRT with GDALBuildVRT (from the command line). A VRT is an XML file that points to your existing raster so is fast to create and takes up only a little space then add the VRT to your QGIS project. Your other option is to go to each hillshade tile layer and turn the stretching off in the layer properties, I think it's MIN-MAX or 'standard deviations' by default; because each tile has different statistics the stretched values do not match.

    – Michael Stimson
    Nov 9 '18 at 1:33













  • Thanks for the info ; I will investigate. First option wouldn't necessarily work since the hillshading is done within a plugin and should be fully automatic. Turning off stretching for each raster layer (before generating images) sounds like a better bet. I could presumably automate that.

    – wotnot
    Nov 9 '18 at 1:45






  • 1





    Seems I need to set the contrast enhancement for the raster layer to 'no enhancement' before running the hillshading.

    – wotnot
    Nov 9 '18 at 2:38



















  • What software are you viewing this in? Is each tile a unique file or is the hillshade a mosaic? It looks to me like the tiles are single images which have been stretched by default, if you mosaic or build a VRT of the hillshade tiles the contrast stretch should be applied over all the tiles the same.

    – Michael Stimson
    Nov 9 '18 at 0:08











  • It is viewed in QGIS. The code shown above generates a TIFF image for each tile, and it is at this point that the inconsistent shading occurs. Agreed, it does look as if the contrast is being stretched, but I am not sure why or how to prevent it. Once generated I dragged and dropped the images into QGIS with the result as shown.

    – wotnot
    Nov 9 '18 at 1:27











  • ArcMap does the same thing, I suggest creating a VRT with GDALBuildVRT (from the command line). A VRT is an XML file that points to your existing raster so is fast to create and takes up only a little space then add the VRT to your QGIS project. Your other option is to go to each hillshade tile layer and turn the stretching off in the layer properties, I think it's MIN-MAX or 'standard deviations' by default; because each tile has different statistics the stretched values do not match.

    – Michael Stimson
    Nov 9 '18 at 1:33













  • Thanks for the info ; I will investigate. First option wouldn't necessarily work since the hillshading is done within a plugin and should be fully automatic. Turning off stretching for each raster layer (before generating images) sounds like a better bet. I could presumably automate that.

    – wotnot
    Nov 9 '18 at 1:45






  • 1





    Seems I need to set the contrast enhancement for the raster layer to 'no enhancement' before running the hillshading.

    – wotnot
    Nov 9 '18 at 2:38

















What software are you viewing this in? Is each tile a unique file or is the hillshade a mosaic? It looks to me like the tiles are single images which have been stretched by default, if you mosaic or build a VRT of the hillshade tiles the contrast stretch should be applied over all the tiles the same.

– Michael Stimson
Nov 9 '18 at 0:08





What software are you viewing this in? Is each tile a unique file or is the hillshade a mosaic? It looks to me like the tiles are single images which have been stretched by default, if you mosaic or build a VRT of the hillshade tiles the contrast stretch should be applied over all the tiles the same.

– Michael Stimson
Nov 9 '18 at 0:08













It is viewed in QGIS. The code shown above generates a TIFF image for each tile, and it is at this point that the inconsistent shading occurs. Agreed, it does look as if the contrast is being stretched, but I am not sure why or how to prevent it. Once generated I dragged and dropped the images into QGIS with the result as shown.

– wotnot
Nov 9 '18 at 1:27





It is viewed in QGIS. The code shown above generates a TIFF image for each tile, and it is at this point that the inconsistent shading occurs. Agreed, it does look as if the contrast is being stretched, but I am not sure why or how to prevent it. Once generated I dragged and dropped the images into QGIS with the result as shown.

– wotnot
Nov 9 '18 at 1:27













ArcMap does the same thing, I suggest creating a VRT with GDALBuildVRT (from the command line). A VRT is an XML file that points to your existing raster so is fast to create and takes up only a little space then add the VRT to your QGIS project. Your other option is to go to each hillshade tile layer and turn the stretching off in the layer properties, I think it's MIN-MAX or 'standard deviations' by default; because each tile has different statistics the stretched values do not match.

– Michael Stimson
Nov 9 '18 at 1:33







ArcMap does the same thing, I suggest creating a VRT with GDALBuildVRT (from the command line). A VRT is an XML file that points to your existing raster so is fast to create and takes up only a little space then add the VRT to your QGIS project. Your other option is to go to each hillshade tile layer and turn the stretching off in the layer properties, I think it's MIN-MAX or 'standard deviations' by default; because each tile has different statistics the stretched values do not match.

– Michael Stimson
Nov 9 '18 at 1:33















Thanks for the info ; I will investigate. First option wouldn't necessarily work since the hillshading is done within a plugin and should be fully automatic. Turning off stretching for each raster layer (before generating images) sounds like a better bet. I could presumably automate that.

– wotnot
Nov 9 '18 at 1:45





Thanks for the info ; I will investigate. First option wouldn't necessarily work since the hillshading is done within a plugin and should be fully automatic. Turning off stretching for each raster layer (before generating images) sounds like a better bet. I could presumably automate that.

– wotnot
Nov 9 '18 at 1:45




1




1





Seems I need to set the contrast enhancement for the raster layer to 'no enhancement' before running the hillshading.

– wotnot
Nov 9 '18 at 2:38





Seems I need to set the contrast enhancement for the raster layer to 'no enhancement' before running the hillshading.

– wotnot
Nov 9 '18 at 2:38










1 Answer
1






active

oldest

votes


















0














OK... Got it. I changed approach a little bit, having realised that I don't have to run the Hillshade algorithm and generate a TIFF. I can just apply hillshade rendering to the memory raster layer.



I have now got a three stage process (repeated for each grid tile):




  1. Create raster layer from xyz ASCII file

  2. Set contrast enhancement to 'none'

  3. Set render to 'hillshade'


Stages 2 and 3 can actually be done via the QGIS GUI quite easily and applied to multiple layers, but I have done it programmatically.



def ImportRaster(self, raster):

from PyQt5.QtCore import QFileInfo

fileInfo = QFileInfo(raster)
path = fileInfo.filePath()
baseName = fileInfo.baseName()

layer = QgsRasterLayer(path, baseName)
QgsProject.instance().addMapLayer(layer)

return layer if layer.isValid() else None

def setNoEnhancement(self, layer): # set contrast enhancement to 'no enhancement'
ContrastEnhancement = QgsContrastEnhancement.NoEnhancement
myBand = layer.renderer().grayBand()
myType = layer.renderer().dataType(myBand)
myEnhancement = QgsContrastEnhancement(myType)
myEnhancement.setContrastEnhancementAlgorithm(ContrastEnhancement, True)
layer.renderer().setContrastEnhancement(myEnhancement)

def setRenderHillshade(self, layer): # set render type to 'hillshade'
r = QgsHillshadeRenderer(layer.dataProvider(), 1, 315, 45)
layer.setRenderer(r)

def XYZToShadedTIFF(self, fname):

l = self.ImportRaster(fname) # import file, return layer 'l'

if not l is None:
self.setNoEnhancement(l) # ContrastEnhancement to 'none'
self.setRenderHillshade(l) # hillshade


This works.



Thanks Michael for the assistance.






share|improve this answer
























    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f301877%2fpyqgis-gdal-hillshade-patchwork-effect%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









    0














    OK... Got it. I changed approach a little bit, having realised that I don't have to run the Hillshade algorithm and generate a TIFF. I can just apply hillshade rendering to the memory raster layer.



    I have now got a three stage process (repeated for each grid tile):




    1. Create raster layer from xyz ASCII file

    2. Set contrast enhancement to 'none'

    3. Set render to 'hillshade'


    Stages 2 and 3 can actually be done via the QGIS GUI quite easily and applied to multiple layers, but I have done it programmatically.



    def ImportRaster(self, raster):

    from PyQt5.QtCore import QFileInfo

    fileInfo = QFileInfo(raster)
    path = fileInfo.filePath()
    baseName = fileInfo.baseName()

    layer = QgsRasterLayer(path, baseName)
    QgsProject.instance().addMapLayer(layer)

    return layer if layer.isValid() else None

    def setNoEnhancement(self, layer): # set contrast enhancement to 'no enhancement'
    ContrastEnhancement = QgsContrastEnhancement.NoEnhancement
    myBand = layer.renderer().grayBand()
    myType = layer.renderer().dataType(myBand)
    myEnhancement = QgsContrastEnhancement(myType)
    myEnhancement.setContrastEnhancementAlgorithm(ContrastEnhancement, True)
    layer.renderer().setContrastEnhancement(myEnhancement)

    def setRenderHillshade(self, layer): # set render type to 'hillshade'
    r = QgsHillshadeRenderer(layer.dataProvider(), 1, 315, 45)
    layer.setRenderer(r)

    def XYZToShadedTIFF(self, fname):

    l = self.ImportRaster(fname) # import file, return layer 'l'

    if not l is None:
    self.setNoEnhancement(l) # ContrastEnhancement to 'none'
    self.setRenderHillshade(l) # hillshade


    This works.



    Thanks Michael for the assistance.






    share|improve this answer




























      0














      OK... Got it. I changed approach a little bit, having realised that I don't have to run the Hillshade algorithm and generate a TIFF. I can just apply hillshade rendering to the memory raster layer.



      I have now got a three stage process (repeated for each grid tile):




      1. Create raster layer from xyz ASCII file

      2. Set contrast enhancement to 'none'

      3. Set render to 'hillshade'


      Stages 2 and 3 can actually be done via the QGIS GUI quite easily and applied to multiple layers, but I have done it programmatically.



      def ImportRaster(self, raster):

      from PyQt5.QtCore import QFileInfo

      fileInfo = QFileInfo(raster)
      path = fileInfo.filePath()
      baseName = fileInfo.baseName()

      layer = QgsRasterLayer(path, baseName)
      QgsProject.instance().addMapLayer(layer)

      return layer if layer.isValid() else None

      def setNoEnhancement(self, layer): # set contrast enhancement to 'no enhancement'
      ContrastEnhancement = QgsContrastEnhancement.NoEnhancement
      myBand = layer.renderer().grayBand()
      myType = layer.renderer().dataType(myBand)
      myEnhancement = QgsContrastEnhancement(myType)
      myEnhancement.setContrastEnhancementAlgorithm(ContrastEnhancement, True)
      layer.renderer().setContrastEnhancement(myEnhancement)

      def setRenderHillshade(self, layer): # set render type to 'hillshade'
      r = QgsHillshadeRenderer(layer.dataProvider(), 1, 315, 45)
      layer.setRenderer(r)

      def XYZToShadedTIFF(self, fname):

      l = self.ImportRaster(fname) # import file, return layer 'l'

      if not l is None:
      self.setNoEnhancement(l) # ContrastEnhancement to 'none'
      self.setRenderHillshade(l) # hillshade


      This works.



      Thanks Michael for the assistance.






      share|improve this answer


























        0












        0








        0







        OK... Got it. I changed approach a little bit, having realised that I don't have to run the Hillshade algorithm and generate a TIFF. I can just apply hillshade rendering to the memory raster layer.



        I have now got a three stage process (repeated for each grid tile):




        1. Create raster layer from xyz ASCII file

        2. Set contrast enhancement to 'none'

        3. Set render to 'hillshade'


        Stages 2 and 3 can actually be done via the QGIS GUI quite easily and applied to multiple layers, but I have done it programmatically.



        def ImportRaster(self, raster):

        from PyQt5.QtCore import QFileInfo

        fileInfo = QFileInfo(raster)
        path = fileInfo.filePath()
        baseName = fileInfo.baseName()

        layer = QgsRasterLayer(path, baseName)
        QgsProject.instance().addMapLayer(layer)

        return layer if layer.isValid() else None

        def setNoEnhancement(self, layer): # set contrast enhancement to 'no enhancement'
        ContrastEnhancement = QgsContrastEnhancement.NoEnhancement
        myBand = layer.renderer().grayBand()
        myType = layer.renderer().dataType(myBand)
        myEnhancement = QgsContrastEnhancement(myType)
        myEnhancement.setContrastEnhancementAlgorithm(ContrastEnhancement, True)
        layer.renderer().setContrastEnhancement(myEnhancement)

        def setRenderHillshade(self, layer): # set render type to 'hillshade'
        r = QgsHillshadeRenderer(layer.dataProvider(), 1, 315, 45)
        layer.setRenderer(r)

        def XYZToShadedTIFF(self, fname):

        l = self.ImportRaster(fname) # import file, return layer 'l'

        if not l is None:
        self.setNoEnhancement(l) # ContrastEnhancement to 'none'
        self.setRenderHillshade(l) # hillshade


        This works.



        Thanks Michael for the assistance.






        share|improve this answer













        OK... Got it. I changed approach a little bit, having realised that I don't have to run the Hillshade algorithm and generate a TIFF. I can just apply hillshade rendering to the memory raster layer.



        I have now got a three stage process (repeated for each grid tile):




        1. Create raster layer from xyz ASCII file

        2. Set contrast enhancement to 'none'

        3. Set render to 'hillshade'


        Stages 2 and 3 can actually be done via the QGIS GUI quite easily and applied to multiple layers, but I have done it programmatically.



        def ImportRaster(self, raster):

        from PyQt5.QtCore import QFileInfo

        fileInfo = QFileInfo(raster)
        path = fileInfo.filePath()
        baseName = fileInfo.baseName()

        layer = QgsRasterLayer(path, baseName)
        QgsProject.instance().addMapLayer(layer)

        return layer if layer.isValid() else None

        def setNoEnhancement(self, layer): # set contrast enhancement to 'no enhancement'
        ContrastEnhancement = QgsContrastEnhancement.NoEnhancement
        myBand = layer.renderer().grayBand()
        myType = layer.renderer().dataType(myBand)
        myEnhancement = QgsContrastEnhancement(myType)
        myEnhancement.setContrastEnhancementAlgorithm(ContrastEnhancement, True)
        layer.renderer().setContrastEnhancement(myEnhancement)

        def setRenderHillshade(self, layer): # set render type to 'hillshade'
        r = QgsHillshadeRenderer(layer.dataProvider(), 1, 315, 45)
        layer.setRenderer(r)

        def XYZToShadedTIFF(self, fname):

        l = self.ImportRaster(fname) # import file, return layer 'l'

        if not l is None:
        self.setNoEnhancement(l) # ContrastEnhancement to 'none'
        self.setRenderHillshade(l) # hillshade


        This works.



        Thanks Michael for the assistance.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 14 '18 at 19:30









        wotnotwotnot

        999




        999






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f301877%2fpyqgis-gdal-hillshade-patchwork-effect%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            Щит и меч (фильм) Содержание Названия серий | Сюжет |...

            is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

            Meter-Bus Содержание Параметры шины | Стандартизация |...