def ring(lat, lon, R, r, proj, EC=2.5): """Creates a ring defined by two circles with radiuses r, R centered at x, y Args: lat, lon: latitude and longitude R: outer radius of the ring in m r: inner radius of the ring in m proj. projection used EC: correction parameter """ if R == r: return None # get projected coordinates (x, y) = proj(lon, lat) # error adjust rings error_r = EC * projections.proj_error(proj, [lat, lon], r, 0) error_R = EC * projections.proj_error(proj, [lat, lon], R, 0) r -= math.fabs(error_r) R += math.fabs(error_R) if R > r: outer_circle = Point(x, y).buffer(R) inner_circle = Point(x, y).buffer(r) else: outer_circle = Point(x, y).buffer(r) inner_circle = Point(x, y).buffer(R) ring = outer_circle.difference(inner_circle) return ring
def ring(lat, lon, R, r, proj, EC=2.5): """Creates a ring defined by two circles with radiuses r, R centered at x, y Args: lat, lon: latitude and longitude R: outer radius of the ring in m r: inner radius of the ring in m proj. projection used EC: correction parameter """ if R == r: return None # get projected coordinates (x, y) = proj(lon, lat) # error adjust rings error_r = EC * projections.proj_error(proj, [lat, lon], r, 0) error_R = EC * projections.proj_error(proj, [lat, lon], R, 0) r -= math.fabs(error_r) R += math.fabs(error_R) if R > r: outer_circle = Point(x, y).buffer(R) inner_circle = Point(x, y).buffer(r) else: outer_circle = Point(x, y).buffer(r) inner_circle = Point(x, y).buffer(R) ring = outer_circle.difference(inner_circle) return ring
def solve(f, R, t, r, g): # make the circle outerCircle = Point(0, 0).buffer(R, 1 << 12) # make the ring innerCircle = Point(0, 0).buffer(R - t - f, 1 << 12) # make the bars bars = [] leftMin = -r - (2 * r + g) * (int(R / (2 * r + g)) + 1) left = leftMin while left < R: bars.append(box(left, -R, left + 2 * r + 2 * f, R)) left += 2 * r + g bottom = leftMin while bottom < R: bars.append(box(-R, bottom, R, bottom + 2 * r + 2 * f)) bottom += 2 * r + g # get the union union = outerCircle.difference(innerCircle) for bar in bars: union = union.union(bar) # intersection with prev shape finalPattern = union.intersection(outerCircle) # calc area ratio result = finalPattern.area / outerCircle.area return '%.6f' % result
def ring(centerx, centery, radius, width): """ a circular ring """ c_out = Point(centerx, centery).buffer(radius) c_in = Point(centerx, centery).buffer(radius - width) return c_out.difference(c_in)
def solve(f, R, t, r, g): # make the circle outerCircle = Point(0, 0).buffer(R, 1 << 12) # make the ring innerCircle = Point(0, 0).buffer(R - t - f, 1 << 12) # make the bars bars = [] leftMin = -r - (2 * r + g) * (int(R / (2 * r + g)) + 1) left = leftMin while left < R: bars.append(box(left, -R, left + 2 * r + 2 * f, R)) left += 2 * r + g bottom = leftMin while bottom < R: bars.append(box(-R, bottom, R, bottom + 2 * r + 2 * f)) bottom += 2 * r + g # get the union union = outerCircle.difference(innerCircle) for bar in bars: union = union.union(bar) # intersection with prev shape finalPattern = union.intersection(outerCircle) # calc area ratio result = finalPattern.area / outerCircle.area return '%.6f' % result
def test_operations(self): point = Point(0.0, 0.0) # General geometry self.assertEqual(point.area, 0.0) self.assertEqual(point.length, 0.0) self.assertAlmostEqual(point.distance(Point(-1.0, -1.0)), 1.4142135623730951) # Topology operations # Envelope self.assertIsInstance(point.envelope, Point) # Intersection self.assertIsInstance(point.intersection(Point(-1, -1)), GeometryCollection) # Buffer self.assertIsInstance(point.buffer(10.0), Polygon) self.assertIsInstance(point.buffer(10.0, 32), Polygon) # Simplify p = loads('POLYGON ((120 120, 121 121, 122 122, 220 120, 180 199, ' '160 200, 140 199, 120 120))') expected = loads('POLYGON ((120 120, 140 199, 160 200, 180 199, ' '220 120, 120 120))') s = p.simplify(10.0, preserve_topology=False) self.assertTrue(s.equals_exact(expected, 0.001)) p = loads('POLYGON ((80 200, 240 200, 240 60, 80 60, 80 200),' '(120 120, 220 120, 180 199, 160 200, 140 199, 120 120))') expected = loads( 'POLYGON ((80 200, 240 200, 240 60, 80 60, 80 200),' '(120 120, 220 120, 180 199, 160 200, 140 199, 120 120))') s = p.simplify(10.0, preserve_topology=True) self.assertTrue(s.equals_exact(expected, 0.001)) # Convex Hull self.assertIsInstance(point.convex_hull, Point) # Differences self.assertIsInstance(point.difference(Point(-1, 1)), Point) self.assertIsInstance(point.symmetric_difference(Point(-1, 1)), MultiPoint) # Boundary self.assertIsInstance(point.boundary, GeometryCollection) # Union self.assertIsInstance(point.union(Point(-1, 1)), MultiPoint) self.assertIsInstance(point.representative_point(), Point) self.assertIsInstance(point.centroid, Point) # Relate self.assertEqual(point.relate(Point(-1, -1)), 'FF0FFF0F2')
def generate(teeth_count=8, tooth_module=1., pressure_angle=deg2rad(20.), backlash=0., frame_count=16): pitch_radius = teeth_count * tooth_module / 2. pitch_circumference = pitch_radius * 2. * numpy.pi tooth_width = pitch_circumference / (2. * teeth_count) tooth_width += backlash addendum = tooth_width * (2 / numpy.pi) dedendum = addendum outer_radius = pitch_radius + addendum inner_radius = pitch_radius - dedendum # Tooth profile profile = numpy.array([ [-(.5 * tooth_width + addendum * numpy.tan(pressure_angle)), addendum], [ -(.5 * tooth_width - dedendum * numpy.tan(pressure_angle)), -dedendum ], [(.5 * tooth_width - dedendum * numpy.tan(pressure_angle)), -dedendum], [(.5 * tooth_width + addendum * numpy.tan(pressure_angle)), addendum] ]) outer_circle = Point(0., 0.).buffer(outer_radius) poly_list = [] prev_X = None l = 2 * tooth_width / pitch_radius for theta in numpy.linspace(0, l, frame_count): X = rotation( profile + numpy.array((-theta * pitch_radius, pitch_radius)), theta) if prev_X is not None: poly_list.append( MultiPoint([x for x in X] + [x for x in prev_X]).convex_hull) prev_X = X def circle_sector(angle, r): box_a = rotate(box(0., -2 * r, 2 * r, 2 * r), -angle / 2, Point(0., 0.)) box_b = rotate(box(-2 * r, -2 * r, 0, 2 * r), angle / 2, Point(0., 0.)) return Point(0., 0.).buffer(r).difference(box_a.union(box_b)) # Generate a tooth profile tooth_poly = cascaded_union(poly_list) tooth_poly = tooth_poly.union(scale(tooth_poly, -1, 1, 1, Point(0., 0.))) # Generate the full gear gear_poly = Point(0., 0.).buffer(outer_radius) for i in range(0, teeth_count): gear_poly = rotate(gear_poly.difference(tooth_poly), (2 * numpy.pi) / teeth_count, Point(0., 0.), use_radians=True) # Job done return gear_poly, pitch_radius, outer_radius, inner_radius
def test_operations(self): point = Point(0.0, 0.0) # General geometry self.assertEqual(point.area, 0.0) self.assertEqual(point.length, 0.0) self.assertAlmostEqual(point.distance(Point(-1.0, -1.0)), 1.4142135623730951) # Topology operations # Envelope self.assertIsInstance(point.envelope, Point) # Intersection self.assertIsInstance(point.intersection(Point(-1, -1)), GeometryCollection) # Buffer self.assertIsInstance(point.buffer(10.0), Polygon) self.assertIsInstance(point.buffer(10.0, 32), Polygon) # Simplify p = loads('POLYGON ((120 120, 121 121, 122 122, 220 120, 180 199, ' '160 200, 140 199, 120 120))') expected = loads('POLYGON ((120 120, 140 199, 160 200, 180 199, ' '220 120, 120 120))') s = p.simplify(10.0, preserve_topology=False) self.assertTrue(s.equals_exact(expected, 0.001)) p = loads('POLYGON ((80 200, 240 200, 240 60, 80 60, 80 200),' '(120 120, 220 120, 180 199, 160 200, 140 199, 120 120))') expected = loads( 'POLYGON ((80 200, 240 200, 240 60, 80 60, 80 200),' '(120 120, 220 120, 180 199, 160 200, 140 199, 120 120))') s = p.simplify(10.0, preserve_topology=True) self.assertTrue(s.equals_exact(expected, 0.001)) # Convex Hull self.assertIsInstance(point.convex_hull, Point) # Differences self.assertIsInstance(point.difference(Point(-1, 1)), Point) self.assertIsInstance(point.symmetric_difference(Point(-1, 1)), MultiPoint) # Boundary self.assertIsInstance(point.boundary, GeometryCollection) # Union self.assertIsInstance(point.union(Point(-1, 1)), MultiPoint) self.assertIsInstance(point.representative_point(), Point) self.assertIsInstance(point.centroid, Point) # Relate self.assertEqual(point.relate(Point(-1, -1)), 'FF0FFF0F2')
def DifferPo(Rx, Ry, Radius): xpoly_Temp = Point(Rx, Ry).buffer(Radius) xpoly = xpoly_Temp.difference(po) DifferPoly = xpoly.difference(xpoly.difference(po.convex_hull)) # xpoly = Point(Rx,Ry).buffer(Radius) # DifferPoly = xpoly.difference(po) #DifferPoly = xpoly.symmetric_difference(po) return DifferPoly
def get_bounds(radius, max_offset): x_bound = 2 * radius y_max, y_min = 2 * radius, -(max_offset + radius) bounding_box = Polygon([(-x_bound, y_min), (x_bound, y_min), (x_bound, y_max), (-x_bound, y_max)]) center = (0, radius) bounding_circle = Point(*center).buffer(2 * radius + max_offset) outer_bound = Point(*center).buffer(GratingEllipse.max_radius) interior = bounding_box.intersection(bounding_circle) bounding_curve = outer_bound.difference(interior) return bounding_curve
def new_rosace(Rint,Rext,N,surrounded=False): circle = Point(0,0).buffer(Rint) shape= circle for i in range(N): cosa = math.cos(i*2*math.pi/N) sina = math.sin(i*2*math.pi/N) circle2 = Point (Rint*cosa,Rint*sina).buffer(Rext) shape=shape.union(circle2) if surrounded: shapeout= Point(0,0).buffer((Rint+Rext)*1.01) shape=shapeout.difference(shape) # shape_in = shape.buffer(-Rext*0.1) # shape = shape.difference(shape_in) return shape
def annulus(r_in, r_out): """ Create an annulus Parameters ---------- r_in, r_out : float inner and outer radius of annulus Returns ------- Shapely Polygon object Example ------- >>> A = annulus(1,2) >>> A.area 9.409645471637816 """ C1 = Point(0,0).buffer(r_in) C2 = Point(0,0).buffer(r_out) return C2.difference(C1)
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]] polygons = SemanticMerger(5).merge(tiles, tile_polygons, topology) self.assertEqual(len(polygons), 1, "Number of found polygon") # use recall and false discovery rate to evaluate the error on the surface tpr = circle.difference(polygons[0]).area / circle.area fdr = polygons[0].difference(circle).area / polygons[0].area self.assertLessEqual(tpr, 0.002, "Recall is low for circle area") self.assertLessEqual(fdr, 0.002, "False discovery rate is low for circle area")
def pcf2d(array_positions, bins_distances, coord_border=None, coord_holes=None, fast_method=False, show_timing=False, plot=False, full_output=False): r""" Computes the 2D radial distribution function (pair correlation function) g(r) for a set of points, corrected to take account of the boundary effects. Parameters: - array_positions (numpy array, shape Nx2): the (x,y) coordinates of N points. - bins_distances (numpy array, shape Mx1): a monotonically increasing array of bin edges defining the values of r for which g(r) is going to be computed. Optional parameters : - coord_border (numpy array, shape Lx2): the (x,y) coordinates of L points, defining the boundary enclosing the area of interest to compute the g(r). Points in array_positions that are outside the area of interest are automatically excluded. !! The list of coordinates must be "valid" in the sense used by the shapely library: linking all the points in order should result in a simple polygon with no line intersecting each other. !! Ex: Assuming one wants a square border of area 1 [[0,0],[0,1],[1,1],[1,0]] is valid (square shape) [[0,0],[0,1],[1,0],[1,1]] is not valid (bow tie shape) If no value is provided, the smallest convex Polygon containing all the points in array_positions is computed using convex_hull. (default value: None) - coord_holes (list of numpy arrays): a list of the (x,y) coordinates of points forming "holes" in the area of interest (useful if one is using a geometry with obstacles or exclusion zones where no particles can be found). It is possible to define several holes (as long as they do not intersect each other). Ex: Assuming the area of interest is a square and one wants to to remove a smaller square at the center coord_border=[[0,0],[0,1],[1,1],[1,0]] coord_holes=[[[0.2,0.2],[0.2,0.8],[0.8,0.8],[0.8,0.2]]] If no value is provided, the area of intereste will be a simple polygon with no hole. (default value: None) - fast_method (bool): if True, all the points whose distance to the boundary is less than the longest distance in bins_distance are excluded from the g(r) computation, and only the points sufficiently far away from the boundary are considered. This method is faster, but might exclude a lot of points. if False, the code computes for each point its distance to the boundary, then computes a normalization factor for the points that are too close to the boundary. This is the default method that correctly takes account of all points, but might be time consuming. (default value: False) - show_timing (bool): if True, the code will print outputs showing timings at different stages of the computation (to let one know what operations are the most time consuming). (default value: False) - plot (bool): if True, shows the points that were kept, and the computed g(r). (default value: False). - full_output (bool): if True, the function also returns also "raw" distribution of distances between the points PDF(r), the new array of coordinates with only the points that were considered for computing g(r), the distance of each point to the closest boundary of the area of interest, the normalization factors, and the estimated density of points in the area of interest. (default value: False). Outputs: - g(r): a 1x(M-1) numpy array (where M is the length of bin_distances) - r: a 1x(M-1) numpy array (where M is the length of bin_distances) Optional output: - PDF(r): a 1x(M-1) numpy array - new_array_positions: a 2xN numpy array - distance_to_boundary: a 1xN numpy array - normalization_factor: a Nx(M-1) numpy array - estimated_density: a float (where N in the number of points in the area of interest and M is the length of bin_distances) """ if show_timing == True: t0 = time.time() if coord_border is None: positions_of_interest = MultiPoint( array_positions) #all the points are considered area_of_interest = positions_of_interest.convex_hull #the boundary is the convex_hull of all the points else: if coord_holes is None: area_of_interest = Polygon( shell=coord_border) #definition of the boundary else: area_of_interest = Polygon( shell=coord_border, holes=coord_holes) #definition of the boundary if not area_of_interest.is_valid: print( 'The list of coordinates your provided for the border is not valid (see help for the definition of valid coord_border).' ) return positions_of_interest = area_of_interest.intersection( MultiPoint(array_positions) ) #only the points inside the area of interest are considered array_positions = np.array( positions_of_interest ) #redefinition of "array_positions" with only the points inside the area of interest (time consuming operation) if show_timing == True: t1 = time.time() - t0 print( 'Creating boundary polygon and array of points inside took %f s' % t1) nb_part = len(array_positions) #number of particles densite = nb_part / (area_of_interest.area) #average density of particles border_area = area_of_interest.boundary #the boundary (line) of the area of interest (polygon) rings = [[] for i in range(len(bins_distances) - 1)] ring_area = np.zeros(len(bins_distances) - 1) #true ring areas ring_area_approx = np.zeros( len(bins_distances) - 1) #approximate ring areas (useful for normalization calculation) #For each distance bin, defines the ring (difference between the disk of radius r[jj+1] and the disk of radius r[jj]) #and computes the area of those rings. for jj in range(len(bins_distances) - 1): inner_circle = Point([0, 0]).buffer(bins_distances[jj]) outer_circle = Point([0, 0]).buffer(bins_distances[jj + 1]) rings[jj] = outer_circle.difference(inner_circle) ring_area_approx[jj] = rings[jj].area ring_area[jj] = np.pi * (bins_distances[jj + 1]**2 - bins_distances[jj]**2) if show_timing == True: t2 = time.time() - t0 print('Creating all ring polygons took %f s' % (t2 - t1)) g_of_r = np.zeros(len(bins_distances) - 1) g_of_r_normalized = np.zeros(len(bins_distances) - 1) #For each point, computes its distance to the boundary, and for each bin computes the normalization factor #(the area of "the intersection of the ring and the area of interest", divided by the ring area) normalisation = np.ones( (nb_part, len(bins_distances) - 1)) #normalization factors to take account of the boundaries dist_to_border = np.zeros(nb_part) if fast_method == True: for ii in range(nb_part): dist_to_border[ii] = positions_of_interest[ii].distance( border_area) #distance of current point to boundary far_enough = np.where(dist_to_border > bins_distances[-1])[ 0] #indexes of points far enough from the boundary array_positions = array_positions[ far_enough, :] #points too close to the boundary are excluded nb_part = len(array_positions) #the new number of points if full_output == True: dist_to_border = dist_to_border[ far_enough] #points too close to the boundary are excluded normalisation = np.ones( (nb_part, len(bins_distances) - 1)) #just so that the matrix has the right size else: for ii in range(nb_part): dist_to_border[ii] = positions_of_interest[ii].distance( border_area) #distance of point ii to boundary if dist_to_border[ii] <= bins_distances[ 0]: #special case the point is too close to the boundary for every r for jj in range(len(bins_distances) - 1): normalisation[ii, jj] = (area_of_interest.intersection( translate(rings[jj], xoff=positions_of_interest[ii].xy[0][0], yoff=positions_of_interest[ii].xy[1] [0])).area) / ring_area_approx[jj] else: for jj in ( np.where(bins_distances > dist_to_border[ii])[0] - 1 ): #the normalization factor needs only to be computed for a subset of r normalisation[ii, jj] = (area_of_interest.intersection( translate(rings[jj], xoff=positions_of_interest[ii].xy[0][0], yoff=positions_of_interest[ii].xy[1] [0])).area) / ring_area_approx[jj] if show_timing == True: t3 = time.time() - t0 print('Computing normalization factors took %f s' % (t3 - t2)) #For each point, computes the distance to others, then compute the g(r) by binning for ii in range(nb_part): #coordinates of the current point x_loc = array_positions[ii, 0] y_loc = array_positions[ii, 1] dist_to_loc = np.sqrt( (array_positions[:, 0] - x_loc)**2 + (array_positions[:, 1] - y_loc)** 2) #distance of the current point to each other point dist_to_loc[ ii] = np.inf #the distance from a point to itself is always zero (it is therefore excluded from the computation) g_of_r = g_of_r + np.histogram(dist_to_loc, bins=bins_distances)[ 0] #computes the histogram of distances to the current point g_of_r_normalized = g_of_r_normalized + np.histogram( dist_to_loc, bins=bins_distances )[0] / ( ring_area * normalisation[ii, :] ) #computes the histogram of distances to the current point normalized by the area of the intersection of the ring and the area of interest if show_timing == True: t4 = time.time() - t0 print('Computing g(r) took %f s' % (t4 - t3)) g_of_r = g_of_r / nb_part #computes PDF(r) g_of_r_normalized = g_of_r_normalized / (nb_part * densite) #computes g(r) radii = (bins_distances[1::] + bins_distances[0:-1]) / 2 #computes the values of "r" if plot == True: plt.figure() plt.scatter(array_positions[:, 0], array_positions[:, 1]) plt.xlabel('x') plt.ylabel('y') plt.title('Points kept to compute g(r)') plt.figure() plt.plot(radii, g_of_r_normalized) plt.xlabel('r') plt.ylabel('g(r)') plt.title('Radial Distribution Function') if full_output == True: results = (g_of_r_normalized, radii, g_of_r, array_positions, dist_to_border, normalisation, densite) else: results = (g_of_r_normalized, radii) if show_timing == True: t5 = time.time() - t0 print('Total time: %f s for %i points ' % (t5, nb_part)) return results
# from pygiser import BLUE, GRAY, set_limits from figures import SIZE, BLUE, GRAY, DARKGRAY, set_limits fig = pyplot.figure(1, figsize=SIZE, dpi=90) a = Point(1, 1).buffer(1.5) b = Point(2, 1).buffer(1.5) # 1 ax = fig.add_subplot(121) patch1 = PolygonPatch(a, fc=GRAY, ec=GRAY, alpha=0.2, zorder=1) ax.add_patch(patch1) patch2 = PolygonPatch(b, fc=GRAY, ec=GRAY, alpha=0.2, zorder=1) ax.add_patch(patch2) c = a.difference(b) patchc = PolygonPatch(c, fc=DARKGRAY, ec=DARKGRAY, alpha=0.5, zorder=2) ax.add_patch(patchc) ax.set_title('a.difference(b)') set_limits(ax, -1, 4, -1, 3) # 2 ax = fig.add_subplot(122) patch1 = PolygonPatch(a, fc=GRAY, ec=GRAY, alpha=0.2, zorder=1) ax.add_patch(patch1) patch2 = PolygonPatch(b, fc=GRAY, ec=GRAY, alpha=0.2, zorder=1) ax.add_patch(patch2) c = b.difference(a)
############################################################################### from shapely.geometry import LineString, MultiLineString, Point from pprint import pprint coords = [((0, 0), (1, 1)), ((-1, 0), (1, 0))] lines = MultiLineString(coords) lines.boundary lines.boundary.boundary lines.boundary.boundary.is_empty ############################################################################### LineString([(0, 0), (1, 1)]).centroid LineString([(0, 0), (1, 1)]).centroid.wkt ############################################################################### a = Point(1, 1).buffer(1.5) b = Point(2, 1).buffer(1.5) a.difference(b) ############################################################################### a = Point(1, 1).buffer(1.5) b = Point(2, 1).buffer(1.5) a.intersection(b) ############################################################################### a = Point(1, 1).buffer(1.5) b = Point(2, 1).buffer(1.5) a.symmetric_difference(b) ############################################################################### a = Point(1, 1).buffer(1.5) b = Point(2, 1).buffer(1.5) a.union(b) ############################################################################### a.union(b).boundary a.boundary.union(b.boundary)
########################## #define some basic geometries circle_small = Point((0.0, 0.0)).buffer(10.0) circle_medium = Point((0.0, 0.0)).buffer(20.0) circle_large = Point((0.0, 0.0)).buffer(30.0) rectangle_small = Polygon( ((-10.0, -5.0), (-10.0, 5.0), (10.0, 5.0), (10.0, -5.0), (-10.0, -5.0))) rectangle_medium = Polygon( ((-15.0, -7.5), (-15.0, 7.5), (15.0, 7.5), (15.0, -7.5), (-15.0, -7.5))) rectangle_large = Polygon(((-20.0, -10.0), (-20.0, 10.0), (20.0, 10.0), (20.0, -10.0), (-20.0, -10.0))) ring_slim = circle_large.difference(circle_medium) ring_thick = circle_large.difference(circle_small) # place buildings across the domain geoms = [] geoms.append( bld.building(ground=translate(circle_medium, xoff=175.0, yoff=185.0), height=30.0, id_bldg=len(geoms))) geoms.append( bld.building(ground=translate(rectangle_large, xoff=155.0, yoff=145.0), height=20.0, id_bldg=len(geoms))) geoms.append( bld.building(ground=rotate(
BLUE = '#6699cc' GRAY = '#999999' fig = pyplot.figure(1, figsize=SIZE, dpi=90) a = Point(1, 1).buffer(1.5) b = Point(2, 1).buffer(1.5) # 1 ax = fig.add_subplot(121) patch1 = PolygonPatch(a, fc=GRAY, ec=GRAY, alpha=0.2, zorder=1) ax.add_patch(patch1) patch2 = PolygonPatch(b, fc=GRAY, ec=GRAY, alpha=0.2, zorder=1) ax.add_patch(patch2) c = a.difference(b) patchc = PolygonPatch(c, fc=BLUE, ec=BLUE, alpha=0.5, zorder=2) ax.add_patch(patchc) ax.set_title('a.difference(b)') xrange = [-1, 4] yrange = [-1, 3] ax.set_xlim(*xrange) ax.set_xticks(range(*xrange) + [xrange[-1]]) ax.set_ylim(*yrange) ax.set_yticks(range(*yrange) + [yrange[-1]]) ax.set_aspect(1) #2 ax = fig.add_subplot(122)
from shapely.geometry import MultiLineString coords = [((0, 0), (1, 1)), ((-1, 0), (1, 0))] lines = MultiLineString(coords) lines.boundary.wkt lines.boundary.boundary.wkt lines.boundary.boundary.is_empty ################################################################################ from shapely.geometry import LineString LineString([(0, 0), (1, 1)]).centroid.wkt ################################################################################ from shapely.geometry import Point a = Point(1, 1).buffer(1.5) b = Point(2, 1).buffer(1.5) a.difference(b).wkt ################################################################################ a = Point(1, 1).buffer(1.5) b = Point(2, 1).buffer(1.5) a.intersection(b).wkt ################################################################################ a = Point(1, 1).buffer(1.5) b = Point(2, 1).buffer(1.5) a.symmetric_difference(b).wkt ################################################################################ a = Point(1, 1).buffer(1.5) b = Point(2, 1).buffer(1.5) a.union(b).wkt
import cairocffi as cairo from shapely.geometry import Point import map.features.nature circle = Point(50, 50).buffer(40, resolution=30) bite = Point(20, 50).buffer(20) hole = Point(60, 50).buffer(10) circle = circle.difference(bite) circle = circle.difference(hole) surface = cairo.PDFSurface("output/map_features_nature_water.pdf", 100, 100) ctx = cairo.Context(surface) waterDrawer = map.features.nature.WaterDrawer() waterDrawer.draw(ctx, [circle]) surface.flush() surface.finish()
def ring(Rext,Rint): shape_out= Point(0,0).buffer(Rext) shape_in = Point (0,0).buffer(Rint) return shape_out.difference(shape_in)
def plot_poly(poly, pen): plot_line(LineString(poly.exterior.coords), pen) for i in poly.interiors: plot_line(LineString(i.coords), pen) # Drawing limits: (left 0; bottom 0; right 10300; top 7650) # = Letter paper on HP-7470A # draw a nice page box page = box(0, 0, 10300, 7650) innerpage = scale(page, xfact=0.99, yfact=0.99, origin='center') hatching = hatchbox(page, 45, 100) # construct crescent circle = Point(5000, 4000).buffer(3000) pt = Point(3500, 4000) circle1 = pt.buffer(2000) crescent = circle.difference(circle1).simplify(10.0) crescent_hatch = crescent.intersection(hatching) # construct a box with a hole in it weebox = box(8000, 5000, 9500, 7000) weehatch = hatchbox(weebox, -45, 40) tbox = scale(weebox, xfact=0.95, yfact=0.95, origin='center') tinybox = scale(weebox, xfact=0.5, yfact=0.5, origin='center') holey = tbox.difference(tinybox) # add fine hatching holey_hatch = holey.intersection(weehatch) # plot stuff .. print 'IN;' # cheapo init code plot_poly(page, 1) # outer page border plot_poly(innerpage, 2) # inner page border
# -*- coding: utf-8 -*- import os from shapely.geometry import Point, LineString, LinearRing, Polygon, MultiLineString coords = [((0,0),(1,1)),((-1,0),(1,0))] lines = MultiLineString(coords) lines.boundary print(list(lines.boundary)) lines.boundary.boundary.is_empty LineString([(0,0),(1,1)]).centroid LineString([(0,0),(1,1)]).centroid.wkt a = Point(1,1).buffer(1.5) b = Point(2,1).buffer(1.5) a.difference(b) a.intersection(b) a.symmetric_difference(b) a.union(b) a.union(b).boundary a.boundary.union(b.boundary) def Test(): assert True