Generator which yields a set of (rx, ry) tuples which describe
        all regions for which the world has tile data
500029
def get_all_regions_with_tiles(self):
        
        for key in self.get_all_keys():
            (layer, rx, ry) = struct.unpack('>BHH', key)
            if layer == 1:
                yield (rx, ry)
1370217
def _global_tiles_from_bounds(tp, bounds, zoom):
    """"""
    seen = set()

    # clip to tilepyramid top and bottom bounds
    left, right = bounds.left, bounds.right
    top = tp.top if bounds.top > tp.top else bounds.top
    bottom = tp.bottom if bounds.bottom < tp.bottom else bounds.bottom

    if left >= tp.left and right <= tp.right:
        for tile in _tiles_from_cleaned_bounds(tp, bounds, zoom):
            yield tile

    # bounds overlap on the Western side with antimeridian
    if left < tp.left:
        for tile in chain(
            # tiles west of antimeridian
            _tiles_from_cleaned_bounds(
                tp,
                Bounds(left + (tp.right - tp.left), bottom, tp.right, top),
                zoom
            ),
            # tiles east of antimeridian
            _tiles_from_cleaned_bounds(
                tp, Bounds(tp.left, bottom, right, top), zoom
            )
        ):
            # make output tiles unique
            if tile.id not in seen:
                seen.add(tile.id)
                yield tile

    # bounds overlap on the Eastern side with antimeridian
    if right > tp.right:
        for tile in chain(
            # tiles west of antimeridian
            _tiles_from_cleaned_bounds(
                tp, Bounds(left, bottom, tp.right, top), zoom
            ),
            # tiles east of antimeridian
            _tiles_from_cleaned_bounds(
                tp,
                Bounds(tp.left, bottom, right - (tp.right - tp.left), top),
                zoom
            )
        ):
            # make output tiles unique
            if tile.id not in seen:
                seen.add(tile.id)
                yield tile
338035
def grid(metadata, layout, params):
  
  x = layout["x"]
  y = layout["y"]
  x_min = np.min(x)
  x_max = np.max(x)
  y_min = np.min(y)
  y_max = np.max(y)

  # this creates the grid
  bins = np.linspace(x_min, x_max, params["n_layer"] - 1)
  xd = np.digitize(x, bins)
  bins = np.linspace(y_min, y_max, params["n_layer"] - 1)
  yd = np.digitize(y, bins)

  # the number of tiles is the number of cells divided by the number of cells in each tile
  num_tiles = int(params["n_layer"]/params["n_tile"])
  print("num tiles", num_tiles)
  # we will save the tiles in an array indexed by the tile coordinates
  tiles = {}
  for ti in range(num_tiles):
    for tj in range(num_tiles):
      tiles[(ti,tj)] = {
        "x": [],
        "y": [],
        "ci": [], # cell-space x coordinate
        "cj": [], # cell-space y coordinate
        "gi": [], # global index
      }

  for i,xi in enumerate(x):
    if(i % 1000 == 0 or i+1 == len(x)):
      print("point", i+1, "/", len(x), end="\r")
    # layout-space coordinates
    yi = y[i]
    # grid-space cell coordinates
    ci = xd[i]
    cj = yd[i]
    # tile coordinate
    ti = math.floor(ci / params["n_tile"])
    tj = math.floor(cj / params["n_tile"])

    # TODO: don't append a point if it doesn't match a filter function provided in params
    filter = params.get("filter", lambda i,metadata: True)
    if(filter(i, metadata=metadata)):
      tiles[(ti,tj)]["x"].append(xi)
      tiles[(ti,tj)]["y"].append(yi)
      tiles[(ti,tj)]["ci"].append(ci)
      tiles[(ti,tj)]["cj"].append(cj)
      tiles[(ti,tj)]["gi"].append(i)
    
  return tiles
1098679
def _get_variant_regions(items):
    
    return list(filter(lambda x: x is not None,
                       [tz.get_in(("config", "algorithm", "variant_regions"), data)
                        for data in items
                        if tz.get_in(["config", "algorithm", "coverage_interval"], data) != "genome"]))
1001089
def _generateLocations(self):
    
    size = self.externalInputSize
    bits = self.numInputBits
    random.seed(self.seed)
    self.locations = []
    for _ in xrange(self.numColumns):
      self.locations.append(
        [self._generatePattern(bits, size) for _ in xrange(self.numLocations)]
      )
1159916
def kml_region(map_source, z, x, y):
    
    map = app.config["mapsources"][map_source]
    kml_doc = KMLRegion(app.config["url_formatter"], map, app.config["LOG_TILES_PER_ROW"],
                        z, x, y)
    return kml_response(kml_doc)
18793
def map(self, width, height):
        
        template = ti.load(os.path.join(script_dir, 'assets', 'template.tmx'))['map0']
        #template.set_view(0, 0, template.px_width, template.px_height)
        template.set_view(0, 0, width*template.tw, height*template.th)

        # TODO: Save the generated map.
        #epoch = int(time.time())
        #filename = 'map_' + str(epoch) + '.tmx'

        # Draw borders
        border_x = template.cells[width]
        for y in xrange(0,height+1):
            border_x[y].tile = template.cells[0][0].tile

        for x in xrange(0,width):
            template.cells[x][height].tile = template.cells[0][0].tile

        # Start within borders
        #self.recursive_division(template.cells, 3, (template.px_width/template.tw)-1, (template.px_height/template.th)-1, 0, 0)
        self.recursive_division(template.cells, 3, width, height, 0, 0)

        return template
754010
def generate_tile(self, region, size):
        """"""
        r = IIIFRequest(identifier=self.identifier,
                        api_version=self.api_version)
        if (region == 'full'):
            r.region_full = True
        else:
            r.region_xywh = region  # [rx,ry,rw,rh]
        r.size_wh = size  # [sw,sh]
        r.format = 'jpg'
        self.generate_file(r, True)
829612
def iter_coords(obj):
    
    if isinstance(obj, (tuple, list)):
        coords = obj
    elif 'features' in obj:
        coords = [geom['geometry']['coordinates'] for geom in obj['features']]
    elif 'geometry' in obj:
        coords = obj['geometry']['coordinates']
    else:
        coords = obj.get('coordinates', obj)
    for coord in coords:
        if isinstance(coord, (float, int)):
            yield tuple(coords)
            break
        else:
            for f in iter_coords(coord):
                yield f
218089
def iteritems(self):
        """"""
        if self.type in ['blob']:
            raise StopIteration

        for path, mode, sha in self.tree.iteritems():
            item = Item(self, sha, path, mode)
            yield item
            for i in item.iteritems():
                yield i
1121189
def iter_regions(self):
        
        # TODO: Implement BoundingBox
        # TODO: Implement sort order
        for x,z in self.regionfiles.keys():
            close_after_use = False
            if (x,z) in self.regions:
                regionfile = self.regions[(x,z)]
            else:
                # It is not yet cached.
                # Get file, but do not cache later.
                regionfile = region.RegionFile(self.regionfiles[(x,z)], chunkclass = self.chunkclass)
                regionfile.loc = Location(x=x,z=z)
                close_after_use = True
            try:
                yield regionfile
            finally:
                if close_after_use:
                    regionfile.close()
609725
def _all_same_area(self, dataset_ids):
        """"""
        all_areas = []
        for ds_id in dataset_ids:
            for scn in self.scenes:
                ds = scn.get(ds_id)
                if ds is None:
                    continue
                all_areas.append(ds.attrs.get('area'))
        all_areas = [area for area in all_areas if area is not None]
        return all(all_areas[0] == area for area in all_areas[1:])
1015754
def generate_chunks(data, chunk_size=DEFAULT_CHUNK_SIZE):
    """"""
    iterator = iter(repeated.getvalues(data))

    while True:
        chunk = list(itertools.islice(iterator, chunk_size))
        if not chunk:
            return

        yield chunk
423471
def bounds(ctx, tile):
    """"""
    click.echo(
        '%s %s %s %s' % TilePyramid(
            ctx.obj['grid'],
            tile_size=ctx.obj['tile_size'],
            metatiling=ctx.obj['metatiling']
        ).tile(*tile).bounds(pixelbuffer=ctx.obj['pixelbuffer'])
    )
124162
def get_all(self):
        ''''''
        for name, values in self._map.items():
            for value in values:
                yield (name, value)
9613
private void generateTin( List<Coordinate> coordinateList ) {
        pm.beginTask("Generate tin...", -1);
        DelaunayTriangulationBuilder b = new DelaunayTriangulationBuilder();
        b.setSites(coordinateList);
        Geometry tinTriangles = b.getTriangles(gf);
        tinGeometries = new Geometry[tinTriangles.getNumGeometries()];
        for( int i = 0; i < tinTriangles.getNumGeometries(); i++ ) {
            tinGeometries[i] = tinTriangles.getGeometryN(i);
        }
        pm.done();
    }
794650
def _union_in_blocks(contours, block_size):
    

    n_contours = len(contours)
    for i in range(0, n_contours, block_size):
        j = min(i + block_size, n_contours)

        inners = []
        for c in contours[i:j]:
            p = _contour_to_poly(c)
            if p.type == 'Polygon':
                inners.append(p)
            elif p.type == 'MultiPolygon':
                inners.extend(p.geoms)
        holes = unary_union(inners)
        assert holes.is_valid

        yield holes