5

I add a new raster layer in the latest QGIS and select a JPG file, but it is all black. I tried adding the TIF version of the same image and that worked.

What is it with the JPG, and how should I import it correctly?

0

3 Answers 3

3

It seems QGIS doesn't set the correct band in the jpg raster. You can fix this by double clicking your raster layer and changing the bands

Where it says Red, Green, Blue Band they must all be the right color bands from the jpg. Change Green band drop down to Band 2 and Blue band drop down to Band 3

enter image description here

0
3

Here is a link to the QGIS forum reporting something similar in terms of band combinations. This article is referring to rasters generated in GRASS but there maybe some similarities.

Another trick that has worked for me in the past. Make sure the .jpg file has an associated world file .jgw and a projection file .prj. These can be generated from exporting through ArcGIS (which I think you mentioned you have access to). I was experiencing a similar problem in geoserver when adding a raster once I added the .jgw and .prj files it fixed my problem.

The reason why I think this may work in your case is that there were a number of qgis forum posts pointing to "black raster images" when the image had no projection information. I believe the addition of the world file and projection file may help here.

1

I was stuck on this problem for a long time and couldn't find any solutions by googling, but finally I figured it out. It comes down to this:

  • Save changes to your attributes
  • Lower your resolution
  • Stretch max and min

I'll take it step by step. This is for Mac but you should be able to follow along.


Create New Attribute Field

  1. In the layers panel: Right click the vector layer, select Open Attribute Table.
  2. Type Cmd-E / Click the Pencil in the toolbar
  3. Type Cmd-W / Click New Field Icon
  4. Fill out the fields
  • Name: some_value_here
  • Type: Whole Number (Integer)
  • Length: 4 (I'm sure this could be 1 or whatever)
  1. Select some_value_here from the dropdown next to the big E (sum sign). Type 1 in the text box. Click Update All.

  2. Type Cmd-S / Click Save Edits

  3. Close the attributes table


Creating Raster

  1. Click Raster -> Conversion -> Rasterize (Vector to Raster)
  2. Select Vector as Input File,
  3. Choose the Attribute Field you just created and saved
  4. Select an output file
  5. Select raster resolution in map units per pixel. This depends on what you're trying to do, but the mistake I originally made was making the resolution TOO HIGH. If it's too high, your data will be just a tiny pixel. Probably unusable. I used 500 x 500 map units per pixel. This means my data covered a city block.
  6. Press okay. Congratulations! Now you have a black rectangle on your screen! ...Wait what?

Fixing the Black Box

  1. Double Click on your new Raster Layer.
  2. Select Singleband pseudocolor
  3. Set Min: 0, Set Max: 1 (This would change if entered something else in the Attributes table)
  4. Interpolation: Discrete
  5. Select a Color from the dropdown. Click Edit.
  6. Click the dropdown arrow (not the color itself) next to Color 1: Click Transparent
  7. Click the dropdown arrow next to Color 2: Select a color you like.
  8. Select Type: Discrete
  9. Delete all the first, and the last two:

Colors

  1. Click Save. The style screen should now look like this. enter image description here
  2. Scroll down, make sure blending mode is Normal, click reset to make sure.
  3. Resampling should be on nearest neighbor.
  4. Click Apply. If you like how it's looking, Click the Style dropdown and save this as default.
  5. Click Ok.

You should now see a wonderful map.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.