I want to display length according to part 1 Image. but now its making like part 2. I am using below code.
import shapefile from PIL import Image,ImageDraw, ImageFont from qgis.utils import iface from PyQt4.QtCore import QVariant import math import psycopg2 try: conn = psycopg2.connect("dbname='postgres' user='postgres' host='localhost' password='mindcrew01'") except: print "I am unable to connect to the database" cur = conn.cursor() r = shapefile.Reader("K:\NEW_GIS\Arkund\Arkund\ESRI SHAPE FILE\ADJUJICATION\Final\Arkund_Corr") shapes = r.shapes() layer = iface.activeLayer() feature_dict = {f.id(): f for f in layer.getFeatures()} index = QgsSpatialIndex() for f in feature_dict.values(): index.insertFeature(f) Chalata_array=[] neighbors_chalata_array={} neighbors_pixels_array={} points_full_array={} for f in feature_dict.values(): polygon_f_id=[] polygon_f_id.append(f.id()) Chalata_array.append(f['STRING_']) neighbors_chalata_first=[] neighbors_chalata_first.append(f['STRING_']) geom = f.geometry() points_full_array_first=[] intersecting_ids = index.intersects(geom.boundingBox()) for intersecting_id in intersecting_ids: intersecting_f = feature_dict[intersecting_id] if (f != intersecting_f and not intersecting_f.geometry().disjoint(geom)): neighbors_chalata_first.append(intersecting_f['STRING_']) polygon_f_id.append(intersecting_f.id()) iwidth = 680 iheight = 449 xdist =shapes[f.id()].bbox[2] - shapes[f.id()].bbox[0] ydist =shapes[f.id()].bbox[3] - shapes[f.id()].bbox[1] xratio = (iwidth/(xdist+82)) yratio = (iheight/(ydist+15)) neighbors_pixels_first={} for get_id in range(len(polygon_f_id)): neighbors_pixels_secound=[] for x,y in r.shapes()[polygon_f_id[get_id]].points: px = int((iwidth - ((shapes[polygon_f_id[0]].bbox[2] - x) * xratio)-100)) py = int(((shapes[polygon_f_id[0]].bbox[3] - y) * yratio)+30) neighbors_pixels_secound.append((px,py)) points_full_array_first.append((px,py)) neighbors_pixels_first[get_id]=neighbors_pixels_secound points_full_array[f['STRING_']]=points_full_array_first neighbors_chalata_array[f['STRING_']]=neighbors_chalata_first neighbors_pixels_array[f['STRING_']]=neighbors_pixels_first #print points_full_array #print neighbors_chalata_array #print neighbors_pixels_array for chalata_no_i in range(len(Chalata_array)): fnt = ImageFont.truetype('C:\example\GJBWAV0B.ttf', 30) fnt_new = ImageFont.truetype('C:\example\GJBWAV0B.ttf', 15) img = Image.new("RGB", (iwidth, iheight), "white") draw = ImageDraw.Draw(img) image_name=Chalata_array[chalata_no_i] for new_chalata_no in range(len(neighbors_pixels_array[Chalata_array[chalata_no_i]])): if(new_chalata_no==0): get_pixels=neighbors_pixels_array[Chalata_array[chalata_no_i]][new_chalata_no] max_point_x=max(get_pixels) min_point_y=min(get_pixels) n = len(get_pixels) # of corners area = 0.0 for i in range
: j = (i + 1) % n area += get_pixels[0] * get_pixels[j][1] area -= get_pixels[j][0] * get_pixels[1] area = abs(area) / 2.0 #new_area=area/1000 cur.execute("SELECT id FROM maap_chalta_no where district=%s and taluka=%s and village=%s and Chalto_Number=%s",("
أكثر...
import shapefile from PIL import Image,ImageDraw, ImageFont from qgis.utils import iface from PyQt4.QtCore import QVariant import math import psycopg2 try: conn = psycopg2.connect("dbname='postgres' user='postgres' host='localhost' password='mindcrew01'") except: print "I am unable to connect to the database" cur = conn.cursor() r = shapefile.Reader("K:\NEW_GIS\Arkund\Arkund\ESRI SHAPE FILE\ADJUJICATION\Final\Arkund_Corr") shapes = r.shapes() layer = iface.activeLayer() feature_dict = {f.id(): f for f in layer.getFeatures()} index = QgsSpatialIndex() for f in feature_dict.values(): index.insertFeature(f) Chalata_array=[] neighbors_chalata_array={} neighbors_pixels_array={} points_full_array={} for f in feature_dict.values(): polygon_f_id=[] polygon_f_id.append(f.id()) Chalata_array.append(f['STRING_']) neighbors_chalata_first=[] neighbors_chalata_first.append(f['STRING_']) geom = f.geometry() points_full_array_first=[] intersecting_ids = index.intersects(geom.boundingBox()) for intersecting_id in intersecting_ids: intersecting_f = feature_dict[intersecting_id] if (f != intersecting_f and not intersecting_f.geometry().disjoint(geom)): neighbors_chalata_first.append(intersecting_f['STRING_']) polygon_f_id.append(intersecting_f.id()) iwidth = 680 iheight = 449 xdist =shapes[f.id()].bbox[2] - shapes[f.id()].bbox[0] ydist =shapes[f.id()].bbox[3] - shapes[f.id()].bbox[1] xratio = (iwidth/(xdist+82)) yratio = (iheight/(ydist+15)) neighbors_pixels_first={} for get_id in range(len(polygon_f_id)): neighbors_pixels_secound=[] for x,y in r.shapes()[polygon_f_id[get_id]].points: px = int((iwidth - ((shapes[polygon_f_id[0]].bbox[2] - x) * xratio)-100)) py = int(((shapes[polygon_f_id[0]].bbox[3] - y) * yratio)+30) neighbors_pixels_secound.append((px,py)) points_full_array_first.append((px,py)) neighbors_pixels_first[get_id]=neighbors_pixels_secound points_full_array[f['STRING_']]=points_full_array_first neighbors_chalata_array[f['STRING_']]=neighbors_chalata_first neighbors_pixels_array[f['STRING_']]=neighbors_pixels_first #print points_full_array #print neighbors_chalata_array #print neighbors_pixels_array for chalata_no_i in range(len(Chalata_array)): fnt = ImageFont.truetype('C:\example\GJBWAV0B.ttf', 30) fnt_new = ImageFont.truetype('C:\example\GJBWAV0B.ttf', 15) img = Image.new("RGB", (iwidth, iheight), "white") draw = ImageDraw.Draw(img) image_name=Chalata_array[chalata_no_i] for new_chalata_no in range(len(neighbors_pixels_array[Chalata_array[chalata_no_i]])): if(new_chalata_no==0): get_pixels=neighbors_pixels_array[Chalata_array[chalata_no_i]][new_chalata_no] max_point_x=max(get_pixels) min_point_y=min(get_pixels) n = len(get_pixels) # of corners area = 0.0 for i in range
أكثر...