本文整理汇总了Python中shapely.affinity.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python affinity.rotate方法的具体用法?Python affinity.rotate怎么用?Python affinity.rotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapely.affinity
的用法示例。
在下文中一共展示了affinity.rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_as_shapely
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def get_as_shapely(self, cell, layer=None, datatype=None):
geometry = []
gdspy_cell = self.gdslib.cells[cell] if isinstance(cell, str) else cell
for polygon in gdspy_cell.polygons:
if self.layer is not None and layer != polygon.layers[0]:
continue
if self.datatype is not None and datatype != polygon.datatypes[0]:
continue
geometry.append(Polygon(polygon.polygons[0]).buffer(0)) # .buffer(0) for healing geometries
for reference in gdspy_cell.references:
sub_geometry = self.get_as_shapely(reference.ref_cell, layer, datatype)
if sub_geometry.is_empty:
continue
sub_geometry = scale(sub_geometry,
*[reference.magnification] * 2) if reference.magnification else sub_geometry
sub_geometry = scale(sub_geometry, -1) if reference.x_reflection else sub_geometry
sub_geometry = rotate(sub_geometry, reference.rotation,
origin=(0, 0)) if reference.rotation else sub_geometry
sub_geometry = translate(sub_geometry, *reference.origin)
geometry.extend(sub_geometry)
return MultiPolygon(geometry)
示例2: get_reduced_layer
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def get_reduced_layer(self, layer: int):
"""
Returns a single shapely object containing the structures on a certain layer from this cell and all added cells.
:param layer: the layer whose structures will be returned
:return: a single shapely-geometry
"""
def translate_and_rotate(geometry, offset, angle):
if not geometry:
return geometry
return translate(rotate(geometry, angle if angle else 0, use_radians=True, origin=(0, 0)), *offset)
return geometric_union(
(self.layer_dict[layer] if layer in self.layer_dict else []) +
[translate_and_rotate(cell['cell'].get_reduced_layer(layer), cell['origin'], cell['angle'])
for cell in self.cells])
示例3: make_outline
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def make_outline(mods):
"""
:param mods:
:return:
"""
pol = mods[0]
n = mods[1]
points = [(0, 0)]*(n+1)
for i in range(n+1):
points[i] = mods[2*i + 2:2*i + 4]
angle = mods[2*n + 4]
poly = Polygon(points)
poly_rotated = affinity.rotate(poly, angle, origin=(0, 0))
return {"pol": int(pol), "geometry": poly_rotated}
示例4: make_polygon
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def make_polygon(mods):
"""
Note: Specs indicate that rotation is only allowed if the center
(x, y) == (0, 0). I will tolerate breaking this rule.
:param mods: (exposure 0/1, n_verts 3<=n<=12, x-center, y-center,
diameter of circumscribed circle >=0, rotation angle around origin)
:return:
"""
pol, nverts, x, y, dia, angle = ApertureMacro.default2zero(6, mods)
points = [(0, 0)]*nverts
for i in range(nverts):
points[i] = (x + 0.5 * dia * cos(2*pi * i/nverts),
y + 0.5 * dia * sin(2*pi * i/nverts))
poly = Polygon(points)
poly_rotated = affinity.rotate(poly, angle, origin=(0, 0))
return {"pol": int(pol), "geometry": poly_rotated}
示例5: _rotate_polygons
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def _rotate_polygons(polygons, angle, r_c):
## polygons: N*8
## r_x: rotate center x
## r_y: rotate center y
## angle: -15~15
poly_list = _quad2boxlist(polygons)
rotate_boxes_list = []
for poly in poly_list:
box = Polygon(poly)
rbox = affinity.rotate(box, angle, r_c)
if len(list(rbox.exterior.coords))<5:
print(poly)
print(rbox)
# assert(len(list(rbox.exterior.coords))>=5)
rotate_boxes_list.append(rbox.boundary.coords[:-1])
res = _boxlist2quads(rotate_boxes_list)
return res
示例6: makeRect
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def makeRect(paramsX):
centerX,centerY,width,height,angle = paramsX
pts = [
(-width/2,height/2),
(width/2,height/2),
(width/2,-height/2),
(-width/2,-height/2),
(-width/2,height/2)]
fitShape = geometry.LineString(pts)
fitShape = affinity.rotate(fitShape, angle,use_radians=True )
fitShape = affinity.translate(fitShape, centerX,centerY )
return fitShape
示例7: test_CheckTessellationInput
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def test_CheckTessellationInput(self):
df = self.df_buildings
df.loc[144, "geometry"] = Polygon([(0, 0), (0, 1), (1, 0)])
df.loc[145, "geometry"] = MultiPoint([(0, 0), (1, 0)]).buffer(0.55)
df.loc[146, "geometry"] = affinity.rotate(df.geometry.iloc[0], 12)
check = mm.CheckTessellationInput(self.df_buildings)
assert len(check.collapse) == 1
assert len(check.split) == 1
assert len(check.overlap) == 2
check = mm.CheckTessellationInput(self.df_buildings, collapse=False)
assert len(check.split) == 1
assert len(check.overlap) == 2
check = mm.CheckTessellationInput(self.df_buildings, split=False)
assert len(check.collapse) == 1
assert len(check.overlap) == 2
check = mm.CheckTessellationInput(self.df_buildings, overlap=False)
assert len(check.collapse) == 1
assert len(check.split) == 1
check = mm.CheckTessellationInput(self.df_buildings, shrink=0)
assert len(check.collapse) == 0
assert len(check.split) == 0
assert len(check.overlap) == 4
示例8: get_shapely_object
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def get_shapely_object(self):
# Start with the "rays"
# noinspection PyTypeChecker
ray_angles = np.linspace(0, np.pi / 2, 8) + np.pi / 2
outer_ray_positions = (np.array([np.cos(ray_angles), np.sin(ray_angles)]) * self.height).T + (self.height, 0)
inner_ray_positions = (np.array([np.cos(ray_angles), np.sin(ray_angles)])
* self.height * self.min_radius_fraction).T + (self.height, 0)
polygons = list()
for outer, inner in zip(outer_ray_positions.reshape(-1, 2, 2), inner_ray_positions.reshape(-1, 2, 2)):
polygons.append(Polygon([outer[0], outer[1], inner[1], inner[0]]))
pass
# Draw the letters
d = self.height * 0.077
k_upper_branch = rotate(box(0, -d, sqrt(2) * self.height / 2 + sqrt(2) * d, d), 45, origin=(0, 0))
k_lower_branch = scale(k_upper_branch, yfact=-1., origin=(0, 0))
k_uncut = k_upper_branch.union(k_lower_branch)
k_unscaled = k_uncut.intersection(box(0, -self.height / 2., self.height / 2. + sqrt(2) * d, self.height / 2.))
k = scale(k_unscaled, 0.8, origin=(0, 0))
polygons.append(translate(k, self.height * 1.05, self.height / 2.))
i = box(0, 0, 2 * d, self.height)
polygons.append(translate(i, self.height * 1.6))
t_overlap = 2
t = box(-d, 0, d, self.height).union(
box(-d * (1 + t_overlap), self.height - 2 * d, d * (1 + t_overlap), self.height))
polygons.append(translate(t, self.height * 2.05))
logo = cascaded_union(polygons)
return translate(logo, *self.origin)
示例9: _channel
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def _channel(self):
channel_object = self._bezier_guide_channel(0, self._outer_channel_width, self._inner_channel_width,
self._channel_length, self._channel_point_2, self._channel_point_3)
x_offset = (self._gate_length + self._gate_choke_length + self._choke_length_2 + self._choke_length_3)
y_offset = (1 - self._channel_position) * self._channel_length
return translate(rotate(channel_object, -np.pi / 2, (0, 0), True), x_offset, y_offset, 0)
# Unite and translate the polygons parts
示例10: get_shapely_object
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def get_shapely_object(self):
shapely_object = geometric_union(
[self._gate(), self._choke_channel(), self._choke_left(), self._choke_right(), self._channel()])
rotated_object = rotate(shapely_object, self._angle, (0, 0), True)
return translate(rotated_object, self._origin[0], self._origin[1], 0)
示例11: test_export_import
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def test_export_import(self):
waveguide = Waveguide([0, 0], 0, 1)
for i_bend in range(9):
waveguide.add_bend(angle=np.pi, radius=60 + i_bend * 40)
offset = (10, 10)
angle = np.pi
cell = Cell('test')
cell.add_to_layer(1, waveguide)
sub_cell = Cell('sub_cell')
sub_cell.add_to_layer(2, waveguide)
cell.add_cell(sub_cell, origin=(0, 0), angle=0)
sub_cell2 = Cell('sub_cell2')
sub_cell2.add_to_layer(3, waveguide)
cell.add_cell(sub_cell2, origin=offset, angle=angle)
cell.save(grid_steps_per_micron=10000)
def assert_almost_equal_shapely(a, b, tolerance=2e-4):
self.assertTrue(a.buffer(tolerance).contains(b))
self.assertTrue(b.buffer(tolerance).contains(a))
assert_almost_equal_shapely(
waveguide.get_shapely_object(), GDSIIImport('test.gds', 'test', 1).get_shapely_object())
assert_almost_equal_shapely(
waveguide.get_shapely_object(), GDSIIImport('test.gds', 'test', 2).get_shapely_object())
assert_almost_equal_shapely(
translate(rotate(waveguide.get_shapely_object(), angle, use_radians=True, origin=(0, 0)),
*offset), GDSIIImport('test.gds', 'test', 3).get_shapely_object())
self.assertTrue(GDSIIImport('test.gds', 'test', 1, 2).get_shapely_object().is_empty)
示例12: normalized_to_map_coordinates
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def normalized_to_map_coordinates(coords: np.ndarray,
translation: List[List[float]],
rotation: List[float]) -> np.ndarray:
"""Denormalize trajectory to bring it back to map frame.
Args:
coords (numpy array): Array of shape (num_tracks x seq_len x 2) containing normalized coordinates
translation (list): Translation matrix used in normalizing trajectories
rotation (list): Rotation angle used in normalizing trajectories
Returns:
_ (numpy array: Array of shape (num_tracks x seq_len x 2) containing coordinates in map frame
"""
abs_coords = []
for i in range(coords.shape[0]):
ls = LineString(coords[i])
# Rotate
ls_rotate = rotate(ls, -rotation[i], origin=(0, 0))
# Translate
M_inv = [1, 0, 0, 1, -translation[i][4], -translation[i][5]]
ls_offset = affine_transform(ls_rotate, M_inv).coords[:]
abs_coords.append(ls_offset)
return np.array(abs_coords)
示例13: make_vectorline
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def make_vectorline(mods):
"""
:param mods: (Exposure 0/1, Line width >= 0, X-start, Y-start, X-end, Y-end,
rotation angle around origin in degrees)
:return:
"""
pol, width, xs, ys, xe, ye, angle = ApertureMacro.default2zero(7, mods)
line = LineString([(xs, ys), (xe, ye)])
box = line.buffer(width/2, cap_style=2)
box_rotated = affinity.rotate(box, angle, origin=(0, 0))
return {"pol": int(pol), "geometry": box_rotated}
示例14: make_centerline
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def make_centerline(mods):
"""
:param mods: (Exposure 0/1, width >=0, height >=0, x-center, y-center,
rotation angle around origin in degrees)
:return:
"""
pol, width, height, x, y, angle = ApertureMacro.default2zero(6, mods)
box = shply_box(x-width/2, y-height/2, x+width/2, y+height/2)
box_rotated = affinity.rotate(box, angle, origin=(0, 0))
return {"pol": int(pol), "geometry": box_rotated}
示例15: make_lowerleftline
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import rotate [as 别名]
def make_lowerleftline(mods):
"""
:param mods: (exposure 0/1, width >=0, height >=0, x-lowerleft, y-lowerleft,
rotation angle around origin in degrees)
:return:
"""
pol, width, height, x, y, angle = ApertureMacro.default2zero(6, mods)
box = shply_box(x, y, x+width, y+height)
box_rotated = affinity.rotate(box, angle, origin=(0, 0))
return {"pol": int(pol), "geometry": box_rotated}