ArcStrabo10.ArcStraboObject.addPoligonGeorefrenced C# (CSharp) Метод

addPoligonGeorefrenced() публичный Метод

public addPoligonGeorefrenced ( IFeatureLayer featureLayer, IFeatureWorkspace featureworkspace ) : void
featureLayer IFeatureLayer
featureworkspace IFeatureWorkspace
Результат void
        public void addPoligonGeorefrenced(IFeatureLayer featureLayer, IFeatureWorkspace featureworkspace)
        {
            try
            {
                //Define vertices

                if (_rasterInfo.rasterType != "Unknown")
                    convertPolygon();

                IMap map = ArcMap.Document.FocusMap;
                AddGraphicToMap(map);
                IWorkspaceEdit editWorkspace = featureworkspace as IWorkspaceEdit;
                editWorkspace.StartEditing(true);
                editWorkspace.StartEditOperation();
                int count = 0;
                if (_rasterInfo.rasterType != "Unknown")
                    count = lngLatSet.Length;
                else
                    count = pointSet.Length;

                for (int j = 0; j < count; j++)
                {
                    IPoint pPoint1 = new ESRI.ArcGIS.Geometry.Point();
                    IPoint pPoint2 = new ESRI.ArcGIS.Geometry.Point();
                    IPoint pPoint3 = new ESRI.ArcGIS.Geometry.Point();
                    IPoint pPoint4 = new ESRI.ArcGIS.Geometry.Point();

                    if (_rasterInfo.rasterType != "Unknown")
                    {
                        pPoint1.PutCoords(lngLatSet[j].leftTopX, lngLatSet[j].leftTopY);
                        pPoint2.PutCoords(lngLatSet[j].rightTopX, lngLatSet[j].rightTopY);
                        pPoint3.PutCoords(lngLatSet[j].rightDownX, lngLatSet[j].rightDownY);
                        pPoint4.PutCoords(lngLatSet[j].leftDownX, lngLatSet[j].leftDownY);
                    }
                    else
                    {
                        // if (pointSet[j].leftTopY < 0)
                        {
                            pPoint1.PutCoords(pointSet[j].leftTopX, pointSet[j].leftTopY);
                            pPoint2.PutCoords(pointSet[j].rightTopX, pointSet[j].rightTopY);
                            pPoint3.PutCoords(pointSet[j].rightDownX, pointSet[j].rightDownY);
                            pPoint4.PutCoords(pointSet[j].leftDownX, pointSet[j].leftDownY);
                        }
                        //else if (_rasterInfo.ratserNegative<0)
                        //{
                        //    pPoint1.PutCoords(pointSet[j].leftTopX, pointSet[j].leftTopY *-1);
                        //    pPoint2.PutCoords(pointSet[j].rightTopX, pointSet[j].rightTopY*-1);
                        //    pPoint3.PutCoords(pointSet[j].rightDownX, pointSet[j].rightDownY*-1);
                        //    pPoint4.PutCoords(pointSet[j].leftDownX, pointSet[j].leftDownY*-1);
                        //}

                    }

                    IPointCollection pPolygon = new Polygon();
                    IPointCollection pPointCollection = pPolygon as IPointCollection;
                    //Add the vertices of the polygon
                    pPointCollection.AddPoints(1, ref pPoint1);
                    pPointCollection.AddPoints(1, ref pPoint2);
                    pPointCollection.AddPoints(1, ref pPoint3);
                    pPointCollection.AddPoints(1, ref pPoint4);

                    ((IPolygon)pPolygon).Close();
                    IFeature iFeature = featureLayer.FeatureClass.CreateFeature();
                    iFeature.Shape = (IPolygon)pPolygon;
                    iFeature.Store();
                    //Feature cursor used to loop through all features in feature class, optionally a query filter can be used.
                    if (_rasterInfo.rasterType != "Unknown")
                    {
                        int num = featureLayer.FeatureClass.FindField("URI");
                        iFeature.set_Value(num, lngLatSet[j].URI.ToString());
                    }
                    iFeature.Store();
                }
                IFeatureCursor fcCursor = featureLayer.FeatureClass.Update(null, true);
                //Stop the operation and provide a name to add to the operation stack.
                editWorkspace.StartEditOperation();
                //Stop editing and save the edits.
                editWorkspace.StopEditing(true);

                map.AddLayer(featureLayer);
            }
            catch (Exception e)
            {
                Log.WriteLine("AddPolygon: " + e.Message);
            }
        }

Usage Example

        protected override void OnClick()
        {
            #region Symbel Recognition
            ArcStrabo10.ArcStraboObject.RasterMapInfo rasterInfo = new ArcStrabo10.ArcStraboObject.RasterMapInfo();
            string dir = "";
            ArcStraboObject arcStraboObject = new ArcStraboObject();
            arcStraboObject.symbolFindRasterLayerPath(rasterInfo);

            string logPath = arcStraboObject.CreateDirectory(rasterInfo.rasterPath, "Log");

            Log.SetLogDir(System.IO.Path.GetTempPath());
            Log.SetOutputDir(System.IO.Path.GetTempPath());
            Log.SetStartTime();
            Log.WriteLine("Start");
            Log.WriteLine("MakingGeoJsonFile Mathod Start  SIMA");
            IMap map = ArcMap.Document.FocusMap;
            arcStraboObject.MakingSymbolGeoJsonFile();
            Log.WriteLine("MakingGeoJsonFile Mathod Finish");

            ////run TextExtraction Layer from Strao.core and load raster Layer
            Log.WriteLine("textLayerExtract Mathod Start SIMA");

            dir =rasterInfo.ratserImgPath;
            arcStraboObject.SymbolExtraction();
            Log.WriteLine("textLayerExtract Mathod Finish");

            /////Add Polygon of OCR Layer
            Log.WriteLine("CreateFeatureClassWithFields Mathod Start SIMA");
            IWorkspace workspace = arcStraboObject.symbolCreateShapefileWorkspace();
            IFeatureWorkspace featureworkspace = (IFeatureWorkspace)workspace;

            IFeatureClass featureClass = arcStraboObject.CreateFeatureClassWithFieldsGeoRef(ArcStrabo10Extension.TextLayerOCRShapefile, featureworkspace);
            IFeatureLayer featureLayer = arcStraboObject.CreateFeatureLayer(featureClass);
            Log.WriteLine("CreateFeatureClassWithFields Mathod Finish");

            Log.WriteLine("AddPolygon Mathod Start");
            arcStraboObject.addPoligonGeorefrenced(featureLayer, featureworkspace);
            Log.WriteLine("AddPolygon Mathod Finish");

            #endregion
        }