I'm developing an app to display a map in QGIS.

The map data is from Bing Map servers. I want to overlay a shapefile on the map. I want the same visual display we see on QGIS.

Like this Wanted output

So my idea is to rasterize the shapefile. But, the output is a raster-like this and all the point shapefile return a black image.

Unwanted output

Anyone, have any idea to solve this?


After I put together the tutorial below, I discovered the tool Convert map to raster, which sounds like it does exactly what you want in one step. Description: "This algorithm rasterizes map canvas content." It didn't giving me exactly the output I expected, but I didn't spend very long testing it. Give it a try, it may do exactly what you want in a lot fewer steps. If not, see below:

How to rasterize polygon outlines

  1. Decide how wide you want the outlines to be, in the unit of measure used by the shapefile. (You can find this information in the shapefile properties under coordinate reference system or CRS.)

In my example, the CRS of my shapefile is EPSG:4326, so its units are decimal degrees. I decided to make my borders 0.02 degrees wide.

  1. Make a buffer of the shapefile. The buffer distance is half of the negative of the value you chose in the last step. Choose round, mitered or beveled joins depending on how you want the corners to look.

My buffer distance is -0.01. I used round joins.

enter image description here

enter image description here

  1. Run the Difference tool to subtract the buffered layer from the original polygon layer.

input layer: polygons difference layer: buffered

enter image description here

Note: the external border is only half as wide as the external border. To fix this, buffer the original polygon with a positive buffer distance (same size as the first buffer), and choose the option to "dissolve result." Subtract the first buffered layer from the second buffered layer, and proceed with step 4.

  1. Dissolve the difference layer

enter image description here

  1. Rasterize the dissolved layer

  2. use the tool set style for raster layer

  • Thanks for your answer. It doesn't work well with my apps. So I use gdal to read the file directly and use it to create the polygon to overlay on my map. But thanks for taking time to do all of this. I appreciate it! – madlink Aug 8 '18 at 14:11
  • If you found a different solution to your problem, please post it as an answer so future users of the site can learn. – csk Aug 9 '18 at 16:29
  • I'm working on it. I will post in if I manage to get it working. Thanks! – madlink Aug 16 '18 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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