當前位置: 首頁>>代碼示例>>Python>>正文


Python Polygon.addContour方法代碼示例

本文整理匯總了Python中Polygon.Polygon.addContour方法的典型用法代碼示例。如果您正苦於以下問題:Python Polygon.addContour方法的具體用法?Python Polygon.addContour怎麽用?Python Polygon.addContour使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Polygon.Polygon的用法示例。


在下文中一共展示了Polygon.addContour方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: shape_center

# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import addContour [as 別名]
def shape_center(shape):
	"""
	computes the center of gravity of a shapefile multi-polygon
	"""
	from Polygon import Polygon
	parts = shape.parts[:]
	parts.append(len(shape.points))
	
	# check for countries that cross the 180° longitude
	
	far_east = False
	far_west = False
	
	for i in range(len(parts)-1):
		pts = shape.points[parts[i]:parts[i+1]]
		if len(pts) == 0: continue
		if pts[0][0] < -90:
			far_west = True
		if pts[0][0] > 90:
			far_east = True
	
	poly = Polygon()
	for i in range(len(parts)-1):
		pts = shape.points[parts[i]:parts[i+1]]
		if far_east and far_west:
			# correct points
			for j in range(len(pts)):
				if pts[j][0] < 0: pts[j][0] += 360
		poly.addContour(pts)
	return poly.center()
開發者ID:kartograph,項目名稱:kartograph.py-old,代碼行數:32,代碼來源:gisutils.py

示例2: restore_poly_from_path_str

# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import addContour [as 別名]
def restore_poly_from_path_str(path_str):
    """
    restores a list of polygons from a SVG path string
    """
    contours = path_str.split('Z')  # last contour may be empty
    from Polygon import Polygon as Poly
    poly = Poly()
    for c_str in contours:
        if c_str.strip() != "":
            pts_str = c_str.strip()[1:].split("L")
            pts = []
            for pt_str in pts_str:
                x, y = map(float, pt_str.split(','))
                pts.append((x, y))
            poly.addContour(pts, is_clockwise(pts))
    return poly
開發者ID:Eugene-msc,項目名稱:kartograph.py,代碼行數:18,代碼來源:cartogram.py

示例3: apply_contours

# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import addContour [as 別名]
    def apply_contours(self, contours):
        """
        constructs a Polygon from contours
        """
        self.contours = contours
        from Polygon import Polygon as GPCPoly
        poly = GPCPoly()
        skip = 0
        for pts_ in contours:
            pts = []
            for pt in pts_:
                if 'deleted' in pt and pt.deleted is True:
                    skip += 1
                    continue
                pts.append((pt[0], pt[1]))
            ishole = utils.is_clockwise(pts)

            if len(pts) > 2:
                poly.addContour(pts, ishole)
        self.poly = poly
開發者ID:Eugene-msc,項目名稱:kartograph.py,代碼行數:22,代碼來源:polygon.py

示例4: generate_polygon

# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import addContour [as 別名]
def generate_polygon(coords, scale):
    """
    Generate a polygon that encompasses a set of grid coordinates.

    :param coords: List of coordinates to draw polygon around
    :param scale: Area around each grid square (1/scale in degrees is area of each point)
    :return: Polygon of area representing the set of points
    :return: Polygon of area representing the set of points
    """
    out_poly = Polygon()
    h_step = 0.51/scale
    for pos in coords:
        # sum up each polygon
        out_poly.addContour([
            (pos[0] - h_step, pos[1] - h_step),
            (pos[0] + h_step, pos[1] - h_step),
            (pos[0] + h_step, pos[1] + h_step),
            (pos[0] - h_step, pos[1] + h_step)
        ])

    out_poly.simplify()
    return out_poly
開發者ID:Humpheh,項目名稱:twied,代碼行數:24,代碼來源:polystacker.py

示例5: Polygon

# 需要導入模塊: from Polygon import Polygon [as 別名]
# 或者: from Polygon.Polygon import addContour [as 別名]
HEX_HEIGH = 24

f1,f2 = 19, 25

fname = sys.argv[1]

img = Image.open(fname)
img.putalpha(0xFFFFFF)

poly = Polygon()
poly.addContour([
    (0,HEX_HEIGH),

        (f1,HEX_HEIGH*2),
        (f1+f2,HEX_HEIGH*2),

    (f1+f1+f2,HEX_HEIGH),

        (f1+f2,0),
        (f1,0)
])


w,h = img.size

for x in range(w):
    for y in range(h):
        if poly.isInside(x,y):
            continue
        
        img.putpixel((x, y), 0)
開發者ID:muromec,項目名稱:iromidori,代碼行數:33,代碼來源:tilehex.py


注:本文中的Polygon.Polygon.addContour方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。