i would like to draw polygons in Blender. The vertices positions are given as a text in PostGIS format. Example :
POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))
I already came up with a script working pretty well for any polygon without holes. However i also need to draw some polygons with holes. Example (the second polygon defines the hole) :
POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(1 1, 1 2, 2 2, 2 1, 1 1))
Here is the python script so far to draw any sequence of polygons without holes :
import io
import csv
import bmesh
data="""
0;2;POLYGON((0 0,30 0,30 30,0 30,0 0))
0;2;POLYGON((4 4,26 4,26 26,4 26,4 4))
"""
f = io.StringIO(data)
csv_f = csv.reader(f, delimiter=';')
i = 0
for row in csv_f:
i+=1
if (len(row)>2):
verts = eval('['+row[2].replace(',','),(').replace(' ',',')[8:-1]+']')
bm = bmesh.new()
for v in verts:
bm.verts.new((v[0], v[1], float(row[0])))
bm.faces.new(bm.verts)
bm.normal_update()
me = bpy.data.meshes.new(row[0])
bm.to_mesh(me)
ob = bpy.data.objects.new(row[0], me)
bpy.context.scene.objects.link(ob)
bpy.context.scene.update()
Executing this script into Blender will create two squares, one inside the other :
My question is : how to remove the inner square from the big square (and resulting into a hole)
I tried to Add a Boolean modifier on the big square, applied to the inner square object, but i get a "Cannot execute boolean operation".
Is there any other way doing this from Blender and that can be scripted into Python ?