Thursday, November 16, 2017

Creating MultiPoint Shapefiles with PyShp

Pyshp let's you create any type of shapefile.  Normally a point shapefile has one point per record.  But
Photo credit:
you can also have a group of points tied to a single record in a Multipoint shapefile.  To create a Multipoint shapefile, you just use the "poly" method in the Writer. The poly method isn't just for polygons. It can also create polylines and polypoints (i.e. MultiPoints)!

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

# 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

# Save the multipoint shapefile"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

1 comment: