pyshp | library reads and writes ESRI Shapefiles | Map library
kandi X-RAY | pyshp Summary
kandi X-RAY | pyshp Summary
The Python Shapefile Library (PyShp) provides read and write support for the Esri Shapefile format. The Shapefile format is a popular Geographic Information System vector data format created by Esri. For more information about this format please read the well-written "ESRI Shapefile Technical Description - July 1998" located at dfs/shapefile.pdf . The Esri document describes the shp and shx file formats. However a third file format called dbf is also required. This format is documented on the web as the "XBase File Format Description" and is a simple file-based database format created in the 1960's. For more on this specification see: Both the Esri and XBase file-formats are very simple in design and memory efficient which is part of the reason the shapefile format remains popular despite the numerous ways to store and exchange GIS data available today. Pyshp is compatible with Python 2.7-3.x. This document provides examples for using PyShp to read and write shapefiles. However many more examples are continually added to the blog and by searching for PyShp on Currently the sample census blockgroup shapefile referenced in the examples is available on the GitHub project site at These examples are straight-forward and you can also easily run them against your own shapefiles with minimal modification. Important: If you are new to GIS you should read about map projections. Please visit: I sincerely hope this library eliminates the mundane distraction of simply reading and writing data, and allows you to focus on the challenging and FUN part of your geospatial project.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Run a test suite
- Create a shapely polygon
- Create a Shape from a GeoJSON object
- Write shape to file
- Checks if the coordinates are a CWL
- Set the polygon shape
- Create a shapely Polygon object
- Creates a polygon
- Creates a POINTZ shape
- Creates a MULTIPOINTZ shape
- Draws a point M
- Creates MULTIPOINTM shapefile
- Draws a polygon
- Make a POLYLINEZ shape
- Create a POLYLIN shape
- Creates a MULTIPOINT shape
- Check if a ring contains a ring
- Return True if point is in the ring
pyshp Key Features
pyshp Examples and Code Snippets
flo.seek(0)
df = geopandas.read_file(shp=flo)
with sftp.open('sites/Sites.shp', bufsize=32768) as f:
df = geopandas.read_file(f)
with sftp.open('sites/Sites.shp', bufsize=32768) as shp,
df = gpd.read_file('zip:///path/to/file.zip!data.gpkg')
df = gpd.read_file('zip://../path/to/file.zip!data.gpkg')
andylu@andylu-ThinkPad-Edge-E130:~/Desktop/Python/Scripts$ sudo find / -type f -iname "unixccompiler.py"
find: ‘/run/user/1000/gvfs’: Permission denied
find: ‘/tmp/.mount_pcloudgeFVGR’: Permission denied
/snap/core/9436/usr/lib/python3.5/d
# This file may be used to create an environment using:
# $ conda create --name --file
# platform: linux-64
_libgcc_mutex=0.1=main
blas=1.0=mkl
bokeh=2.0.2=py37_0
bzip2=1.0.8=h7b6447c_0
ca-certificates=2020.1.1=0
cartopy=0.17.0=py37hbb7e
import shapefile
from json import dumps
# read the shapefile
reader = shapefile.Reader("my.shp")
fields = reader.fields[1:]
field_names = [field[0] for field in fields]
buffer = []
for sr in reader.shapeRecords():
from shapely.geometry import shape
from shapely.geometry.ops import unary_union
union = unary_union([shape(s.__geo_interface__) for s in geometries_list])
temp_df['rel_contribution'] = 0.0
temp_df['rel_contribution'] = temp_df['overlay_area']/sum(temp_df.area)
temp_df = merged_df[merged_df['seed_index'] == row['seed_index']]
# Merge datafarme
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
# cartopy-0.17.0 pyshp-2.1.0
cm = 180
proj = ccrs.PlateCarree(central_longitude=cm)
fig = plt.figure(figsize=[5, 8])
ax = fig.add_subplot(1, 1, 1, projection=proj)
ax.coastlines()
pip install --upgrade --user matplotlib numpy pyproj pyshp OWSLib Pillow
sudo apt install libgeos-dev
pip install --user --upgrade basemap-1.2.0rel.tar.gz
Community Discussions
Trending Discussions on pyshp
QUESTION
So I have gone through the forums in search for an answer but haven't found one that works for me. I am using Windows machine and my Django application works on Localhost but when I try to deploy the same application to Heroku it gives me this error.
...ANSWER
Answered 2021-Nov-14 at 11:37In your current requirements.txt
you marked pywin32
with environment marker platform_system == "Windows"
. I think the syntax is wrong. The correct syntax from PEP 496 is:
QUESTION
data source: https://catalog.data.gov/dataset/nyc-transit-subway-entrance-and-exit-data
I tried looking for a similar problem but I can't find an answer and the error does not help much. I'm kinda frustrated at this point. Thanks for the help. I'm calculating the closest distance from a point.
...ANSWER
Answered 2021-Oct-11 at 14:21geopandas 0.10.1
- have noted that your data is on kaggle, so start by sourcing it
- there really is only one issue
shapely.geometry.MultiPoint()
constructor does not work with a filtered series. Pass it a numpy array instead and it works. - full code below, have randomly selected a point to serve as
gpdPoint
QUESTION
After digging I cannot manage to understand what happened with our server. I got this error when loading the web.
It was working and anyone touch anything. I have changed the ownership of the application.txt because this error. [Wed Dec 16 04:38:12.059839 2020] [wsgi:error] [pid 12343:tid 140072894818048] [remote xx.xx.xxx.xx:xxxxx] ValueError: Unable to configure handler 'file': [Errno 13] Permission denied: '/opt/yhmp-app/YHMP/eamena/logs/application.txt'
After this it is showing up the next error in the browser:
and all this is coming form the error.log when trying to access:
...ANSWER
Answered 2020-Dec-16 at 14:42Was the servers version of django upgraded? patterns
was deprecated in 1.10
https://stackoverflow.com/a/38799716/1464664
current implementations looks like this
QUESTION
I know that it is possible to read a shapefile from a zipfile by extracting it in memory and then reading it: https://gis.stackexchange.com/questions/250092/using-pyshp-to-read-a-file-like-object-from-a-zipped-archive
Fiona also has ways to read a shapefile from memory: https://pypi.org/project/Fiona/1.5.0/
However, I haven't been able to find a way to read in a .gpkg (geopackage) in the same way.
How do I extract a geopackage from a zipfile and then into a geopandas geodataframe?
...ANSWER
Answered 2020-Aug-23 at 21:24You can read it directly by specifying the path to gpkg within zip.
QUESTION
The shell command pip install cartopy
led to several errors.
At first, the following error occurred:
...ANSWER
Answered 2020-Aug-04 at 08:40After searching solutions to the main error message c++: error: unrecognized command line option '-R'
, I finally found it in this discussion.
What I did was searching for the relevant files using the mighty find
method:
QUESTION
I want to run a batch file in a Conda environment, not in the base env, but in another virtual environment (here pylayers).
I copied the activate.bat
script from F:\Anaconda3\Scripts
to F:\Anaconda3\envs\pylayers\Scripts
.
And my batch script (installer_win.bat
) is:
ANSWER
Answered 2020-Jun-15 at 00:59To run a bat file from a dos prompt inside a new (non-base) conda env, you can try something like this:
prompt> cmd "/c activate ds_tensorflow && myfile.bat && deactivate"
contents of myfile.bat to show you are in the non-base env:
QUESTION
I have a 2D map divided in a grid of rectangles - about 45,000 of them - and a number of polygons/multipolygons derived from shapefiles (I currently read them with the shapefile library pyshp). Unfortunately, a few of these polygons are rather complex and made up by a large number of points (one of them has 640,000 points) and can have holes in them.
What I am trying to do is to check, for each of these polygons, which cell centers (the cells of my grid) fall inside that specific polygon. However, having about 45,000 cell centers and 150 polygons is taking quite a while to check everything using shapely. This is what I am doing, more or less:
...ANSWER
Answered 2020-Jun-09 at 10:56If you'd like to perform less comparison operations, you can try to use the shapely str-tree feature. Consider the following code:
QUESTION
I want to generate 1000 random points within a specific ZIP Code Tabulation Area shapefile using pyshp. My code is:
...ANSWER
Answered 2020-Mar-04 at 21:14I am using geopandas
since I think it makes it easier. I don't know if there is an easy way to achieve this solely with pyshp
:
QUESTION
I have a "seed" GeoDataFrame (GDF)(RED) which contains a 0.5 arc minutes global grid ((180*2)*(360*2) = 259200). Each cell contains an absolute population estimate. In addition, I have a "leech" GDF (GREEN) with roughly 8250 adjoining non-regular shapes of various sizes (watersheds).
I wrote a script to allocate the population estimates to the geometries in the leech GDF based on the overlapping area between grid cells (seed GDF) and the geometries in the leech GDF. The script works perfectly fine for my sample data (see below). However, once I run it on my actual data, it is very slow. I ran it overnight and the next morning only 27% of the calculations had been performed. I will have to run this script many times and waiting for two days each time, is simply not an option.
After doing a bit of literature research, I already replaced (?) for loops with for index i in df.iterrows()
(or is this the same as "conventional" python for loops) but it didn't bring about the performance imporvement I had hoped for.
Any suggestion son how I can speed up my code? In twelve hours, my script only processed only ~30000 rows out of ~200000.
My expected output is the column leech_df['leeched_values']
.
ANSWER
Answered 2020-Feb-27 at 18:33It might be worthy to profile your code in details to get precise insights of what is your bottleneck.
Bellow some advises to already improve your script performance:
- Avoid
list.append(1)
to count occurrences, usecollection.Counter
instead; - Avoid
pandas.DataFrame.iterrows
, usepandas.DataFrame.itertuples
instead; - Avoid extra assignation that are not needed, use
pandas.DataFrame.fillna
instead:
Eg. this line:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pyshp
You can use pyshp like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page