Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/run_checks_build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ jobs:
fail-fast: false
matrix:
python-version: [
"3.9",
"3.10",
"3.11",
"3.12",
"3.13",
"3.14",
"3.13",
"3.12",
"3.15-dev",
"3.11",
"3.10",
"3.9",
]
os: [
"macos-latest",
"ubuntu-24.04",
"windows-latest",
"macos-latest",
]


Expand Down
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ Finally, you can use all of the above methods to read shapefiles directly from t


>>> # from a zipped shapefile on website
>>> sf = shapefile.Reader("https://github.com/JamesParrott/PyShp_test_shapefile/raw/main/gis_osm_natural_a_free_1.zip")
>>> sf = shapefile.Reader("https://geodata.ucdavis.edu/gadm/gadm4.1/shp/gadm41_ATA_shp.zip")

>>> # from a shapefile collection of files in a github repository
>>> sf = shapefile.Reader("https://pubs.usgs.gov/of/2000/of00-006/gisdata/coverage/airports.shp")
Expand Down Expand Up @@ -940,6 +940,7 @@ length of text values to save space:

>>> r = shapefile.Reader('shapefiles/test/dtype')
>>> assert r.record(0) == ['Hello', 'World', 'World'*50]
>>> r.close()

Date fields are created using the 'D' type, and can be created using either
date objects, lists, or a YYYYMMDD formatted string.
Expand All @@ -964,6 +965,7 @@ Field length or decimal have no impact on this type:
>>> assert r.record(1) == [date(1998,1,30)]
>>> assert r.record(2) == [date(1998,1,30)]
>>> assert r.record(3) == [None]
>>> r.close()

Numeric fields are created using the 'N' type (or the 'F' type, which is exactly the same).
By default the fourth decimal argument is set to zero, essentially creating an integer field.
Expand All @@ -989,6 +991,7 @@ To store very large numbers you must increase the field length size to the total
>>> r = shapefile.Reader('shapefiles/test/dtype')
>>> assert r.record(0) == [1, 1.32, 1.3217328, -3.2302e-25, 1.3217328, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000]
>>> assert r.record(1) == [None, None, None, None, None, None]
>>> r.close()


Finally, we can create boolean fields by setting the type to 'L'.
Expand Down Expand Up @@ -1025,6 +1028,7 @@ None is interpreted as missing.
Record #4: [None]
>>> r.record(5)
Record #5: [None]
>>> r.close()

You can also add attributes using keyword arguments where the keys are field names.

Expand Down Expand Up @@ -1150,6 +1154,7 @@ This can be particularly useful for copying from one file to another:
... w.record(*shaperec.record)
... w.shape(shaperec.shape.__geo_interface__)

>>> r.close()
>>> w.close()


Expand Down Expand Up @@ -1256,7 +1261,7 @@ For reading shapefiles in any non-utf8 encoding, such as Latin-1, just
supply the encoding option when creating the Reader class.


>>> r = shapefile.Reader("shapefiles/test/latin1.shp", encoding="latin1")
>>> r = shapefile.Reader("shapefiles/latin1.shp", encoding="latin1")
>>> r.record(0) == [2, u'Ñandú']
True

Expand All @@ -1269,21 +1274,24 @@ should give you the same unicode string you started with.
>>> w.fields = r.fields[1:]
>>> w.record(*r.record(0))
>>> w.null()
>>> r.close()
>>> w.close()

>>> r = shapefile.Reader("shapefiles/test/latin_as_utf8.shp", encoding="utf8")
>>> r.record(0) == [2, u'Ñandú']
True
>>> r.close()

If you supply the wrong encoding and the string is unable to be decoded, PyShp will by default raise an
exception. If however, on rare occasion, you are unable to find the correct encoding and want to ignore
or replace encoding errors, you can specify the "encodingErrors" to be used by the decode method. This
applies to both reading and writing.


>>> r = shapefile.Reader("shapefiles/test/latin1.shp", encoding="ascii", encodingErrors="replace")
>>> r = shapefile.Reader("shapefiles/latin1.shp", encoding="ascii", encodingErrors="replace")
>>> r.record(0) == [2, u'�and�']
True
>>> r.close()



Expand All @@ -1297,7 +1305,7 @@ of records and complex geometries.
As an example, let's load this Natural Earth shapefile of more than 4000 global administrative boundary polygons:


>>> sf = shapefile.Reader("https://github.com/nvkelso/natural-earth-vector/blob/master/10m_cultural/ne_10m_admin_1_states_provinces?raw=true")
>>> sf = shapefile.Reader("https://archive.org/download/ne_10m_admin_1_states_provinces/ne_10m_admin_1_states_provinces.zip")

When first creating the Reader class, the library only reads the header information
and leaves the rest of the file contents alone. Once you call the records() and shapes()
Expand Down Expand Up @@ -1491,6 +1499,8 @@ Shapefiles containing M-values can be examined in several ways:
>>> r.shape(0).m # flat list of M-values
[0.0, None, 3.0, None, 0.0, None, None]

>>> r.close()


### Shapefiles with elevation (Z) values

Expand Down Expand Up @@ -1524,6 +1534,8 @@ To examine a Z-type shapefile you can do:
>>> r.shape(0).z # flat list of Z-values
[18.0, 20.0, 22.0, 0.0, 0.0, 0.0, 0.0, 15.0, 13.0, 14.0]

>>> r.close()

### 3D MultiPatch Shapefiles

Multipatch shapes are useful for storing composite 3-Dimensional objects.
Expand Down Expand Up @@ -1583,8 +1595,6 @@ installed) from the test file:
python test_shapefile.py
```

Linux/Mac and similar platforms may need to run `$ dos2unix README.md` in order
to correct line endings in README.md, if Git has not automatically changed them.

## Network tests

Expand All @@ -1598,7 +1608,7 @@ pytest -m "not network"
```
or the doctests via:
```shell
python shapefile.py -m "not network"
python test_shapefile.py -m "not network"
```
or ii) by cloning a repo of the files they download, serving these on localhost in a separate process,
and running the network tests with the environment variable REPLACE_REMOTE_URLS_WITH_LOCALHOST to `yes`:
Expand All @@ -1614,7 +1624,7 @@ REPLACE_REMOTE_URLS_WITH_LOCALHOST=yes && pytest
```
or the doctests via:
```bash
REPLACE_REMOTE_URLS_WITH_LOCALHOST=yes && python shapefile.py
REPLACE_REMOTE_URLS_WITH_LOCALHOST=yes && python test_shapefile.py
```
The network tests alone can also be run (without also running all the tests that don't
make network requests) using: `pytest -m network` (or the doctests using: `python shapefile.py -m network`).
Expand Down
4 changes: 2 additions & 2 deletions run_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@


blockgroups_file = REPO_ROOT / "shapefiles" / "blockgroups.shp"
edit_file = REPO_ROOT / "shapefiles" / "test" / "edit.shp"
merge_file = REPO_ROOT / "shapefiles" / "test" / "merge.shp"
edit_file = REPO_ROOT / "shapefiles" / "edit.shp"
merge_file = REPO_ROOT / "shapefiles" / "merge.shp"
states_provinces_file = PYSHP_TEST_REPO / "ne_10m_admin_1_states_provinces.shp"
tiny_countries_file = PYSHP_TEST_REPO / "ne_110m_admin_0_tiny_countries.shp"
gis_osm_natural_file = PYSHP_TEST_REPO / "gis_osm_natural_a_free_1.zip"
Expand Down
File renamed without changes.
File renamed without changes.
Binary file added shapefiles/corrupt_too_long.dbf
Binary file not shown.
Binary file added shapefiles/corrupt_too_long.shp
Binary file not shown.
Binary file added shapefiles/corrupt_too_long.shx
Binary file not shown.
Binary file renamed shapefiles/test/edit.dbf → shapefiles/edit.dbf
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file renamed shapefiles/test/merge.dbf → shapefiles/merge.dbf
Binary file not shown.
File renamed without changes.
File renamed without changes.
Loading
Loading