GeospatialPython / pyshp

This library reads and writes ESRI Shapefiles in pure Python.
MIT License
1.1k stars 259 forks source link

how can I write a multipoint shape? #127

Closed makhand closed 6 years ago

makhand commented 6 years ago

I see point, line and poly, but no multipoint in the code or instructions. If I needed to write a multipoint object, how would I do this?

GeospatialPython commented 6 years ago

You just use the "poly" method in the Writer. The poly method isn't just for polygons, it can also create polylines and polypoints!

Here's a simple Multipoint shapefile:

import shapefile

# Create our writer as a multipoint shapefile
w = shapefile.Writer(shapefile.MULTIPOINT)

# We'll create a single dbf field
w.field("NAME","C",40)

# Create a single-part, multi-point shape by declaring the shape
# type after the parts/points list
w.poly([[[3,4],[5,6],[7,8],[9,8]]], shapeType=shapefile.MULTIPOINT)

# Create a record for this feature
w.record("Group1")

# Save the multipoint shapefile
w.save("mpoint")

Repeat the poly and record steps to add additional shapes.

Add another nested list of points in the first poly method argument to add more parts to the same record