PyQGIS raster image shifted from vector shapefile The 2019 Stack Overflow Developer Survey...

Unbreakable Formation vs. Cry of the Carnarium

Why is the maximum length of openwrt’s root password 8 characters?

Does a dangling wire really electrocute me if I'm standing in water?

Idiomatic way to prevent slicing?

Families of ordered set partitions with disjoint blocks

Springs with some finite mass

What do hard-Brexiteers want with respect to the Irish border?

Is domain driven design an anti-SQL pattern?

What is the motivation for a law requiring 2 parties to consent for recording a conversation

How to answer pointed "are you quitting" questioning when I don't want them to suspect

How to deal with fear of taking dependencies

Inflated grade on resume at previous job, might former employer tell new employer?

Did USCIS resume its biometric service for UK visa?

Spanish for "widget"

Should I use my personal or workplace e-mail when registering to external websites for work purpose?

Access elements in std::string where positon of string is greater than its size

Is "plugging out" electronic devices an American expression?

Landlord wants to switch my lease to a "Land contract" to "get back at the city"

Dual Citizen. Exited the US on Italian passport recently

Geography at the pixel level

How to manage monthly salary

Monty Hall variation

Fractional alignment

Why is Grand Jury testimony secret?



PyQGIS raster image shifted from vector shapefile



The 2019 Stack Overflow Developer Survey Results Are InPyQGIS overlaying raster image on vector map correctly?Unattractive image artefact when exporting from QGIS's Print ComposerJoining table to shapefile with pyQGISoverlaying raster layer hides my vector layers in PyQGISVector to Raster using GDAL (gdal.RasterizeLayer) : Error in Output Raster(generating output raster with NAN values)Create Vector Grid from a features Extent with PyQGISDraw shapefile over PNG image in RChecking if vector coordinates are inside raster file using pyqgis?Create a raster layer that represents the distance from each polygon cell to the closest point in a bufferrender Raster Layer from pyQgis 3PyQGIS overlaying raster image on vector map correctly?





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







0















I previously asked a question about my raster image being larger and shifted over from my vector image here, but now I realize that the raster image is only shifted to the left and up from the vector map (both image and map are defined in decimal degree coordinates). The vector layer is a world shapefile and the raster image is a .png image that is overlain on the shapefile.



Below I have two examples where the raster image is shifted when uploaded on the shapefile in PyQGIS:
example1example2



The blue and green are part of the vector shapefile (blue being the ocean and green being the land). The purple, white grid, and green contours are part of the raster image. The larger red X represents the set of coordinates that were defined on the vector map. The smaller red X represents the same set of coordinates, but on the raster image. Here is where I can tell that the raster image is shifted compared to the vector map because the red X's represent the same coordinates (i.e. 75.23694W, 39.86N for the second image).



I am wondering how to fix this? Is there anyway to easily correct the raster location to the correct area?



My PyQGIS code to upload the raster image is below:



def addRasterImage1(self):
x = self.lon0
y = self.lat0
self.layers = []
fileName = 'Desktop'

dir = os.path.dirname(fileName) if fileName is not None else "." #path of the saved raster image
formats = ["*.%s" % "PNG"]

file = myfile_list[k_zt] #raster image to load onto vector image
print file
if file:
layer = QgsRasterLayer(file, fileName)
print "layer",layer

if not layer.isValid():
return

# add layer to the registry
QgsMapLayerRegistry.instance().addMapLayer(layer)

# # set extent to the extent of layer
self.canvas.setExtent(layer.extent())
self.layers.insert(0, QgsMapCanvasLayer(layer))

print "layers number:",len(self.layers)
self.canvas.setLayerSet(self.layers)
self.canvas.refresh()
self.MyWorldLayer(ext = False)


Where self.MyWorldLayer(ext = False) is the vector shapefile map.
Please let me know if you have any suggestions on how to fix this!









share





























    0















    I previously asked a question about my raster image being larger and shifted over from my vector image here, but now I realize that the raster image is only shifted to the left and up from the vector map (both image and map are defined in decimal degree coordinates). The vector layer is a world shapefile and the raster image is a .png image that is overlain on the shapefile.



    Below I have two examples where the raster image is shifted when uploaded on the shapefile in PyQGIS:
    example1example2



    The blue and green are part of the vector shapefile (blue being the ocean and green being the land). The purple, white grid, and green contours are part of the raster image. The larger red X represents the set of coordinates that were defined on the vector map. The smaller red X represents the same set of coordinates, but on the raster image. Here is where I can tell that the raster image is shifted compared to the vector map because the red X's represent the same coordinates (i.e. 75.23694W, 39.86N for the second image).



    I am wondering how to fix this? Is there anyway to easily correct the raster location to the correct area?



    My PyQGIS code to upload the raster image is below:



    def addRasterImage1(self):
    x = self.lon0
    y = self.lat0
    self.layers = []
    fileName = 'Desktop'

    dir = os.path.dirname(fileName) if fileName is not None else "." #path of the saved raster image
    formats = ["*.%s" % "PNG"]

    file = myfile_list[k_zt] #raster image to load onto vector image
    print file
    if file:
    layer = QgsRasterLayer(file, fileName)
    print "layer",layer

    if not layer.isValid():
    return

    # add layer to the registry
    QgsMapLayerRegistry.instance().addMapLayer(layer)

    # # set extent to the extent of layer
    self.canvas.setExtent(layer.extent())
    self.layers.insert(0, QgsMapCanvasLayer(layer))

    print "layers number:",len(self.layers)
    self.canvas.setLayerSet(self.layers)
    self.canvas.refresh()
    self.MyWorldLayer(ext = False)


    Where self.MyWorldLayer(ext = False) is the vector shapefile map.
    Please let me know if you have any suggestions on how to fix this!









    share

























      0












      0








      0








      I previously asked a question about my raster image being larger and shifted over from my vector image here, but now I realize that the raster image is only shifted to the left and up from the vector map (both image and map are defined in decimal degree coordinates). The vector layer is a world shapefile and the raster image is a .png image that is overlain on the shapefile.



      Below I have two examples where the raster image is shifted when uploaded on the shapefile in PyQGIS:
      example1example2



      The blue and green are part of the vector shapefile (blue being the ocean and green being the land). The purple, white grid, and green contours are part of the raster image. The larger red X represents the set of coordinates that were defined on the vector map. The smaller red X represents the same set of coordinates, but on the raster image. Here is where I can tell that the raster image is shifted compared to the vector map because the red X's represent the same coordinates (i.e. 75.23694W, 39.86N for the second image).



      I am wondering how to fix this? Is there anyway to easily correct the raster location to the correct area?



      My PyQGIS code to upload the raster image is below:



      def addRasterImage1(self):
      x = self.lon0
      y = self.lat0
      self.layers = []
      fileName = 'Desktop'

      dir = os.path.dirname(fileName) if fileName is not None else "." #path of the saved raster image
      formats = ["*.%s" % "PNG"]

      file = myfile_list[k_zt] #raster image to load onto vector image
      print file
      if file:
      layer = QgsRasterLayer(file, fileName)
      print "layer",layer

      if not layer.isValid():
      return

      # add layer to the registry
      QgsMapLayerRegistry.instance().addMapLayer(layer)

      # # set extent to the extent of layer
      self.canvas.setExtent(layer.extent())
      self.layers.insert(0, QgsMapCanvasLayer(layer))

      print "layers number:",len(self.layers)
      self.canvas.setLayerSet(self.layers)
      self.canvas.refresh()
      self.MyWorldLayer(ext = False)


      Where self.MyWorldLayer(ext = False) is the vector shapefile map.
      Please let me know if you have any suggestions on how to fix this!









      share














      I previously asked a question about my raster image being larger and shifted over from my vector image here, but now I realize that the raster image is only shifted to the left and up from the vector map (both image and map are defined in decimal degree coordinates). The vector layer is a world shapefile and the raster image is a .png image that is overlain on the shapefile.



      Below I have two examples where the raster image is shifted when uploaded on the shapefile in PyQGIS:
      example1example2



      The blue and green are part of the vector shapefile (blue being the ocean and green being the land). The purple, white grid, and green contours are part of the raster image. The larger red X represents the set of coordinates that were defined on the vector map. The smaller red X represents the same set of coordinates, but on the raster image. Here is where I can tell that the raster image is shifted compared to the vector map because the red X's represent the same coordinates (i.e. 75.23694W, 39.86N for the second image).



      I am wondering how to fix this? Is there anyway to easily correct the raster location to the correct area?



      My PyQGIS code to upload the raster image is below:



      def addRasterImage1(self):
      x = self.lon0
      y = self.lat0
      self.layers = []
      fileName = 'Desktop'

      dir = os.path.dirname(fileName) if fileName is not None else "." #path of the saved raster image
      formats = ["*.%s" % "PNG"]

      file = myfile_list[k_zt] #raster image to load onto vector image
      print file
      if file:
      layer = QgsRasterLayer(file, fileName)
      print "layer",layer

      if not layer.isValid():
      return

      # add layer to the registry
      QgsMapLayerRegistry.instance().addMapLayer(layer)

      # # set extent to the extent of layer
      self.canvas.setExtent(layer.extent())
      self.layers.insert(0, QgsMapCanvasLayer(layer))

      print "layers number:",len(self.layers)
      self.canvas.setLayerSet(self.layers)
      self.canvas.refresh()
      self.MyWorldLayer(ext = False)


      Where self.MyWorldLayer(ext = False) is the vector shapefile map.
      Please let me know if you have any suggestions on how to fix this!







      python raster pyqgis qgsmapcanvas qgsvectorlayer





      share












      share










      share



      share










      asked 2 mins ago









      user137875user137875

      233




      233






















          0






          active

          oldest

          votes












          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%2f318296%2fpyqgis-raster-image-shifted-from-vector-shapefile%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f318296%2fpyqgis-raster-image-shifted-from-vector-shapefile%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

          (145452) 2005 RN43 Классификация | Примечания | Ссылки |...

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

          Энтрерриос (город) Содержание История | Географическое...