def test_triangulate(points): # Run test triangles = pytess.triangulate(points) # Visualize import sys sys.path.append("/Volumes/karim/Desktop/Python Programming/site_packages") import pydraw img = pydraw.Image(500, 500) for triangle in triangles: if len(triangle) != 3: print "warning: returned non-triangle" triangle_xy = [map(int, point[:2]) for point in triangle] xmid, ymid, zmid = midpoint(triangle) img.drawpolygon(triangle_xy, fillcolor=(0, zmid, zmid), outlinecolor=None) #for point in points: # img.drawsquare(*point[:2], fillsize=2, fillcolor=(0,222,0)) #img.save("test.png") #img.view() return triangles
def uniontesting(VIEWGEOMS=False): #------------------- # UNION TESTING #------------------- print("#-------------------") print("# UNION TESTING") print("#-------------------") #simple union test u1 = Polygon(exterior=[(10,10),(100,10),(100,100),(10,100)], interiors=[[(20,20),(20,90),(90,90),(90,20)]]) polygonslist = [( [(30.0,30.0),(50.0,30.0),(50.0,50.0),(30.0,50.0)], [] ), ( [(60,60),(80,60),(80,80),(60,80)], [] )] u2 = MultiPolygon(polygonslist) result = u1.union(u2) print("union %s"%result) if VIEWGEOMS: result.view() #test multiple cumulative union on entire shapefile print("") print("cumulative union:") # setup image drawer import pydraw crs = pydraw.CoordinateSystem([-180,90,180,-90]) img = pydraw.Image(1000,500, background=(0,0,111), crs=crs) # load and loop shapefile import geovis.shapefile_fork as pyshp cshapesfile = "D:/Test Data/cshapes/cshapes.shp" natearthfile = "D:/Test Data/necountries/necountries.shp" linesfile = "D:/Test Data/lines/ne_50m_rivers_lake_centerlines.shp" pointfile = "D:/Test Data/gtd_georef/gtd_georef.shp" reader = pyshp.Reader(cshapesfile) oldshape = False stopindex = 9 for index,shape in enumerate(reader.iterShapes()): geotype = shape.__geo_interface__["type"] geom = geoj2geom(shape) #add to cumulative union if oldshape: union = oldshape.union(geom) print(" %s"%union) try: img.drawgeojson(union) #img.drawgeojson(geom) oldshape = union except: #img2 = pydraw.Image(1000,500, background=(0,0,111), crs=crs) #img2.drawgeojson(oldshape, fillcolor=(0,222,0)) #img2.drawgeojson(geom, fillcolor=(222,0,0)) #img2.view() pass else: oldshape = geom if index == stopindex: if VIEWGEOMS: img.drawgeojson(union) img.view() union.view(crs=crs) break img.view()
def test_draw(testname, subjpoly, clippoly, mode): t = time.time() resultpolys = clip_polygon(subjpoly, clippoly, mode) print("finished:", resultpolys, time.time() - t) crs = pydraw.CoordinateSystem([-1, -1, 11, 11]) img = pydraw.Image(400, 400, crs=crs) img.drawpolygon(subjpoly, fillcolor=(222, 0, 0)) img.drawpolygon(clippoly, fillcolor=(0, 222, 0)) for ext, holes in resultpolys: img.drawpolygon(ext, holes) img.drawgridticks(1, 1) img.save("test_output/" + testname + "-" + mode + ".png")
def test_draw(testname, subjpoly, clippoly, mode): t = time.time() #print testname, mode resultpolys = clip_polygon(subjpoly, clippoly, mode) print("finished:", len(resultpolys), time.time() - t) print("start", str(resultpolys)[:100]) print("end", str(resultpolys)[-100:]) crs = pydraw.CoordinateSystem([0, 80, 45, 50]) img = pydraw.Image(300, 300, crs=crs) img.drawpolygon(subjpoly, fillcolor=(222, 0, 0, 111)) img.drawpolygon(clippoly, fillcolor=(0, 222, 0, 111)) for ext, holes in resultpolys: img.drawpolygon(ext, holes) img.drawgridticks(10, 10) img.save("test_output/" + testname + "-" + mode + ".png")
def test_voronoi(points): # Run test polygons = pytess.voronoi(points) # Visualize import sys sys.path.append("/Volumes/karim/Desktop/Python Programming/site_packages") import pydraw crs = pydraw.CoordinateSystem([0, 0, 500, 500]) img = pydraw.Image(500, 500) for i, (center, poly) in enumerate(polygons): #print i, poly ## def pairwise(iterable): ## a, b = itertools.tee(iterable) ## next(b, None) ## return itertools.izip(a, b) ## ## for line in pairwise(poly): ## (x1,y1),(x2,y2) = line ## img.drawline( x1,y1,x2,y2, fillcolor=(i/1.3,111,111), ## outlinecolor=None ) ## img.view() img.drawpolygon(poly, fillcolor=(i / 1.3, 111, 111), outlinecolor=(0, 0, 0)) ## ## img.view() if center: img.drawsquare(*center[:2], fillsize=2, fillcolor=(0, 222, 0)) ## for point in points: ## img.drawsquare(*point[:2], fillsize=2, fillcolor=(0,222,0)) img.save("test.png") img.view()
def distancetesting(VIEWGEOMS=False): #------------------- # DISTANCE TESTING #------------------- print("#-------------------") print("# DISTANCE TESTING") print("#-------------------") _point = Point(52,53) _multipoint = MultiPoint([(55,70),(52,60),(63,80)]) maingeoms = [_multipoint] othergeoms = [Point(100,100), MultiPoint([(100,100),(100,10),(10,10),(10,100),(55,55)]), LineString([(72.0,50.0),(45.0,35.0),(10.0,70.0),(100.0,100.0)]), MultiLineString([[(72.0,50.0),(45.0,35.0),(10.0,70.0),(100.0,100.0)], [(90,80),(75,33),(36,60)]]), Polygon([(72.0,50.0),(45.0,35.0),(10.0,70.0),(100.0,100.0)]), Polygon(exterior=[(10,100),(10,100),(100,100),(100,10),(10,10)], interiors=[[(40,40),(40,90),(90,90),(90,40),(40,40)], [(20.2,20.2),(20.2,30.9),(30.9,30.9),(30.9,20.2),(20.2,20.2)]]), MultiPolygon([([(62.0,73.0),(75.0,65.0),(81,90)], []),([(10.0,30.0),(55.0,45.0),(22,31),(24,12),(8,9)],[])]) ] for main in maingeoms: for other in othergeoms: result = main.distance(other, getclosestpoints=True) print("%s -> %s = %s"%(main.geom_type,other.geom_type,result)) if VIEWGEOMS: import pydraw crs = pydraw.CoordinateSystem([0,0,120,120]) img = pydraw.Image(400,400,crs=crs) img.drawgeojson(other) img.drawgeojson(main, fillcolor=(222,0,0)) if result.get("closestpoint_self"): closestpoint_self = Point(*result["closestpoint_self"]) img.drawcircle(*closestpoint_self.coords[0], fillsize=3, fillcolor=None, outlinecolor=(0,0,222)) if result.get("closestpoint_other"): closestpoint_other = Point(*result["closestpoint_other"]) img.drawcircle(*closestpoint_other.coords[0], fillsize=3, fillcolor=None, outlinecolor=(0,222,0)) img.view() print("")
poly.append((float(x), float(y))) return poly except ValueError: return None if __name__ == "__main__": import random subjpoly = [(0,0),(6,0),(6,6),(0,6),(0,0)] #clippoly = [(4,4),(10,4),(10,10),(4,10),(4,4)] #simple overlap clippoly = [(1,4),(3,8),(5,4),(5,10),(1,10),(1,4)] #jigzaw overlap #clippoly = [(7,7),(7,9),(9,9),(9,7),(7,7)] #smaller, outside #clippoly = [(2,2),(2,4),(4,4),(4,2),(2,2)] #smaller, inside #clippoly = [(-1,-1),(-1,7),(7,7),(7,-1),(-1,-1)] #larger, covering all #clippoly = [(-10,-10),(-10,-70),(-70,-70),(-70,-10),(-10,-10)] #larger, outside #clippoly = [(random.randrange(0,10),random.randrange(0,10)) for _ in range(10)] #random resultpolys = clip_polygon(subjpoly,clippoly,"union") print("finished:",resultpolys) import pydraw crs = pydraw.CoordinateSystem([-1,-1,11,11]) img = pydraw.Image(400,400, crs=crs) img.drawpolygon(subjpoly, fillcolor=(222,0,0)) img.drawpolygon(clippoly, fillcolor=(0,222,0)) for ext,holes in resultpolys: img.drawpolygon(ext,holes) img.drawgridticks(1,1) img.view()
def offset(polys, amount, tip_decorator=tip_decorator_pointy, debug_callback=None): """Shrink or grow a polygon by a given amount. Reference: Xiaorui Chen and Sara McMains. Polygon Offsetting by Computing Winding Numbers Proceedings of IDETC/CIE 2005. ASME 2005 International Design Engineering Technical Conferences & Computers and Information in Engineering Conference @type polys: List @param polys: The list of polygons to offset. Counter-clockwise polygons will be treated as islands, clockwise polygons as holes. @type amount: float @param amount: The amount to offset. Positive values will grow the polygon, negative values will shrink. @type tip_decorator: function @param tip_decorator: A function used for decorating tips generated in the offset polygon """ # fix passing a single polygon instead of a poly list if isinstance(polys, Polygon): polys = [polys] if amount == 0: return polys ## # ensure that the polygon is counterclockwise ## # not needed anymore... ## newpolys = [] ## for poly in polys: ## if poly.is_clockwise(): poly = poly.clone().flip() ## newpolys.append(poly) ## polys = newpolys def offset_poly(poly): r = [] for i in range(len(poly.points)): #changed from modulous to skip next, but fails to process start/end point c, n, n2 = poly.points[i], poly.points[ (i + 1) % len(poly)], poly.points[(i + 2) % len(poly)] is_convex = point_orientation(c, n, n2) #changed from (c,n,n2) unit_normal = (n - c).normal().normalize() unit_normal2 = (n2 - n).normal().normalize() c_prime = c + unit_normal * amount n_prime = n + unit_normal * amount n2_prime = n2 + unit_normal2 * amount n_prime2 = n + unit_normal2 * amount r.append(c_prime) r.append(n_prime) if is_convex == (amount > 0): r.append(n) else: r.extend( tip_decorator(c_prime, n_prime, n_prime2, n2_prime, True)) ## if amount > 0: ## if is_convex: ## r.extend(tip_decorator(c_prime, n_prime, n_prime2, n2_prime, False)) ## else: ## r.append(n) ## else: ## if is_convex: ## r.append(n) ## else: ## r.extend(tip_decorator(c_prime, n_prime, n_prime2, n2_prime, True)) return r def decompose(poly_points): """Decompose a possibly self-intersecting polygon into multiple simple polygons.""" def inorder_extend(v, v1, v2, ints): """Extend a sequence v by points ints that are on the segment v1, v2""" k, r = None, False if v1.x < v2.x: k = lambda i: i.x r = True elif v1.x > v2.x: k = lambda i: i.x r = False elif v1.y < v2.y: k = lambda i: i.y r = True else: k = lambda i: i.y r = False l = sorted(ints, key=k, reverse=r) i = next((i for i, p in enumerate(v) if p == v2), -1) assert (i >= 0) for e in l: v.insert(i, e) pts = [p for p in poly_points] # find self-intersections ints = defaultdict(list) for i in range(len(pts)): for j in range(i + 1, len(pts)): a = pts[i] b = pts[(i + 1) % len(pts)] c = pts[j] d = pts[(j + 1) % len(pts)] x = intersect_lineseg_lineseg(a, b, c, d) if x and x not in (a, b, c, d): ints[(a, b)].append(x) ints[(c, d)].append(x) # add self-intersection points to poly for k, v in ints.iteritems(): inorder_extend(pts, k[0], k[1], v) # build a list of loops out = [] while pts: # build up a list of seen points until we re-visit one - a loop! seen = [] for p in pts + [pts[0]]: if p not in seen: seen.append(p) else: break loop = seen[seen.index(p):] # remove the loop from pts for p in loop: pts.remove(p) out.append(loop) return out def winding_number(p, raw): # compute winding number of point #http://softsurfer.com/Archive/algorithm_0103/algorithm_0103.htm wn = 0 for pp in raw: for a, b in list(zip(pp, pp[1:])) + [(pp[-1], pp[0])]: if a.y < p.y and b.y > p.y: i = intersect_lineseg_ray(a, b, p, p + VECTOR_X) if i and i.x > p.x: wn -= 1 if a.y > p.y and b.y < p.y: i = intersect_lineseg_ray(a, b, p, p + VECTOR_X) if i and i.x > p.x: wn += 1 return wn def find_point_in_poly(pts): # find point inside of pts according to http://www.exaflop.org/docs/cgafaq/cga2.html#Subject%202.06:%20How%20do%20I%20find%20a%20single%20point%20inside%20a%20simple%20polygonu # alternative approaches at http://stackoverflow.com/questions/9797448/get-a-point-inside-the-polygon, http://www.dummies.com/how-to/content/how-to-pinpoint-the-center-of-a-triangle.html def threeways(iterable): import itertools args = [iter(iterable)] * 3 return itertools.izip_longest(fillvalue=None, *args) for a, b, c in threeways(pts): avgx = sum([each.x for each in (a, b, c)]) / 3.0 avgy = sum([each.y for each in (a, b, c)]) / 3.0 triangle_center = Vector(avgx, avgy) if Polygon.contains_point_s([a, b, c], triangle_center): print "triangle", (a, b, c), triangle_center return triangle_center ## if len(pts) == 3: return (pts[0] + pts[1] + pts[2]) / 3 ## ## ## # find convex point v ## v = None ## for i in range(len(pts)): ## a, v, b = pts[i-1], pts[i], pts[(i+1) % len(pts)] ## if not point_orientation(a,v,b): break ## ## ## q_s = [ q for q in pts if q not in [a,v,b] and point_in_triangle(q, a,v,b) ] ## ## if len(pts) >= 5: ## dbg(v, 0x000000, "V") ## dbg(a, 0x000000, "A") ## dbg(b, 0x000000, "B") ## ## for q in q_s: ## dbg(q, 0x000000, "Q") ## ## if q_s: ## # return the midpoint of the shortest diagonal qv ## q = min(q_s, key=lambda q: (q-v).length_squared ) ## ## ## return (q - v) / 2.0 + v ## else: ## # no diagonal from v, return midpoint of ab instead ## return (b - a) / 2.0 + a def dbg(p, color, text): if debug_callback: debug_callback(p, color, text) # ensure that the input polygons are not self-intersecting newpolys = [] for poly in polys: newpolys.extend( [Polygon.from_pointlist(part) for part in decompose(poly)]) polys = newpolys #decompose(newpolys) # construct the raw offset data raw = [] for poly in polys: offset = offset_poly(poly) decomp = decompose(offset) # somehow detect only the square and arced loops # and turn them clockwise if negative inner offset raw.extend(decomp) #print "\n-----------------\n" output = [] raw = (Polygon.simplify_sequence(each) for each in raw) raw = [each for each in raw if len(each) >= 3] #modified #import pydraw import random import sys sys.path.append("C:\\Users\\BIGKIMO\\Github\\PyDraw") import pydraw crs = pydraw.CoordinateSystem([ -58.071399886445136, 1.8362450855291712, -53.986117882640414, 6.0018090894086527 ]) img = pydraw.Image(500, 500, crs=crs) for poly in raw: #poly = Polygon.simplify_sequence(poly) #if len(poly) < 3: continue #if poly[0] != poly[-1]: poly.append(poly[0]) p = find_point_in_poly(poly) print winding_number(p, [poly]) wn = winding_number( p, raw ) #NOTE! Doing wn on [poly] instead helps in many cases but not all print wn, len(poly), str(poly)[:100] #dbg(p, 0xffff00, "%d %d" % (wn, len(poly))) #print "%d %d" % (wn, len(poly)) # shrink: include poly in solution only if winding number of that region is greater than 1 # grow: include only if winding number is 1 if wn > 0: #modified, orig wn == 1 on right side output.append(Polygon.from_pointlist(poly)) img.drawpolygon([(ver.x, ver.y) for ver in poly], fillcolor=(0, random.randrange(0, 255), 0), outlinecolor=(0, 0, 0)) else: img.drawpolygon([(ver.x, ver.y) for ver in poly], fillcolor=(random.randrange(0, 255), 0, 0), outlinecolor=(0, 0, 0)) # run union to combine all final offset poly parts # ... img.drawcircle(-55.091, 5.805, fillsize=20, outlinecolor=(0, 0, 222), fillcolor=None) img.view() return output
test_random = [random_n(0,500,2)+random_n(0,222,1) for _ in range(10)] test_dude = [[174.50415,494.59368],[215.21844,478.87939],[207.36129,458.87939],[203.07558,441.02225],[203.07558,418.1651], [210.93272,394.59367],[224.50415,373.1651],[241.64701,358.1651],[257.36129,354.59367],[275.93272,356.73653], [293.07558,359.59367],[309.50415,377.45082],[322.36129,398.1651],[331.64701,421.73653],[335.21844,437.45082], [356.64701,428.52225],[356.1113,428.34367],[356.1113,428.34367],[368.78987,419.59368],[349.50415,384.59367], [323.78987,359.59367],[290.93272,343.87939],[267.36129,341.02225],[264.50415,331.02225],[264.50415,321.02225], [268.78987,306.02225],[285.93272,286.02225],[295.21844,270.30796],[303.78987,254.59367],[306.64701,213.87939], [320,202.36218],[265,202.36218],[286.64701,217.45082],[293.78987,241.02225],[285,257.36218],[270.93272,271.73653], [254.50415,266.02225],[250.93272,248.1651],[256.64701,233.1651],[256.64701,221.02225],[245.93272,215.30796], [238.78987,216.73653],[233.78987,232.45082],[232.36129,249.59367],[243.07558,257.09367],[242.89701,270.30796], [235.93272,279.95082],[222.36129,293.1651],[205.21844,300.6651],[185,297.36218],[170,242.36218],[175,327.36218], [185,322.36218],[195,317.36218],[230.75415,301.02225],[235.39701,312.45082],[240.57558,323.52225], [243.61129,330.48653],[245.21844,335.12939],[245.03987,344.4151],[229.86129,349.4151],[209.14701,362.09367], [192.89701,377.80796],[177.18272,402.27225],[172.36129,413.87939],[169.14701,430.48653],[168.61129,458.52225], [168.61129,492.80796]] triangles = triangulate_onlyneighbours([p+[192.0] for p in test1]) import sys sys.path.append("/Volumes/karim/Desktop/Python Programming/site_packages") import pydraw img = pydraw.Image(500,500) for triangle in triangles: triangle2d = [corner[:2] for corner in triangle] img.drawpolygon(triangle2d, fillcolor=(222,0,0), outlinecolor=(0,222,0) ) img.view()
#Tester for the PyDraw module if __name__ == "__main__": import pydraw crs = pydraw.CoordinateSystem([0,0,100,100]) img = pydraw.Image(880,440, background=(222,0,0), crs=crs) #img = Image(filepath="C:/Users/BIGKIMO/Desktop/hmm.png") #print crs.getinfo() #SINGLE PIXEL TEST img.put(94.7,94.7,(0,0,222)) #img.put(95.7,98,(0,0,222)) #img.put(98,95.7,(0,0,222)) #GREEN POLYGONS WITH OUTLINE #img.drawpolygon(coords=[(30,30),(90,10),(90,90),(10,90),(30,30)], fillcolor=(0,222,0), outlinecolor=(0,0,0), outlinewidth=12, outlinejoinstyle="round") #img.drawpolygon(coords=[(80,20),(50,15),(20,44),(90,50),(50,90),(10,50),(30,20),(50,10)], fillcolor=(0,222,0), outlinecolor=(0,0,0), outlinewidth=5, outlinejoinstyle="round") #POLYGON WITH HOLES img.drawpolygon(coords=[(30,30),(90,10),(90,90),(10,90),(30,30)], holes=[[(51,41),(77,51),(77,65),(51,77),(51,41)] , [(43,63),(49,63),(49,69),(43,69),(43,63)]], fillcolor=(222,222,0), outlinecolor=(0,0,0), outlinewidth=12, outlinejoinstyle="round") #MISC MULTILINE TEST #img.drawmultiline(coords=[(90,20),(80,20),(50,15),(20,44),(90,50),(50,90),(10,50),(30,20),(50,10)], fillcolor=(0,0,0), fillsize=8, outlinecolor=None, joinstyle="miter") #img.drawmultiline(coords=[(10,50),(50,50),(50,90)], fillcolor=(0,0,0), fillsize=8, outlinecolor=None, joinstyle="round") #img.drawmultiline(coords=[(10,50),(50,50),(60,90)], fillcolor=(0,111,0), fillsize=12, outlinecolor=None, joinstyle="round") #SINGLE LINE TEST #img.drawline(22,11,88,77,fillcolor=(222,0,0),fillsize=8, capstyle="round") #img.drawline(22,66,88,77,fillcolor=(222,0,0,166),fillsize=11, capstyle="round")
import py2d, py2d.Math import random import geovis import geovis.shapefile_fork as pyshp shape = pyshp.Reader("D:/Test Data/cshapes/cshapes.shp").shape(1) p = py2d.Math.Polygon.from_pointlist( py2d.Math.Polygon.simplify_sequence( py2d.Math.Polygon.from_tuples(shape.points))) p_buf = p.offset( p, -0.15 ) #before mod, works up until 0.3 but going further gives empty result ##coords = list(reversed([(10,10),(90,10),(80,90),(50,60),(20,77)])) ##p = py2d.Math.Polygon.from_tuples(coords) ##p_buf = py2d.Math.Polygon.offset(p, 15.12) #before mod, works up until 0.3 but going further gives empty result ### import pydraw crs = pydraw.CoordinateSystem(shape.bbox) #[0,100,100,0]) img = pydraw.Image(500, 500, crs=crs) for eachbuf in p_buf: img.drawpolygon(eachbuf.as_tuple_list(), fillcolor=(222, 0, 0), outlinecolor=(0, 0, 0)) img.drawpolygon(p.as_tuple_list(), fillcolor=None, outlinecolor=(0, 222, 0)) img.view() #save("C:/Users/BIGKIMO/Desktop/buftest.png")
def func4(): # # draw grid # GR = 50 # file = open("grid.txt","w") # for i in xrange(GR+1): # lat1, lat2 = 30.16, 30.34 # lng1 = 120.04+i*((120.24-120.04)/GR) # lng2 = 120.04+i*((120.24-120.04)/GR) # file.write("map.addOverlay(new BMap.Polyline([new BMap.Point("+str(lng1)+","+str(lat1)+"),new BMap.Point("+str(lng2)+","+str(lat2)+")], {strokeColor:\"red\", strokeWeight:1, strokeOpacity:0.25}));\n") # for i in xrange(GR+1): # lng1, lng2 = 120.04, 120.24 # lat1 = 30.16+i*((30.34-30.16)/GR) # lat2 = 30.16+i*((30.34-30.16)/GR) # file.write("map.addOverlay(new BMap.Polyline([new BMap.Point("+str(lng1)+", "+str(lat1)+"),new BMap.Point("+str(lng2)+", "+str(lat2)+")], {strokeColor:\"red\", strokeWeight:1, strokeOpacity:0.25}));\n") # file.close() # # merge spark result # import fileinput # seen, num, sommap, assign = set(), 0, {}, {} # for line in fileinput.input("som/output_si.txt"): # part = line.strip().replace("[","").replace("]","").split(",") # if str(part[:2]) not in seen: # seen.add(str(part[:2])) # num, px, py = num+1, float(part[0]), float(part[1]) # sommap[num] = {"center":[px,py],"wd_e":[0 for i in xrange(24)],"wd_d":[0 for i in xrange(24)],"we_e":[0 for i in xrange(24)],"we_d":[0 for i in xrange(24)]} # fileinput.close() # c = 0 # for line in fileinput.input("data/movement/move_statistic.txt"): # c += 1 # print c # part = line.strip().split("\t")[1:] # for p in part: # try: # a, w, i, s = p.split(" ")[0], int(p.split(" ")[1]), int(p.split(" ")[2]), int(p.split(" ")[3]) # if not assign.has_key(tuple([int(a.split(",")[0]),int(a.split(",")[1])])): # sommin, distmin = 0, 0 # for k,v in sommap.iteritems(): # dist = euclidean(v["center"],[int(a.split(",")[0]),int(a.split(",")[1])]) # if sommin == 0 or dist < distmin: # sommin, distmin = k, dist # assign[tuple([int(a.split(",")[0]),int(a.split(",")[1])])] = sommin # if w == 1 and s == 1: # sommap[assign[tuple([int(a.split(",")[0]),int(a.split(",")[1])])]]["wd_e"][i] += 1 # if w == 1 and s == 0: # sommap[assign[tuple([int(a.split(",")[0]),int(a.split(",")[1])])]]["wd_d"][i] += 1 # if w == 0 and s == 1: # sommap[assign[tuple([int(a.split(",")[0]),int(a.split(",")[1])])]]["we_e"][i] += 1 # if w == 0 and s == 0: # sommap[assign[tuple([int(a.split(",")[0]),int(a.split(",")[1])])]]["we_d"][i] += 1 # except: # continue # fileinput.close() # file = open("data/movement/move_statistic_merge.txt","w") # for k,v in sommap.iteritems(): # file.write(str(k)+" "+" ".join([str(i) for i in v["wd_e"]])+" "+" ".join([str(i) for i in v["wd_d"]])+" "+" ".join([str(i) for i in v["we_e"]])+" "+" ".join([str(i) for i in v["we_d"]])+"\n") # file.close() # # generate document # file = open("GibbsLDA++/out.txt","w") # file.write("368\n") # c = 0 # for line in fileinput.input("data/movement/move_statistic_merge.txt"): # part = line.split(" ") # grid, feature = part[0], [int(i) for i in part[1:]] # feature = [int(feature[i]/5.0) if 0<=i<24*2 else int(feature[i]/2.0) for i in xrange(len(feature))] # for i in xrange(24): # for j in xrange(feature[i]+1): # file.write(str(i)+",1,E ") # for i in xrange(24): # for j in xrange(feature[24+i]+1): # file.write(str(i)+",1,D ") # for i in xrange(24): # for j in xrange(feature[48+i]+1): # file.write(str(i)+",0,E ") # for i in xrange(24): # for j in xrange(feature[72+i]+1): # file.write(str(i)+",0,D ") # file.write("\n") # fileinput.close() # file.close() # ./src/lda -est -alpha 0.5 -beta 0.5 -ntopics 8 -niters 1000 -savestep 2000 -twords 10 -dfile out.txt # movement func 1 seen, somlist = set(), [] for line in fileinput.input("som/output_si.txt"): part = line.strip().replace("[","").replace("]","").split(",") if str(part[:2]) not in seen: seen.add(str(part[:2])) somlist.append([float(part[0])*5, 1000-float(part[1])*5, 0]) fileinput.close() cnt = 0 # for line in fileinput.input("GibbsLDA++/model-final.theta"): for line in fileinput.input("LDA/model-final.theta"): prob = [float(i) for i in line.strip().split(" ")] somlist[cnt][2] = prob.index(max(prob)) cnt += 1 import pytesselate import itertools polygons = pytesselate.voronoi(somlist) print len(polygons) import pydraw crs = pydraw.CoordinateSystem([0,0,1000,1000]) img = pydraw.Image(1000,1000) for i,(center,poly) in enumerate(polygons): if center: if somlist[i][2] == 0: img.drawpolygon(poly,fillcolor=(0,0,0),outlinecolor=(0,0,0)) if somlist[i][2] == 1: img.drawpolygon(poly,fillcolor=(255,0,0),outlinecolor=(0,0,0)) if somlist[i][2] == 2: img.drawpolygon(poly,fillcolor=(0,255,0),outlinecolor=(0,0,0)) if somlist[i][2] == 3: img.drawpolygon(poly,fillcolor=(0,0,255),outlinecolor=(0,0,0)) if somlist[i][2] == 4: img.drawpolygon(poly,fillcolor=(0,255,255),outlinecolor=(0,0,0)) if somlist[i][2] == 5: img.drawpolygon(poly,fillcolor=(255,0,255),outlinecolor=(0,0,0)) if somlist[i][2] == 6: img.drawpolygon(poly,fillcolor=(255,255,0),outlinecolor=(0,0,0)) if somlist[i][2] == 7: img.drawpolygon(poly,fillcolor=(255,255,255),outlinecolor=(0,0,0)) # img.drawsquare(*center[:2], fillsize=2, fillcolor=(255,0,0)) img.save("test.png") img.view() y0list, y1list, y2list, y3list = [], [], [], [] # for line in fileinput.input("GibbsLDA++/model-final.phi"): for line in fileinput.input("LDA/model-final.phi"): prob = [float(i) for i in line.strip().split(" ")] y0, y1, y2, y3 = prob[0:24], prob[24:48], prob[48:72], prob[72:96] y0list.append(y0) y1list.append(y1) y2list.append(y2) y3list.append(y3) fig = plt.figure() ax1 = fig.add_subplot(241) ax1.plot([i for i in xrange(24)], y0list[0], c="red") ax1.plot([i for i in xrange(24)], y1list[0], c="yellow") ax1.plot([i for i in xrange(24)], y2list[0], c="green") ax1.plot([i for i in xrange(24)], y3list[0], c="blue") ax1.set_xlim(0,23) ax1.set_ylim(0,0.15) ax2 = fig.add_subplot(242) ax2.plot([i for i in xrange(24)], y0list[1], c="red") ax2.plot([i for i in xrange(24)], y1list[1], c="yellow") ax2.plot([i for i in xrange(24)], y2list[1], c="green") ax2.plot([i for i in xrange(24)], y3list[1], c="blue") ax2.set_xlim(0,23) ax2.set_ylim(0,0.15) ax3 = fig.add_subplot(243) ax3.plot([i for i in xrange(24)], y0list[2], c="red") ax3.plot([i for i in xrange(24)], y1list[2], c="yellow") ax3.plot([i for i in xrange(24)], y2list[2], c="green") ax3.plot([i for i in xrange(24)], y3list[2], c="blue") ax3.set_xlim(0,23) ax3.set_ylim(0,0.15) ax4 = fig.add_subplot(244) ax4.plot([i for i in xrange(24)], y0list[3], c="red") ax4.plot([i for i in xrange(24)], y1list[3], c="yellow") ax4.plot([i for i in xrange(24)], y2list[3], c="green") ax4.plot([i for i in xrange(24)], y3list[3], c="blue") ax4.set_xlim(0,23) ax4.set_ylim(0,0.15) ax5 = fig.add_subplot(245) ax5.plot([i for i in xrange(24)], y0list[4], c="red") ax5.plot([i for i in xrange(24)], y1list[4], c="yellow") ax5.plot([i for i in xrange(24)], y2list[4], c="green") ax5.plot([i for i in xrange(24)], y3list[4], c="blue") ax5.set_xlim(0,23) ax5.set_ylim(0,0.15) ax6 = fig.add_subplot(246) ax6.plot([i for i in xrange(24)], y0list[5], c="red") ax6.plot([i for i in xrange(24)], y1list[5], c="yellow") ax6.plot([i for i in xrange(24)], y2list[5], c="green") ax6.plot([i for i in xrange(24)], y3list[5], c="blue") ax6.set_xlim(0,23) ax6.set_ylim(0,0.15) ax7 = fig.add_subplot(247) ax7.plot([i for i in xrange(24)], y0list[6], c="red") ax7.plot([i for i in xrange(24)], y1list[6], c="yellow") ax7.plot([i for i in xrange(24)], y2list[6], c="green") ax7.plot([i for i in xrange(24)], y3list[6], c="blue") ax7.set_xlim(0,23) ax7.set_ylim(0,0.15) ax8 = fig.add_subplot(248) ax8.plot([i for i in xrange(24)], y0list[7], c="red") ax8.plot([i for i in xrange(24)], y1list[7], c="yellow") ax8.plot([i for i in xrange(24)], y2list[7], c="green") ax8.plot([i for i in xrange(24)], y3list[7], c="blue") ax8.set_xlim(0,23) ax8.set_ylim(0,0.15) plt.show() # # movement func 2 # seen, somlist = set(), [] # for line in fileinput.input("som/output_si.txt"): # part = line.strip().replace("[","").replace("]","").split(",") # if str(part[:2]) not in seen: # seen.add(str(part[:2])) # somlist.append([float(part[0])*5, 1000-float(part[1])*5, [0]*8]) # fileinput.close() # print len(somlist) # cnt = 0 # for line in fileinput.input("GibbsLDA++/model-final.theta"): # somlist[cnt][2] = [float(i) for i in line.strip().split(" ")] # cnt += 1 # import pytesselate # import itertools # polygons = pytesselate.voronoi(somlist) # import pydraw # crs = pydraw.CoordinateSystem([0,0,1000,1000]) # img = pydraw.Image(1000,1000) # c = 7 # for i,(center,poly) in enumerate(polygons): # if center: # img.drawpolygon(poly,fillcolor=(255*somlist[i][2][c],255*somlist[i][2][c],255*somlist[i][2][c]),outlinecolor=(0,0,0)) # img.save("figure/class_"+str(c)+".png") # # img.view() # # poi func1 # tagmap = {} # for line in fileinput.input("data/poi/poi.txt"): # part = line.strip().split("\t") # tag, lng, lat = part[0], float(part[1]), float(part[2]) # if 120.04<=lng<=120.24 and 30.16<=lat<=30.34: # tagmap[tag] = 1 if not tagmap.has_key(tag) else tagmap[tag]+1 # fileinput.close() # taglist = [] # for k,v in tagmap.iteritems(): # taglist.append({"k":k,"v":v}) # taglist = sorted(taglist, key=lambda x:x["v"]) # tag, count = [], [] # for item in taglist: # if item["k"] in ["公司","购物","美食","房产","休闲","政府","丽人","金融","医疗","宾馆","汽车","教育","培训","旅游","运动"]: # item["k"] = "company" if item["k"] == "公司"\ # else "shopping" if item["k"] == "购物"\ # else "food" if item["k"] == "美食"\ # else "housing" if item["k"] == "房产"\ # else "leisure" if item["k"] == "休闲"\ # else "government" if item["k"] == "政府"\ # else "beauty" if item["k"] == "丽人"\ # else "finance" if item["k"] == "金融"\ # else "medical" if item["k"] == "医疗"\ # else "hotel" if item["k"] == "宾馆"\ # else "car" if item["k"] == "汽车"\ # else "education" if item["k"] == "教育"\ # else "training" if item["k"] == "培训"\ # else "traveling" if item["k"] == "旅游"\ # else "physical" if item["k"] == "运动"\ # else "" # tag.append(unicode(item["k"],"utf-8")) # count.append(item["v"]) # for i in xrange(len(count)): # print round(float(count[i])/sum(count),4) # import matplotlib.pyplot as plt # import numpy as np # y_pos = np.arange(len(tag)) # plt.barh(y_pos, count, align='center', alpha=0.4) # plt.yticks(y_pos, tag) # plt.xlabel('count') # plt.title('POI statistics') # plt.show() # # poi func2 # seen, num, sommap, assign = set(), 0, {}, {} # for line in fileinput.input("som/output_si.txt"): # part = line.strip().replace("[","").replace("]","").split(",") # if str(part[:2]) not in seen: # seen.add(str(part[:2])) # px, py = float(part[0]), float(part[1]) # sommap[num] = {"center":[px,py],"poi":[0]*15} # num += 1 # fileinput.close() # for line in fileinput.input("data/poi/poi.txt"): # part = line.strip().split("\t") # tag, lng, lat = part[0], float(part[1]), float(part[2]) # if tag in ["公司","购物","美食","房产","休闲","政府","丽人","金融","医疗","宾馆","汽车","教育","培训","旅游","运动"] and 120.04<=lng<120.24 and 30.16<=lat<30.34: # lng, lat = int((lng-120.04)/(120.24-120.04)*200), int((lat-30.16)/(30.34-30.16)*200) # tag = 0 if tag == "公司"\ # else 1 if tag == "购物"\ # else 2 if tag == "美食"\ # else 3 if tag == "房产"\ # else 4 if tag == "休闲"\ # else 5 if tag == "政府"\ # else 6 if tag == "丽人"\ # else 7 if tag == "金融"\ # else 8 if tag == "医疗"\ # else 9 if tag == "宾馆"\ # else 10 if tag == "汽车"\ # else 11 if tag == "教育"\ # else 12 if tag == "培训"\ # else 13 if tag == "旅游"\ # else 14 if tag == "运动"\ # else -1 # if not assign.has_key(tuple([lng, lat])): # sommin, distmin = 0, 0 # for k,v in sommap.iteritems(): # dist = euclidean(v["center"],[lng, lat]) # if sommin == 0 or dist < distmin: # sommin, distmin = k, dist # assign[tuple([lng, lat])] = sommin # sommap[assign[tuple([lng, lat])]]["poi"][tag] += 1 # fileinput.close() # classlist = [[0]*15 for i in xrange(8)] # num = 0 # for line in fileinput.input("GibbsLDA++/model-final.theta"): # prob = [float(i) for i in line.strip().split(" ")] # for c in xrange(8): # classlist[c] = [i+j for i,j in zip(classlist[c], [k*prob[c] for k in sommap[num]["poi"]])] # num += 1 # fileinput.close() # print classlist # classlist = [[float(classlist[i][j])/sum(classlist[i]) for j in xrange(15)] for i in xrange(8)] # avg = [0.2304,0.2043,0.1472,0.1332,0.0504,0.0393,0.0391,0.0321,0.0263,0.0242,0.0223,0.0185,0.0128,0.0100,0.0099] # classlist = [[classlist[i][j]-avg[j] for j in xrange(15)] for i in xrange(8)] # import matplotlib.pyplot as plt # import numpy as np # fig = plt.figure() # ax1 = fig.add_subplot(241) # tag = [str(i) for i in xrange(15)] # y_pos = np.arange(len(tag)) # plt.bar(y_pos, classlist[0], align='center', alpha=0.4) # plt.xticks(y_pos, tag) # ax1.set_ylim(-0.1,0.1) # ax2 = fig.add_subplot(242) # tag = [str(i) for i in xrange(15)] # y_pos = np.arange(len(tag)) # plt.bar(y_pos, classlist[1], align='center', alpha=0.4) # plt.xticks(y_pos, tag) # ax2.set_ylim(-0.1,0.1) # ax3 = fig.add_subplot(243) # tag = [str(i) for i in xrange(15)] # y_pos = np.arange(len(tag)) # plt.bar(y_pos, classlist[2], align='center', alpha=0.4) # plt.xticks(y_pos, tag) # ax3.set_ylim(-0.1,0.1) # ax4 = fig.add_subplot(244) # tag = [str(i) for i in xrange(15)] # y_pos = np.arange(len(tag)) # plt.bar(y_pos, classlist[3], align='center', alpha=0.4) # plt.xticks(y_pos, tag) # ax4.set_ylim(-0.1,0.1) # ax5 = fig.add_subplot(245) # tag = [str(i) for i in xrange(15)] # y_pos = np.arange(len(tag)) # plt.bar(y_pos, classlist[4], align='center', alpha=0.4) # plt.xticks(y_pos, tag) # ax5.set_ylim(-0.1,0.1) # ax6 = fig.add_subplot(246) # tag = [str(i) for i in xrange(15)] # y_pos = np.arange(len(tag)) # plt.bar(y_pos, classlist[5], align='center', alpha=0.4) # plt.xticks(y_pos, tag) # ax6.set_ylim(-0.1,0.1) # ax7 = fig.add_subplot(247) # tag = [str(i) for i in xrange(15)] # y_pos = np.arange(len(tag)) # plt.bar(y_pos, classlist[6], align='center', alpha=0.4) # plt.xticks(y_pos, tag) # ax7.set_ylim(-0.1,0.1) # ax8 = fig.add_subplot(248) # tag = [str(i) for i in xrange(15)] # y_pos = np.arange(len(tag)) # plt.bar(y_pos, classlist[7], align='center', alpha=0.4) # plt.xticks(y_pos, tag) # ax8.set_ylim(-0.1,0.1) # plt.show() # # generate document poi # seen, num, sommap, assign = set(), 0, {}, {} # for line in fileinput.input("som/output_si.txt"): # part = line.strip().replace("[","").replace("]","").split(",") # if str(part[:2]) not in seen: # seen.add(str(part[:2])) # px, py = float(part[0]), float(part[1]) # sommap[num] = {"center":[px,py],"poi":[0]*15} # num += 1 # fileinput.close() # count = 0 # for line in fileinput.input("data/poi/poi.txt"): # count += 1 # print count # part = line.strip().split("\t") # tag, lng, lat = part[0], float(part[1]), float(part[2]) # if tag in ["公司","购物","美食","房产","休闲","政府","丽人","金融","医疗","宾馆","汽车","教育","培训","旅游","运动"] and 120.04<=lng<120.24 and 30.16<=lat<30.34: # lng, lat = int((lng-120.04)/(120.24-120.04)*200), int((lat-30.16)/(30.34-30.16)*200) # tag = 0 if tag == "公司"\ # else 1 if tag == "购物"\ # else 2 if tag == "美食"\ # else 3 if tag == "房产"\ # else 4 if tag == "休闲"\ # else 5 if tag == "政府"\ # else 6 if tag == "丽人"\ # else 7 if tag == "金融"\ # else 8 if tag == "医疗"\ # else 9 if tag == "宾馆"\ # else 10 if tag == "汽车"\ # else 11 if tag == "教育"\ # else 12 if tag == "培训"\ # else 13 if tag == "旅游"\ # else 14 if tag == "运动"\ # else -1 # if not assign.has_key(tuple([lng, lat])): # sommin, distmin = 0, 0 # for k,v in sommap.iteritems(): # dist = euclidean(v["center"],[lng, lat]) # if sommin == 0 or dist < distmin: # sommin, distmin = k, dist # assign[tuple([lng, lat])] = sommin # sommap[assign[tuple([lng, lat])]]["poi"][tag] += 1 # fileinput.close() # file = open("GibbsLDA++/out_poi.txt","w") # file.write("368\n") # for k,v in sommap.iteritems(): # file.write("-1 "+" ".join([" ".join([str(x) for y in xrange(v["poi"][x])]) for x in xrange(15)])+"\n") # file.close() # ./src/lda -est -alpha 0.5 -beta 0.5 -ntopics 8 -niters 1000 -savestep 2000 -twords 10 -dfile out_poi.txt # # movement func 1 # seen, somlist = set(), [] # for line in fileinput.input("som/output_si.txt"): # part = line.strip().replace("[","").replace("]","").split(",") # if str(part[:2]) not in seen: # seen.add(str(part[:2])) # somlist.append([float(part[0])*5, 1000-float(part[1])*5, 0]) # fileinput.close() # cnt = 0 # for line in fileinput.input("GibbsLDA++/model-final.theta"): # prob = [float(i) for i in line.strip().split(" ")] # somlist[cnt][2] = prob.index(max(prob)) # cnt += 1 # import pytesselate # import itertools # polygons = pytesselate.voronoi(somlist) # print len(polygons) # import pydraw # crs = pydraw.CoordinateSystem([0,0,1000,1000]) # img = pydraw.Image(1000,1000) # for i,(center,poly) in enumerate(polygons): # if center: # if somlist[i][2] == 0: # img.drawpolygon(poly,fillcolor=(0,0,0),outlinecolor=(0,0,0)) # if somlist[i][2] == 1: # img.drawpolygon(poly,fillcolor=(255,0,0),outlinecolor=(0,0,0)) # if somlist[i][2] == 2: # img.drawpolygon(poly,fillcolor=(0,255,0),outlinecolor=(0,0,0)) # if somlist[i][2] == 3: # img.drawpolygon(poly,fillcolor=(0,0,255),outlinecolor=(0,0,0)) # if somlist[i][2] == 4: # img.drawpolygon(poly,fillcolor=(0,255,255),outlinecolor=(0,0,0)) # if somlist[i][2] == 5: # img.drawpolygon(poly,fillcolor=(255,0,255),outlinecolor=(0,0,0)) # if somlist[i][2] == 6: # img.drawpolygon(poly,fillcolor=(255,255,0),outlinecolor=(0,0,0)) # if somlist[i][2] == 7: # img.drawpolygon(poly,fillcolor=(255,255,255),outlinecolor=(0,0,0)) # # img.drawsquare(*center[:2], fillsize=2, fillcolor=(255,0,0)) # img.save("test.png") # img.view() # ylist = [] # for line in fileinput.input("GibbsLDA++/model-final.phi"): # prob = [float(i) for i in line.strip().split(" ")] # ylist.append(prob) # print len(ylist[0]) # fig = plt.figure() # ax1 = fig.add_subplot(241) # ax1.plot([i for i in xrange(16)], ylist[0], c="red") # ax1.set_xlim(0,15) # ax1.set_ylim(0,1.0) # ax2 = fig.add_subplot(242) # ax2.plot([i for i in xrange(16)], ylist[1], c="red") # ax2.set_xlim(0,15) # ax2.set_ylim(0,1.0) # ax3 = fig.add_subplot(243) # ax3.plot([i for i in xrange(16)], ylist[2], c="red") # ax3.set_xlim(0,15) # ax3.set_ylim(0,1.0) # ax4 = fig.add_subplot(244) # ax4.plot([i for i in xrange(16)], ylist[3], c="red") # ax4.set_xlim(0,15) # ax4.set_ylim(0,1.0) # ax5 = fig.add_subplot(245) # ax5.plot([i for i in xrange(16)], ylist[4], c="red") # ax5.set_xlim(0,15) # ax5.set_ylim(0,1.0) # ax6 = fig.add_subplot(246) # ax6.plot([i for i in xrange(16)], ylist[5], c="red") # ax6.set_xlim(0,15) # ax6.set_ylim(0,1.0) # ax7 = fig.add_subplot(247) # ax7.plot([i for i in xrange(16)], ylist[6], c="red") # ax7.set_xlim(0,15) # ax7.set_ylim(0,1.0) # ax8 = fig.add_subplot(248) # ax8.plot([i for i in xrange(16)], ylist[7], c="red") # ax8.set_xlim(0,15) # ax8.set_ylim(0,1.0) # plt.show() # # movement func 2 # seen, somlist = set(), [] # for line in fileinput.input("som/output_si.txt"): # part = line.strip().replace("[","").replace("]","").split(",") # if str(part[:2]) not in seen: # seen.add(str(part[:2])) # somlist.append([float(part[0])*5, 1000-float(part[1])*5, [0]*8]) # fileinput.close() # print len(somlist) # cnt = 0 # for line in fileinput.input("GibbsLDA++/model-final.theta"): # somlist[cnt][2] = [float(i) for i in line.strip().split(" ")] # cnt += 1 # import pytesselate # import itertools # polygons = pytesselate.voronoi(somlist) # import pydraw # crs = pydraw.CoordinateSystem([0,0,1000,1000]) # img = pydraw.Image(1000,1000) # c = 6 # for i,(center,poly) in enumerate(polygons): # if center: # img.drawpolygon(poly,fillcolor=(255*somlist[i][2][c],255*somlist[i][2][c],255*somlist[i][2][c]),outlinecolor=(0,0,0)) # img.save("figure/class_"+str(c)+".png") # # img.view() pass
def testall(): import pydraw crs = pydraw.CoordinateSystem([0, 0, 100, 100]) img = pydraw.Image(880, 440, background=(222, 0, 0), crs=crs) img.drawgridticks() #img = Image(filepath="C:/Users/BIGKIMO/Desktop/hmm.png") #print crs.getinfo() #SINGLE PIXEL TEST img.put(94.7, 94.7, (0, 0, 222)) #img.put(95.7,98,(0,0,222)) #img.put(98,95.7,(0,0,222)) #GREEN POLYGONS WITH OUTLINE #img.drawpolygon(coords=[(30,30),(90,10),(90,90),(10,90),(30,30)], fillcolor=(0,222,0), outlinecolor=(0,0,0), outlinewidth=12, outlinejoinstyle="round") #img.drawpolygon(coords=[(80,20),(50,15),(20,44),(90,50),(50,90),(10,50),(30,20),(50,10)], fillcolor=(0,222,0), outlinecolor=(0,0,0), outlinewidth=5, outlinejoinstyle="round") #POLYGON WITH HOLES img.drawpolygon(coords=[(30, 30), (90, 10), (90, 90), (10, 90), (30, 30)], holes=[[(51, 41), (77, 51), (77, 65), (51, 77), (51, 41)], [(43, 63), (49, 63), (49, 69), (43, 69), (43, 63)]], fillcolor=(222, 222, 0), outlinecolor=(0, 0, 0), outlinewidth=12, outlinejoinstyle="round") #MISC MULTILINE TEST #img.drawmultiline(coords=[(90,20),(80,20),(50,15),(20,44),(90,50),(50,90),(10,50),(30,20),(50,10)], fillcolor=(0,0,0), fillsize=8, outlinecolor=None, joinstyle="miter") #img.drawmultiline(coords=[(10,50),(50,50),(50,90)], fillcolor=(0,0,0), fillsize=8, outlinecolor=None, joinstyle="round") #img.drawmultiline(coords=[(10,50),(50,50),(60,90)], fillcolor=(0,111,0), fillsize=12, outlinecolor=None, joinstyle="round") #SINGLE LINE TEST #img.drawline(22,11,88,77,fillcolor=(222,0,0),fillsize=8, capstyle="round") #img.drawline(22,66,88,77,fillcolor=(222,0,0,166),fillsize=11, capstyle="round") ##img.drawline(44,33,55,80,fillcolor=(222,0,0),fillsize=0.5) #VARIOUS OTHER SHAPES img.drawbezier([(10, 10), (50, 140), (90, 10)]) #img.drawpolygon([(90,50),(90-5,50-5),(90+5,50+5),(90-5,50+5),(90,50)], fillcolor=(222,0,0)) img.drawcircle(50, 50, fillsize=30, fillcolor=(222, 222, 0), outlinecolor=(0, 0, 222), outlinewidth=1) img.drawarc(44, 62, radius=30, opening=90, facing=360, outlinecolor=(0, 0, 222), outlinewidth=1) img.drawrectangle([42, 42, 88, 55], fillcolor=(0, 0, 222), outlinecolor=(211, 111, 0), outlinewidth=4, outlinejoinstyle="round") img.drawsquare(80, 80, fillsize=13, fillcolor=(111, 0, 222), outlinecolor=(211, 0, 0), outlinewidth=1, outlinejoinstyle="miter") #TEST DATA PASTE #img = Image().load("C:/Users/BIGKIMO/Desktop/puremap.png") #data = Image().load("C:/Users/BIGKIMO/Desktop/hmm.png").imagegrid #img.pastedata(444,222,data,transparency=0.5) img.view() img.save("C:/Users/BIGKIMO/Desktop/hmm.png")