[R-sig-Geo] Fill raster with information if it intersects with a Polygon for ASCii File

Alex Mandel tech_dev at wildintellect.com
Fri May 12 17:30:25 CEST 2017


Does the output need to be an ASCII Raster or a text file with center
coordinates of each cell and a value?

#Make a raster of value 1
#Mask that raster with the polygon layer, updatevalue=0 to set the area
outside the polygon to 0
mask()
https://www.rdocumentation.org/packages/raster/versions/2.5-8/topics/mask

To save as ASCII raster check the writeRaster (rgdal parameters).

To write a text file 1 line with center coordinates and and values,
rasterToPoints()
 https://www.rdocumentation.org/packages/raster/versions/2.5-8/topics/rasterToPoints
Then put the coords in the DataFrame and write.csv, or use writeOGR with
csv as the output format.


You could also rasterize the polygons, and reclassify. Or make the point
layer from the raster and use over, or intersect to pull values into the
points.

Hope that gives you some options.

-Alex

On 05/12/2017 01:21 AM, Miriam Püts wrote:
> Hi everyone,
> 
> I am fairly new at working with raster in R. I have combed through the threats about raster and shape files, but I could find completely what I was looking for. 
> 
> May I start with the task at hand:
> 
> I want to create a raster with geographic choordinates (done with raster function). 
> Next I would like to fill this raster with the information, if each cell is intersecting with a shape file (Polygon) or not. 
> Next I need to write an ASCii file with the choords, and 1 or 0 for intersecting or not. 
> 
> The reason why I am doing this is because I am working with Ecospace and I would like to include marine protected areas not by drawing but by reading an ASCii file. 
> 
> I hope I made clear what I am going for.
> 
> Thanks for information!
> 
> 
> <°)))>< >°)))>< >°)))>< >°)))><
> 
> Miriam Püts
> Marine Lebende Ressourcen/ Marine Living Resources
> Thünen-Institut für Seefischerei/ Thünen Institute of Sea fisheries
> Palmaille 9
> 22767 Hamburg (Germany)
> 
> Tel:  +49 40 38905-105 
> Mail: miriam.puets at thuenen.de
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list