Exemple #1
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            //1 Get two data before and after lossy compression (Data is stored in the form of feature class)
            string gdbPath            = @"filePath\fileName.gdb";
            string beforeFeaClassName = "FeatureClassNameXXX";
            string afterFeaClassName  = "FeatureClassNameXXX";

            CommonTool    CommonTool     = new CommonTool(gdbPath);
            IFeatureClass beforeFeaClass = CommonTool.OpenFeatureClass(beforeFeaClassName); //Data before lossy compression
            IFeatureClass afterFeaClass  = CommonTool.OpenFeatureClass(afterFeaClassName);  //data after lossy compression
            int           elementIdIndex = beforeFeaClass.FindField("id");                  //Get attribute address

            //2 Statistics and output of accuracy loss results
            // Output address settings for experimental results
            string filePath = System.IO.Directory.GetCurrentDirectory() + "\\FolderName";

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            string       txtPath = filePath + "\\FileName" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
            StreamWriter sw      = new StreamWriter(txtPath, true);

            // Get the element Id set
            List <int>     idList    = new List <int>();
            IFeatureCursor feaCursor = beforeFeaClass.Search(null, false);
            IFeature       fea       = null;

            while ((fea = feaCursor.NextFeature()) != null)
            {
                string feaIdStr = fea.get_Value(elementIdIndex).ToString();
                if (feaIdStr == "")
                {
                    continue;
                }
                int feaId = int.Parse(feaIdStr);
                if (!idList.Contains(feaId))
                {
                    idList.Add(feaId);
                }
            }

            double       geometricChangeRatioSum = 0; //Total loss of geometric accuracy
            double       semanticChangeRatioSum  = 0; //Total loss of semantic accuracy
            IQueryFilter qf = new QueryFilterClass();

            for (int i = 0; i < idList.Count; i++)
            {
                qf.WhereClause = "id =" + idList[i];

                // Statistical differences in the number of units before and after fusion
                double beforeUnitCount      = beforeFeaClass.FeatureCount(qf);
                double afterUnitCount       = afterFeaClass.FeatureCount(qf);
                double geometricChangeRatio = Math.Abs(beforeUnitCount - afterUnitCount) / beforeUnitCount;
                geometricChangeRatioSum += geometricChangeRatio;

                //Statistical semantic accuracy loss
                //Get the ObjectID of units in element region before fusion
                IFeatureCursor fCursor      = beforeFeaClass.Search(qf, false);
                IFeature       f            = null;
                List <int>     beforeIdList = new List <int>();

                while ((f = fCursor.NextFeature()) != null)
                {
                    beforeIdList.Add(f.OID);
                }
                double beforCount = beforeIdList.Count;//the number of units in element region before fusion

                //Get the ObjectID of units in element region after fusion
                fCursor = afterFeaClass.Search(qf, false);
                f       = null;
                List <int> afterIdList = new List <int>();

                while ((f = fCursor.NextFeature()) != null)
                {
                    afterIdList.Add(f.OID);
                }

                double afterCount       = afterIdList.Count; //the number of units in element region after fusion
                double coincidenceCount = 0;                 //the number of coincidence units

                //Get the number of coincidence units in two regions before and after fusion
                for (int j = 0; j < beforeIdList.Count; j++)
                {
                    if (afterIdList.Contains(beforeIdList[j]))
                    {
                        coincidenceCount++;
                    }
                }

                double semanticChangeCountRatio = (Math.Abs(beforCount - coincidenceCount) + Math.Abs(afterCount - coincidenceCount)) / beforCount; //Get the semantic accuracy loss
                semanticChangeRatioSum += semanticChangeCountRatio;                                                                                 //Update the semantic accuracy loss

                //output result of individual element region
                sw.WriteLine("Element Id," + idList[i] + ",Units number before fusion," + beforeUnitCount + ",Units number after fusion," + afterUnitCount + ",Geometric accuracy loss," + geometricChangeRatio + ",Semantic accuracy loss," + semanticChangeCountRatio);
                sw.Flush();
            }

            // Output overall statistical result
            sw.WriteLine("Average geometric accuracy loss," + geometricChangeRatioSum / idList.Count + ",Average semantic accuracy loss," + semanticChangeRatioSum / idList.Count);
            sw.Flush();
            sw.Close();;
            MessageBox.Show("OK");
        }
Exemple #2
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            //1 Gosper curve construction
            //1.1 Generate character encoding
            int    iterateNum = 3;   //Set the number of iterations
            string codeString = "A"; //Initial encoding

            //Iterative replacement of encoding by regular expression
            string         replace        = "A|B";
            Regex          regex          = new Regex(replace);
            MatchEvaluator matchEvaluator = new MatchEvaluator(Rules);

            //Complete the specified number of iterations
            for (int i = 0; i < iterateNum; i++)
            {
                codeString = regex.Replace(codeString, matchEvaluator);
            }
            ///1.2 Generate Gosper curves according to character encoding
            //Start point setting
            GosperX = oriX;
            GosperY = oriY;
            IPoint oriPt = new PointClass();

            oriPt.X = GosperX;
            oriPt.Y = GosperY;

            //Add start point to node set
            curvePtCol = new PolylineClass();
            curvePtCol.AddPoint(oriPt);

            //Translate character encoding and draw according to its meaning
            for (int i = 0; i < codeString.Length; i++)
            {
                string order = codeString[i].ToString();
                switch (order)
                {
                case "A":
                case "B":
                    GenerateGosperNode(forwardAngle);
                    break;

                case "-":
                    forwardAngle -= Math.PI / 3;    //Turn 60 degrees counter clockwise
                    break;

                case "+":
                    forwardAngle += Math.PI / 3;    //Turn 60 degrees clockwise
                    break;
                }
            }

            //2 Output the generated Gosper curve
            //Output address settings
            string     gdbPath        = @"FilePath\FileName.gdb";
            string     GosperLineName = "GosperLine";//Set the output name
            CommonTool commonTool     = new CommonTool(gdbPath);

            //Output the result
            GosperLine = curvePtCol as IPolyline;
            IFeatureClass gosperLineFeaClass = commonTool.CreateFeatureClassWithoutAttribute(GosperLineName, esriGeometryType.esriGeometryPolyline);
            IFeature      lineFea            = gosperLineFeaClass.CreateFeature();

            lineFea.Shape = GosperLine;
            lineFea.Store();

            MessageBox.Show("OK");
        }