Ejemplo n.º 1
0
 def check(self, id0, poly1):
     "Check's if two polygon's are neighbors"
     if id0 in self.Q:
         self.cache_hits += 1
         poly0 = self.Q[id0]
     else:
         self.cache_misses += 1
         poly0 = self.geoObj.get(id0)
         poly0.id = id0
         self.Q.add(poly0)
     common = set(poly0.vertices).intersection(set(poly1.vertices))
     if len(common) > 1 and self.joinType == ROOK:
         #double check rook
         if get_shared_segments(poly0, poly1, True):
             return ROOK
         return False
         #for vert in common:
         #    idx = poly0.vertices.index(vert)
         #    IDX = poly1.vertices.index(vert)
         #    try:
         #        if poly0.vertices[idx+1] == poly1.vertices[IDX+1] or poly0.vertices[idx+1] == poly1.vertices[IDX-1]\
         #        or poly0.vertices[idx-1] == poly1.vertices[IDX+1] or poly0.vertices[idx-1] == poly1.vertices[IDX-1]:
         #            return ROOK
         #    except IndexError:
         #        pass
         #return False
     elif len(common) > 0:
         return QUEEN
     else:
         return False
Ejemplo n.º 2
0
    def doWeights(self):
        pw = self.potentialW
        polygonCache = {}
        w = {}
        shpFileObject = self.shpFileObject
        for polyId in xrange(self.numPoly):
            if polyId not in polygonCache:
                iVerts = set(shpFileObject.get(polyId).vertices)
                polygonCache[polyId] = iVerts
            else:
                iVerts = polygonCache[polyId]
            potentialNeighbors = pw[polyId]
            if polyId not in w:
                w[polyId] = set()
            for j in potentialNeighbors:
                if j not in polygonCache:
                    polygonCache[j] = set(shpFileObject.get(j).vertices)
                common = iVerts.intersection(polygonCache[j])
                join = False
                if len(common) > 1:  # ROOK
                    #double check rook
                    poly0 = shpFileObject.get(polyId)
                    poly1 = shpFileObject.get(j)
                    if get_shared_segments(poly0, poly1, True):
                        join = True
                    #for vert in common:
                    #    idx = poly0.vertices.index(vert)
                    #    IDX = poly1.vertices.index(vert)
                    #    try:
                    #        if poly0.vertices[idx+1] == poly1.vertices[IDX+1] or poly0.vertices[idx+1] == poly1.vertices[IDX-1]\
                    #        or poly0.vertices[idx-1] == poly1.vertices[IDX+1] or poly0.vertices[idx-1] == poly1.vertices[IDX-1]:
                    #            join = True
                    #            break
                    #    except IndexError:
                    #        pass
                if len(common) > 0:  # QUEEN
                    if self.wttype == QUEEN:
                        join = True
                if join:
                    w[polyId].add(j)
                    if j not in w:
                        w[j] = set()
                    w[j].add(polyId)

            del polygonCache[polyId]
        self.w = w
Ejemplo n.º 3
0
 def check(self, id0, poly1):
     "Check's if two polygon's are neighbors"
     if id0 in self.Q:
         self.cache_hits += 1
         poly0 = self.Q[id0]
     else:
         self.cache_misses += 1
         poly0 = self.geoObj.get(id0)
         poly0.id = id0
         self.Q.add(poly0)
     common = set(poly0.vertices).intersection(set(poly1.vertices))
     if len(common) > 1 and self.joinType == ROOK:
         #double check rook
         if get_shared_segments(poly0, poly1, True):
             return ROOK
         return False
     elif len(common) > 0:
         return QUEEN
     else:
         return False
Ejemplo n.º 4
0
 def check(self, id0, poly1):
     "Check's if two polygon's are neighbors"
     if id0 in self.Q:
         self.cache_hits += 1
         poly0 = self.Q[id0]
     else:
         self.cache_misses += 1
         poly0 = self.geoObj.get(id0)
         poly0.id = id0
         self.Q.add(poly0)
     common = set(poly0.vertices).intersection(set(poly1.vertices))
     if len(common) > 1 and self.joinType == ROOK:
         #double check rook
         if get_shared_segments(poly0, poly1, True):
             return ROOK
         return False
     elif len(common) > 0:
         return QUEEN
     else:
         return False