How can I decreased polygon Shape in python?

المشرف العام

Administrator
طاقم الإدارة
I am using below code but i want to little bit decrease polygon Shape.

import shapefile

from PIL import Image,ImageDraw, ImageFont

import math

fnt_new = ImageFont.truetype('C:\example\Lohit-Gujarati.ttf', 15)

r = shapefile.Reader("K:\NEW_GIS\Arkund\Arkund\ESRI SHAPE FILE\ADJUJICATION\Final\Arkund_Corr")

shapes = r.shapes()

xdist = r.shapes()[48].bbox[2] - r.shapes()[48].bbox[0]

ydist = r.shapes()[48].bbox[3] - r.shapes()[48].bbox1

iwidth = 680

iheight =449

xratio = (iwidth/xdist)

yratio = (iheight/ydist)

pixels = []

for x,y in r.shapes()[48].points:

px = int((iwidth - (((r.shapes()[48].bbox[2]) - x) * xratio))-160)py = int((((r.shapes()[48].bbox[3]) - y) * yratio)+50)pixels.append((px,py))img = Image.new("RGB", (800, 500), "white")

draw = ImageDraw.Draw(img)

new_x=''

new_y=''

for new_i in range(len(pixels)):

if(new_i!=0): new_pixels=[(new_x,new_y),(pixels[new_i][0],pixels[new_i][1])] x_line = [p[0] for p in new_pixels] y_line = [p[1] for p in new_pixels] centroid_new = ((sum(x_line) / len(new_pixels))+5, (sum(y_line) / len(new_pixels))-15) line_length=math.hypot(pixels[new_i][0] - new_x, pixels[new_i][1]-new_y) new_line_length=line_length/3.28084 org_length="{:.2f}".format(new_line_length) draw.text(centroid_new, org_length, font=fnt_new, fill='black') draw.line(new_pixels, fill="black", width=4)new_x=pixels[new_i][0]new_y=pixels[new_i][1]draw.polygon(pixels,outline="black", fill="white")

img_new_name="C:/example/Garpani_corrected_new_32.png" img.save(img_new_name)



أكثر...
 
أعلى