def mapfeature(index, shape, sf): # map individual features, returns Features sf_xrange = sf.bbox[2] - sf.bbox[0] sf_yrange = sf.bbox[3] - sf.bbox[1] ft = Feature() ft.id = index + 1 if sf.shapeType == 1: (ptx, pty) = shape.points[0] sh_bbox = (ptx, pty, ptx, pty) else: sh_bbox = shape.bbox ft_xmin = (sh_bbox[0] - sf.bbox[0]) / sf_xrange * 255.0 # not sure why this rounding is needed, but it is mod_xmin = (ft_xmin % 1 - 0.005) % 1 + int(ft_xmin) ft.xmin = int(floor(mod_xmin)) if ft.xmin < 0: ft.xmin = 0 ft_ymin = (sh_bbox[1] - sf.bbox[1]) / sf_yrange * 255.0 mod_ymin = (ft_ymin % 1 - 0.005) % 1 + int(ft_ymin) ft.ymin = int(floor(mod_ymin)) if ft.ymin < 0: ft.ymin = 0 ft_xmax = (sh_bbox[2] - sf.bbox[0]) / sf_xrange * 255.0 mod_xmax = (ft_xmax % 1 + 0.005) % 1 + int(ft_xmax) ft.xmax = int(ceil(mod_xmax)) if ft.xmax > 255: ft.xmax = 255 ft_ymax = (sh_bbox[3] - sf.bbox[1]) / sf_yrange * 255.0 mod_ymax = (ft_ymax % 1 + 0.005) % 1 + int(ft_ymax) ft.ymax = int(ceil(mod_ymax)) if ft.ymax > 255: ft.ymax = 255 return ft
def mapfeature(index, shape, sf): # map individual features, returns Features sf_xrange = sf.bbox[2] - sf.bbox[0] sf_yrange = sf.bbox[3] - sf.bbox[1] ft = Feature() ft.id = index + 1 if sf.shapeType == 1: (ptx, pty) = shape.points[0] sh_bbox = (ptx, pty, ptx, pty) else: sh_bbox = shape.bbox ft_xmin = ((sh_bbox[0] - sf.bbox[0]) / sf_xrange * 255.0) # not sure why this rounding is needed, but it is mod_xmin = (ft_xmin % 1 - .005) % 1 + int(ft_xmin) ft.xmin = int(floor(mod_xmin)) if ft.xmin < 0: ft.xmin = 0 ft_ymin = ((sh_bbox[1] - sf.bbox[1]) / sf_yrange * 255.0) mod_ymin = (ft_ymin % 1 - .005) % 1 + int(ft_ymin) ft.ymin = int(floor(mod_ymin)) if ft.ymin < 0: ft.ymin = 0 ft_xmax = ((sh_bbox[2] - sf.bbox[0]) / sf_xrange * 255.0) mod_xmax = (ft_xmax % 1 + .005) % 1 + int(ft_xmax) ft.xmax = int(ceil(mod_xmax)) if ft.xmax > 255: ft.xmax = 255 ft_ymax = ((sh_bbox[3] - sf.bbox[1]) / sf_yrange * 255.0) mod_ymax = (ft_ymax % 1 + .005) % 1 + int(ft_ymax) ft.ymax = int(ceil(mod_ymax)) if ft.ymax > 255: ft.ymax = 255 return ft
#if self.featuresinlevel(level) >= 8: # return #print "Slurping %s features from node %s" % (len(child.allfeatures()),child.id) node.features.extend(child.allfeatures()) #node.full = True child.features = [] child.holdfeatures = [] return if __name__ == "__main__": t = Tree(4) for i in range(8): f = Feature() f.xmin = 120 f.xmax = 130 f.ymin = 120 f.ymax = 130 t.insert(f) f = Feature() f.xmin = 130 f.xmax = 140 f.ymin = 130 f.ymax = 140 t.insert(f)
# return #print "Slurping %s features from node %s" % (len(child.allfeatures()),child.id) node.features.extend(child.allfeatures()) #node.full = True child.features = [] child.holdfeatures = [] return if __name__ == "__main__": t = Tree(4) for i in range(8): f = Feature() f.xmin = 120 f.xmax = 130 f.ymin = 120 f.ymax = 130 t.insert(f) f = Feature() f.xmin = 130 f.xmax = 140 f.ymin = 130 f.ymax = 140 t.insert(f)