Пример #1
0
 private void createFeatureClass()
 {
     if (outftr == null)
     {
         //mfldIndex = new int[bCnt];
         segIndex = 0;
         IFields     flds  = new FieldsClass();
         IFieldsEdit fldsE = (IFieldsEdit)flds;
         IField      fld   = new FieldClass();
         IFieldEdit  fldE  = (IFieldEdit)fld;
         fldE.Name_2 = "SegID";
         fldE.Type_2 = esriFieldType.esriFieldTypeInteger;
         fldsE.AddField(fldE);
         //IField fld2 = new FieldClass();
         //IFieldEdit fldE2 = (IFieldEdit)fld2;
         //fldE2.Name_2 = "Cluster";
         //fldE2.Type_2 = esriFieldType.esriFieldTypeInteger;
         //fldsE.AddField(fldE2);
         //for (int i = 0; i < bCnt; i++)
         //{
         //    IField mFld = new FieldClass();
         //    IFieldEdit mFldE = (IFieldEdit)mFld;
         //    mFldE.Name_2 = "Band" + i.ToString();
         //    mFldE.Type_2 = esriFieldType.esriFieldTypeDouble;
         //    fldsE.AddField(mFld);
         //}
         outftr   = geoUtil.createFeatureClass((IWorkspace2)OutWorkSpace, OutName, flds, esriGeometryType.esriGeometryPolygon, ((IRasterProps)InputRaster).SpatialReference);
         segIndex = outftr.FindField("SegID");
         //clustIndex = outftr.FindField("Cluster");
         //for (int i = 0; i < bCnt; i++)
         //{
         //    mfldIndex[i] = outftr.FindField("Band" + i.ToString());
         //}
     }
 }
Пример #2
0
        private void createFeatureClass()
        {
            string      ftClsPath = rsUtil.TempMosaicDir + "\\catBnd.shp";
            IFields     flds      = new FieldsClass();
            IFieldsEdit fldsE     = (IFieldsEdit)flds;
            IField      fld       = new FieldClass();
            IFieldEdit  fldE      = (IFieldEdit)fld;

            fldE.Name_2 = "catIndex";
            fldE.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            fldsE.AddField(fldE);
            ftCls = geoUtil.createFeatureClass(ftClsPath, fldsE, esriGeometryType.esriGeometryPolygon, sr);
            int catInd = ftCls.FindField("catIndex");
            int cnt    = 0;

            foreach (IRaster rs in inrs)
            {
                IFeature ftr = ftCls.CreateFeature();
                ftr.set_Value(catInd, cnt);
                IEnvelope        ext   = ((IRasterProps)rs).Extent;
                IPolygon         poly  = new PolygonClass();
                IPointCollection pColl = (IPointCollection)poly;
                pColl.AddPoint(ext.UpperLeft);
                pColl.AddPoint(ext.UpperRight);
                pColl.AddPoint(ext.LowerRight);
                pColl.AddPoint(ext.LowerLeft);
                poly.Close();
                ftr.Shape = poly;
                ftr.Store();
                cnt++;
            }
        }
Пример #3
0
        public IFeatureClass reprojectInFeatureClass(IFeatureClass InFeatureClass, ISpatialReference SpatialReference)
        {
            IWorkspace tempWorkspace = geoUtil.OpenWorkSpace(tempWksStr);
            string     outNm         = ((IDataset)InFeatureClass).BrowseName + "_PR";

            outNm = geoUtil.getSafeOutputNameNonRaster(wks, outNm);
            IFields     outFlds  = new FieldsClass();
            IFieldsEdit outFldsE = (IFieldsEdit)outFlds;
            IField      inFld    = InFeatureClass.Fields.get_Field(InFeatureClass.FindField(ftrField));
            IField      outFld   = new FieldClass();

            if (inFld.Type == esriFieldType.esriFieldTypeOID)
            {
                IFieldEdit outFldE = (IFieldEdit)outFld;
                outFldE.Type_2 = esriFieldType.esriFieldTypeInteger;
                outFldE.Name_2 = inFld.Name;
            }
            else
            {
                IClone cl = (IClone)inFld;
                outFld = (IField)cl.Clone();
            }
            outFldsE.AddField(outFld);
            IFeatureClass outFtrCls = geoUtil.createFeatureClass((IWorkspace2)tempWorkspace, outNm, outFldsE, InFeatureClass.ShapeType, SpatialReference);
            string        ozName    = ftrField;
            int           ozIndex   = outFtrCls.FindField(ozName);

            if (ozIndex == -1)
            {
                ozName  = ftrField + "_1";
                ozIndex = outFtrCls.FindField(ozName);
            }
            int          izIndex = InFeatureClass.FindField(ftrField);
            IQueryFilter qf      = new QueryFilterClass();

            qf.SubFields = InFeatureClass.ShapeFieldName + "," + ftrField;
            IFeatureCursor fCur    = InFeatureClass.Search(qf, false);
            IFeature       ftr     = fCur.NextFeature();
            IWorkspaceEdit wksE    = (IWorkspaceEdit)tempWorkspace;
            bool           weStart = true;

            if (wksE.IsBeingEdited())
            {
                weStart = false;
            }
            else
            {
                wksE.StartEditing(false);
            }
            wksE.StartEditOperation();
            try
            {
                while (ftr != null)
                {
                    object          vl   = ftr.get_Value(izIndex);
                    IFeatureProject ftrP = (IFeatureProject)ftr;
                    ftrP.Project(SpatialReference);
                    IFeature oFtr = outFtrCls.CreateFeature();
                    oFtr.Shape = ftr.Shape;
                    if (ozIndex > -1)
                    {
                        oFtr.set_Value(ozIndex, vl);
                    }
                    oFtr.Store();
                    ftr = fCur.NextFeature();
                }
                ftrField = ozName;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                wksE.StopEditOperation();
                if (weStart)
                {
                    wksE.StopEditing(true);
                }
            }
            return(outFtrCls);
        }
Пример #4
0
 public void RunCloudMetrics(IFeatureClass sampleLocation, float sampleRadius, string LasDir, string DtmDir = "", double cutBelow = 0, double cutAbove = 150, int shape = 0)
 {
     if (fusionInstalled)
     {
         string      LasDatasetPath  = LasDir + "\\LasFile.lasd";
         string      LasFeatureClass = LasDir + "\\LasBoundary.shp";
         ILasDataset lsDset          = new LasDatasetClass();
         ((ILasDataset2)lsDset).SaveAs(LasDatasetPath, true);
         ILasDatasetEdit lsDsetE = (ILasDatasetEdit)lsDset;
         IStringArray    sArr;
         lsDsetE.AddFolder(LasDir, "las", true, out sArr);
         lsDsetE.Save();
         ISpatialReference sp        = lsDset.SpatialReference;
         IFeatureClass     extFtrCls = geoUtil.createFeatureClass(LasFeatureClass, null, esriGeometryType.esriGeometryPolygon, sp);
         string            lasName   = geoUtil.createField(extFtrCls, "LasName", esriFieldType.esriFieldTypeString, false);
         IFeatureCursor    ftrCur    = extFtrCls.Insert(true);
         IFeatureBuffer    ftrBuff   = extFtrCls.CreateFeatureBuffer();
         int lasNameIndex            = extFtrCls.FindField(lasName);
         for (int i = 0; i < lsDset.FileCount; i++)
         {
             ILasFile  lsFile = lsDset.get_File(i);
             string    lsPath = lsFile.Name;
             IEnvelope lsEnv  = lsFile.Extent;
             IPolygon  poly   = new PolygonClass();
             poly.SpatialReference = sp;
             IPointCollection pCol = (IPointCollection)poly;
             pCol.AddPoint(lsEnv.LowerLeft);
             pCol.AddPoint(lsEnv.UpperLeft);
             pCol.AddPoint(lsEnv.UpperRight);
             pCol.AddPoint(lsEnv.LowerRight);
             poly.Close();
             ftrBuff.Shape = poly;
             ftrBuff.set_Value(lasNameIndex, lsPath);
             ftrCur.InsertFeature(ftrBuff);
         }
         ftrCur.Flush();
         System.Runtime.InteropServices.Marshal.ReleaseComObject(ftrCur);
         int[]          cloudMetricFieldsIndex = addCloudMetricFields(sampleLocation);
         IFeatureCursor pntCur = sampleLocation.Update(null, true);
         IFeature       pntftr = pntCur.NextFeature();
         while (pntftr != null)
         {
             Console.WriteLine("Working on Plot OID = " + pntftr.OID.ToString());
             IGeometry geo = pntftr.Shape;
             IPoint    pnt = (IPoint)geo;
             IEnvelope env = new EnvelopeClass();
             env.PutCoords(pnt.X - sampleRadius, pnt.Y - sampleRadius, pnt.X + sampleRadius, pnt.Y + sampleRadius);
             ISpatialFilter sf = new SpatialFilterClass();
             sf.Geometry   = env;
             sf.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
             IFeatureCursor polyCur  = extFtrCls.Search(sf, true);
             IFeature       polyftr  = polyCur.NextFeature();
             List <string>  lasFiles = new List <string>();
             while (polyftr != null)
             {
                 lasFiles.Add(polyftr.get_Value(lasNameIndex).ToString());
                 polyftr = polyCur.NextFeature();
             }
             System.Runtime.InteropServices.Marshal.ReleaseComObject(polyCur);
             if (lasFiles.Count > 0)
             {
                 //Console.WriteLine("Number of las files for point " + pntftr.OID.ToString() + " = " + lasFiles.Count.ToString());
                 object[] metricValues = extractCloudMetrics(env, lasFiles, 0, DtmDir, cutBelow, cutAbove, shape);
                 for (int i = 0; i < metricValues.Length; i++)
                 {
                     object vl      = metricValues[i];
                     int    vlIndex = cloudMetricFieldsIndex[i];
                     if (vlIndex > -1)
                     {
                         pntftr.set_Value(vlIndex, vl);
                     }
                 }
             }
             pntCur.UpdateFeature(pntftr);
             pntftr = pntCur.NextFeature();
         }
     }
 }