raster to polygon - zero values - polygon

I am trying to convert a raster of cell size 50x50 into a polygon without success.
The raster file has some values and most of them are zero values. When I convert the raster using the tool Raster to polygon, the result is a big polygon for all the values equal to zero, instead of a polygon for each cell with zero value.
Someone knows how to create an independent polygon for each zero value?
I attached an image of my resutls.

Read this article ... it may solve your problem:
https://support.esri.com/en/technical-article/000012696
Steps:
1) Use the Raster to Point tool to convert each pixel to a point (found in Conversion Tools > From Raster). These points are later used to label polygons.
2) Navigate to ArcToolbox > Data Management Tools > Feature Class > Create Fishnet. The values entered into this tool are taken from the properties of the raster. To access the properties of the raster, right-click the raster in the Table Of Contents in ArcMap > Properties > Source tab.
3) Navigate to ArcToolbox > Data Management Tools > Features > Feature To Polygon. Run the Feature to Polygon tool on the fishnet output from step 2, with the Raster to Points output specified in the Label Features field. This gives the final polygon which has a field named GRID_CODE with the cell values of the raster.

Related

raster:: extract produces an empty list

I am trying to extract the values of pixels in a DSM(CHM) within digitized tree crowns.
first I set my working directory read in the shapefile and raster.
TreeCrowns <-shapefile("plot1sag_shape/plot1sag.shp")
CHM <- raster('272280split4.tif')
Then I try to extract the pixel values
pixel <- raster::extract(CHM, TreeCrowns, method= 'simple', weights=FALSE, fun=NULL)
But I get an empty list with all NULL values for every polygon. I have confirmed that the CHM and polygons are in the same location. What can I do to fix this?
Since your shapefile consists of polygon, the extract() function need to know how to summarise the pixel values across a polygon via the fun= argument. Since you provide fun=NULL, the function interpret as returning NULL values to summarise the pixel values.
Try fun=mean or fun=sum (and they mean different thing so see which one suits you).
That probably happens because the polygons and the raster do not overlap. Can you show(CHM) and TreeCrowns? Have you looked at
plot(CHM)
lines(TreeCrowns)
Or are your polygons very small relative to the raster cells? In that case try argument small=TRUE

How to change number of layers of a raster brick

When I load a tiff image in R as raster brick then I have the expected number of pixels (number rows and columns) when I check afterwards the details of the image. But I expect 44 layers. I think I can change the number of layers with the nlayers function. Unfortunately, this does not work. The number of layers remain at 4.
sample_brick = brick("file_example_TIFF_1MB.tiff", nlayers = 44)
Can someone help me how to adapt the number of layers?
Here you can find a example tiff image.
https://file-examples.com/wp-content/uploads/2017/10/file_example_TIFF_1MB.tiff
The brick function creates a RasterBrick that has all the layers that are in your file.
Your expectation is probably wrong.
You cannot add imaginary layers when creating an object from file.

Calculating the percentage of the area that a polygon covers a cell in a raster in QGIS

I'm having trouble with using QGIS.
I have a GRIB file containing meteorlogical data, this is loaded in QGIS as rasterdata if I'm not mistaken.
I also have a shape-file containing a polygon, describing regions within the area covered in the GRIB file.
What I need to know, is how many % of a raster-cell is covered by a region within the polygon. I'm using QGIS.
What I have done so far, is I rasterized the polygon, and used zonal statistics to calculate the SUM and COUNT on the shape-file, and then used the field calculator to calculate the percentage covered. This does not seem to provide the result I hoped for.
Can anyone push me in the right direction?

Create stage height raster using least cost path and r

I have a point shapefile of Station IDs and stageheights. I would like to create a raster where each cell has the stage height value (in meters) of the closest in situ station to that cell.
I want this raster to match up with another raster. So I would like it if I could input both a raster I have created (dataset 3 described below) and my point shapefile (1).
Datasets:
1) Point Shapefile with stage heights of a river delta
2) Shapefile of the river delta extent
3) Raster of the delta where NA's represent land (could also have them be zero's if need be) and 1's are water. Two datasets 10 meter resolution and 30 meter resolution.
One conceptual issue I am having is with the amount of small streams I have.
For example (pictured in image below), station 1 (circled in blue) is technically closer to the black x region than station 2 (circled in red), but the stage height value in red is more representative of point x. There are NA's in between the two streams, does that mean that the value will not jump across streams?
How can I reassign the values in my Raster (all the 1's) to the stage height of the nearest station and make sure that these values are not jumping from stream to stream? Do I need to use least cost path? What is the best way to do this?
I would like to use R, but can use ArcMap if I must.
So I'm not sure what tools you have available to you but I think this answer may be useful:
Calculating attribute for network distance between multiple points in ArcGIS Desktop?
Here the questioner was looking to calculate distances on roads to some points, but your problem seems similar. I think the main point I would make here is that you should do your network distance classification prior to worrying about the raster layer. You may have to convert from polygon to lines or some workaround to get your data into a format that works, but this is the kind of job the tool is designed to do.
After you have reclassified your river shapefile based on their network distance to a given point, then convert the polygons to raster and use this to classify your original raster. You could do this in R or Arcmap. Arcmap will probably be faster.

Determining the size of grid cells in a raster

Is there a good method for determining the size of individual grid cells in a RasterLayer? I can access the resolution but I need the actual size in km^2. I've tried using the area() with my raster but it's not finding the window. I've also tried creating a SpatialGridDataFrame from my raster but have had no luck computing the area of each individual grid cell. Any help would be appreciated.
The cells size is the product of the x and y resolution prod(res(x)) if you have a planar coordinate reference system. Otherwise, if your crs is longitude/latitude, cell size will change with latitude, and you can indeed use the area function to get the size of each cell.
I take it that "it's not finding the window." refers to this error message Error in as.owin.default(w) : Can't interpret W as a window.
This is a name conflict with spatstat. So either do not load spatstat or call the raster function explicitly raster::area(x).

Resources