blankblank blank




Assigning Attributes From A Polygon Shapefile To Another Shapefile



Here’s a recap of yesterday’s request from TD:

Wondering if you know of an easy way to create centroids (points) from polygons – I am using MapWindow and various other free tools. What I am ultimately trying to do is assign attribute data (parcel #) to a polygon shapefile representing buildings.  In other words, for each building polygon I want to assign it the correct parcel #.

Yesterday’s post went through the first part of this process, converting the building polygon shapefile  into a centroids (approximate building geometric centers) point shapefile, carrying over the building shapefile attributes to the corresponding centroid points. Now I need to assign attribute data from the parcel polygon shapefile to the centroids.

For this, I’ll use the most recent version (the 4.7 Release Candidate) of the freeware GIS program MapWindow, whose features have been the subjects of many previous posts on this blog. First step is to load in the parcel polygon shapefile (parceltest.shp; displayed here as green polygons), and the centroids point shapefile (centroid.shp; the red dots):

4-5-2009-8.38.59 PM

From the GIS Tools => Vector menu, select the “Identity Of Shapes With Polygon” function:

4-5-2009-8.42.54 PM

(Yeah, the function window title has a different name than the menu item, at least for now in the Release Candidate)

The “Input Shapefile” is the one I want to assign polygon attributes to (centroid.shp), while the “Identity Shapefile” is the source of those attributes (parcel info in this case, so parceltest.shp). The final output shapefile is specified under “File to Save Results. Note: you can’t just type in a filename in the box, you have to click on the folder icon at the right and enter the desired output name there. Checking the “Add Results to” box will add the output shapefile to the current display after processing is done. Click on OK to process the shapefiles; in this case, with the box checked, the output file will be added to the layers list:

4-5-2009-8.47.04 PM

To check to make sure the output point file has all the attributes from the polygon file, I’ll click the Attribute Table Editor button on the toolbar to open the output file’s attribute table. In this case, there were fields with the same name in both the input and identity shapefiles, and I got pop-up boxes to rename these fields to eliminate the name conflicts:

4-5-2009-8.49.31 PM

Once the attribute table came up, I could see that all of the parcel information (numbers, street addresses, county, state, etc.), which weren’t in the original building centroid shapefile, were now assigned to the corresponding centroids, including cases where more than one building was located on a single parcel:

4-5-2009-8.56.26 PM

The input shapefile doesn’t have to be a point shapefile. For example, I could have taken the original building polygon shapefile (used to generate the centroids) as the input shapefile in this process, and the parcel polygon shapefile as the identity shapefile. The result would have been a building polygon shapefile with the appropriate parcel shapefile attributes added to every building’s data in the attribute table. If I still wanted centroids, I could then take this new shapefile and use the process from yesterday’s post to generate a centroid point shapefile with all of the building attributes.


Looking for something else? Enter some keywords below, then click "Search".    




2 Responses to “Assigning Attributes From A Polygon Shapefile To Another Shapefile”


  1. 1 Tyson

    Regarding the last paragraph: “I could have taken the original building polygon shapefile (used to generate the centroids) as the input shapefile in this process, and the parcel polygon shapefile as the identity shapefile. The result would have been a building polygon shapefile with the appropriate parcel shapefile attributes added to every building’s data in the attribute table.”

    Mostly true. There is a quirk in the MapWindow “Identity of features by Polygon” GIS Tools implementation. Using the building and parcels examples cited in two previous posts, when a building polygon is not wholly located within a parcel polygon (presumably due to errors when converting a raster satellite image to a vector shapefile…) MapWindow will “split” the building into two separate buildings along the parcel boundary. While this may be suitable for some applications, it is not when trying to “assign” parcel data to individual buildings. For this application, it is much better to first find the centroid of each building, then assign the parcel attributes using the centroids. The centroid of each individual building is likely to fall within the boundary of the correct parcel shape, and the resulting shapefile generated by MapWindow will not have “extra” building shapes.

  2. 2 Leszek Pawlowicz

    If there’s a unique identifier for the buildings that gets passed on to the centroids, it should be possible to link the parcel data from the centroid file to building shapefile.

Comments are currently closed; feel free to contact me with questions/issues.