Exemplo n.º 1
0
    def project(self, x=None, y=None, toproj=None, method='bilinear'):
        """
        Project array
        
        :param x: To x coordinates.
        :param y: To y coordinates.
        :param toproj: To projection.
        :param method: Interpolation method: ``bilinear`` or ``neareast`` .
        
        :returns: (*MIArray*) Projected array
        """
        yy = self.dims[self.ndim - 2].getDimValue()
        xx = self.dims[self.ndim - 1].getDimValue()
        if toproj is None:
            toproj = self.proj

        if x is None or y is None:
            pr = ArrayUtil.reproject(self.array.array, xx, yy, self.proj,
                                     toproj)
            r = pr[0]
            x = pr[1]
            y = pr[2]
            dims = []
            ydim = Dimension()
            ydim.setDimValues(MIArray(y).aslist())
            dims.append(ydim)
            xdim = Dimension()
            xdim.setDimValues(MIArray(x).aslist())
            dims.append(xdim)
            rr = DimArray(MIArray(r), dims, self.fill_value, toproj)
            return rr

        if method == 'bilinear':
            method = ResampleMethods.Bilinear
        else:
            method = ResampleMethods.NearestNeighbor
        if isinstance(x, list):
            r = ArrayUtil.reproject(self.array.array, xx, yy, x, y, self.proj,
                                    toproj, self.fill_value, method)
        elif isinstance(x, MIArray):
            if x.rank == 1:
                r = ArrayUtil.reproject(self.array.array, xx, yy, x.aslist(),
                                        y.aslist(), self.proj, toproj,
                                        self.fill_value, method)
            else:
                r = ArrayUtil.reproject(self.array.array, xx, yy, x.asarray(),
                                        y.asarray(), self.proj, toproj,
                                        self.fill_value, method)
        else:
            r = ArrayUtil.reproject(self.array.array, xx, yy, x.asarray(),
                                    y.asarray(), self.proj, toproj,
                                    self.fill_value, method)
        #r = ArrayUtil.reproject(self.array.array, xx, yy, x.asarray(), y.asarray(), self.proj, toproj, self.fill_value, method)
        return MIArray(r)
Exemplo n.º 2
0
def project(x, y, fromproj=KnownCoordinateSystems.geographic.world.WGS1984, toproj=KnownCoordinateSystems.geographic.world.WGS1984):
    """
    Project geographic coordinates from one projection to another.
    
    :param x: (*array_like*) X coordinate values for projection.
    :param y: (*array_like*) Y coordinate values for projection.
    :param fromproj: (*ProjectionInfo*) From projection. Default is longlat projection.
    :param toproj: (*ProjectionInfo*) To projection. Default is longlat projection.
    
    :returns: (*array_like*, *array_like*) Projected geographic coordinates.
    """
    if isinstance(fromproj, str):
        fromproj = ProjectionInfo(fromproj)
    if isinstance(toproj, str):
        toproj = ProjectionInfo(toproj)
    if isinstance(x, (tuple, list)):
        x = array(x)
    if isinstance(y, (tuple, list)):
        y = array(y)
    if isinstance(x, MIArray):
        outxy = ArrayUtil.reproject(x.asarray(), y.asarray(), fromproj, toproj)
        return MIArray(outxy[0]), MIArray(outxy[1])
    else:
        inpt = PointD(x, y)
        outpt = Reproject.reprojectPoint(inpt, fromproj, toproj)
        return outpt.X, outpt.Y
Exemplo n.º 3
0
 def project(self, x=None, y=None, toproj=None, method='bilinear'):
     """
     Project array
     
     :param x: To x coordinates.
     :param y: To y coordinates.
     :param toproj: To projection.
     :param method: Interpolation method: ``bilinear`` or ``neareast`` .
     
     :returns: (*MIArray*) Projected array
     """
     yy = self.dims[self.ndim - 2].getDimValue()
     xx = self.dims[self.ndim - 1].getDimValue()
     if toproj is None:
         toproj = self.proj
     
     if x is None or y is None:
         pr = ArrayUtil.reproject(self.array.array, xx, yy, self.proj, toproj)
         r = pr[0]
         x = pr[1]
         y = pr[2]
         dims = []
         ydim = Dimension()
         ydim.setDimValues(MIArray(y).aslist())
         dims.append(ydim)
         xdim = Dimension()
         xdim.setDimValues(MIArray(x).aslist())    
         dims.append(xdim)
         rr = DimArray(MIArray(r), dims, self.fill_value, toproj)
         return rr
     
     if method == 'bilinear':
         method = ResampleMethods.Bilinear
     else:
         method = ResampleMethods.NearestNeighbor
     if isinstance(x, list):
         r = ArrayUtil.reproject(self.array.array, xx, yy, x, y, self.proj, toproj, self.fill_value, method)
     elif isinstance(x, MIArray):
         if x.rank == 1:
             r = ArrayUtil.reproject(self.array.array, xx, yy, x.aslist(), y.aslist(), self.proj, toproj, self.fill_value, method)
         else:
             r = ArrayUtil.reproject(self.array.array, xx, yy, x.asarray(), y.asarray(), self.proj, toproj, self.fill_value, method)
     else:
         r = ArrayUtil.reproject(self.array.array, xx, yy, x.asarray(), y.asarray(), self.proj, toproj, self.fill_value, method)
     #r = ArrayUtil.reproject(self.array.array, xx, yy, x.asarray(), y.asarray(), self.proj, toproj, self.fill_value, method)
     return MIArray(r)
Exemplo n.º 4
0
def reproject(a, x=None, y=None, fromproj=None, xp=None, yp=None, toproj=None, method='bilinear'):
    """
    Project array
    
    :param a: (*array_like*) Input array.
    :param x: (*array_like*) Input x coordinates.
    :param y: (*array_like*) Input y coordinates.
    :param fromproj: (*ProjectionInfo*) Input projection.
    :param xp: (*array_like*) Projected x coordinates.
    :param yp: (*array_like*) Projected y coordinates.
    :param toproj: (*ProjectionInfo*) Output projection.
    :param method: Interpolation method: ``bilinear`` or ``neareast`` .
    
    :returns: (*NDArray*) Projected array
    """
    if isinstance(a, DimArray):
        y = a.dimvalue(a.ndim - 2)
        x = a.dimvalue(a.ndim - 1)
        if fromproj is None:
            fromproj = a.proj
            
    if toproj is None:
        toproj = KnownCoordinateSystems.geographic.world.WGS1984
    
    if xp is None or yp is None:
        pr = ArrayUtil.reproject(a.asarray(), x.aslist(), y.aslist(), fromproj, toproj)
        r = pr[0]        
        return NDArray(r)
    
    if method == 'bilinear':
        method = ResampleMethods.Bilinear
    else:
        method = ResampleMethods.NearestNeighbor
    if isinstance(xp, (list, tuple)):
        xp = NDArray(xp)
    if isinstance(yp, (list, tuple)):
        yp = NDArray(yp)
    xp, yp = ArrayUtil.meshgrid(xp.asarray(), yp.asarray())
    r = ArrayUtil.reproject(a.asarray(), x.aslist(), y.aslist(), xp, yp, fromproj, toproj, method)
    return NDArray(r)