How to use the shapely.affinity.translate function in shapely

To help you get started, we’ve selected a few shapely examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github holoviz / spatialpandas / tests / geometry / strategies.py View on Github external
sg_multipolygons = []
    for _ in range(n):
        xmid=draw(st.floats(-50, 50))
        ymid=draw(st.floats(-50, 50))
        polygon = draw(st_polygon(xmid=xmid, ymid=ymid))
        m = draw(st.integers(min_value=1, max_value=4))

        # populate polygons with m copies of polygon
        polygons = [polygon] * m

        # translate polygons so they don't overlap
        _, _, last_x1, last_y1 = polygons[0].bounds
        for j in range(1, m):
            polygon = scale(polygons[j], 0.8, 0.5)
            poly_x0, poly_y0, poly_x1, poly_y1 = polygon.bounds
            new_polygon = translate(
                polygon, yoff=last_y1 - poly_y0 + 1
            )
            _, _, last_x1, last_y1 = new_polygon.bounds
            polygons[j] = new_polygon

        sg_multipolygons.append(sg.MultiPolygon(polygons))

    result = from_shapely(sg_multipolygons)
    if geoseries:
        result = GeoSeries(result)
    return result
github waliens / sldc / test / test_merger.py View on Github external
def testMerger(self):
        # build chunks for the polygons
        tile_box = box(0, 0, 512, 256)  # a box having the same dimension as the tile
        circle = Point(600, 360)
        circle = circle.buffer(250)

        circle_part1 = tile_box.intersection(circle)
        circle_part2 = translate(tile_box, xoff=512).intersection(circle)
        circle_part3 = translate(tile_box, yoff=256).intersection(circle)
        circle_part4 = translate(tile_box, xoff=512, yoff=256).intersection(circle)
        circle_part5 = translate(tile_box, yoff=512).intersection(circle)
        circle_part6 = translate(tile_box, xoff=512, yoff=512).intersection(circle)

        # create topology
        fake_image = FakeImage(1024, 768, 3)
        fake_builder = FakeTileBuilder()
        topology = fake_image.tile_topology(fake_builder, 512, 256)

        tile1 = topology.tile(1)
        tile2 = topology.tile(2)
        tile3 = topology.tile(3)
        tile4 = topology.tile(4)
        tile5 = topology.tile(5)
        tile6 = topology.tile(6)

        tiles = [tile1.identifier, tile2.identifier, tile3.identifier, tile4.identifier, tile5.identifier, tile6.identifier]
        tile_polygons = [[circle_part1], [circle_part2], [circle_part3], [circle_part4], [circle_part5], [circle_part6]]
github BerkeleyAutomation / Urban_Driving_Simulator / fluids / assets / shape.py View on Github external
def update_points(self, x, y, angle):
        dx = self.x - x
        dy = self.y - y
        dangle = (angle - self.angle + 6 * np.pi) % (2 * np.pi)
        self.x = x
        self.y = y
        self.angle = angle % (2 * np.pi)
        # origin = np.array([self.x, self.y])
        # self.points = self.origin_points.dot(rotation_array(self.angle)) + origin
        # xs, ys = self.points[:,0], self.points[:,1]

        self.shapely_obj = shapely.affinity.translate(self.shapely_obj,
                                                      -dx, -dy)
        self.shapely_obj = shapely.affinity.rotate(self.shapely_obj,
                                                   -dangle,
                                                   (self.x, self.y),
                                                   use_radians=True)
        self.points = np.array(self.shapely_obj.exterior.coords)
        xs, ys = self.points[:,0], self.points[:,1]
        self.minx, self.maxx = min(xs), max(xs)
        self.miny, self.maxy = min(ys), max(ys)
github wez / clacker / tools / pcb.py View on Github external
j2 = None

        trrs_type = self.shape_config.get('trrs', None) if self.shape_config else None
        if trrs_type == 'basic':
            trrs = circuit.trrs(ref='J1')
            trrs.set_ident('J1')
            trrs.set_position(translate(cxlate(shapes['trrs']), 0, 5.5))
            trrs.set_rotation(90);
            trrs.reserve_i2c()
        elif trrs_type == 'left+right':
            trrs = circuit.trrs(ref='J1', dual=True)
            trrs.set_position(translate(cxlate(shapes['trrs']), 0, 5.5))
            trrs.set_rotation(90);
            trrs.reserve_i2c()
            j1 = circuit.jumper3(ref='JP1')
            j1.set_position(translate(cxlate(shapes['trrs']), 9, 3))
            j2 = circuit.jumper3(ref='JP2')
            j2.set_position(translate(cxlate(shapes['trrs']), 9, 9.5))
            j2.set_rotation(180)

            j1.part['1'] += circuit.net('3V3')
            j1.part['2'] += trrs.part['R2']
            j1.part['3'] += circuit.net('GND')

            j2.part['1'] += circuit.net('GND')
            j2.part['2'] += trrs.part['S']
            j2.part['3'] += circuit.net('3V3')
        else:
            trrs = None

        rj45_type = self.shape_config.get('rj45', None) if self.shape_config else None
        if rj45_type == 'basic':
github wez / clacker / tools / pcb.py View on Github external
j2.set_rotation(180)

            j1.part['1'] += circuit.net('3V3')
            j1.part['2'] += trrs.part['R2']
            j1.part['3'] += circuit.net('GND')

            j2.part['1'] += circuit.net('GND')
            j2.part['2'] += trrs.part['S']
            j2.part['3'] += circuit.net('3V3')
        else:
            trrs = None

        rj45_type = self.shape_config.get('rj45', None) if self.shape_config else None
        if rj45_type == 'basic':
            rj45 = circuit.rj45(ref='J1')
            rj45.set_position(translate(cxlate(shapes['rj45']), 0, 14))
            rj45.set_rotation(180);
            rj45.reserve_i2c()
            rj45_right = None
        elif rj45_type == 'left+right':
            rj45 = circuit.rj45(ref='J1')
            rj45.set_position(translate(cxlate(shapes['rj45']), 7.5, 14))
            rj45.set_rotation(0);
            rj45.flip()
            rj45_right = circuit.rj45(ref='J2')
            rj45_right.set_position(translate(cxlate(shapes['rj45']), 0, 14))
            rj45_right.set_rotation(180);
            rj45.reserve_i2c()
            rj45_right.reserve_i2c()
        elif rj45_type == 'magjack':
            rj45 = circuit.rj45_magjack()
            rj45.set_position(translate(cxlate(shapes['rj45']), 0, 0))
github kundajelab / dfim / dfim / plot.py View on Github external
def add_letter_to_axis(ax, let, x, y, height):
    """Add 'let' with position x,y and height height to matplotlib axis 'ax'.
    """
    for polygon, color in zip(letters_polygons[let], colors[let]):
        new_polygon = affinity.scale(
            polygon, yfact=height, origin=(0, 0, 0))
        new_polygon = affinity.translate(
            new_polygon, xoff=x, yoff=y)
        patch = PolygonPatch(
            new_polygon, edgecolor=color, facecolor=color)
        ax.add_patch(patch)
    return
github Ultimaker / Cura / cura / OneAtATimeIterator.py View on Github external
def flip_y(polygon):
            tm2 = [1, 0, 0, -1, 0, 0]
            return affinity.affine_transform(affinity.translate(polygon, yoff = -machine_size[1]), tm2)
github meshulam / sly / cubemaker / cube.py View on Github external
if edge_type == EDGE_SOLO:
            return unary_union(teeth)

        num_teeth = round_nearest_odd(distance / self.tooth_width)
        real_width = distance / num_teeth

        if edge_type == EDGE_OVER:
            start_ind = 0
        else:
            start_ind = 1

        base_tooth = box(-self.tooth_slop/2, 0,
                         real_width + self.tooth_slop/2, self.thickness)

        for tick in range(start_ind, num_teeth, 2):
            tooth = translate(base_tooth, xoff=tick*real_width)
            teeth.append(tooth)

        return unary_union(teeth)
github wez / clacker / tools / circuitlib / shape.py View on Github external
def cxlate(shape):
        return translate(shape,
                            PCBNEW_SPACING - xlate_bounds.bounds[0],
                            PCBNEW_SPACING - xlate_bounds.bounds[1])
github HelgeGehring / gdshelpers / gdshelpers / parts / ntron.py View on Github external
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)