Skip to content

Commit b626183

Browse files
Merged several pull requests
The most significant change is the addition of the iterShapeRecords() method which is the same as the shapeRecords() method using iterators for large files. Also removed the html and pdf versions of the README file.
1 parent c86c4f4 commit b626183

File tree

3 files changed

+43
-32
lines changed

3 files changed

+43
-32
lines changed

README.md

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,15 @@ 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
28-
only available on the google code project site at
29-
[http://code.google.com/p/pyshp](http://code.google.com/p/pyshp). These
27+
Currently the sample census blockgroup shapefile referenced in the examples is available on the google code project site at
28+
[https://github.com/GeospatialPython/pyshp](https://github.com/GeospatialPython/pyshp). These
3029
examples are straight-forward and you can also easily run them against your
3130
own shapefiles manually with minimal modification. Other examples for specific
32-
topics are continually added to the pyshp wiki on google code and the blog
31+
topics are continually added to the pyshp wiki on GitHub and the blog
3332
[http://GeospatialPython.com](http://GeospatialPython.com).
3433

3534
Important: For information about map projections, shapefiles, and Python
36-
please visit: [http://code.google.com/p/pyshp/wiki/MapProjections](http://code
37-
.google.com/p/pyshp/wiki/MapProjections)
35+
please visit: [https://github.com/GeospatialPython/pyshp/wiki/Map-Projections](https://github.com/GeospatialPython/pyshp/wiki/Map-Projections)
3836

3937
I sincerely hope this library eliminates the mundane distraction of simply
4038
reading and writing data, and allows you to focus on the challenging and FUN
@@ -72,7 +70,7 @@ OR
7270
>>> sf = shapefile.Reader("shapefiles/blockgroups.dbf")
7371

7472
OR any of the other 5+ formats which are potentially part of a shapefile. The
75-
library does not care about extensions.
73+
library does not care about file extensions.
7674

7775
### Reading Shapefiles from File-Like Objects
7876

@@ -176,7 +174,7 @@ index which is 7.
176174

177175
A record in a shapefile contains the attributes for each shape in the
178176
collection of geometry. Records are stored in the dbf file. The link between
179-
geometry and attributes is the foundation of Geographic Information Systems.
177+
geometry and attributes is the foundation of all geographic information systems.
180178
This critical link is implied by the order of shapes and corresponding records
181179
in the shp geometry file and the dbf attribute file.
182180

@@ -276,7 +274,7 @@ Now let's read the first two points for that same record:
276274
>>> len(points)
277275
2
278276

279-
The shapeRec() method reads a single shape/record pair at the specified index.
277+
The shapeRecord() method reads a single shape/record pair at the specified index.
280278
To get the 4th shape record from the blockgroups shapfile use the third index:
281279

282280

@@ -292,6 +290,13 @@ The blockgroup key and population count:
292290

293291
>>> len(points)
294292
2
293+
294+
There is also an iterShapeRecords() method to iterate through large files:
295+
296+
>>> shapeRecs = sf.iterShapeRecords()
297+
>>> for shape, rec in shapeRecs:
298+
... # do something here
299+
295300

296301
## Writing Shapefiles
297302

@@ -384,21 +389,6 @@ Geometry is added using one of three methods: "null", "point", or "poly". The
384389
"null" method is used for null shapes, "point" is used for point shapes, and
385390
"poly" is used for everything else.
386391

387-
**Adding a Null shape**
388-
389-
Because Null shape types (shape type 0) have no geometry the "null" method is
390-
called without any arguments.
391-
392-
393-
>>> w = shapefile.Writer()
394-
395-
>>> w.null()
396-
397-
The writer object's shapes list will now have one null shape:
398-
399-
400-
>>> assert w.shapes()[0].shapeType == shapefile.NULL
401-
402392
**Adding a Point shape**
403393

404394
Point shapes are added using the "point" method. A point is specified by an x,
@@ -431,13 +421,28 @@ using a single method called "poly".
431421
>>> w.poly(shapeType=3, parts=[[[122,37,4,9], [117,36,3,4]], [[115,32,8,8],
432422
... [118,20,6,4], [113,24]]])
433423

424+
**Adding a Null shape**
425+
426+
Because Null shape types (shape type 0) have no geometry the "null" method is
427+
called without any arguments. This type of shapefile is rarely used but it is valid.
428+
429+
430+
>>> w = shapefile.Writer()
431+
432+
>>> w.null()
433+
434+
The writer object's shapes list will now have one null shape:
435+
436+
437+
>>> assert w.shapes()[0].shapeType == shapefile.NULL
438+
434439
### Creating Attributes
435440

436441
Creating attributes involves two steps. Step 1 is to create fields to contain
437442
attribute values and step 2 is to populate the fields with values for each
438443
shape record.
439444

440-
The following attempts to create a complete shapefile:
445+
The following attempts to create a complete shapefile. The attribute and field names are not very creative:
441446

442447

443448
>>> w = shapefile.Writer(shapefile.POINT)
@@ -483,13 +488,13 @@ names.
483488
### File Names
484489

485490
File extensions are optional when reading or writing shapfiles. If you specify
486-
them Pyshp ignores them anyway. When you save files you can specify a base
491+
them PyShp ignores them anyway. When you save files you can specify a base
487492
file name that is used for all three file types. Or you can specify a nmae for
488493
one or more file types. In that case, any file types not assigned will not
489494
save and only file types with file names will be saved. If you do not specify
490495
any file names (i.e. save()), then a unique file name is generated with the
491496
prefix "shapefile_" followed by random characters which is used for all three
492-
files. The unique file name is returned as a string. _
497+
files. The unique file name is returned as a string.
493498

494499

495500
>>> targetName = w.save()
@@ -517,7 +522,7 @@ write them.
517522
## Editing Shapefiles
518523

519524
The Editor class attempts to make changing existing shapefiles easier by
520-
handling the reading and writing details behind the scenes.
525+
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.
521526

522527
Let's add shapes to existing shapefiles:
523528

README.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ PyShp
33

44
:Author: Joel Lawhead - [email protected]
55

6-
:Version 1.2.1
6+
:Version 1.2.2
77

8-
:Revised: May 11, 2014
8+
:Revised: January 9, 2015
99

1010
.. contents::
1111

@@ -291,7 +291,13 @@ The blockgroup key and population count:
291291
>>> points = shapeRec.shape.points[0:2]
292292

293293
>>> len(points)
294-
2
294+
2
295+
296+
There is also an iterShapeRecords() method to iterate through large files:
297+
298+
>>> shapeRecs = sf.iterShapeRecords()
299+
>>> for shape, rec in shapeRecs:
300+
... # do something here
295301

296302
Writing Shapefiles
297303
++++++++++++++++++

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup
22

33
setup(name='pyshp',
4-
version='1.2.0',
4+
version='1.2.2',
55
description='Pure Python read/write support for ESRI Shapefile format',
66
long_description=open('README.txt').read(),
77
author='Joel Lawhead',

0 commit comments

Comments
 (0)