def __init__(self, x, y, value): Point2D.__init__(self, x, y) self._downnode = None self._upnodes = [] self._pitflag = True self._value = value self._rain = 0
def __init__(self, x, y, data, radius=None, label=None): # call the super-class constructor Point2D.__init__(self, x, y) # define the additional attributes of some data, a symbol radius and a label # Having both data and radius makes it easier to keep the original data # but rescale for any plotting purposes self._data = data self._radius = radius self._label = label
def __init__(self, x, y,data,radius=None,label=None): # call the super-class constructor Point2D.__init__(self, x, y) # define the additional attributes of some data, a symbol radius and a label # Having both data and radius makes it easier to keep the original data # but rescale for any plotting purposes self._data=data self._radius=radius self._label=label
def __init__(self, x, y, value): Point2D.__init__(self, x, y) self._downnode = None self._upnodes = [] self._pitflag = True self._value = value self._flow = None self._rainfall = 1 self._lakeDepth = 0 self._lakeFlag = False
def __init__(self, x, y, value): """Initializes FlowNode with _downnode, _upnoddes, _pitflag, _value, _rainfall, and _lakedepth.""" Point2D.__init__(self, x, y) self._downnode = None self._upnodes = [] self._pitflag = True self._value = value self._rainfall = 1 self._lakedepth = 0
def __init__(self, *args): if len(args) == 4: p1 = Point2D(args[0], args[1]) p2 = Point2D(args[2], args[3]) self._segPoints = (p1, p2) elif len(args) == 1: plist = args[0] p1 = plist[0] p2 = plist[1] self._segPoints = (p1.clone(), p2.clone()) else: p1 = args[0] p2 = args[1] self._segPoints = (p1.clone(), p2.clone())
def __init__(self,x,y, value, rainfall=None): """Constructor for FlowNode Input Parameter: x – x-position of node within grid y – y-position of node within grid value – value at the node position (e.g. elevation) """ Point2D.__init__(self,x,y) #use constructor of super class self._downnode=None #is set with setDownnode() self._upnodes=[] self._pitflag=True #set to true as FlowNode doesn't have a downnode at the moment self._value=value self._rainfall=rainfall self._lakedepth=0
def getIntersectLine(self, point): x1 = self.getStart().get_x() y1 = self.getStart().get_y() x2 = self.getEnd().get_x() y2 = self.getEnd().get_y() x3 = point.get_x() y3 = point.get_y() #trap x coords same if (x2 == x1): return (Point2D(x1, point.get_y())) #trap y coords same if (y1 == y2): return (Point2D(point.get_x(), y1)) m1 = (y2 - y1) / (x2 - x1) c1 = y1 - (m1 * x1) c2 = y3 + (x3 / m1) x4 = (c2 - c1) / (m1 + (1. / m1)) y4 = (m1 * x4) + c1 return Point2D(x4, y4)
def __init__(self,*args): """creates a segment object Input Parameter: list of 4 coordinates (x1, y1, x2, y2) OR list with a tuple of two Point2D objects OR list with two Point2D objects """ if len(args)==4: p1=Point2D(args[0],args[1]) p2=Point2D(args[2],args[3]) self._segPoints=(p1,p2) elif len(args)==1: plist=args[0] p1=plist[0] p2=plist[1] self._segPoints=(p1.clone(),p2.clone()) else: p1=args[0] p2=args[1] self._segPoints=(p1.clone(),p2.clone())
def resolveForces2(self, boundary_scale, damping, alpha=0.3): """This version of the implementation is based on Ryo Inoue, Eihan Shimizu's paper: Construction of Circular and Rectangular Cartograms by Solving Constrained Non-linear Optimization Problems""" # Set centre of circle x_resultant = 0 y_resultant = 0 #Summers bearingDif = 0 ratDist = 0 #For each neighbour of the point for link in self._links: #Get neighbours centre, distance and max_seperation otherp = link.getLink() distance = self.distance(otherp) max_sep = link.getMaxSep() #If the neighbour isn't overlapping if (distance > max_sep): #Get the geographical bearing to current neighbour gBearing = link.getGBearing() #Get the current cartogram bearing to current neighbour cBearing = self.bearingTo( Point2D(link.getLinkX(), link.getLinkY())) #Add to summers from equation ratDist += ((distance / max_sep) - 1)**2 bearingDif += (cBearing - gBearing)**2 #Calculate the scaling scaling = alpha * ratDist + (1 - alpha) * bearingDif # finally add up all the forces from all the other atoms x_resultant = self._x * scaling y_resultant = self._y * scaling return (x_resultant, y_resultant)
def getIntersectLine(self,point): """Helper method to return intersect point on the segment line (from a point) i.e. closest point on the segment line from another point Input parameter: point – 2Dpoint to calculate the closest instersect from Returns: a Point2D object """ x1=self.getStart().get_x() y1=self.getStart().get_y() x2=self.getEnd().get_x() y2=self.getEnd().get_y() x3=point.get_x() y3=point.get_y() # calculate intersection m1 = (y2-y1)/(x2-x1) c1 = y1-(m1*x1) c2 = y3+(x3/m1) x4 =(c2-c1)/(m1+(1./m1)) y4=(m1*x4)+c1 return Point2D(x4,y4)
def addPoint(self,point): """Adds a Point to the Polyline""" if isinstance(point, Point2D): self._allPoints.append(point.clone ()) elif isinstance(point, tuple): self._allPoints.append(Point2D(point[0],point[1]))
def addPoint(self, point): if isinstance(point, Point2D): self._allPoints.append(point.clone()) elif isinstance(point, tuple): self._allPoints.append(Point2D(point[0], point[1]))