Skip to content

Commit b838e9a

Browse files
committed
New readme section on common errors, warning suppression
See also #240
1 parent ff28b24 commit b838e9a

16 files changed

+25
-4
lines changed

README.md

+25-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ The Python Shapefile Library (PyShp) reads and writes ESRI Shapefiles in pure Py
3838
- [Adding Geometry](#adding-geometry)
3939
- [Geometry and Record Balancing](#geometry-and-record-balancing)
4040
- [Advanced Use](#advanced-use)
41-
- [Shapefile Language and Character Encoding](#shapefile-language-and-character-encoding)
41+
- [Common Errors and Fixes](#common-errors-and-fixes)
42+
- [Warnings and Logging](#warnings-and-logging)
43+
- [Shapefile Encoding Errors](#shapefile-encoding-errors)
4244
- [Reading Large Shapefiles](#reading-large-shapefiles)
4345
- [Iterating through a shapefile](#iterating-through-a-shapefile)
4446
- [Limiting which fields to read](#limiting-which-fields-to-read)
@@ -1029,11 +1031,30 @@ most shapefile software.
10291031

10301032
# Advanced Use
10311033

1032-
## Shapefile Language and Character Encoding
1034+
## Common Errors and Fixes
1035+
1036+
Below we list some commonly encountered errors and ways to fix them.
1037+
1038+
### Warnings and Logging
1039+
1040+
By default, PyShp chooses to be transparent and provide the user with logging information and warnings about non-critical issues when reading or writing shapefiles. This behavior is controlled by the module constant `VERBOSE` (which defaults to True). If you would rather suppress this information, you can simply set this to False:
1041+
1042+
1043+
>>> shapefile.VERBOSE = False
1044+
1045+
All logging happens under the namespace `shapefile`. So another way to suppress all PyShp warnings would be to alter the logging behavior for that namespace:
1046+
1047+
1048+
>>> import logging
1049+
>>> logging.getLogger('shapefile').setLevel(logging.ERROR)
1050+
1051+
### Shapefile Encoding Errors
10331052

10341053
PyShp supports reading and writing shapefiles in any language or character encoding, and provides several options for decoding and encoding text.
1035-
Most shapefiles are written in UTF-8 encoding, PyShp's default encoding, so in most cases you don't
1036-
have to specify the encoding. For reading shapefiles in any other encoding, such as Latin-1, just
1054+
Most shapefiles are written in UTF-8 encoding, PyShp's default encoding, so in most cases you don't have to specify the encoding.
1055+
If you encounter an encoding error when reading a shapefile, this means the shapefile was likely written in a non-utf8 encoding.
1056+
For instance, when working with English language shapefiles, a common reason for encoding errors is that the shapefile was written in Latin-1 encoding.
1057+
For reading shapefiles in any non-utf8 encoding, such as Latin-1, just
10371058
supply the encoding option when creating the Reader class.
10381059

10391060

shapefiles/test/balancing.dbf

0 Bytes
Binary file not shown.

shapefiles/test/contextwriter.dbf

0 Bytes
Binary file not shown.

shapefiles/test/dtype.dbf

0 Bytes
Binary file not shown.

shapefiles/test/edit.dbf

0 Bytes
Binary file not shown.

shapefiles/test/line.dbf

0 Bytes
Binary file not shown.

shapefiles/test/linem.dbf

0 Bytes
Binary file not shown.

shapefiles/test/linez.dbf

0 Bytes
Binary file not shown.

shapefiles/test/merge.dbf

0 Bytes
Binary file not shown.

shapefiles/test/multipatch.dbf

0 Bytes
Binary file not shown.

shapefiles/test/multipoint.dbf

0 Bytes
Binary file not shown.

shapefiles/test/onlydbf.dbf

0 Bytes
Binary file not shown.

shapefiles/test/point.dbf

0 Bytes
Binary file not shown.

shapefiles/test/polygon.dbf

0 Bytes
Binary file not shown.

shapefiles/test/shapetype.dbf

0 Bytes
Binary file not shown.

shapefiles/test/testfile.dbf

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)