예제 #1
0
        private static async Task CreateFeatures(List <CCProGraphic> mapPointList, string layerName, bool isKML)
        {
            ArcGIS.Core.Data.RowBuffer rowBuffer = null;
            try
            {
                var layer = MapView.Active.Map.GetLayersAsFlattenedList().Where(x => x.Name == Path.GetFileNameWithoutExtension(layerName)).FirstOrDefault();
                if (layer == null)
                {
                    MessageBox.Show("Something went wrong");
                }
                else
                {
                    await QueuedTask.Run(() =>
                    {
                        if (layer is FeatureLayer)
                        {
                            var featureLayer = (FeatureLayer)layer;

                            using (var table = featureLayer.GetTable())
                            {
                                TableDefinition definition = table.GetDefinition();
                                int shapeIndex             = definition.FindField("Shape");

                                foreach (var point in mapPointList)
                                {
                                    rowBuffer = table.CreateRowBuffer();

                                    var geom = !point.MapPoint.HasZ ?
                                               new MapPointBuilder(point.MapPoint).ToGeometry() :
                                               MapPointBuilder.CreateMapPoint(point.MapPoint.X, point.MapPoint.Y, point.MapPoint.SpatialReference);
                                    rowBuffer[shapeIndex] = geom;
                                    foreach (var item in point.Attributes)
                                    {
                                        int idx = definition.FindField(item.Key);
                                        if (idx > -1)
                                        {
                                            rowBuffer[idx] = item.Value == null ? "" : item.Value;
                                        }
                                    }
                                    ArcGIS.Core.Data.Row row = table.CreateRow(rowBuffer);
                                }
                            }

                            //Set header text
                            var cimFeatureDefinition     = featureLayer.GetDefinition() as ArcGIS.Core.CIM.CIMFeatureLayer;
                            var cimDisplayTable          = cimFeatureDefinition.FeatureTable;
                            var displayField             = cimDisplayTable.DisplayField;
                            cimDisplayTable.DisplayField = TabBaseViewModel.CoordinateFieldName;
                            featureLayer.SetDefinition(cimFeatureDefinition);

                            //set label property
                            var lc = featureLayer.LabelClasses.FirstOrDefault();
                            lc.SetExpression(string.Format("[{0}]", TabBaseViewModel.CoordinateFieldName));
                            lc.SetExpressionEngine(LabelExpressionEngine.VBScript);

                            //Get simple renderer from feature layer
                            CIMSimpleRenderer currentRenderer = featureLayer.GetRenderer() as CIMSimpleRenderer;
                            if (currentRenderer != null)
                            {
                                CIMSymbolReference sybmol = currentRenderer.Symbol;
                                //var outline = SymbolFactory.ConstructStroke(ColorFactory.RedRGB, 1.0, SimpleLineStyle.Solid);
                                //var s = SymbolFactory.ConstructPolygonSymbol(ColorFactory.RedRGB, SimpleFillStyle.Null, outline);
                                var s = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 3.0);
                                if (isKML)
                                {
                                    s.SetSize(CoordinateConversionLibrary.Constants.SymbolSize);
                                }
                                CIMSymbolReference symbolRef = new CIMSymbolReference()
                                {
                                    Symbol = s
                                };
                                currentRenderer.Symbol = symbolRef;

                                featureLayer.SetRenderer(currentRenderer);
                            }
                        }
                    });
                }
            }
            catch (GeodatabaseException exObj)
            {
                System.Diagnostics.Debug.WriteLine(exObj);
                throw;
            }
            finally
            {
                if (rowBuffer != null)
                {
                    rowBuffer.Dispose();
                }
            }
        }
예제 #2
0
        public static async Task <List <Dictionary <string, Tuple <object, bool> > > > ImportFromExcel(string fileName)
        {
            var           tableName     = "ExcelData";
            var           lstDictionary = new List <Dictionary <string, Tuple <object, bool> > >();
            List <object> arguments     = new List <object>();

            arguments.Add(fileName);
            arguments.Add(tableName);
            var env            = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);
            var valueArray     = Geoprocessing.MakeValueArray(arguments.ToArray());
            var progressDialog = new ProgressDialog("Processing.. Please wait");

            progressDialog.Show();
            try
            {
                IGPResult result = await Geoprocessing.ExecuteToolAsync("ExcelToTable_conversion", valueArray, env, null, null, GPExecuteToolFlags.Default);

                if (!result.IsFailed)
                {
                    lstDictionary = await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
                    {
                        using (Geodatabase geodatabase = new Geodatabase(FgdbFileToConnectionPath(CoreModule.CurrentProject.DefaultGeodatabasePath)))
                        {
                            QueryDef queryDef = new QueryDef
                            {
                                Tables      = tableName,
                                WhereClause = "1 = 1",
                            };

                            using (RowCursor rowCursor = geodatabase.Evaluate(queryDef, false))
                            {
                                while (rowCursor.MoveNext())
                                {
                                    var dictionary = new Dictionary <string, Tuple <object, bool> >();
                                    using (ArcGIS.Core.Data.Row row = rowCursor.Current)
                                    {
                                        for (int i = 0; i < row.GetFields().Count; i++)
                                        {
                                            var key = row.GetFields()[i].Name;
                                            var val = rowCursor.Current[i];
                                            dictionary.Add(key, Tuple.Create(val, false));
                                        }
                                    }
                                    lstDictionary.Add(dictionary);
                                }
                            }
                        }
                        progressDialog.Hide();
                        return(lstDictionary);
                    });
                }
                else
                {
                    progressDialog.Hide();
                    MessageBox.Show("ExcelToTable_conversion operation failed.");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                progressDialog.Hide();
            }
            return(lstDictionary);
        }
예제 #3
0
        /// <summary>
        /// Create polyline features from graphics and add to table
        /// </summary>
        /// <param name="graphicsList">List of graphics to add to table</param>
        /// <returns></returns>
        private static async Task CreateFeatures(List <ProGraphic> graphicsList, string layerName)
        {
            ArcGIS.Core.Data.RowBuffer rowBuffer = null;

            try
            {
                var layer = MapView.Active.Map.GetLayersAsFlattenedList().Where(x => x.Name == Path.GetFileNameWithoutExtension(layerName)).FirstOrDefault();
                if (layer == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Something went wrong");
                }
                else
                {
                    await QueuedTask.Run(() =>
                    {
                        if (layer is FeatureLayer)
                        {
                            var featureLayer = (FeatureLayer)layer;

                            using (var table = featureLayer.GetTable())
                            {
                                TableDefinition definition = table.GetDefinition();
                                int shapeIndex             = definition.FindField("Shape");

                                foreach (ProGraphic graphic in graphicsList)
                                {
                                    rowBuffer = table.CreateRowBuffer();

                                    if (graphic.Geometry is Polyline)
                                    {
                                        Polyline poly         = new PolylineBuilder(graphic.Geometry as Polyline).ToGeometry();
                                        rowBuffer[shapeIndex] = poly;
                                    }
                                    else if (graphic.Geometry is Polygon)
                                    {
                                        rowBuffer[shapeIndex] = new PolygonBuilder(graphic.Geometry as Polygon).ToGeometry();
                                    }

                                    ArcGIS.Core.Data.Row row = table.CreateRow(rowBuffer);
                                }
                            }

                            //Get simple renderer from feature layer
                            CIMSimpleRenderer currentRenderer = featureLayer.GetRenderer() as CIMSimpleRenderer;
                            if (currentRenderer != null)
                            {
                                CIMSymbolReference sybmol = currentRenderer.Symbol;

                                var outline = SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.RedRGB, 1.0, SimpleLineStyle.Solid);
                                var s       = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Null, outline);
                                CIMSymbolReference symbolRef = new CIMSymbolReference()
                                {
                                    Symbol = s
                                };
                                currentRenderer.Symbol = symbolRef;

                                featureLayer.SetRenderer(currentRenderer);
                            }
                        }
                    });
                }
            }
            catch (GeodatabaseException exObj)
            {
                System.Diagnostics.Debug.WriteLine(exObj);
                throw;
            }
            finally
            {
                if (rowBuffer != null)
                {
                    rowBuffer.Dispose();
                }
            }
        }