I have a raster layer and a shapefile which contains a network of polylines. I am trying to find a way to calculate the number of pixels in the raster layer that a specific polyline goes through. It would be great if they was a way to extract the raster cell value as well.
Run Extract by Mask and use your polyline as the mask input. It will pull the values from underneath the polyline and then you can open the attribute table and check the Count field to get the number of pixels. This tool requires Spatial Analyst, and I'm also making an assumption you're working with an integer raster; Floating point rasters do not have attribute tables.
Thanks so much for your response. The extract by mask tool worked great but I have a several polylines group together in one feature layer. The polyline feature layer has a single attribute table but there are several line segments each having their own properties. I've attached a photo to be clear. I would like to add the number of pixels field to the attribute table for each line segment. I know I can select each line segment and make it its own feature layer but is there a more efficient way of doing it?
After reading your post and thinking a bit more about this, I don't think Extract by Mask is all that viable. It would require you to summarize each raster created from selected polylines which is just more work. This a.m. I ran Zonal Statistics as Table with many polylines (for the zone features) and it worked really well. The only thing is that it doesn't extract the underlying raster values to form a new raster like the extraction tools do. It will however, provide you with some meaningful statistics about the underlying pixels. Count, Min, Max, Range, Mean, etc... All you have to do is join the output table back to your original polylines using the same field you specified in the Zone Field parameter of the tool. Let me know if this works better for you.
Also, do you polylines cross each other? This will be problematic unless managed properly. What version are you using?
To answer your question, the polylines do not cross each other. My colleague actually just built a tool that deletes identical polylines and ensures that each line segment arc has only two nodes. I am using arcGIS 10.
The Zonal Statistic as Table tool worked great. The tool did a great job counting the number of pixels as well as the mean value of the raster cell which is exactly what I wanted. However, I ran into trouble when I tried to join the newly created table back to the polyline attribute table. The join is not validating because there are reserved words (COUNT, MAX, MIN, etc). Is there a way to get around this?