Skip to content

Commit 5d51227

Browse files
Merge pull request #61 from micahcochran/merge-readme
Merge README text into markdown file. Remove text version.
2 parents 50b6217 + 6b28182 commit 5d51227

File tree

3 files changed

+52
-685
lines changed

3 files changed

+52
-685
lines changed

README.md

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Pyshp is compatible with Python 2.4-3.x.
2424

2525
This document provides examples for using pyshp to read and write shapefiles.
2626

27-
Currently the sample census blockgroup shapefile referenced in the examples is available on the google code project site at
27+
Currently the sample census blockgroup shapefile referenced in the examples is available on the GitHub project site at
2828
[https://github.com/GeospatialPython/pyshp](https://github.com/GeospatialPython/pyshp). These
2929
examples are straight-forward and you can also easily run them against your
3030
own shapefiles manually with minimal modification. Other examples for specific
@@ -46,8 +46,8 @@ Before doing anything you must import the library.
4646
>>> import shapefile
4747

4848
The examples below will use a shapefile created from the U.S. Census Bureau
49-
Blockgroups data set near San Francisco, CA and available in the subversion
50-
repository of the pyshp google code site.
49+
Blockgroups data set near San Francisco, CA and available in the git
50+
repository of the pyshp GitHub site.
5151

5252
## Reading Shapefiles
5353

@@ -128,13 +128,17 @@ Each shape record contains the following attributes:
128128
'points'
129129
'shapeType'
130130

131-
* shapeType: an integer representing the type of shape as defined by the shapefile specification.
131+
* shapeType: an integer representing the type of shape as defined by the
132+
shapefile specification.
132133

133134

134135
>>> shapes[3].shapeType
135136
5
136137

137-
* bbox: If the shape type contains multiple points this tuple describes the lower left (x,y) coordinate and upper right corner coordinate creating a complete box around the points. If the shapeType is a Null (shapeType == 0) then an AttributeError is raised.
138+
* bbox: If the shape type contains multiple points this tuple describes the
139+
lower left (x,y) coordinate and upper right corner coordinate creating a
140+
complete box around the points. If the shapeType is a
141+
Null (shapeType == 0) then an AttributeError is raised.
138142

139143

140144
>>> # Get the bounding box of the 4th shape.
@@ -143,12 +147,16 @@ Each shape record contains the following attributes:
143147
>>> ['%.3f' % coord for coord in bbox]
144148
['-122.486', '37.787', '-122.446', '37.811']
145149

146-
* parts: Parts simply group collections of points into shapes. If the shape record has multiple parts this attribute contains the index of the first point of each part. If there is only one part then a list containing 0 is returned.
150+
* parts: Parts simply group collections of points into shapes. If the shape
151+
record has multiple parts this attribute contains the index of the first
152+
point of each part. If there is only one part then a list containing 0 is
153+
returned.
147154

148155
>>> shapes[3].parts
149156
[0]
150157

151-
* points: The points attribute contains a list of tuples containing an (x,y) coordinate for each point in the shape.
158+
* points: The points attribute contains a list of tuples containing an
159+
(x,y) coordinate for each point in the shape.
152160

153161
>>> len(shapes[3].points)
154162
173
@@ -183,8 +191,12 @@ You can call the "fields" attribute of the shapefile as a Python list. Each
183191
field is a Python list with the following information:
184192

185193
* Field name: the name describing the data at this column index.
186-
* Field type: the type of data at this column index. Types can be: Character, Numbers, Longs, Dates, or Memo. The "Memo" type has no meaning within a GIS and is part of the xbase spec instead.
187-
* Field length: the length of the data found at this column index. Older GIS software may truncate this length to 8 or 11 characters for "Character" fields.
194+
* Field type: the type of data at this column index. Types can be: Character,
195+
Numbers, Longs, Dates, or Memo. The "Memo" type has no meaning within a
196+
GIS and is part of the xbase spec instead.
197+
* Field length: the length of the data found at this column index. Older GIS
198+
software may truncate this length to 8 or 11 characters for "Character"
199+
fields.
188200
* Decimal length: the number of decimal places found in "Number" fields.
189201

190202
To see the fields for the Reader object above (sf) call the "fields"
@@ -264,7 +276,7 @@ list of field values as demonstrated in the "Reading Records" section.
264276
Let's read the blockgroup key and the population for the 4th blockgroup:
265277

266278

267-
>>> shapeRecs3.record[1:3]
279+
>>> shapeRecs[3].record[1:3]
268280
['060750601001', 4715]
269281

270282
Now let's read the first two points for that same record:
@@ -295,17 +307,18 @@ The blockgroup key and population count:
295307
There is also an iterShapeRecords() method to iterate through large files:
296308

297309
>>> shapeRecs = sf.iterShapeRecords()
298-
>>> for shape, rec in shapeRecs:
310+
>>> for shapeRec in shapeRecs:
299311
... # do something here
312+
... pass
300313

301314

302315
## Writing Shapefiles
303316

304-
The PSL tries to be as flexible as possible when writing shapefiles while
317+
PyShp tries to be as flexible as possible when writing shapefiles while
305318
maintaining some degree of automatic validation to make sure you don't
306319
accidentally write an invalid file.
307320

308-
The PSL can write just one of the component files such as the shp or dbf file
321+
PyShp can write just one of the component files such as the shp or dbf file
309322
without writing the others. So in addition to being a complete shapefile
310323
library, it can also be used as a basic dbf (xbase) library. Dbf files are a
311324
common database format which are often useful as a standalone simple database
@@ -333,9 +346,10 @@ shapefile specification. It is important to note that numbering system has
333346
several reserved numbers which have not been used yet therefore the numbers of
334347
the existing shape types are not sequential.
335348

336-
There are three ways to set the shape type: - Set it when creating the class
337-
instance. - Set it by assigning a value to an existing class instance. - Set
338-
it automatically to the type of the first shape by saving the shapefile.
349+
There are three ways to set the shape type:
350+
* Set it when creating the class instance.
351+
* Set it by assigning a value to an existing class instance.
352+
* Set it automatically to the type of the first shape by saving the shapefile.
339353

340354
To manually set the shape type for a Writer object when creating the Writer:
341355

@@ -443,7 +457,8 @@ Creating attributes involves two steps. Step 1 is to create fields to contain
443457
attribute values and step 2 is to populate the fields with values for each
444458
shape record.
445459

446-
The following attempts to create a complete shapefile. The attribute and field names are not very creative:
460+
The following attempts to create a complete shapefile. The attribute and
461+
field names are not very creative:
447462

448463

449464
>>> w = shapefile.Writer(shapefile.POINT)
@@ -523,7 +538,10 @@ write them.
523538
## Editing Shapefiles
524539

525540
The Editor class attempts to make changing existing shapefiles easier by
526-
handling the reading and writing details behind the scenes. This class is experimental and should be avoided for production use. You can do the same thing by reading a shapefile into memory, making changes to the python objects, and write out a new shapefile with the same or different name.
541+
handling the reading and writing details behind the scenes. This class is
542+
experimental and should be avoided for production use. You can do the same
543+
thing by reading a shapefile into memory, making changes to the python objects,
544+
and write out a new shapefile with the same or different name.
527545

528546
Let's add shapes to existing shapefiles:
529547

@@ -566,17 +584,27 @@ Remove the last shape in the polygon shapefile.
566584
>>> e.delete(-1)
567585
>>> e.save('shapefiles/test/polygon')
568586

569-
## Python __geo_interface__
587+
## Python \_\_geo_interface\_\_
570588

571-
The Python __geo_interface__ convention provides a data interchange interface
589+
The Python \_\_geo_interface\_\_ convention provides a data interchange interface
572590
among geospatial Python libraries. The interface returns data as GeoJSON. More
573-
information on the __geo_interface__ protocol can be found at: [https://gist.g
591+
information on the \_\_geo_interface\_\_ protocol can be found at: [https://gist.g
574592
ithub.com/sgillies/2217756](https://gist.github.com/sgillies/2217756). More
575593
information on GeoJSON is available at
576-
[http://geojson.org](http://geojson.org)
577594
[http://geojson.org](http://geojson.org).
578595

579596

580597
>>> s = sf.shape(0)
581598
>>> s.__geo_interface__["type"]
582599
'MultiPolygon'
600+
601+
# Testing
602+
603+
The testing framework is doctest, which are located in this file README.md.
604+
In the same folder as README.md and shapefile.py, from the command line run
605+
```
606+
$ python shapefile.py
607+
```
608+
609+
Linux/Mac and similar platforms will need to run `$ dos2unix README.md` in order
610+
correct line endings in README.md.

0 commit comments

Comments
 (0)