Exemple #1
0
        private bool CREATEPOLYGONFEATURE(string sClassName, string sPoints, string sVars)
        {
            IFeatureClass pFC;
            IFeatureWorkspace pFWKS;
            IFeature pFeat;
            IPolygon pPolygon;
            IPoint[] pPts;
            IMxDocument pMXDoc;
            IGeometryBridge2 pGeoBrg;
            IPointCollection4 pPointColl;
            string[,] sVar;

            try
            {
                SW1.Reset();
                SW1.Start();
                pMXDoc = GetDoc();
                pPts = GetPoints(sPoints, pMXDoc.FocusMap.SpatialReference);
                if (pPts != null)
                {
                    if (pPts.GetUpperBound(0) > 0)
                    {
                        sVar = GetVars(sVars);
                        pGeoBrg = new GeometryEnvironment() as IGeometryBridge2;
                        pPointColl = new PolygonClass();
                        pGeoBrg.AddPoints(pPointColl, pPts);
                        pFWKS = (IFeatureWorkspace)Workspace;
                        pFC = pFWKS.OpenFeatureClass(sClassName);
                        if (pFC != null)
                        {
                            if (pEditor != null)
                            {
                                pEditor.StartOperation();
                                pFeat = pFC.CreateFeature();
                                pPolygon = (IPolygon)pPointColl;
                                pFeat.Shape = (IGeometry)pPolygon;
                                SetFields(pFeat, sVar);
                                pFeat.Store();
                                Logger.WriteLine("OID:" + pFeat.OID);
                                pEditor.StopOperation("Create Polygon");
                            }
                            else
                            {
                                Logger.WriteLine("Editor not found");
                            }
                        }
                        SW1.Stop();
                        RecordActionTime("CreatePOYGONFeature: " ,SW1.ElapsedMilliseconds);
                        return true;
                    }
                    else
                    {
                        Logger.WriteLine("Missing Geometry");
                        return false;
                    }
                }
                else
                {
                    Logger.WriteLine("Null Geometry");
                    return false;
                }
            }
            catch (COMException ComEX)
            {
                Logger.WriteLine("Error in CreatePOLYGONFeature: " + ComEX.ErrorCode + " :" + ComEX.Message + ":" + ComEX.StackTrace);
                return false;
            }
            catch (Exception EX)
            {
                Logger.WriteLine("Error in CreatePOLYGONFeature: " + EX.Message + ":" + EX.StackTrace);
                return false;
            }
        }