private void simpleButton1_Click(object sender, EventArgs e)
        {
            double offsetValue = -1;

            try
            {
                offsetValue = Convert.ToDouble(textEdit1.Text);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("请输入数值类型", "提示信息", MessageBoxButtons.OK);
                return;
            }
            try
            {
                //启动编辑
                IFeatureLayer featureLayer  = mLayer as IFeatureLayer;
                IFeatureClass pFeatureClass = featureLayer.FeatureClass;

                IWorkspace    workspace     = null;
                IEngineEditor mEngineEditor = mEngineEditor = new EngineEditorClass();
                if (pFeatureClass.FeatureDataset != null)
                {
                    workspace = pFeatureClass.FeatureDataset.Workspace;
                    mEngineEditor.EditSessionMode = esriEngineEditSessionMode.esriEngineEditSessionModeVersioned;
                    mEngineEditor.StartEditing(workspace, mMap);
                    ((IEngineEditLayers)mEngineEditor).SetTargetLayer(featureLayer, -1);
                    mEngineEditor.StartOperation();
                }



                ISelectionSet mSelectionSet = (mLayer as IFeatureSelection).SelectionSet;
                ICursor       mCursor;
                mSelectionSet.Search(null, false, out mCursor);

                IFeature mFeature = mCursor.NextRow() as IFeature;
                while (mFeature != null)
                {
                    IGeometry  geometry  = mFeature.ShapeCopy;
                    IPolycurve polycurve = geometry as IPolycurve;
                    polycurve.Generalize(offsetValue);
                    mFeature.Shape = polycurve as IGeometry;
                    mFeature.Store();
                    mFeature = mCursor.NextRow() as IFeature;
                }
                if (workspace != null)
                {
                    mEngineEditor.StopEditing(true);
                }

                this.Dispose();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("简化失败", "提示信息", MessageBoxButtons.OK);
            }
        }
Example #2
0
        public static string ConvertGeometryToJson(IGeometry geometry,
                                                   bool isGeneralize = false)
        {
            string geomJsonStr = null;

            try
            {
                ITopologicalOperator topoGeom = geometry as ITopologicalOperator;
                topoGeom.Simplify();
                //IPolygon polygon = topoGeom as IPolygon;
                //if (polygon != null)
                //{
                //    polygon.Generalize(1);
                //}

                //if (geometry.SpatialReference == null || geometry.SpatialReference.Name == "Unknown")
                //{
                //    geometry.SpatialReference = SpatialRefOpt.GetProjectedCoordinate(esriSRProjCS4Type.esriSRProjCS_Xian1980_3_Degree_GK_CM_120E);
                //}

                if (isGeneralize)
                {
                    ISpatialReference  spatialReference = geometry.SpatialReference;
                    enumSpatialRelType spatialRelType   = GetSpatialRelType(spatialReference);
                    double             offset           = 0.000001;
                    if (spatialRelType == enumSpatialRelType.GCS)
                    {
                        offset = 0.00000001;
                    }
                    IPolycurve polycurve = geometry as IPolycurve;
                    polycurve.Generalize(offset);
                }

                IJSONWriter jsonWriter = new JSONWriterClass();
                jsonWriter.WriteToString();

                JSONConverterGeometryClass jsonCon = new JSONConverterGeometryClass();
                jsonCon.WriteGeometry(jsonWriter, null, geometry, false);

                geomJsonStr = Encoding.UTF8.GetString(jsonWriter.GetStringBuffer());
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("\nConvertGeometryToJson::error::" + ex.Source + ".\n" + ex.ToString());
            }
            return(geomJsonStr);
        }
Example #3
0
 public override void OnClick()
 {
     try
     {
         frmMaxAllowableOffset _frmMaxAllowableOffset = new frmMaxAllowableOffset()
         {
             Text = "综合"
         };
         if (_frmMaxAllowableOffset.ShowDialog() == DialogResult.OK)
         {
             double       maxAllowableOffset = _frmMaxAllowableOffset.MaxAllowableOffset;
             IEnumFeature featureSelection   = _context.FocusMap.FeatureSelection as IEnumFeature;
             featureSelection.Reset();
             IFeature       feature       = featureSelection.Next();
             IWorkspaceEdit editWorkspace = Yutai.ArcGIS.Common.Editor.Editor.EditWorkspace;
             editWorkspace.StartEditOperation();
             IPolycurve shape = null;
             while (feature != null)
             {
                 shape = feature.Shape as IPolycurve;
                 if (shape != null && editWorkspace == (feature.Class as IDataset).Workspace)
                 {
                     shape.Generalize(maxAllowableOffset);
                     feature.Shape = shape;
                     feature.Store();
                 }
                 feature = featureSelection.Next();
             }
             editWorkspace.StopEditOperation();
             _context.ActiveView.Refresh();
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message);
     }
 }