Select to view content in your preferred language

How to read a shapefile

1341
7
10-09-2012 08:37 AM
irinivozinaki
Deactivated User
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
Frequent Contributor
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
Deactivated User
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
Frequent Contributor
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
Deactivated User
Thank you very much for your help...I hope that I will manage it!
Have a nice day!
0 Kudos
irinivozinaki
Deactivated User
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
Frequent Contributor
absolutely.. in fact, you should be able to use the same methods with your point file as with the polygon.
0 Kudos