2

This is the vector I got after I changed the polygon into raster and back to polygon, the perimeter is now full integersenter image description hereI would like to convert my polygon data into a raster file to change the pixel resolution and then would like to convert it back to polygon data since this will allow it to be resampled to another resolution. The issue I face is that in the original polygon data that I convert it contains decimals like 1.87, I convert this field into a raster then when I convert this back to vector the values given are integers such as 2. How do I make sure the decimals are retained?

enter image description here

New contributor
AhmedTech is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
8
  • 1
    Does vector data really have a concept of "resolution"? Aug 4 at 14:32
  • 1
    Vector data doesn't have pixels, hence no pixel resolution. Maybe provide images of your current data and what you're trying to achieve.
    – Erik
    Aug 4 at 14:36
  • @Erik Thank you for responses. Yes I too am confused about this concept. Basically I have two datasets, one is in raster which represents forest fragments and another is in vector which represents individual fire data including perimeter of fire, the land cover its in etc. The forest fragment data has a resolution of 100m whilst fire data has 500m resolution. I need to make the fire data at 100m resolution, the same as forest fragment. I assumed changing pixel sizes to be the same would do the trick. I am not sure how to go about this. I will add pictures
    – AhmedTech
    Aug 4 at 14:41
  • @Erik The perimeter with integer values picture is the polygon that I converted to raster then back to polygon. It is now integer values rather then decimals? Also am I even going it about the correct way to resample vector data this way to match raster
    – AhmedTech
    Aug 4 at 14:45
  • 1
    Also, your continent-wide screenshot is not very useful. As an alternative, please edit your question to include a screenshot that shows both the raster and the polygon data zoomed in enough to illustrate their native resolution.
    – Stu Smith
    Aug 4 at 15:31

2 Answers 2

0

If the values are not preserved as decimals, you can recreate them in the polygonized layer by adding a new attribute with field calculater and get the raster-value of a point inside the polygon using this expression:

 raster_value( 'name_of_your_raster_layer', 1, point_on_surface($geometry))

Replace 1 by the number of the raster layer's band from which you want to get the pixel value.

enter image description here

9
  • Thank you so much for this response, however I am struggling to follow. Apologies I am new to this. Where can I find this? Where do I input that command. Could you send screenshots please? This is very much appreciated. Also are you referring to the polygonised layer after I converted to raster or just the original one?
    – AhmedTech
    Aug 4 at 14:56
  • See updated answer with screenshot. You can do this on the polygonized layer.
    – Babel
    Aug 4 at 15:10
  • Thank you so much for your help. I am sure this will help. I will update you when this works, once I get something sorted in this. I am just having issues with the values that are coming out of perimeter, they dont seem to match the values in the vector data which is weird, maybe its because of the resampled data do you think. Yes actually do you think the perimeter values have changed since I have changed the resolution. So usually Fire ID 1 had perimeter of 8.4, but then in the new polygon it says value of 4, does that show its working? Or maybe I did something wrong
    – AhmedTech
    Aug 4 at 15:40
  • Maybe you use different CRS for your layers?
    – Babel
    Aug 4 at 16:09
  • Unfortunately its the same. I am going to ask the teacher how he expects to resample vector data? I am confused as to why someone should do that?
    – AhmedTech
    Aug 4 at 16:11
0

You don't say how you converted your polygon data to raster, but if you use the QGIS Raster > Conversion > Rasterize (Vector to Raster) tool it has the option to output the raster as a Float32 data type, which contains decimal places. Thus, your 1.87 will not be rounded to an integer value.

enter image description here

The tool also has the option to select which polygon field you wish to use as the output raster value. In my example below, that field is acres.

enter image description here

Having said this, your situation may contain a more important underlying question: should you be doing your analysis using all raster data, or all polygon data, instead of jumping back and forth between polygon and raster? That topic is out of scope for this question, but I would urge you to settle on one data type. Which data type you decide depends on the analysis you intend to conduct.

1
  • Thank you for your response. I have already done what you placed up there which is why I am confused. In terms of what datatype, I am just trying to resize the resolution of the fire data to match the resolution of the forest fragment data, and then combine the 2. One is 500m and another is 100m, I need to make them both 100m which is why I am doing this, I cant think of any other way
    – AhmedTech
    Aug 4 at 15:51

Your Answer

AhmedTech is a new contributor. Be nice, and check out our Code of Conduct.

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.