20 Replies Latest reply on Mar 29, 2013 7:47 AM by erice-esristaff

    Merge Raster data (table) with shapefile of counties

    rob_ford16
      Hi all. Thanks for any response in advance.

      My question is this: I have a raster image that details land use data for a state (Ohio). I also have a shapefile of all Ohio counties. I want to be able to export a table that has the raster values for each county listed. Basically, I need to query every county in the state. I've attached a ZIP file with 2 pictures and a layer file that contains the raster data and shapefile I am working with.

      I would consider myself an advanced-beginner with ArcGIS, so forgive any naivety on my part.

      Thanks for any and all help!
        • Re: Merge Raster data (table) with shapefile of counties
          rob_ford16
          Basically, as an example, I want to know how much land is covered by forest, corn, and soybeans in every County, Ohio based on the raster image. Thanks again for anyone who bothers to respond! :)
          • Re: Merge Raster data (table) with shapefile of counties
            erice-esristaff
            Hi Robert,

            You should check out the Zonal Histogram tool.  Your zones are the counties and the value raster would be your landuse raster.  This tool will give you the breakdown of each landuse within each zone.

            Best,
            Eric
            • Re: Merge Raster data (table) with shapefile of counties
              rob_ford16
              Thanks, but I have tried this method and it does not produce what I need. The resulting table does not tell me what the resulting values even stand for. I have attached what the outcome of this method is.

              However, the table does have the format that I need. (IE values for every county in the state)

              Thanks for the reply!
              • Re: Merge Raster data (table) with shapefile of counties
                erice-esristaff
                Hi Robert,

                I personally dislike the formatting of the output table, but it's not hard to get the landuse descriptions back.  All you would have to do is join the output table back to the raster attribute table.  The output table has a field called LABEL which you can use to join back to the VALUE field in the raster. Once this join is in place you'll have landuse descriptions back.  Since each zone becomes a field, you can't really expect to join this back to the original polygon zones. 

                I have an alternative workflow where you convert the landuse raster to polygons and run the Tabulate Intersection tool (new at 10.1) then I usually follow that up with the Pivot Table tool before joining the table back to my polygons.

                Best,
                Eric
                • Re: Merge Raster data (table) with shapefile of counties
                  rob_ford16
                  Hi Eric,

                  Thanks for the reply again. I currently only have access to ArcGIS 10 not 10.1.

                  I tried the join and got the resulting table attached. Also, there is no "LABEL" field in any of the tables I am working with so I'm not sure what you mean here. The table that was created is not correct as it shows cotton grown in the county, which cotton is not grown anywhere in Ohio.

                  I appreciate the help!

                  Best,
                  Rob
                  • Re: Merge Raster data (table) with shapefile of counties
                    erice-esristaff
                    Robert,

                    We will get this sorted out together...

                    Originally, I assumed you were symbolizing the landuse raster using Unique Value rendering and thus the zonal histogram table's label field would have the unique values for the raster in that column and require joining the zonal output table back to the input value raster table where Label = Value to establish/retain the landuse descriptions.  I found that if you symbolize by Unique Values, but use the description field for the value field (on symbology tab) rather than the Value field, when you run Zonal Histogram the label field will automatically contain the descriptions your looking for so no further join is required.  Please see screenshot-1 of result I obtained with this method.

                    Based on the table you sent and lack of label field, I do not believe you are using the Unique Value renderer.  My example case is simple with only 7 landuse categories so ArcMap automatically uses Unique Value, but if your data has more than 26 unique values (and it does) then ArcMap will display it with a stretched renderer.  If you leave it as stretched, AND your inputting a raster layer (rather than a raster dataset) then the layer's symbology defines the number of classes.  When it's stretched you get 256 classes so most of your landuse will be zero's for each county.  Hopefully this second screenshot helps clarify what is happening.  The table on the left is Zonal Histogram with the Unique Value renderer and the table on the right is with Stretched.  What you see is that the value 7 was stretched to 256 - county 1 still has 447 pixels of wetlands and county 2 has zero, but clearly using stretched is not the way to run this tool since the values for each landuse are stretched to the full 8 bit range and aren't really meaningful in terms of properly being able to join it back to get descriptions.  This is how you got cotton growing in Ohio! The stretched value was joined, not the real value.  :D

                    To summarize:
                    1. Use the Unique Value renderer on the landuse raster.
                    2. On the symbology tab, set the value field to the landuse description field like in screenshot-3. My description field just happens to be called Landuse.
                    3. Run Zonal Histogram.

                    This should produce what you're looking for without further joins.

                    Best,
                    Eric
                    • Re: Merge Raster data (table) with shapefile of counties
                      rob_ford16
                      Eric,

                      From your images, I see that my original data that I provided was not accessible. If you private message me your email, I can share a layer package with you via Google Drive (it's too large to upload here 15 MB +).

                      Also, my data is already displayed the way you say and show, but I still cannot figure out how to get the landuse descriptions back. I still just get the table like before.

                      Thanks again!
                      • Re: Merge Raster data (table) with shapefile of counties
                        rob_ford16
                        Also, attached is a screen capture of what I am doing with the Zonal Histogram tool, the raster table and symbology, and the resulting table again.
                        • Re: Merge Raster data (table) with shapefile of counties
                          rob_ford16
                          Eric,

                          So after playing around, I noticed if I change the symbology value field from "Class_Name" to "Value", Zonal histogram will output the labels column into the table (attached), but they still do not mean anything. If I try it with the "Class_Name" instead, I get the following message:

                          "Background processing has encountered a serious error and is unable to continue."

                          Thanks again for all of your help and  patience! :)
                          • Re: Merge Raster data (table) with shapefile of counties
                            rob_ford16
                            Okay so here is a link to the layer package with my data. Hopefully this works for anyone that downloads it!

                            If it doesn't, it would be great to know so I can figure out how to make it! :)

                            https://docs.google.com/file/d/0B_RLQsI9g3GWbUFDOGR4dkM4VWM/edit?usp=sharing
                            • Re: Merge Raster data (table) with shapefile of counties
                              erice-esristaff
                              Hi Rob,

                              Thanks for the data. I did a quick test using the workflow I described earlier and got exactly what I said we'd get.  What sp are you using with v10.0?  I am using 10.1 sp1 (the latest release).

                              -Eric
                              • Re: Merge Raster data (table) with shapefile of counties
                                erice-esristaff
                                One more thing since you're on an old release.  The name of your raster indicates it was the result of a clip operation.  I believe in your version, the table is not automatically updated and even records that were clipped off are still in your table with counts set to 0.  For example, in the data you sent, the raster has Barley with a significant number of pixels in the count column, but when I do zonal on it I get 0 for every county.  You should probably run the Build Raster Attribute Table tool to get an up to date raster attribute table before running Zonal Histogram.  It will make your output table look cleaner and won't be filled with 0's like in my last screenshot.  Back up/ copy your raster before rebuilding the table.

                                Best,
                                Eric
                                • Re: Merge Raster data (table) with shapefile of counties
                                  rob_ford16
                                  Eric,

                                  Thanks again. I am using sp5 (the latest from what I can tell). I will try it out again later this afternoon and get back to you. Also, I am assuming the numbers in the table represent pixels correct?

                                  I am comparing this acreage with another websites (http://nassgeodata.gmu.edu/CropScape/) that also lists pixel counts per county (screen shot of Lucas County, Ohio attached). The tables don't seem to match up if it is pixel counts.

                                  Again I will mess with it some more this afternoon and get back to you.

                                  Sorry I keep complicating the issue!

                                  I can't thank you enough!
                                  • Re: Merge Raster data (table) with shapefile of counties
                                    rob_ford16
                                    eric,

                                    Tried your workflow again but this time I added the Raster file to a personal geodatabase and did the Build Raster Attribute Table tool.

                                    Worked like a charm now. Not sure why it didn't like not being in a geodatabase.

                                    Finally got a table with a label column! But the values do no match the ones in your screenshot for some reason. Table is attached.

                                    Again, do these numbers represent pixels, acreage, or some other attribute?

                                    At least I finally figured out the original problem so thanks again!
                                    • Re: Merge Raster data (table) with shapefile of counties
                                      erice-esristaff
                                      I hadn't rebuilt the table before running zonal for that screenshot.  The numbers are definitely counts, not acreage or some other unit.

                                      Eric
                                      • Re: Merge Raster data (table) with shapefile of counties
                                        rob_ford16
                                        So I made a step by step guide for this problem. It is attached here. Hope it helps other people trying to figure this out!
                                        • Re: Merge Raster data (table) with shapefile of counties
                                          uncledish
                                          Rob or Eric,

                                          I'm wondering why Tabulate Area wouldn't have worked for what you were trying to do. Wouldn't it produce the same table?
                                          • Re: Merge Raster data (table) with shapefile of counties
                                            rob_ford16
                                            Tabulate area does not produce the table format I want.

                                            Now I have another issue. Zonal Histogram seems to ONLY work for certain files. I am attempting to do this for a few states and only certain states are working.

                                            Let me note that all of the states are in a geodatabase with the same formatting. All of the rasters are in a separate geodatabase with the same formatting.

                                            My question is why on Earth will Zonal Histogram only work for certain states (polygons)? Formats are the same. File Locations are the same.

                                            What is wrong with this program?
                                            • Re: Merge Raster data (table) with shapefile of counties
                                              JSwain-esristaff
                                              The morphology of the counties is probably causing the issue.  Depending on your data, that is what I would look into.  Also per the help documentation,

                                              If the zone input is a feature dataset, a vector-to-raster conversion will be internally applied to it. To ensure that the results of the conversion will align properly with the value raster, it is recommended that you check that the extent and snap raster are set appropriately in the environment settings and the raster settings.

                                              Since the internal raster must have an attribute table, an error will occur if one was not created in the conversion. If this happens, convert your feature dataset directly with Feature To Raster, Polygon To Raster, Point To Raster, or Polyline To Raster. Generate an attribute table for it as described in the previous tip and use the resulting raster as your Zone input.


                                              Also depends on how much NoData is covered by your zones.
                                              • Re: Merge Raster data (table) with shapefile of counties
                                                erice-esristaff
                                                The zones are counties Jeff, and there isn't a state in the union with more counties than the maximum unique values to render so it should be building a table during the conversion.  At this point, I would suggest Rob contact Esri Support and have an analyst go through it with him.  Rob posted this same question to the GP forum but included more details in that thread, specifically about the background gp process failing with error messages.  The first test is obviously running it in the foreground to narrow the issue down. After that, I would do what you suggested and convert the zones into raster datasets and run it again, to narrow down the issue some more. Support will know what to do in terms of other troubleshooting.

                                                Best,
                                                Eric