How to read a shapefile

1043
7
10-09-2012 08:37 AM
irinivozinaki
New Contributor III
Hi

I am a really new python user and I need to read a shapefile named "hpq0"
I have tried the following:

import shapefile
sf = shapefile.Reader("shapefiles/hpq0.shp")


but nothing happens. Obviously in this way the path to find the shapefile "hpq.shp" is not defined.
Is there any procedure for reading shapefiles except from the one described in this:
http://pypi.python.org/pypi/pyshp/#reading-shapefiles


Thank you very much in advance!!!
Tags (2)
0 Kudos
7 Replies
ChristopherThompson
Occasional Contributor III
I'm not sure what you mean by 'read' the shapefile.. are you trying to get at the values in the attribute table? gather the geometry, or do something else?
0 Kudos
DanPatterson_Retired
MVP Emeritus
Read up on Cursors in the online help, specifically Searchcursors
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000039000000
0 Kudos
irinivozinaki
New Contributor III
Yes I am trying to read the attribute table records and then I would like to insert these values in specific equations according to several scenarios.
0 Kudos
ChristopherThompson
Occasional Contributor III
Dan's suggestions about looking at Search Cursors is valuable, also look at the tools for working with tables and table views.  If you need to work through a table, fitting values from fields into formulae and then updating other fields in the same or another table look up the help topics on Update and Insert Cursors as well.  Those are probably the key things for what you want to do.  Reading and writing geometries are a bit different though still operate well using cursors.
0 Kudos
irinivozinaki
New Contributor III
Thank you very much for your help...I hope that I will manage it!
Have a nice day!
0 Kudos
irinivozinaki
New Contributor III
Me again!

I manage it!!! I can read the data in the columns of a polygon shapefile. But I have one more question.
Is it possible reading the columns data in the attribute table of a point shapefile?
Thank you!
0 Kudos
ChristopherThompson
Occasional Contributor III
absolutely.. in fact, you should be able to use the same methods with your point file as with the polygon.
0 Kudos