Union of rasters

    Usage:
        union(rasters)
    where:
        rasters is a list of GeoRaster objects
421707
def union(rasters):
    
    if sum([rasters[0].x_cell_size == i.x_cell_size for i in rasters]) == len(rasters) \
       and sum([rasters[0].y_cell_size == i.y_cell_size for i in rasters]) == len(rasters)\
       and sum([rasters[0].projection.ExportToProj4() == i.projection.ExportToProj4() for i in rasters]) == len(rasters):
        if sum([rasters[0].nodata_value == i.nodata_value for i in rasters]) == len(rasters):
            ndv = rasters[0].nodata_value
        else:
            ndv = np.nan
        if ndv == None:
            ndv = np.nan
        if sum([rasters[0].datatype == i.datatype for i in rasters]) == len(rasters):
            datatype = rasters[0].datatype
        else:
            datatype = None
        projection = rasters[0].projection
        lonmin = min([i.xmin for i in rasters])
        lonmax = max([i.xmax for i in rasters])
        latmin = min([i.ymin for i in rasters])
        latmax = max([i.ymax for i in rasters])
        shape = (np.abs(np.floor((latmax-latmin)/rasters[0].y_cell_size)).astype(int), np.floor((lonmax-lonmin)/rasters[0].x_cell_size).astype(int))
        out = ndv*np.ones(shape)
        outmask = np.ones(shape).astype(bool)
        for i in rasters:
            (row, col) = map_pixel(i.xmin, i.ymax, rasters[0].x_cell_size, rasters[0].y_cell_size, lonmin, latmax)
            out[row:row+i.shape[0], col:col+i.shape[1]] = np.where(i.raster.data != i.nodata_value, i.raster.data,\
                                                         out[row:row+i.shape[0], col:col+i.shape[1]])
            outmask[row:row+i.shape[0], col:col+i.shape[1]] = np.where(i.raster.mask == False, False,\
                                                         outmask[row:row+i.shape[0], col:col+i.shape[1]])
        out = np.ma.masked_array(out, mask=outmask, fill_value=ndv)
        return GeoRaster(out, (lonmin, rasters[0].x_cell_size, 0.0, latmax, 0.0, rasters[0].y_cell_size), nodata_value=ndv, projection=projection, datatype=datatype)
    else:
        raise RasterGeoError('Rasters need to have same pixel sizes. Use the aggregate or dissolve functions to generate correct GeoRasters')
291089
def _raster_layers(self):
        
        layers = []

        raster_datasource = gdal.Open(self.uri.absoluteFilePath())
        if raster_datasource:
            subdatasets = raster_datasource.GetSubDatasets()
            if len(subdatasets) == 0:
                metadata = raster_datasource.GetMetadata()
                layers.append(metadata['IDENTIFIER'])
            else:
                for subdataset in subdatasets:
                    layers.append(subdataset[0].split(':')[2])

        return layers
390359
def union(*sets, **kwargs):
    
    sets = _set_preprocess(sets, **kwargs)
    return as_index( _set_concatenate(sets), axis=0, base=True).unique
857139
def union(self, *iterables):
        
        return self.__class__(chain(iter(self), *iterables), key=self._key)
1100053
def block_reduce(self, block_size, how=np.ma.mean):
        '''
        
        '''
        raster2 = block_reduce(self.raster, block_size, func=how)
        geot = self.geot
        geot = (geot[0], block_size[0] * geot[1], geot[2], geot[3], geot[4],
                block_size[1] * geot[-1])
        return GeoRaster(raster2, geot, nodata_value=self.nodata_value,\
                        projection=self.projection, datatype=self.datatype)
1188246
def uniontypes(type_: Type[Any]) -> Set[Type[Any]]:
    '''
    
    '''
    if not is_union(type_):
        raise ValueError('Not a Union: ' + str(type_))

    if hasattr(type_, '__args__'):
        return set(type_.__args__)
    elif hasattr(type_, '__union_params__'):
        return set(type_.__union_params__)
    raise AttributeError('The typing API for this Python version is unknown')
1038295
def union_all! datastream
      keys = self.headers | datastream.headers

      output = []

      (self.data + datastream.data).each do |input_row|

        output_row = {}

        keys.each do |key|
          output_row[key] = input_row[key]
        end

        output << output_row
      end

      self.data = output
      self
    end
1065665
static <S, E1, E2> GraphTraversal<S, E2> union(
            GraphTraversal<S, ? extends E1> start, Iterable<GraphTraversal<? super E1, ? extends E2>> traversals) {
        // This is safe, because we know all the arguments are of the right type
        //noinspection unchecked
        GraphTraversal<E1, E2>[] array = (GraphTraversal<E1, E2>[]) Iterables.toArray(traversals, GraphTraversal.class);

        return start.union(array);
    }
252720
def union(self, other):
        
        if isinstance(other, self.__class__):
            return self.client.sunion([self.name, other.name])
        else:
            return self._as_set().union(other)
462065
def union(other)
      if other.is_a?(RelativeComplement)
        # A ∪ ¬B = ¬B ∪ A
        other.union(self)
      elsif other.is_a?(AbstractSet)
        unless other.is_a?(RelativeSet) and size < other.size
          hash = other.inject(@hash.clone){|h,o| h[o] = true; h }

          if hash.empty?
            NullSet.build
          else
            RelativeSet.new(hash)
          end
        else
          # For efficiency, iterate the smaller of the two sets: A ∪ B = B ∪ A
          if other.empty?
            self
          else
            other.union(self)
          end
        end
      else
        union(Cantor.build(other))
      end
    end
1374704
def union(self):
        
        usegs = reduce(operator.or_, self.values())
        usegs.name = ' | '.join(self.keys())
        return usegs
909549
def raster(self, name=None, **creteria):
        """"""
        if name:
            asset = self.assets[name]
            if asset["type"] in raster_types:
                __object = asset.get('__object')
                if isinstance(__object, GeoRaster2):
                    return __object
                else:
                    return GeoRaster2.from_assets([asset])
            else:
                return None

        if creteria:
            key = next(iter(creteria))
            value = creteria[key]
        else:
            # default creteria is to return a visual raster
            key = 'product'
            value = 'visual'

        rasters = {k: asset for k, asset in self.assets.items() if asset['type'] in raster_types}
        raster_list = list(rasters.values())
        # if there is only a single raster in the assetes and it hase a GeoRaster object serve the object
        if len(raster_list) == 1 and isinstance(raster_list[0].get('__object'), GeoRaster2):
            return raster_list[0].get('__object')
        rasters = {k: r for k, r in rasters.items() if r[key] == value}
        raster = GeoRaster2.from_assets(rasters)
        return raster
490882
public static List<Range> union(List<Range> ranges){
        ranges = new ArrayList<Range>(ranges);
        Collections.sort(ranges, new Comparator<Range>(){
            @Override
            public int compare(Range r1, Range r2){
                return r1.min-r2.min;
            }
        });
        List<Range> union = new ArrayList<Range>();
        for(Range r: ranges){
            if(union.isEmpty())
                union.add(r);
            else
                CollectionUtil.addAll(union, union.remove(union.size() - 1).union(r));
        }
        return union;
    }
1127041
def spatial_join(other, buffer = 0, table_alias = 'features', other_alias = 'other_features', geom = 'geom_lowres')
      scope = features_scope(self).select("#{geom} AS geom").select(:spatial_model_id)

      other_scope = features_scope(other)
      other_scope = other_scope.select("ST_Union(#{geom}) AS geom").select("ST_Buffer(ST_Union(#{geom}), #{buffer.to_i}) AS buffered_geom")

      return joins(%Q(INNER JOIN (#{scope.to_sql}) AS #{table_alias} ON #{table_alias}.spatial_model_id = #{table_name}.id))
            .joins(%Q(INNER JOIN (#{other_scope.to_sql}) AS #{other_alias} ON ST_Intersects(#{table_alias}.geom, #{other_alias}.buffered_geom)))
    end
965469
def union(self, other):
        
        result = IntervalSet()
        for el in self:
            result.add(el)
        for el in other:
            result.add(el)
        return result
592654
public void union(Rect r) {
        union(r.left, r.top, r.right, r.bottom);
    }
196644
public static void union (IRectangle src1, IRectangle src2, Rectangle dst) {
        float x1 = Math.min(src1.minX(), src2.minX());
        float y1 = Math.min(src1.minY(), src2.minY());
        float x2 = Math.max(src1.maxX(), src2.maxX());
        float y2 = Math.max(src1.maxY(), src2.maxY());
        dst.setBounds(x1, y1, x2 - x1, y2 - y1);
    }