/// <summary> /// 获取与一个Feature有关的Raster参数,[0]offX,[1]offY,[2]sizeX,[3]sizeY /// </summary> /// <param name="Trans"></param> /// <param name="aFeat"></param> /// <returns></returns> private static int[] subRasterInfo(double[] Trans, int xSize, int ySize, OSGeo.OGR.Feature aFeat) { //拿到Buffer Featuer的壳 OSGeo.OGR.Geometry bufGeom = aFeat.GetGeometryRef(); OSGeo.OGR.Envelope bufEnve = new OSGeo.OGR.Envelope(); bufGeom.GetEnvelope(bufEnve); //判断壳是否超出全局范围,是则赋边界值 double maxX, minY; StaticTools.imageToGeoSpace(Trans, xSize, ySize, out maxX, out minY); if (bufEnve.MinX < Trans[0]) { bufEnve.MinX = Trans[0]; } if (bufEnve.MaxY > Trans[3]) { bufEnve.MaxY = Trans[3]; } if (bufEnve.MaxX > maxX) { bufEnve.MaxX = maxX; } if (bufEnve.MinY < minY) { bufEnve.MinY = minY; } //通过壳坐标拿到SubRaster的起点及行列数 var a = new int[4]; int leftUpX, leftUpY, rightDownX, rightDownY; StaticTools.geoToImageSpace(Trans, bufEnve.MinX, bufEnve.MaxY, out leftUpX, out leftUpY); StaticTools.geoToImageSpace(Trans, bufEnve.MaxX, bufEnve.MinY, out rightDownX, out rightDownY); a[0] = leftUpX; a[1] = leftUpY; a[2] = Math.Abs(rightDownX - leftUpX); a[3] = Math.Abs(leftUpY - rightDownY); bufGeom.Dispose(); bufEnve.Dispose(); return(a); }