I have downloaded the 2006 census tract files. This version does not have the shapefiles format but the tiger format. I am able to load the data in python using following code:

import ogr
drv_tiger = ogr.GetDriverByName('TIGER')
abc = drv_tiger.Open('AK/')

There are roughly 18 layers in abc. The layer 6 is polygon. Since I am new to all this so I don't understand the organization that well. Lets say I get handle of layer 6. From there how do I extract tract shapes and finally, how do I convert them to shape files.

Update 2: Based upon new answer, I am able to load the layers in postgres using ogr2ogr and shp2pgsql tool. The sample output of the polygon layer looks as follows:

    polyid | statecu | countycu | tract | block | blkgrp | state | county 
      2 |       2 |       13 |   100 |  1986 |      1 |     2 |     13
      3 |       2 |       13 |   100 |  3998 |      3 |     2 |     13
      4 |       2 |       13 |   100 |  1052 |      1 |     2 |     13
      5 |       2 |       13 |   100 |  1052 |      1 |     2 |     13
      6 |       2 |       13 |   100 |  1985 |      1 |     2 |     13
      8 |       2 |       13 |   100 |  2025 |      2 |     2 |     13
      9 |       2 |       13 |   100 |  1051 |      1 |     2 |     13
     11 |       2 |       13 |   100 |  1986 |      1 |     2 |     13
     12 |       2 |       13 |   100 |  1054 |      1 |     2 |     13
     13 |       2 |       13 |   100 |  2000 |      2 |     2 |     13
     14 |       2 |       13 |   100 |  2000 |      2 |     2 |     13

Still need to figure out how to derive the shapefile given the polyids for each tract. It seems I need to refer to complete chain, but not sure. Possibly, one has to merge all the polyids for block to form the completechain for the tract.

  • Can you provide screen shot(s) of the results you have received? e.g. "handle of layer 6"
    – whyzar
    Commented Oct 27, 2016 at 21:17
  • I don't display anything right now. It is just another command "l6 = abc.GetLayer(6)". I do get back a reference to layer6 in variable l6. Not sure how to proceed from there.
    – Kabira K
    Commented Oct 27, 2016 at 21:48
  • I browsed the technical documentation (www2.census.gov/geo/pdfs/maps-data/data/tiger/tiger2006se/…). It doesn't talk in terms of layers but in terms of record types and GT-polygons. It seems record type A of the GT-polygon refers to geographic entity codes. Census tract happens to be one of the geographic entity with entity code ''T'. If I can somehow get access to record type A of the polygons then filter out ones with T code, i would a step closer. Just don't know how.
    – Kabira K
    Commented Oct 28, 2016 at 2:44
  • A few more details: I was able to extract the 'polygon' layer which contains several features. Each feature has bunch of attributes on of hem is tract. But the values are numbers such 100, 200, 300, 500. Not sure what they mean
    – Kabira K
    Commented Oct 31, 2016 at 16:46

2 Answers 2


Good question. So lets review,

The TIGER/Line files are typically used in conjunction with geographic information system (GIS), or similar, software. The U.S. Census Bureau provides the TIGER/Line files in ASCII text format only

I found a blog entry by Josh Long about this with PostGIS. All of that code he references can be found here in the upstream repo. That code is 9 years old but the script tigerpoly2.py should give you an idea of how this is done in Python with ogr.

Also potentially useful, is this answer which addresses the same thing using command line arguments ogr2ogr and ogrinfo (which still work, I tried them).

ogr2ogr -a_srs EPSG:4269 -f "ESRI Shapefile" outputDir TGR48043.RT1
# You may want to add -G for `geography` type.
shp2pgsql -D outputDir/CompleteChain.prj yourSchema.yourTable | psql

QGIS also gives you the ability to export to the .shp files, which may be easier if you don't need all of them from every zone in every state. Just extract the zip, select to import a new vector layer, select all files, and select any file exported (it'll figure it out).

qgis import

  • Nice! I am quite close now. I tried the ogr2ogr+postgis route (I had those handy). I am able to load the layers. Please see the updated question. I describe the output of the polygon layer in posgis. I will gleam through the rest links and try to locate how link polygon layer with the completeChain, but if you happen to know then do share. Thanks for the references was really helpful.
    – Kabira K
    Commented Nov 4, 2016 at 15:20
  • I talked to a collegue who uses ArcGis and he mentioned a routine in ArcGIS called ''dissolve''. Google search led me to 'ST_Union' command for postGIS. Dissolve/ST_Union is relevant because census does not have tract shapefiles but block shapefiles which need to be dissolved to a block. The question is how do I get to the block shapes. Had to dig this info out from tigerpoly2.py code. Essentially, you join as follows: Polygon(cnid, polyid) in [polychainlink(cnidl, polyidl), polychainlin(cnidr, polyidr)]. continued...
    – Kabira K
    Commented Nov 5, 2016 at 14:50
  • .... now take tlids of the join and reference the complete chain table to get the geom. Take the geoms and dissolve it to get the tract shapefiles. Let me know your thoughts. And thanks so much for the references. I think I finally was able to put 2 and 2 together, although one was on Mars and other embedded within a Hilbert Space.
    – Kabira K
    Commented Nov 5, 2016 at 14:53

I've looked at the documentation on the US Census site. Record type 2 has up to ten LAT and LONG points, which you can concatenate into the "Well-Known-Text" (WKT) format, see examples on wikipedia

Maybe you can use a python library to transform from WKT into a geometry object, probably py-gdalogr?

from osgeo import ogr

# Create ring
ring = ogr.Geometry(ogr.wkbLinearRing)
ring.AddPoint(1179091.1646903288, 712782.8838459781)
ring.AddPoint(1161053.0218226474, 667456.2684348812)
ring.AddPoint(1214704.933941905, 641092.8288590391)
ring.AddPoint(1228580.428455506, 682719.3123998424)
ring.AddPoint(1218405.0658121984, 721108.1805541387)
ring.AddPoint(1179091.1646903288, 712782.8838459781)

# Create polygon
poly = ogr.Geometry(ogr.wkbPolygon)

print poly.ExportToWkt()

If you are open to another useful tool, I'd suggest that you use PostgreSQL with PostGIS to transform the text version of the tract data into a geometry (or geography) object, using this function: ST_GeomFromText (postgis.net)

At that point, you can easily use the command line function "pgsql2shp" to extract the data within postgres into a shape file (or keep it in postgres for analysis, even with python as PL/python).

  • 1
    Geoffrey, the question is not about converting a set of point to shapefile format. It has more to do with how to extract polylines from census data, more precisely, the polylines for tracts. It is true that record type 2 contains additional lat/long to form a complete chain. There are two questions: how to we extract the lat/longs and how do they relate to census tract.
    – Kabira K
    Commented Oct 31, 2016 at 15:08
  • I said polylines in the above comment, what I meant was polygons.
    – Kabira K
    Commented Oct 31, 2016 at 16:32
  • Per the US Census documentation, "The chains in the TIGER/ Line® files are complete chains because they form polygon boundaries and intersect other chains only at nodes." Commented Oct 31, 2016 at 19:21
  • The main point is this, if you can build these "blocks" as polygons from the Lat/Long points provided, then each of the block polygons can be lumped together into block groups, and then into tracts, and that depends upon the relational data (aka "attribute" data) contained within the files (in postgis, that's the ST_Union function). See hierarchical chart on page 4-4, 2006SE Tiger/Line doc. Record Type S has specific Tract data element. Be careful, since they specifically state that tracts are defined only for the 10-year census 2000, and not the 2006 version. Commented Oct 31, 2016 at 19:43
  • Would be really if you provide some code outline for this. My understanding is that the record types for census corresponds to layers in the ogr world. A layer contains several features. However, I am not able to extract either the shape or the relevant attributes of these feature.
    – Kabira K
    Commented Oct 31, 2016 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.