Example #1
0
 private void convertFeatureClass()
 {
     if (RoadRaster == null)
     {
         IFeatureClassDescriptor ftrDesc = new FeatureClassDescriptorClass();
         IQueryFilter            qf      = new QueryFilterClass();
         ftrDesc.Create(RoadFeatureClass, qf, RoadsSpeedField);
         IConversionOp convOp = new RasterConversionOpClass();
         IRasterAnalysisEnvironment       rasterAnalysisEnvironment       = (IRasterAnalysisEnvironment)convOp;
         IRasterAnalysisGlobalEnvironment rasterAnalysisGlobalEnvironment = (IRasterAnalysisGlobalEnvironment)convOp;
         rasterAnalysisGlobalEnvironment.AvoidDataConversion = true;
         rasterAnalysisEnvironment.OutSpatialReference       = sp;
         rasterAnalysisEnvironment.OutWorkspace = OutWorkspace;
         //object cells = Dem.RasterInfo.CellSize;
         object ext = ((IGeoDataset)RoadFeatureClass).Extent;
         //object snap = ((IGeoDataset)Dem);
         rasterAnalysisEnvironment.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, Dem);
         rasterAnalysisEnvironment.SetExtent(esriRasterEnvSettingEnum.esriRasterEnvValue, ext, Dem);
         string                 outRdName = rsUtil.getSafeOutputName(OutWorkspace, "sRoads");
         IRasterDataset         geoDset   = convOp.ToRasterDataset((IGeoDataset)ftrDesc, "GRID", OutWorkspace, outRdName);
         IGeoDatasetSchemaEdit2 geoSch    = (IGeoDatasetSchemaEdit2)geoDset;
         if (geoSch.CanAlterSpatialReference)
         {
             geoSch.AlterSpatialReference(rasterAnalysisEnvironment.OutSpatialReference);
         }
         RoadRaster = rsUtil.createIdentityRaster(geoDset);
     }
 }
Example #2
0
        private void getFeaturePath()
        {
            string outPath = null;
            string outName = "";

            ESRI.ArcGIS.CatalogUI.IGxDialog gxDialog = new ESRI.ArcGIS.CatalogUI.GxDialogClass();
            gxDialog.AllowMultiSelect = true;
            ESRI.ArcGIS.Catalog.IGxObjectFilter flt = null;
            flt = new ESRI.ArcGIS.Catalog.GxFilterRasterDatasetsClass();
            gxDialog.ObjectFilter = flt;
            gxDialog.Title        = "Select a Raster";
            ESRI.ArcGIS.Catalog.IEnumGxObject eGxObj;
            if (gxDialog.DoModalOpen(0, out eGxObj))
            {
                ESRI.ArcGIS.Catalog.IGxObject gxObj = eGxObj.Next();
                while (gxObj != null)
                {
                    outPath = gxObj.FullName;
                    outName = gxObj.BaseName;
                    if (!rstDic.ContainsKey(outName))
                    {
                        rstDic.Add(outName, rsUtil.createIdentityRaster(outPath));
                        //cmbInRaster1.Items.Add(outName);
                        lsbRaster.Items.Add(outName);
                    }
                    else
                    {
                        rstDic[outName] = rsUtil.createIdentityRaster(outPath);
                    }
                    gxObj = eGxObj.Next();
                }
                //cmbInRaster1.SelectedItem = outName;
            }
            return;
        }
Example #3
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 #4
0
        private string getRaster()
        {
            string[] nm;
            ESRI.ArcGIS.Catalog.IGxObjectFilter flt = new ESRI.ArcGIS.Catalog.GxFilterRasterDatasetsClass();
            string rstPath = frmHlp.getPath(flt, out nm, false)[0];

            frmHlp.FunctionRasterDictionary[nm[0]] = rsUtil.createIdentityRaster(rstPath);
            return(nm[0]);
        }
Example #5
0
        private void setRasterType()
        {
            string wksPath = wks.PathName;

            if (wksPath.EndsWith(".accdb") || wksPath.EndsWith(".mdb") || wksPath.EndsWith(".sde"))
            {
                rsType = rasterUtil.rasterType.GDB;
            }
            else
            {
                rsType = rasterUtil.rasterType.IMAGINE;
            }
            string lastRS  = "";
            bool   checkNA = false;

            foreach (string s in System.IO.Directory.GetFiles(resultsDir, "arrivaltime*.txt"))
            {
                lastRS = System.IO.Path.GetFileNameWithoutExtension(s);
                string[] sArr   = lastRS.Split(new char[] { '_' });
                int      perNum = System.Convert.ToInt32(sArr[2]);
                if (perNum > numPer)
                {
                    numPer = perNum;
                }
                int firNum = System.Convert.ToInt32(sArr[1]);
                if (firNum > numFir)
                {
                    numFir = firNum;
                }
                int iterNum = System.Convert.ToInt32(sArr[0].Replace("arrivaltime", ""));
                if (iterNum == 0)
                {
                    checkNA = true;
                }
                if (iterNum > numIter)
                {
                    numIter = iterNum;
                }
                lastRS = s;
            }
            if (checkNA && numIter > 0)
            {
                iterLst.Add(0);
            }
            iterLst.Add(numIter);
            snapRaster = rsUtil.createIdentityRaster(lastRS);
        }
Example #6
0
        private void getFeaturePath()
        {
            ESRI.ArcGIS.Catalog.IGxObjectFilter flt = new ESRI.ArcGIS.Catalog.GxFilterRasterDatasetsClass();
            string[] nm;
            string   outPath = frmHlp.getPath(flt, out nm, false)[0];
            string   outName = nm[0];

            frmHlp.FunctionRasterDictionary[outName] = rsUtil.createIdentityRaster(outPath);
            cmbInRaster1.Text = outName;
            return;
        }
Example #7
0
 private void populateCmb()
 {
     if (mp != null)
     {
         IEnumLayer rstLyrs = vUtil.getActiveViewLayers(viewUtility.esriIRasterLayer);
         ILayer     lyr     = rstLyrs.Next();
         while (lyr != null)
         {
             string       lyrNm  = lyr.Name;
             IRasterLayer rstLyr = (IRasterLayer)lyr;
             IRaster      rst    = rsUtil.createRaster(((IRaster2)rstLyr.Raster).RasterDataset);
             if (!rstDic.ContainsKey(lyrNm))
             {
                 IDataset dSet = (IDataset)((IRaster2)rst).RasterDataset;
                 rstDic.Add(lyrNm, rsUtil.createIdentityRaster(rst));
                 lyrDic.Add(lyrNm, dSet.Workspace.PathName + "\\" + dSet.BrowseName);
                 lsbLayers.Items.Add(lyrNm);
             }
             lyr = rstLyrs.Next();
         }
         IEnumLayer ftrLyrs = vUtil.getActiveViewLayers(viewUtility.esriIFeatureLayer);
         lyr = ftrLyrs.Next();
         while (lyr != null)
         {
             string        lyrNm  = lyr.Name;
             IFeatureLayer ftrLyr = (IFeatureLayer)lyr;
             IFeatureClass ftrCls = ftrLyr.FeatureClass;
             if (!ftrDic.ContainsKey(lyrNm))
             {
                 ftrDic.Add(lyrNm, ftrCls);
                 IDataset dSet = (IDataset)ftrCls;
                 lyrDic.Add(lyrNm, dSet.Workspace.PathName + "\\" + dSet.BrowseName);
                 lsbLayers.Items.Add(lyrNm);
             }
             lyr = rstLyrs.Next();
         }
     }
     lsbFunctions.Items.AddRange(Enum.GetNames(typeof(batchCalculations.batchGroups)));
     lsbFunctions.SelectedItem = lsbFunctions.Items[0];
 }
Example #8
0
        private void getPath(bool isRaster)
        {
            string outPath = null;
            string outName = "";

            ESRI.ArcGIS.CatalogUI.IGxDialog gxDialog = new ESRI.ArcGIS.CatalogUI.GxDialogClass();
            gxDialog.AllowMultiSelect = false;
            ESRI.ArcGIS.Catalog.IGxObjectFilter flt = null;
            if (isRaster)
            {
                flt = new ESRI.ArcGIS.Catalog.GxFilterDatasetsClass();
            }
            else
            {
                flt = new ESRI.ArcGIS.Catalog.GxFilterFileGeodatabasesClass();
            }
            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 (isRaster)
                {
                    string           wksPath    = geoUtil.getDatabasePath(outPath);
                    IWorkspace       wks        = geoUtil.OpenWorkSpace(wksPath);
                    IEnumDatasetName rsDsetName = wks.get_DatasetNames(esriDatasetType.esriDTRasterDataset);
                    bool             rsCheck    = false;
                    IDatasetName     dsName     = rsDsetName.Next();
                    while (dsName != null)
                    {
                        if (outName.ToLower() == dsName.Name.ToLower())
                        {
                            rsCheck = true;
                            break;
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(dsName);
                        dsName = rsDsetName.Next();
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rsDsetName);
                    if (rsCheck)
                    {
                        if (!rstDic.ContainsKey(outName))
                        {
                            rstDic.Add(outName, rsUtil.createIdentityRaster(outPath));
                            cmbRst.Items.Add(outName);
                        }
                        else
                        {
                            rstDic[outName] = rsUtil.createIdentityRaster(outPath);
                        }
                    }
                    else
                    {
                        ftrDic[outName] = geoUtil.getFeatureClass(outPath);
                    }
                    cmbRst.Text = outName;
                }
                else
                {
                    txtOutWorkspace.Text = outPath;
                }
            }
            return;
        }
Example #9
0
        private void setInRs()
        {
            IFunctionRasterDataset dset = rsUtil.getBand(valueraster, 0);

            inrs = rsUtil.createIdentityRaster(dset, rstPixelType.PT_FLOAT);
        }
Example #10
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string strataStr = cmbStrata.Text;
            string plotsStr  = cmbPlots.Text;
            string standsStr = cmbStands.Text;

            if (strataStr == null || strataStr == "")
            {
                MessageBox.Show("You must specify a Stratification layer", "No Zone", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (plotsStr == null || plotsStr == "")
            {
                MessageBox.Show("You must specify a plots layer", "No Value", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (lsbFields.Items.Count < 1)
            {
                MessageBox.Show("You must select at least on Field to summarize", "No Fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            List <IField> fldLst    = new List <IField>();
            IFeatureClass pltFtrCls = ftrDic[plotsStr];

            for (int i = 0; i < lsbFields.Items.Count; i++)
            {
                IField fld = pltFtrCls.Fields.get_Field(pltFtrCls.FindField(lsbFields.Items[i].ToString()));
                fldLst.Add(fld);
            }
            this.Visible = false;


            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Summarizing plots. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            //Statistics.ModelHelper.runProgressBar("Summarizing");
            try
            {
                IFeatureClass standFtrCls = null;
                if (ftrDic.ContainsKey(standsStr))
                {
                    standFtrCls = ftrDic[standsStr];
                }
                if (rstDic.ContainsKey(strataStr))
                {
                    rp.addMessage("Summarizing FIA plots using raster...");
                    IRaster strataRs = rstDic[strataStr];
                    IFunctionRasterDataset stratafDset = rsUtil.createIdentityRaster(strataRs);
                    //outTbl = rsUtil.zonalStats(zRs, vRs, oTbl, rsLst.ToArray(), rp, chbClassCounts.Checked);
                    fiaIntegration.summarizeBiomassPolygon(pltFtrCls, fldLst.ToArray(), stratafDset, standFtrCls, geoUtil, rsUtil);
                }
                else
                {
                    rp.addMessage("Summarizing FIA plots using polygon");
                    rp.Refresh();
                    IFeatureClass strataFtr = ftrDic[strataStr];
                    //outTbl = rsUtil.zonalStats(zFtr, zFld, vRs, oTbl, rsLst.ToArray(), rp, chbClassCounts.Checked);
                    fiaIntegration.summarizeBiomassPolygon(pltFtrCls, fldLst.ToArray(), strataFtr, standFtrCls, geoUtil);
                }
                if (mp != null && addToMap)
                {
                    rp.Refresh();
                }

                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
            }
            finally
            {
                Statistics.ModelHelper.closeProgressBar();
                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 .";
                rp.stepPGBar(100);
                rp.addMessage("Finished summarizing" + t);
                rp.enableClose();
                this.Close();
            }
        }
Example #11
0
        private void getFeaturePath(bool featureClass)
        {
            string outPath = null;
            string outName = "";

            ESRI.ArcGIS.CatalogUI.IGxDialog gxDialog = new ESRI.ArcGIS.CatalogUI.GxDialogClass();
            gxDialog.AllowMultiSelect = false;
            ESRI.ArcGIS.Catalog.IGxObjectFilter flt = null;
            if (featureClass)
            {
                flt = new ESRI.ArcGIS.Catalog.GxFilterPointFeatureClassesClass();
            }
            else
            {
                flt = new ESRI.ArcGIS.Catalog.GxFilterDatasets();
            }
            gxDialog.ObjectFilter = flt;
            gxDialog.Title        = "Select";
            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 (featureClass)
                {
                    ftrDic[outName] = geoUtil.getFeatureClass(outPath);
                    cmbSampleFeatureClass.Items.Add(outName);
                    cmbSampleFeatureClass.Text = outName;
                }
                else
                {
                    string       wksPath = geoUtil.getDatabasePath(outPath);
                    IWorkspace   wks     = geoUtil.OpenWorkSpace(wksPath);
                    IEnumDataset rsDset  = wks.get_Datasets(esriDatasetType.esriDTAny);
                    bool         rsCheck = false;
                    IDataset     ds      = rsDset.Next();
                    while (ds != null)
                    {
                        if (outName.ToLower() == ds.Name.ToLower() && (ds.Type == esriDatasetType.esriDTMosaicDataset || ds.Type == esriDatasetType.esriDTRasterDataset || ds.Type == esriDatasetType.esriDTRasterCatalog))
                        {
                            rsCheck = true;
                            break;
                        }
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(ds);
                        ds = rsDset.Next();
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(rsDset);
                    if (rsCheck)
                    {
                        rstDic[outName] = rsUtil.createIdentityRaster(outPath);
                        cmbRaster.Items.Add(outName);
                        cmbRaster.Text = outName;
                    }
                    else
                    {
                        ftrDic[outName] = geoUtil.getFeatureClass(outPath);
                        cmbRaster.Items.Add(outName);
                        cmbRaster.Text = outName;
                    }
                }
            }
            return;
        }
Example #12
0
        private void btnClip_Click(object sender, EventArgs e)
        {
            string rstNm     = cmbInRaster1.Text;
            string outNm     = txtOutName.Text;
            string newXValue = txtValueX.Text;
            string newYValue = txtValueY.Text;

            if (newXValue == "" || newXValue == null || newYValue == "" || newYValue == null || rstNm == "" || rstNm == null)
            {
                MessageBox.Show("You must have a raster layer selected and valid x and y values", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNm == "" || outNm == null)
            {
                MessageBox.Show("You must specify an output raster name", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Transforming Raster. This may take a while...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            try
            {
                IRaster rst = rstDic[rstNm];
                IFunctionRasterDataset fRst = rsUtil.createIdentityRaster(rst);
                double vlX = System.Convert.ToDouble(newXValue) * fRst.RasterInfo.CellSize.X;
                double vlY = System.Convert.ToDouble(newYValue) * fRst.RasterInfo.CellSize.Y;
                outraster = rsUtil.createRaster(rsUtil.shiftRasterFunction(rst, vlX, vlY));
                if (mp != null && addToMap)
                {
                    rp.addMessage("Calculating Statistics...");

                    rp.Refresh();
                    IRasterLayer rstLyr = new RasterLayerClass();
                    //rsUtil.calcStatsAndHist(((IRaster2)outraster).RasterDataset);
                    rstLyr.CreateFromRaster(outraster);
                    rstLyr.Name    = outNm;
                    rstLyr.Visible = false;
                    mp.AddLayer(rstLyr);
                }
                outrastername     = outNm;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.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 .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Transforming Raster" + t);
                rp.enableClose();
                this.Close();
            }
        }
Example #13
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            string inRst1Nm = cmbInRaster1.Text;
            string inRst2Nm = cmbInRaster2.Text;
            string outNmRst = txtOutName.Text;
            int    pChange  = trbPercent.Value;

            if (inRst1Nm == "" || inRst1Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 1 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (inRst2Nm == "" || inRst2Nm == null)
            {
                MessageBox.Show("You must specify an input raster for In Raster 2 or type in a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (outNmRst == "" || outNmRst == null)
            {
                MessageBox.Show("You must specify an output raster name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            IRaster rs1 = rstDic[inRst1Nm];
            IRaster rs2 = rstDic[inRst2Nm];

            this.Visible = false;
            esriUtil.Forms.RunningProcess.frmRunningProcessDialog rp = new RunningProcess.frmRunningProcessDialog(false);
            DateTime dt = DateTime.Now;

            rp.addMessage("Creating Raster. This may take a while...");
            rp.addMessage("Calculating Statistics...");
            rp.stepPGBar(10);
            rp.TopMost = true;
            rp.Show();
            rp.Refresh();
            normalization nm = new normalization(rsUtil.createIdentityRaster(rs1), rsUtil.createIdentityRaster(rs2), pChange, rsUtil);

            try
            {
                double[][] coef = nm.Coefficients;
                outraster     = rsUtil.createRaster(nm.OutRaster);
                outrastername = outNmRst;
                int bCnt = ((IRasterBandCollection)outraster).Count;
                for (int i = 0; i < bCnt; i++)
                {
                    double[] intSlp    = coef[i];
                    double   intercept = intSlp[0];
                    double   slope     = intSlp[1];
                    double   r2        = intSlp[2];
                    rp.addMessage("R2, Intercept, Slope (" + (i + 1).ToString() + ") = " + r2.ToString() + ", " + intercept.ToString() + ", " + slope.ToString());
                }
                if (!(txtModelPath.Text == "" || txtModelPath.Text == null))
                {
                    nm.writeModel(txtModelPath.Text);
                }
                if (mp != null && aM)
                {
                    //rsUtil.calcStatsAndHist(((IRaster2)outRs).RasterDataset);
                    IRasterLayer rsLyr = new RasterLayerClass();
                    rsLyr.CreateFromRaster(outraster);
                    rsLyr.Name    = outrastername;
                    rsLyr.Visible = false;
                    mp.AddLayer((ILayer)rsLyr);
                }
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                rp.addMessage(ex.ToString());
                Console.WriteLine(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 .";
                rp.stepPGBar(100);
                rp.addMessage("Finished Normalizing Image" + t);
                rp.enableClose();
                this.Close();
            }
        }