Export geometry shape to wkt

I’m trying up to run the following python code to extract the wkt from shapefile, as I’m new python user, I got an error as following, still don’t know how to use snappy to do so?, Please any suggestions,

import shapefile
import pygeoif

r = shapefile.Reader(“D:\STUDY\Sh.files\ROI\ROI-2019.shp”)

g=[]

for s in r.shapes():
g.append(pygeoif.geometry.as_shape(s))

m = pygeoif.MultiPoint(g)

print m.wkt

image

I solved it, the last one pirnt m.wkt should be print(m.wkt), But still if some hints to run the same using snappy!

import shapefile
import pygeoif

r = shapefile.Reader(“D:\STUDY\Sh.files\ROI\ROI-2019.shp”)

g=[]

for s in r.shapes():
g.append(pygeoif.geometry.as_shape(s))

m = pygeoif.MultiPoint(g)

print (m.wkt)

Hi Falah,

what needs to be done to read a shapefile can be seen in this Java snippet:

The reads the shapefil and creates a VectorDataNode which can be added to the product.

Simpler is just the reading of the shapefile intto Feature objects.

The conversion to WKT string can be seen here:

So I think your code is simple :slight_smile:

2 Likes

Thanks a lot for your great assistance, New user is blind in the beginning, but I promise I’ll open my four eyes :blush:

It’s hard to find as long as you don’t know where to look for it.