Work with shp data in Python

--

Sometimes we need to work with some graphical and GIS data in very specific format. Here I will show how to work with shp data foramt in Python.

Here is a library pyshp. Install it

pip install pyshp

Then open some file using pyshp

import shapefilepath_shp_file = 'LineFeature.shp'path_sf = shapefile.Reader(path_shp_file)

We can list points in shp data

shp = path_sf.shapes()[0]points = shp.pointsprint(points)

Result

[(27.01890117981722, 53.323636127351705), (27.018302950803267, 53.3234231966127),

WE can visualize points using matplotlib library. That’s very simple. Import matplotlib.pyplot

import numpy as npimport matplotlib.pyplot as plt

and visualize point

x = [p[0] for p in points]y = [p[1] for p in points]plt.scatter(x, y)plt.plot(x, y)plt.show()

Result

--

--

No responses yet