def _create_border(self, geometry: HybridGeometry, width, append=None): altitude = (np.vstack( chain(*(mesh.tolist() for mesh in geometry.faces)))[:, :, 2].max() + 1) / 1000 geometry = self.buffered_bbox.intersection(geometry.geom) lines = tuple( chain(*(((geom.exterior, *geom.interiors) if isinstance(geom, Polygon) else ( geom, )) for geom in getattr(geometry, 'geoms', (geometry, ))))) if not lines: return np.empty((0, 3, 3 + len(append))) lines = unary_union(lines).buffer(width, cap_style=CAP_STYLE.flat, join_style=JOIN_STYLE.mitre) vertices, faces = triangulate_polygon(lines) triangles = np.dstack( (vertices[faces], np.full( (faces.size, 1), fill_value=altitude).reshape((-1, 3, 1)))) return self._append_to_vertices(triangles.astype(np.float32), append)
def create_full(cls, geom, vertices_offset, faces_offset): """ Create by triangulating a polygon and adding the resulting facets to the total list. """ if isinstance(geom, (LineString, MultiLineString, Point)): return HybridGeometry(geom, set()), np.empty((0, 2), dtype=np.int32), np.empty((0, 3), dtype=np.uint32) vertices = deque() faces = deque() faces_i = deque() for subgeom in assert_multipolygon(geom): new_vertices, new_faces = triangulate_polygon(subgeom) new_faces += vertices_offset vertices.append(new_vertices) faces.append(new_faces) faces_i.append(set(range(faces_offset, faces_offset+new_faces.shape[0]))) vertices_offset += new_vertices.shape[0] faces_offset += new_faces.shape[0] if not vertices: return HybridGeometry(geom, set()), np.empty((0, 2), dtype=np.int32), np.empty((0, 3), dtype=np.uint32) vertices = np.vstack(vertices) faces = np.vstack(faces) return HybridGeometry(geom, tuple(faces_i)), vertices, faces
def _create_border(self, geometry: HybridGeometry, width, append=None): altitude = (np.vstack(chain(*(mesh.tolist() for mesh in geometry.faces)))[:, :, 2].max()+1)/1000 geometry = self.buffered_bbox.intersection(geometry.geom) lines = tuple(chain(*( ((geom.exterior, *geom.interiors) if isinstance(geom, Polygon) else (geom,)) for geom in getattr(geometry, 'geoms', (geometry,)) ))) if not lines: return np.empty((0, 3, 3+len(append))) lines = unary_union(lines).buffer(width, cap_style=CAP_STYLE.flat, join_style=JOIN_STYLE.mitre) vertices, faces = triangulate_polygon(lines) triangles = np.dstack((vertices[faces], np.full((faces.size, 1), fill_value=altitude).reshape((-1, 3, 1)))) return self._append_to_vertices(triangles.astype(np.float32), append)