[Qgis-user] Raster to Vector without losing the symbology

Craig Shelden craig.shelden at comcast.net
Mon Jul 19 14:25:28 PDT 2021


Krishna, 

Can you share a bit more about the raster image source file?  How discrete are the colors?

If there are only a few colors, then this workflow may meet the need, however kludged it may be.  

See if this approach helps... it worked for me with only a few colors... with more than a few, it would almost certainly fail.

Step 0 - determine how unique the colors are that you're working from...and how many there are.

Step 1 - take core RGB raster and split into three greyscale images... keep dimensions the same as the original and duplicate the world files for the core RGB raster so there's also a world file for each channel.

Step 2 - import the three greyscale images into QGIS.  

Step 3 = In Raster Calculator [1] extract each single R, G, xor B unique color value of interest into an output image 

Step 4 - Use Polygonize [2] on the output from step 3  ... AND also using Step # 3's output as a Screen under Polygonize's advanced options.  

Step 5 - apply the unique colors to the output.

Step 6 - Save the output shape file.

Repeat as needed.

This approach worked sufficiently well to take LIDAR-generated raster vegetation base maps from the mapping software OCAD [3] and convert those raster images to shape files for returning to OCAD as vectors and assignment to vegetation types.  Those shape files do get big... and over any substantive area, I can easily end up with > 150 K shapes in each file.

I set up a presentation file showing the approach using the QGIS graphical modeler [4] in a shared Google Drive, if you want to look it over.

Shortfalls and work arounds:: theoretically, I **think** the raster calculator should work on the original RGB source file, but I could never get it to work, so I tried the decompose-and-reassemble approach ...and it did work. ...and being lazy and busy, once I found a working approach I kept using it.

I'm sure it could be improved, but I don't use it often enough to warrant a hard scrub for optimization... and there are lots of other things to do while the graphical modeler runs through the hoops.

[1] Raster Calculator documentation page: https://docs.qgis.org/3.16/en/docs/user_manual/working_with_raster/raster_analysis.html#raster-calculator

[2] Polygonize documentation page:
https://docs.qgis.org/3.16/en/docs/user_manual/processing_algs/gdal/rasterconversion.html?highlight=polygonize#polygonize-raster-to-vector

[3] OCAD Home Page https://www.ocad.com/en/

[3] My efforts at creating shapes from rasters 
Filename: Creating_shapes_007.pdf 
 https://drive.google.com/drive/folders/1y7OKQM3XNqrTMFEgj8YM5-4WSY0CAQnl?usp=sharing 

Hope this helps.

All my best,
Craig

[Message trimmed]

> 
> 
> Today's Topics:
> 
>    1. Re: Raster to Vector without losing the symbology (Andy Harfoot)
> 
> 
> ----------------------------------------------------------------------
> 
> Message: 1
> Date: Mon, 19 Jul 2021 14:40:06 +0100
> From: Andy Harfoot <ajph at geodata.soton.ac.uk>
> To: qgis-user at lists.osgeo.org
> Subject: Re: [Qgis-user] Raster to Vector without losing the symbology

> 
> Or extract the three bands into three separate vector files and then 
> union the three together to get the unique combinations of RGB values.
> 
> Cheers,
> 
> Andy

> >
> >> Le 18 juill. 2021 ? 12:51, krishna Ayyala <ayyalakrishna at gmail.com> a 
> >> ?crit?:
> >>
> >> ?
> >> I have an image on my qgis map that has 3 bands. Band1 (red), 
> >> Band2(green) and Band3(blue). This image has different?colors.Is it 
> >> possible to convert this image into a vector?which should look 
> >> exactly like the image.
> >>
> >> That means; Is it possible to have the vector file that should?have 
> >> the same colors as that of the image.
> >>
> >> Regards.


More information about the Qgis-user mailing list