Esempio n. 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();
                }
            }
        }
Esempio n. 2
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();
                }
            }
        }