Example #1
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string ftrPath = cmbFtrCls.Text;
            string imgPath = txtImgWks.Text;
            string outPath = txtOutWks.Text;

            if (ftrPath == "" || ftrPath == null)
            {
                MessageBox.Show("Missing Feature Class");
                return;
            }
            if (imgPath == "" || imgPath == null)
            {
                MessageBox.Show("Missing image directory\\workspace");
                return;
            }
            if (outPath == "" || outPath == null)
            {
                MessageBox.Show("Missing output workspace");
                return;
            }
            RunningProcess.frmRunningProcessDialog rd = new RunningProcess.frmRunningProcessDialog(false);
            this.Visible = false;
            rd.addMessage("Making Tiles. This may take a while....");
            rd.stepPGBar(10);
            rd.TopMost = true;
            DateTime dt = DateTime.Now;

            rd.Show();
            try
            {
                IFeatureClass            ftrCls  = ftrDic[ftrPath];
                IWorkspace               imgWks  = geoUtil.OpenRasterWorkspace(imgPath);
                IWorkspace               outWks  = geoUtil.OpenWorkSpace(outPath);
                IFunctionRasterDataset[] outDset = ftrUtil.tiledMosaics(ftrCls, imgWks, outWks);
                for (int i = 0; i < outDset.Length; i++)
                {
                    IRasterLayer lyr = new RasterLayerClass();
                    lyr.Name = "Tile_" + (i + 1).ToString();
                    lyr.CreateFromDataset((IRasterDataset)outDset[i]);
                    frmHlp.TheMap.AddLayer(lyr);
                }
            }
            catch (Exception ex)
            {
                rd.addMessage(ex.ToString());
            }
            finally
            {
                DateTime dt2 = DateTime.Now;
                TimeSpan ts  = dt2.Subtract(dt);
                string   t   = " in " + ts.Days.ToString() + " days " + ts.Hours.ToString() + " hours " + ts.Minutes.ToString() + " minutes and " + ts.Seconds.ToString() + " seconds .";
                rd.stepPGBar(100);
                rd.addMessage("Finished Making Tiles" + t);
                rd.enableClose();
                this.Close();
                rd.stepPGBar(100);
            }
        }
Example #2
0
        public void convertFeatureToRaster(IFeatureClass InFeatureClass, string fldName)
        {
            ftrCls   = InFeatureClass;
            ftrField = fldName;
            IDataset dSet    = (IDataset)InFeatureClass;
            string   outRsNm = dSet.BrowseName;

            wks = dSet.Workspace;
            if (vRs != null)
            {
                if (!checkProjectionsFtr())
                {
                    if (rd != null)
                    {
                        rd.addMessage("Re-projecting feature class to match value raster's projection");
                    }
                    InFeatureClass = reprojectInFeatureClass(InFeatureClass, vRs.RasterInfo.SpatialReference);
                }
            }
            IWorkspace             wksTemp = geoUtil.OpenRasterWorkspace(tempWksStr);
            IFunctionRasterDataset rs      = rsUtil.createIdentityRaster(rsUtil.convertFeatureClassToRaster(InFeatureClass, rasterUtil.rasterType.IMAGINE, wksTemp, outRsNm, vRs.RasterInfo.CellSize.X, (IRasterDataset)vRs));

            rs = rsUtil.createIdentityRaster(rs, rstPixelType.PT_FLOAT);
            int fieldIndex = InFeatureClass.FindField(fldName);

            if (fieldIndex == -1)
            {
                fieldIndex = InFeatureClass.FindField(fldName + "_1");
            }
            if (fldName.ToLower() == InFeatureClass.OIDFieldName.ToLower() || fieldIndex == -1)
            {
                zRs = rs;
            }
            else
            {
                IRemapFilter   rFilt  = new RemapFilterClass();
                IFeatureCursor ftrCur = InFeatureClass.Search(null, false);
                IFeature       ftr    = ftrCur.NextFeature();

                while (ftr != null)
                {
                    double id  = ftr.OID;
                    double nVl = System.Convert.ToDouble(ftr.get_Value(fieldIndex));
                    if (Double.IsNaN(nVl) || Double.IsInfinity(nVl))
                    {
                        ftr = ftrCur.NextFeature();
                    }
                    else
                    {
                        //Console.WriteLine("adding oid = " + id.ToString() + " and value = " + nVl.ToString());
                        rFilt.AddClass(id, id + 1, nVl);
                        ftr = ftrCur.NextFeature();
                    }
                }
                zRs = rsUtil.calcRemapFunction(rs, rFilt);
            }
        }
Example #3
0
        private void cmbSampleFeatureClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            string txt = cmbSampleFeatureClass.Text;

            if (txt == null || txt == "")
            {
                return;
            }
            IWorkspace wks     = ftrDic[txt];
            string     wksPath = wks.PathName;

            plrR.OutWorkspace = geoUtil.OpenRasterWorkspace(wksPath);
            cmbModelDir.Items.Clear();
            System.IO.DirectoryInfo dinfo = new System.IO.DirectoryInfo(wksPath + "\\SASOUTPUT");
            foreach (System.IO.DirectoryInfo dInfo2 in dinfo.GetDirectories())
            {
                cmbModelDir.Items.Add(dInfo2.Name);
            }
            cmbModelDir.SelectedItem = "GENERLIZED_LOGISTIC";
        }
Example #4
0
        private void getFeaturePath(Control cmb, ESRI.ArcGIS.Catalog.IGxObjectFilter flt)
        {
            string outPath = null;
            string outName = "";

            ESRI.ArcGIS.CatalogUI.IGxDialog gxDialog = new ESRI.ArcGIS.CatalogUI.GxDialogClass();
            gxDialog.AllowMultiSelect = false;
            gxDialog.ObjectFilter     = flt;
            gxDialog.Title            = "Select a Feature";
            ESRI.ArcGIS.Catalog.IEnumGxObject eGxObj;
            if (gxDialog.DoModalOpen(0, out eGxObj))
            {
                ESRI.ArcGIS.Catalog.IGxObject gxObj = eGxObj.Next();
                outPath = gxObj.FullName;
                outName = gxObj.BaseName;
                if (cmb.Name.ToLower() == "cmbraster")
                {
                    IRaster oRs = null;
                    if (!rstDic.ContainsKey(outName))
                    {
                        oRs = rsUtil.returnRaster(outPath);
                        rstDic.Add(outName, oRs);
                        cmbRaster.Items.Add(outName);
                    }
                    else
                    {
                        oRs             = rsUtil.returnRaster(outPath);
                        rstDic[outName] = oRs;
                    }
                    object ndv = ((IRasterProps)((IRasterBandCollection)oRs).Item(0)).NoDataValue;
                    //txtNoData.Text = (ndv.ToString());
                }
                else
                {
                    outWks = geoUtil.OpenRasterWorkspace(outPath);
                }
                cmb.Text = outName;
            }
            return;
        }
Example #5
0
        private void createSedimentSurfaces()
        {
            IWorkspace sedWks = geoUtil.OpenRasterWorkspace(sedDir);

            sedRaster = rsUtil.createIdentityRaster(sedRaster, rstPixelType.PT_FLOAT);
            IFeatureCursor ftrCur        = ftrCls.Search(null, false);
            IFeature       ftr           = ftrCur.NextFeature();
            IRemapFilter   fine10        = new RemapFilterClass();
            IRemapFilter   fine50        = new RemapFilterClass();
            IRemapFilter   t1fine10      = new RemapFilterClass();
            IRemapFilter   t1fine50      = new RemapFilterClass();
            IRemapFilter   hsf10         = new RemapFilterClass();
            IRemapFilter   hsf50         = new RemapFilterClass();
            int            fine10Index   = ftrCls.FindField(f10fld);
            int            fine50Index   = ftrCls.FindField(f50fld);
            int            t1fine10Index = ftrCls.FindField(t10fld);
            int            t1fine50Index = ftrCls.FindField(t50fld);
            int            hsf10Index    = ftrCls.FindField(hsf10fld);
            int            hsf50Index    = ftrCls.FindField(hsf50fld);

            IRemapFilter[] remapArr = { fine10, fine50, t1fine10, t1fine50, hsf10, hsf50 };
            int[]          fldArr   = { fine10Index, fine50Index, t1fine10Index, t1fine50Index, hsf10Index, hsf50Index };
            int            cnt      = 0;
            int            numCells = System.Convert.ToInt32(treatCellSize.X / cellSize);

            while (ftr != null)
            {
                //need to set up remap filters for each raster and create a new raster for each sediment value
                double oid = System.Convert.ToInt32(ftr.OID);
                cnt = 0;
                foreach (IRemapFilter remap in remapArr)
                {
                    int    indexVl = fldArr[cnt];
                    double vl      = System.Convert.ToDouble(ftr.get_Value(indexVl)) * (Math.Pow((cellSize * 3.2808399), 2) / 43560);
                    remap.AddClass(oid, oid + 0.00001, vl);
                    // Console.WriteLine("Converting oid " + oid.ToString() + " to " + vl.ToString() );
                    cnt++;
                }
                ftr = ftrCur.NextFeature();
            }
            cnt = 1;
            IFunctionRasterDataset[] rsArr = { rsfine10, rsfine50, rst1Fine10, rst1Fine50, rshsf10, rshsf50 };
            foreach (IRemapFilter remap in remapArr)
            {
                string rsNm = "";
                IFunctionRasterDataset rs = null;
                IFunctionRasterDataset rr = rsUtil.calcRemapFunction(sedRaster, remap);
                //IRaster xx = rsUtil.setnullToValueFunction(rr, 0);
                //IRaster rRs = rsUtil.returnRaster(rsUtil.saveRasterToDataset(xx, "xxx"+cnt.ToString(), tWks, rasterUtil.rasterType.IMAGINE));
                //IRaster rs = calcAgFunction(rr, numCells, rasterUtil.focalType.SUM);
                switch (cnt)
                {
                case 1:
                    rsfine10 = calcAgFunction(rr, "n10", numCells);
                    rs       = rsfine10;
                    rsNm     = "n10";
                    break;

                case 2:
                    rsfine50 = calcAgFunction(rr, "n50", numCells);
                    rs       = rsfine50;
                    rsNm     = "n50";
                    break;

                case 3:
                    rst1Fine10 = calcAgFunction(rr, "t10", numCells);
                    rs         = rst1Fine10;
                    rsNm       = "t10";
                    break;

                case 4:
                    rst1Fine50 = calcAgFunction(rr, "t50", numCells);
                    rs         = rst1Fine50;
                    rsNm       = "t50";
                    break;

                case 5:
                    rshsf10 = calcAgFunction(rr, "h10", numCells);
                    rs      = rshsf10;
                    rsNm    = "h10";
                    break;

                case 6:
                    rshsf50 = calcAgFunction(rr, "h50", numCells);
                    rs      = rshsf50;
                    rsNm    = "h50";
                    break;

                default:
                    break;
                }
                cnt++;
                if (createinter && rsNm != "" && rs != null)
                {
                    rsUtil.saveRasterToDataset(rsUtil.createRaster(rs), rsNm, wks, rasterUtil.rasterType.IMAGINE);
                }
            }
        }
Example #6
0
        public void ConvertGridMetricsToRaster(string metricsDir, string outDir, int[] metrics)
        {
            string[] metricFiles = System.IO.Directory.GetFiles(metricsDir, "*.csv");
            string[] headerFiles = System.IO.Directory.GetFiles(metricsDir, "*.txt");
            IPnt     cellSize;

            IPnt[]     tlPntArr;
            int[]      rwArr;
            int[]      clmArr;
            float      noDataVl;
            IEnvelope  ext     = getExtentsFromHeader(headerFiles, out cellSize, out tlPntArr, out rwArr, out clmArr, out noDataVl);
            IWorkspace outWks  = geoUtil.OpenRasterWorkspace(outDir);
            string     exePath = "\"" + fusDir + "\\" + csv2Grid + "\"";

            IRasterEdit[] rsArr = new IRasterEdit[metrics.Length];
            for (int i = 0; i < metrics.Length; i++)
            {
                int            clm        = metrics[i];
                string         metricName = MetricsArr[clm];
                IRasterDataset rsDset     = rsUtil.createNewRaster(ext, cellSize, outWks, metricName, 1, rstPixelType.PT_FLOAT, rasterUtil.rasterType.IMAGINE, null);//rsWk2.CreateRasterDataset(metricName+".img","IMAGINE Image",ext.LowerLeft,w,h,cellSize.X,cellSize.Y,1,rstPixelType.PT_FLOAT,null,true);
                IRasterBand    rsB        = ((IRasterBandCollection)rsDset).Item(0);
                IRasterProps   rsP        = (IRasterProps)rsB;
                rsP.NoDataValue = noDataVl;
                IRaster rs = ((IRasterDataset2)rsDset).CreateFullRaster();
                rsArr[i] = (IRasterEdit)rs;
            }
            foreach (string s in metricFiles)
            {
                Console.WriteLine("Working on " + s);
                int  pntIndex = System.Array.IndexOf(metricFiles, s);
                IPnt tl = tlPntArr[pntIndex];
                int  cl, rw;
                ((IRaster2)rsArr[0]).MapToPixel(tl.X, tl.Y, out cl, out rw);
                IPnt tlp = new PntClass();
                tlp.X = cl;
                tlp.Y = rw;
                int  rws   = rwArr[pntIndex];
                int  clms  = clmArr[pntIndex];
                IPnt bSize = new PntClass();
                bSize.SetCoords(clms, rws);
                System.Array[] pbSafeArr = new System.Array[metrics.Length];
                IPixelBlock3[] pbArr     = new IPixelBlock3[metrics.Length];
                for (int i = 0; i < metrics.Length; i++)
                {
                    IRasterEdit  rsE = rsArr[i];
                    IRaster      rs  = (IRaster)rsE;
                    IPixelBlock3 pb  = (IPixelBlock3)rs.CreatePixelBlock(bSize);
                    rs.Read(tlp, (IPixelBlock)pb);
                    //pb.Mask(0);
                    pbArr[i] = pb;
                    System.Array vlArr = (System.Array)pb.get_PixelData(0);
                    pbSafeArr[i] = vlArr;
                }
                using (System.IO.StreamReader sr = new System.IO.StreamReader(s))
                {
                    string hdr = sr.ReadLine();
                    while (!sr.EndOfStream)
                    {
                        string   ln    = sr.ReadLine();
                        string[] lnArr = ln.Split(new char[] { ',' });
                        int      r     = (rws - 1) - System.Convert.ToInt32(lnArr[0]);
                        int      c     = System.Convert.ToInt32(lnArr[1]);
                        for (int i = 0; i < metrics.Length; i++)
                        {
                            int   clIndex = metrics[i];
                            float clVl    = System.Convert.ToSingle(lnArr[clIndex]);
                            if (clVl != noDataVl)
                            {
                                pbSafeArr[i].SetValue(clVl, c, r);
                            }
                        }
                    }
                    sr.Close();
                }
                for (int i = 0; i < metrics.Length; i++)
                {
                    IPixelBlock3 pb = pbArr[i];
                    pb.set_PixelData(0, pbSafeArr[i]);
                    rsArr[i].Write(tlp, (IPixelBlock)pb);
                }
            }
            for (int i = 0; i < rsArr.Length; i++)
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(rsArr[i]);
            }
        }