Questions tagged [pyshp]

Pyshp is a pure Python shapefile library which can be used to read, write and edit ESRI shapefiles.

Filter by
Sorted by
Tagged with
0 votes
0 answers
41 views

pyshp not working properly when creating polygons (offset + missing polygons)

I have a Esri shapefile thats projected in NSIDC EASE-Grid Global that has roughly 50k polygons. I wrote the Python script below to create a grid that covers the span of each polygons bbox (note I don'...
Joe Jameson's user avatar
0 votes
1 answer
409 views

How to add/install library in python notebook or QGIS (python console)?

It gives the error while I am using command line to install the library or package. As you can see in the attached file (the python_console_in_QGIS, command_line_python, and the library_want_to_follow)...
Hasan's user avatar
  • 55
0 votes
1 answer
88 views

How to start reading shapefile in QGIS using python console? [closed]

How do I start reading shapefile using Python console in QGIS? I am sharing the script that I am trying to follow, however, it gives me an error.
Hasan's user avatar
  • 55
0 votes
1 answer
128 views

Writing PolylineZ shapefile with pyshp [closed]

I am trying to write a POLYLINEZ file in Python with pyshp and find the documentation lacking... When importing a POLYLINEZ shapefile, the x,y values are separate from the z values. (sf.shape().points ...
Anna1's user avatar
  • 3
1 vote
0 answers
259 views

Label coordinates that fall in a specific shapefile

I have a dataframe for individuals, each individual has X and Y coordinates, and I have a .shp file that has a number of polygons. individuals dataframe look like: ind_ID x_coordinates y_coordinates ...
Nora S's user avatar
  • 11
0 votes
1 answer
317 views

Retrieving coordinates using PyShp

I am working with historical wind track data, which can be found here. How can I use pyshp to retrieve all the lat & lon along the windtrack correctly? I used the following code found on a ...
ah_'s user avatar
  • 1
3 votes
2 answers
861 views

pip install inside QGIS fails

As I am trying to import a pip module directly in the built-in python I need to install pyshp first. I am trying this directly inside qgis running import pip pip.main(['install', 'pyshp']) ...
Riccardo's user avatar
  • 2,648
3 votes
2 answers
2k views

Getting coordinates of individual polygon in shapefile

I just started working with shapefiles. I need to take polygon # 93 (Sea of ​​Japan) in a large shapefile and build a sea map in bokeh Python. How do I refer to a specific polygon in a shapefile? ...
NadeY's user avatar
  • 43
0 votes
0 answers
40 views

Clip shapefile by polygon [duplicate]

I am trying to clip shapefile by polygon with following code but I had this error. How can I correct the error? import shapefile # Create a reader instance r = shapefile.Reader(r"C:\Users\ADMIN\...
ADMIN's user avatar
  • 1
1 vote
0 answers
406 views

Split LineString with MultiPoint - Shapely

I want to split a LineString object at a MultiPoint object. I use the following code to do this. Among other things, I use the functions interpolate() and project() to snap the points onto the line ...
lroost's user avatar
  • 19
10 votes
2 answers
798 views

Sorting records by attribute in shapefile using PyShp

I know how to get records in a shapefile using PyShp, but how to sort records by an attribute (i.e., "NAME" or "POPULATION")? My code: import shapefile file = "c:/data/cities....
user183925's user avatar
5 votes
1 answer
408 views

Reading single row in PyShp with shapefile.Reader

I use PyShp and shapefile.Reader to read shapefile files. If I want to read a whole file I use: with shapefile.Reader(file) as shp: for row_num, row in enumerate(shp.iterRecords()): print(...
datasciencebegginer's user avatar
8 votes
2 answers
435 views

Python: shapefile.Reader, how to set up .iloc?

I would like to set up range of reading by shapefile.Reader. I couldn't find any suitable documentation. I would like to read rows 0-100. In Pandas or GeoPandas I use df.iloc[0:100], but what should I ...
datasciencebegginer's user avatar
3 votes
0 answers
590 views

Editing shapefile adding fields with values with pyshp

I'm trying to add some fields to a shapefile using pyshp. The code I have to far is: import shapefile # Read in our existing shapefile r = shapefile.Reader(r"C:\...\Edit_SHP\TracksLines.shp"...
user179413's user avatar
1 vote
2 answers
205 views

Checking if geopoint is in shapefile containing world cities

I have approximately 13 million (lat,long) geocoordinates. I also have a shapefile containing 3460 cities. I need to find the City in which this geocoordinate can be found. This is what I am currently ...
aziz-ashy's user avatar
3 votes
2 answers
258 views

Setting up a section using shapefile.Reader

I would like to open some shapefile with shapefile.Reader but I would like to see some part of it, for example 10000-20000 records. How to set up a section? I can't find that in documentation. with ...
5676's user avatar
  • 141
2 votes
0 answers
624 views

How to merge lines from shapefile using PyShp and Shapely and save them in a new shapefile?

I have files with line segments that cover road network of towns. The issue is that each street with specific name consists of smaller segments that I need to merge into one line covering the whole ...
krltos's user avatar
  • 223
0 votes
0 answers
120 views

How to check integrity of Python-processed shapefile

In my QGIS project of American railroads, using USGS Base Topo Layer and shapefiles giving railroad details as of 2015, I have used the Python-3 pyshp library to edit the dbf database, adding some ...
Michiel Rademakers's user avatar
1 vote
0 answers
111 views

Differentiating between stacked parcel shapefile and general parcel shapefile using Python [closed]

I am totally new to this domain. I would like to detect stacked parcel shapefile and mapped respective data or outlines created to all stacked parcels. In a general case where only one parcel on land ...
Avinash Dalvi's user avatar
2 votes
1 answer
376 views

I cannot manage to export coordinates to a shapefile using Python

This is the test code I have written: import shapefile w = shapefile.Writer(shapefile.POLYGON) w.poly(parts=[[[1,5],[5,5],[5,1],[3,3],[1,1]]]) w.field('FIRST_FLD','C','40') w.field('SECOND_FLD','C','...
Carl's user avatar
  • 23
4 votes
1 answer
565 views

Only integer part of field values read by pyshp when creating point shapefile from QGIS

While using flopy that bases some of the functions in the export.shapefile_utils module on pyshp (namely shp2recarray), I've come across a behavior I cannot understand. Whenever I read some point data ...
Javgs's user avatar
  • 101
1 vote
0 answers
168 views

Clipping a raster with a shapefile created with coordinates

I created a polygon shapefile this way: def createShapefile(shapefileDir, ROI): w = shp.Writer(shapefileDir, shapeType=shp.POLYGON) w.field('FIRST_FLD','C','40') w.record('poly1') ROI = [[...
Daniel Rojas Pérez's user avatar
2 votes
2 answers
926 views

Clipping Shapefile in Pure Python

I am trying to implement the code found at this site: http://geospatialpython.com/2015/05/clipping-shapefile-in-pure-python.html The function I am trying to implement: import shapefile # Create a ...
ushham's user avatar
  • 103
1 vote
1 answer
901 views

Does pyshp provide CRS?

I am using https://pypi.org/project/pyshp/ to read records and geometry. Is there a way to read CRS data without pyproj or fiona?
Vincent Buscarello's user avatar
7 votes
1 answer
2k views

Creating new shapefile using pyshp

I am trying to strip data out of an existing shapefile to create new shapefiles. I have made the loop work, and made the new file, but I cannot work out why I cannot add records to the new file I am ...
ushham's user avatar
  • 103
0 votes
0 answers
453 views

Using pyshp to create line shapefiles with color

I am using PyShp to create line shapefile in Python. w = shapefile.Writer('shapefiles/line') w.field('name', 'C') w.line([ [[3,2],[2,6]] ]) w.record('linestring1') w.close() Is there a way to ...
fengdongyuxi's user avatar
0 votes
1 answer
368 views

Writing shapefile of multiple geometry using Python [duplicate]

How to make a shapefile containing points, polygon, and line using python shapely or pyshp?
Shoaib Ahmed's user avatar
2 votes
0 answers
740 views

Shapefile or GeoJSON? [closed]

I'm interested in understanding the relative merits of using GeoJSON or shapefile formats for handling geo-spatial data, particularly in an open-source, Python (CKAN project), web-development context. ...
user16548's user avatar
2 votes
1 answer
2k views

Rebuilding .shx using python/pyshp?

EDIT: I've tried running the code linked in the duplicate flag, it's posted here for reference, and it doesn't run. I had already referred to that answer in my initial post. My problem Downloaded ...
maxo's user avatar
  • 21
1 vote
1 answer
5k views

Why is PyShp unable to open my .dbf or .shp files? [closed]

Trying to learn to use Python to map some geographic data by following some tutorial and I can't seem to get them to work. I'm hoping this is just a simple error on my part. First, the link(s) to ...
JDubs's user avatar
  • 11
3 votes
1 answer
2k views

Setting reference frame for shapefile with pyshp?

I'm using pyshp to create new shapefiles with Python 3. My code runs without errors, but when I open the resulting file in ArcMap I get this error: The following datasource you added is missing ...
Anders's user avatar
  • 495
1 vote
2 answers
2k views

ShapefileException when reading shapefile using PyShp

I'm trying to read in a shapefile and keep getting a File Not Found error and this exception: ShapefileException: Unable to open /Users/name/Documents/shapefile.shp Here's what I've got: import ...
mike's user avatar
  • 11
4 votes
1 answer
704 views

Does pyshp read .prj files properly?

I want to read a shapefile using pyshp: sf = shapefile.Reader(('/tmp/India_PCs_Boundary_4_2_19/India_PCs_Boundary.shp')) but when I look at the result, the polygons look all squishy and distorted; ...
Dan B's user avatar
  • 41
0 votes
3 answers
1k views

Convert CSV file in shapefile with pyshp/shapefile

I'm trying to convert a file.csv to a file.shp through the pyshp / shapefile module. The content of the CSV is: Lon,Lat,Vel,Dir 15.9576198620869825,41.1791119428255143,9.3949995040893555,92....
Domenico Fuoco's user avatar
0 votes
1 answer
403 views

Splitting a Shapefile based off coordinates in Python using osgeo (ogr) or pyshp

I'm having trouble with splitting a shapefile of all the regions in Mongolia into a smaller shapefile based off some input coordinates. The big shapefile I'm trying to split can be found here: https:/...
JackLidge's user avatar
  • 338
2 votes
1 answer
1k views

PyShp error: Object does not implement __geo_interface__

I'd like to convert geometry to WKT with pyshp and pygeoif using this suggestion, but pyshp throws a following error: Traceback (most recent call last): File "E:/!Projects/imScrape/...
Basile's user avatar
  • 3,543
1 vote
1 answer
382 views

PointZ elevation issue PYSHP

I have created a shapefile with approximately 300 feature of shapeType POINTZ. I can fill my attributs and define point. Here is my function that i call for each feature: def upd_shp(fn, geo, attr): ...
Bazinga's user avatar
  • 13
0 votes
1 answer
3k views

Buffering point shapefile using gdal/ogr: how to copy over input attributes to output shp?

Editing my previous question which asked the best way to buffer a point shapefile in python to add more detail and clarity to what I'm looking for. I have found a method here to iterate through an ...
user20408's user avatar
  • 1,505
4 votes
1 answer
780 views

Automating recording fields in a shapefile via pyshp

I am following the tutorial here for how to convert a csv to shp using pyshp. I am almost there, with one issue. In the tutorial, the person loops over the rows in the csv, and for each field, assigns ...
user20408's user avatar
  • 1,505
3 votes
1 answer
989 views

Working with shapefiles in Python

I am currently working on the problem of generating roads from Openstreetmap files. I use these Osm files to create a shapefile from all different road types with different roadway numbers, widths and ...
freddykrueger's user avatar
1 vote
2 answers
423 views

Converting .csv file to file.shp using Python gives IndexError?

I have a file.csv like the following: 37.0925854357,14.3860984446,0.0000079572,0.0000939491,0.0000028935 37.0978554286,14.5199850398,0.0000041594,0.0000821038,0.0000047924 37.1029267200,14.6538928343,...
Domenico Fuoco's user avatar
1 vote
0 answers
165 views

Iterating over pyshp writer object records

The current branch of pyshp has removed the Editor class that combines reading and writing records. The justification is that removing the Editor has been planned for a while now, and might as well ...
Micks Ketches's user avatar
2 votes
1 answer
2k views

Converting coordinates from shapefile using python?

I am really new to working with this kind of data. I have been trying to work with a shapefile that I wish to convert to geojson. The source has both shapefiles and geojson downloads available, but ...
Nathan Weyer's user avatar
1 vote
1 answer
3k views

Python - Convert csv with unknown number of columns to shapefile

I have this script that converts a csv file to a shapefile. In this case I am specifying manually the name of columns header. Since now I have files with a big and always different number of columns, ...
F. Cian's user avatar
  • 31
3 votes
1 answer
625 views

Storing a geographic minimum spanning tree with PyShp

I have a list of geographic coordinates (longitudes, latitudes in decimal degrees) as follows: -72.9833,10.6167 -63.1167,10.55 -63.1167,7.91667 -65.9667,10.3167 -67.4333,8.93333 -68.4,10.6167 -70....
maurobio's user avatar
  • 155
3 votes
1 answer
542 views

Python pyshp reads some field values as None

Reading the records of AL082017_pts.shp in a recent hurricane path file with pyshp results in a lot of None. Here's the first record: sf = shapefile.Reader('AL082017_pts.shp') print sf.record(0) ...
Martin Burch's user avatar
2 votes
1 answer
2k views

Converting Shapefile points to Lat/Long?

Quick Overview of the Project: I have 9000 records of individuals, each with a coordinate pair in a csv. I also have a shapefile/folder(dbf, prj, sbn, sbx, shp, shx) of municipalities within the range ...
Martin Goni's user avatar
7 votes
2 answers
19k views

Finding out if coordinate is within shapefile (.shp) using pyshp?

I'm trying to map coordinate data to a municipality. Reverse geocoders aren't as accurate as I need them to be (I was using geocoder pkg before), so I found a .shp that maps and names all the ...
Martin Goni's user avatar
9 votes
2 answers
7k views

Using pyshp to read a file-like object from a zipped archive

Presume I have an archive, foo.zip. It contains the parts of a shapefile: foo.shp, foo.dbf, foo.shx, foo.prj, and foo.cpg. I want to work with this shapefile in python, using pyshp, AKA the shapefile ...
JP Ferguson's user avatar
0 votes
0 answers
1k views

Plotting shapefiles with Pyshp in Python omits some shapes

I want to plot a cloropleth map of Scotland with Pyshp, but only a fraction of the shapes are plotted. The shapefile of Scotland has 32 shapes, and it is available here. The values dictating the ...
FaCoffee's user avatar
  • 813