本文整理汇总了Python中shapely.affinity.translate方法的典型用法代码示例。如果您正苦于以下问题:Python affinity.translate方法的具体用法?Python affinity.translate怎么用?Python affinity.translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapely.affinity
的用法示例。
在下文中一共展示了affinity.translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [as 别名]
def run(self, slide):
"""Run the workflow on the given image and upload the results to cytomine"""
results = self._workflow.process(slide)
# Upload results
for polygon, dispatch, cls, proba in results:
if cls is not None:
# if image is a window, the polygon must be translated
if isinstance(slide, ImageWindow):
polygon = translate(polygon, slide.abs_offset_x, slide.abs_offset_y)
# actually upload the annotation
_upload_annotation(
self._cytomine,
slide.image_instance,
polygon,
label=cls,
proba=proba
)
return results
示例2: get_as_shapely
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [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)
示例3: make
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [as 别名]
def make(self):
# Create new geometry
dx = self.destination[0] - self.origin[0]
dy = self.destination[1] - self.origin[1]
self.geometry = [DrawToolShape(affinity.translate(geom.geo, xoff=dx, yoff=dy))
for geom in self.draw_app.get_selected()]
# Delete old
self.draw_app.delete_selected()
# # Select the new
# for g in self.geometry:
# # Note that g is not in the app's buffer yet!
# self.draw_app.set_selected(g)
self.complete = True
示例4: utility_geometry
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [as 别名]
def utility_geometry(self, data=None):
"""
Temporary geometry on screen while using this tool.
:param data:
:return:
"""
if self.origin is None:
return None
if len(self.draw_app.get_selected()) == 0:
return None
dx = data[0] - self.origin[0]
dy = data[1] - self.origin[1]
return DrawToolUtilityShape([affinity.translate(geom.geo, xoff=dx, yoff=dy)
for geom in self.draw_app.get_selected()])
示例5: offset
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [as 别名]
def offset(self, vect):
"""
Offsets geometry on the XY plane in the object by a given vector.
:param vect: (x, y) offset vector.
:type vect: tuple
:return: None
"""
dx, dy = vect
# Drills
for drill in self.drills:
drill['point'] = affinity.translate(drill['point'], xoff=dx, yoff=dy)
# Recreate geometry
self.create_geometry()
示例6: addBridge
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [as 别名]
def addBridge(x, y, rot, sizex, sizey):
bpy.ops.mesh.primitive_plane_add(size=sizey*2, calc_uvs=True, enter_editmode=False, align='WORLD', location=(0, 0, 0), rotation=(0, 0, 0))
b = bpy.context.active_object
b.name = 'bridge'
# b.show_name=True
b.dimensions.x = sizex
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
bpy.ops.object.editmode_toggle()
bpy.ops.transform.translate(value=(0, sizey / 2, 0), constraint_axis=(False, True, False),
orient_type='GLOBAL', mirror=False, use_proportional_edit=False,
proportional_edit_falloff='SMOOTH', proportional_size=1)
bpy.ops.object.editmode_toggle()
bpy.ops.object.convert(target='CURVE')
b.location = x, y, 0
b.rotation_euler.z = rot
return b
示例7: add_shadow
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [as 别名]
def add_shadow(self, geometry, elevation, clip_path=None):
# add a shadow for the given geometry with the given elevation and, optionally, a clip path
elevation = float(min(elevation, 2))
blur_radius = elevation / 3 * 0.25
shadow_geom = translate(geometry.buffer(blur_radius),
xoff=(elevation / 3 * 0.12), yoff=-(elevation / 3 * 0.12))
if clip_path is not None:
if shadow_geom.distance(clip_path) >= blur_radius:
return
blur_id = 'blur'+str(int(elevation*100))
if elevation not in self.blurs:
self.defs += ('<filter id="'+blur_id+'" width="200%" height="200%" x="-50%" y="-50%">'
'<feGaussianBlur stdDeviation="'+str(blur_radius * self.scale)+'"/>'
'</filter>')
self.blurs.add(elevation)
attribs = ' filter="url(#'+blur_id+')" fill="#000" fill-opacity="0.2"'
if clip_path:
attribs += ' clip-path="url(#'+self.register_clip_path(clip_path)+')"'
shadow = self._create_geometry(shadow_geom, attribs)
self.g += shadow
示例8: makeRect
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [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
示例9: _get_spatiotemporal_ref
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [as 别名]
def _get_spatiotemporal_ref(row):
#print(type(row['geo_intersection']))
if type(row['geo_intersection']) == LineString:
pt0 = Point(row['geo_intersection'].coords[0])
ptn = Point(row['geo_intersection'].coords[-1])
t = row['prev_t']
t_delta = row['t'] - t
len = row['line'].length
t0 = t + (t_delta * row['line'].project(pt0)/len)
tn = t + (t_delta * row['line'].project(ptn)/len)
# to avoid intersection issues with zero length lines
if ptn == translate(pt0, 0.00000001, 0.00000001):
t0 = row['prev_t']
tn = row['t']
# to avoid numerical issues with timestamps
if is_equal(tn, row['t']):
tn = row['t']
if is_equal(t0, row['prev_t']):
t0 = row['prev_t']
return {'pt0':pt0, 'ptn':ptn, 't0':t0, 'tn':tn}
else:
return None
示例10: get_shapely_object
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [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)
示例11: _example
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [as 别名]
def _example():
import gdsCAD.core
from gdshelpers.geometry import convert_to_gdscad
kit_logo = KITLogo([0, 0], 1)
wwu_logo = WWULogo([0, 0], 1, 1)
cell = gdsCAD.core.Cell('LOGOS')
cell.add(convert_to_gdscad(kit_logo))
cell.add(convert_to_gdscad(translate(wwu_logo.get_shapely_object(), 2.5)))
cell.show()
示例12: _channel
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [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
示例13: get_shapely_object
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [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)
示例14: get_patches
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [as 别名]
def get_patches(self, origin=(0, 0), angle_sum=0, angle=0, layers: Optional[List[int]] = None):
from descartes import PolygonPatch
def rotate_pos(pos, rotation_angle):
if rotation_angle is None:
return pos
c, s = np.cos(rotation_angle), np.sin(rotation_angle)
result = np.array([[c, -s], [s, c]]).dot(pos)
return result
own_patches = []
for layer, geometry in self.layer_dict.items():
if layers is not None and layer not in layers:
continue
geometry = geometric_union(geometry)
if geometry.is_empty:
continue
geometry = translate(rotate(geometry, angle_sum, use_radians=True, origin=(0, 0)), *origin)
own_patches.append(
PolygonPatch(geometry, color=['red', 'green', 'blue', 'teal', 'pink'][(layer - 1) % 5], linewidth=0))
sub_cells_patches = [p for cell_dict in self.cells for p in
cell_dict['cell'].get_patches(
np.array(origin) + rotate_pos(cell_dict['origin'], angle),
angle_sum=angle_sum + (cell_dict['angle'] or 0), angle=cell_dict['angle'],
layers=layers)]
return own_patches + sub_cells_patches
示例15: test_image_pxbounds_overlapping
# 需要导入模块: from shapely import affinity [as 别名]
# 或者: from shapely.affinity import translate [as 别名]
def test_image_pxbounds_overlapping(self):
wv2 = CatalogImage(WV02_CATID)
_bands, ysize, xsize = wv2.shape
image_shape = shape(wv2)
image_bounds = image_shape.bounds
width = image_bounds[2] - image_bounds[0]
clip_area = translate(image_shape, xoff=-0.5 * width)
xmin, ymin, xmax, ymax = wv2.pxbounds(clip_area, clip=True)
self.assertEqual(xmin, 0)
self.assertEqual(ymin, 0)
self.assertEqual(xmax, xsize/2)
self.assertEqual(ymax, ysize)