Skip to content

Commit af24202

Browse files
authored
Merge pull request #1 from GeospatialPython/master
Sync before fixing error
2 parents 75d28ae + fa8df8b commit af24202

File tree

8 files changed

+102
-702
lines changed

8 files changed

+102
-702
lines changed

.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: python
2+
python:
3+
- '2.7'
4+
script:
5+
- touch foo
6+
deploy:
7+
provider: pypi
8+
user: jlawhead
9+
password:
10+
secure: w1ErvS4wRNUVlWOtisWIC9BZiV6qecAKUN8/KUHxpEPRe54DKYgd9VMPlEktHIEFqHiUw0QH3ObJZCghDDjbu9CliGU1plIOlBbxaX2EL6sAlmmZuwm2Xw2NplVclKI2QHyFLlABlKkH5eoFVFoMxdXMTGHAMcubk+EJoKEVHsGDhhHGaT1T8I8gV1kIzpYBe2/3b5Nol1/lKpFqHet017IJ8TZWziHsx91zqqDj9+T0cX3QllkZNn4PtY4KojcszTQyRQGwcEV9mzL/npmHtIqEIhQCqRc5vv+/wMU7aFfpA8NZEIcxb79nwiuSfmA6/iONBzHFJYPIws7cWJpBfTHYHX8uxUq9Nh4FTIPutIO92cx8xp5+ftTZRXxi4Wi6ESycMp/erQHgGPlvjkgzwWFwNCkMCCGAGZfH2aaSOBSAxf/s8DBGWQ9OzqtWxirHy/hzjdleWduFii1aw0I5nxjgvKzgM/jeBn9nd8Y3+HfsY0wPlowjHwLONew/kjSy8kVDva65Jf25ATb589NExBMLrU0rN1hlNMqJZHCfnzTiqFJQ+ybOPFrs9jpa1m3ezWTnCJg+8Gs6Qj6O8mwpbWPg6I4O9nP2Ivye0WgR1tvRFmbxoo5BAMWCzbzQYngInSY/EGn8hWXORG2hqKU4UH9LlAbFWbbHskFxTiUrotc=
11+
on:
12+
tags: true
13+
distributions: sdist bdist_wheel
14+
repo: GeospatialPython/pyshp

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include *.md *.txt *.TXT
2+
recursive-include shapefiles *.dbf *.sbn *.sbx *.shp *.shx

README.md

+58-31
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ despite the numerous ways to store and exchange GIS data available today.
2222

2323
Pyshp is compatible with Python 2.4-3.x.
2424

25-
This document provides examples for using pyshp to read and write shapefiles.
25+
This document provides examples for using pyshp to read and write shapefiles. However
26+
many more examples are continually added to the pyshp wiki on GitHub, the blog [http://GeospatialPython.com](http://GeospatialPython.com),
27+
and by searching for pyshp on [http://gis.stackexchange.com](http://gis.stackexchange.com).
2628

27-
Currently the sample census blockgroup shapefile referenced in the examples is available on the google code project site at
29+
Currently the sample census blockgroup shapefile referenced in the examples is available on the GitHub project site at
2830
[https://github.com/GeospatialPython/pyshp](https://github.com/GeospatialPython/pyshp). These
2931
examples are straight-forward and you can also easily run them against your
30-
own shapefiles manually with minimal modification. Other examples for specific
31-
topics are continually added to the pyshp wiki on GitHub and the blog
32-
[http://GeospatialPython.com](http://GeospatialPython.com).
32+
own shapefiles with minimal modification.
3333

34-
Important: For information about map projections, shapefiles, and Python
35-
please visit: [https://github.com/GeospatialPython/pyshp/wiki/Map-Projections](https://github.com/GeospatialPython/pyshp/wiki/Map-Projections)
34+
Important: If you are new to GIS you should read about map projections.
35+
Please visit: [https://github.com/GeospatialPython/pyshp/wiki/Map-Projections](https://github.com/GeospatialPython/pyshp/wiki/Map-Projections)
3636

3737
I sincerely hope this library eliminates the mundane distraction of simply
3838
reading and writing data, and allows you to focus on the challenging and FUN
@@ -42,12 +42,11 @@ part of your geospatial project.
4242

4343
Before doing anything you must import the library.
4444

45-
4645
>>> import shapefile
4746

4847
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.
48+
Blockgroups data set near San Francisco, CA and available in the github
49+
repository of the pyshp GitHub site.
5150

5251
## Reading Shapefiles
5352

@@ -128,13 +127,17 @@ Each shape record contains the following attributes:
128127
'points'
129128
'shapeType'
130129

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

133133

134134
>>> shapes[3].shapeType
135135
5
136136

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

139142

140143
>>> # Get the bounding box of the 4th shape.
@@ -143,12 +146,16 @@ Each shape record contains the following attributes:
143146
>>> ['%.3f' % coord for coord in bbox]
144147
['-122.486', '37.787', '-122.446', '37.811']
145148

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.
149+
* parts: Parts simply group collections of points into shapes. If the shape
150+
record has multiple parts this attribute contains the index of the first
151+
point of each part. If there is only one part then a list containing 0 is
152+
returned.
147153

148154
>>> shapes[3].parts
149155
[0]
150156

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

153160
>>> len(shapes[3].points)
154161
173
@@ -183,8 +190,12 @@ You can call the "fields" attribute of the shapefile as a Python list. Each
183190
field is a Python list with the following information:
184191

185192
* 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.
193+
* Field type: the type of data at this column index. Types can be: Character,
194+
Numbers, Longs, Dates, or Memo. The "Memo" type has no meaning within a
195+
GIS and is part of the xbase spec instead.
196+
* Field length: the length of the data found at this column index. Older GIS
197+
software may truncate this length to 8 or 11 characters for "Character"
198+
fields.
188199
* Decimal length: the number of decimal places found in "Number" fields.
189200

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

266277

267-
>>> shapeRecs3.record[1:3]
278+
>>> shapeRecs[3].record[1:3]
268279
['060750601001', 4715]
269280

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

297308
>>> shapeRecs = sf.iterShapeRecords()
298-
>>> for shape, rec in shapeRecs:
309+
>>> for shapeRec in shapeRecs:
299310
... # do something here
311+
... pass
300312

301313

302314
## Writing Shapefiles
303315

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

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

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.
348+
There are three ways to set the shape type:
349+
* Set it when creating the class instance.
350+
* Set it by assigning a value to an existing class instance.
351+
* Set it automatically to the type of the first shape by saving the shapefile.
339352

340353
To manually set the shape type for a Writer object when creating the Writer:
341354

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

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

448462

449463
>>> w = shapefile.Writer(shapefile.POINT)
@@ -523,7 +537,10 @@ write them.
523537
## Editing Shapefiles
524538

525539
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.
540+
handling the reading and writing details behind the scenes. This class is
541+
experimental, has lots of issues, and should be avoided for production use. *You can do the same
542+
thing by reading a shapefile into memory, making changes to the python objects,
543+
and write out a new shapefile with the same or different name.*
527544

528545
Let's add shapes to existing shapefiles:
529546

@@ -566,17 +583,27 @@ Remove the last shape in the polygon shapefile.
566583
>>> e.delete(-1)
567584
>>> e.save('shapefiles/test/polygon')
568585

569-
## Python __geo_interface__
586+
## Python \_\_geo_interface\_\_
570587

571-
The Python __geo_interface__ convention provides a data interchange interface
572-
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
588+
The Python \_\_geo_interface\_\_ convention provides a data interchange interface
589+
among geospatial Python libraries. The interface returns data as GeoJSON which gives you
590+
nice compatability with other libraries and tools including Shapely, Fiona, and PostGIS.
591+
More 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

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

0 commit comments

Comments
 (0)