internal async Task AddGraphicToMap(Geometry geom, CIMColor color, bool IsTempGraphic = false, double size = 1.0, string text = "")
        {
            if (geom == null || MapView.Active == null)
            {
                return;
            }

            CIMSymbolReference symbol = null;

            if (!string.IsNullOrWhiteSpace(text) && geom.GeometryType == GeometryType.Point)
            {
                await QueuedTask.Run(() =>
                {
                    //var tg = new CIMTextGraphic() { Placement = Anchor.CenterPoint, Text = text};
                });
            }
            else if (geom.GeometryType == GeometryType.Point)
            {
                await QueuedTask.Run(() =>
                {
                    var s  = SymbolFactory.ConstructPointSymbol(color, size, SimpleMarkerStyle.Circle);
                    symbol = new CIMSymbolReference()
                    {
                        Symbol = s
                    };
                });
            }
            else if (geom.GeometryType == GeometryType.Polyline)
            {
                await QueuedTask.Run(() =>
                {
                    var s  = SymbolFactory.ConstructLineSymbol(color, size);
                    symbol = new CIMSymbolReference()
                    {
                        Symbol = s
                    };
                });
            }
            else if (geom.GeometryType == GeometryType.Polygon)
            {
                await QueuedTask.Run(() =>
                {
                    var outline = SymbolFactory.ConstructStroke(ColorFactory.Black, 1.0, SimpleLineStyle.Solid);
                    var s       = SymbolFactory.ConstructPolygonSymbol(color, SimpleFillStyle.Solid, outline);
                    symbol      = new CIMSymbolReference()
                    {
                        Symbol = s
                    };
                });
            }

            await QueuedTask.Run(() =>
            {
                var disposable = MapView.Active.AddOverlay(geom, symbol);
                overlayObjects.Add(disposable);

                GraphicsList.Add(new ProGraphic(disposable, geom, IsTempGraphic));
            });
        }
        internal async Task AddGraphicToMap(Geometry geom, CIMColor color, bool IsTempGraphic = false, double size = 1.0)
        {
            if (geom == null || MapView.Active == null)
            {
                return;
            }

            CIMSymbolReference symbol = null;

            if (geom.GeometryType == GeometryType.Point)
            {
                await QueuedTask.Run(() =>
                {
                    var s  = SymbolFactory.ConstructPointSymbol(color, size, SimpleMarkerStyle.Circle);
                    symbol = new CIMSymbolReference()
                    {
                        Symbol = s
                    };
                });
            }
            else if (geom.GeometryType == GeometryType.Polyline)
            {
                await QueuedTask.Run(() =>
                {
                    var s  = SymbolFactory.ConstructLineSymbol(color, size);
                    symbol = new CIMSymbolReference()
                    {
                        Symbol = s
                    };
                });
            }
            else if (geom.GeometryType == GeometryType.Polygon)
            {
                await QueuedTask.Run(() =>
                {
                    var outline = SymbolFactory.ConstructStroke(ColorFactory.RedRGB, 1.0, SimpleLineStyle.Solid);
                    var s       = SymbolFactory.ConstructPolygonSymbol(color, SimpleFillStyle.Null, outline);
                    symbol      = new CIMSymbolReference()
                    {
                        Symbol = s
                    };
                });
            }

            await QueuedTask.Run(() =>
            {
                var disposable = MapView.Active.AddOverlay(geom, symbol);
                overlayObjects.Add(disposable);

                var gt = GetGraphicType();

                GraphicsList.Add(new Graphic(gt, disposable, geom, this, IsTempGraphic));

                RaisePropertyChanged(() => HasMapGraphics);
            });
        }
        internal async Task <string> AddGraphicToMap(Geometry geom, CIMColor color, bool IsTempGraphic = false, double size = 1.0, string text = "", SimpleMarkerStyle markerStyle = SimpleMarkerStyle.Circle, string tag = "")
        {
            if (geom == null || MapView.Active == null)
            {
                return(string.Empty);
            }

            CIMSymbolReference symbol = null;

            if (!string.IsNullOrWhiteSpace(text) && geom.GeometryType == GeometryType.Point)
            {
                await QueuedTask.Run(() =>
                {
                    // TODO add text graphic
                    //var tg = new CIMTextGraphic() { Placement = Anchor.CenterPoint, Text = text};
                });
            }
            else if (geom.GeometryType == GeometryType.Point)
            {
                await QueuedTask.Run(() =>
                {
                    var s  = SymbolFactory.ConstructPointSymbol(color, size, markerStyle);
                    symbol = new CIMSymbolReference()
                    {
                        Symbol = s
                    };
                });
            }
            else if (geom.GeometryType == GeometryType.Polyline)
            {
                await QueuedTask.Run(() =>
                {
                    var s  = SymbolFactory.ConstructLineSymbol(color, size);
                    symbol = new CIMSymbolReference()
                    {
                        Symbol = s
                    };
                });
            }
            else if (geom.GeometryType == GeometryType.Polygon)
            {
                await QueuedTask.Run(() =>
                {
                    var outline = SymbolFactory.ConstructStroke(ColorFactory.Black, 1.0, SimpleLineStyle.Solid);
                    var s       = SymbolFactory.ConstructPolygonSymbol(color, SimpleFillStyle.Solid, outline);
                    symbol      = new CIMSymbolReference()
                    {
                        Symbol = s
                    };
                });
            }

            var result = await QueuedTask.Run(() =>
            {
                var disposable = MapView.Active.AddOverlay(geom, symbol);
                var guid       = Guid.NewGuid().ToString();
                ProGraphicsList.Add(new ProGraphic(disposable, guid, geom, IsTempGraphic, tag));
                return(guid);
            });

            return(result);
        }
Example #4
0
        internal async Task PerformAnalysis(MapPoint ptStartLoc, MapView mapView, ProgressorSource ps)
        {
            ps.Progressor.Message = "Running the analysis...";
            ps.Progressor.Status  = "Gathering and verifying parameter data";
            string sReqUrl = Properties.Settings.Default.QryPointToState;
            string sReq    = String.Format("{0}?returnGeometry=false&returnDistinctValues=false&geometry={1}&geometryType=esriGeometryPoint&f=json&outFields=*&spatialRel=esriSpatialRelIntersects",
                                           sReqUrl, ptStartLoc.ToJson());
            // Find out what state the user clicked; or report an error if outside the U.S.
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sReq);
            string         sResp;

            try {
                using (StreamReader sread = new StreamReader(req.GetResponse().GetResponseStream()))
                    sResp = sread.ReadToEnd();
            } catch (Exception e) {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error mapping the chosen spot to a petroleum area district in the U.S.A.: " + e.Message);
                return;
            }
            dynamic respPADDState = JsonConvert.DeserializeObject(sResp);

            try {
                string sState = respPADDState.features[0].attributes.STATE.ToString();
                // Find out what PADD zone the state is in
                SelectedPADDZone = PaddStateToZone[sState];
            } catch (Exception e) {
                System.Diagnostics.Debug.WriteLine("Exception getting PADD for chosen spot: " + e.Message);
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Please choose a spot within the U.S.A.");
                return /*null*/;
            }

            // Find out the gallons/$1.00 in that PADD zone
            double nFuelCost = PADDZoneToFuelCost[SelectedPADDZone];

            // Find out the miles per dollar each vehicle: (mi / gal) / (dollars / gal)
            // Map is in meters, so convert miles to meters
            Vehicle[]            orderedVehicles        = SelectedVehicles.OrderBy(vehicle => vehicle.Mpg).ToArray <Vehicle>();
            IEnumerable <double> vehicleMetersPerDollar =
                orderedVehicles.Select(vehicle => (vehicle.MetersPerGallon) / nFuelCost);

            string   sDistsParam   = String.Join(" ", vehicleMetersPerDollar.ToArray());
            MapPoint ptStartLocNoZ = await QueuedTask.Run(() => {
                MapPoint ptNoZ = MapPointBuilder.CreateMapPoint(ptStartLoc.X, ptStartLoc.Y, ptStartLoc.SpatialReference);
                return(ptNoZ);
            });

            // No corresponding type for the needed GPFeatureRecordSetLayer parameter
            string sStartGeom     = ptStartLocNoZ.ToJson();
            string sStartLocParam = "{\"geometryType\":\"esriGeometryPoint\",\"features\":[{\"geometry\":" + sStartGeom + "}]}";


            // Run the query
            ps.Progressor.Status = "Executing the analysis";
            string sGPUrl = Properties.Settings.Default.GPFindSA;

            sGPUrl += String.Format("?Distances={0}&Start_Location={1}&f=json", sDistsParam, sStartLocParam);
            HttpWebRequest  reqSA = (HttpWebRequest)WebRequest.Create(sGPUrl);
            HttpWebResponse wr;

            try {
                wr = (HttpWebResponse)reqSA.GetResponse();
                if (wr.StatusCode != HttpStatusCode.OK)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error running analysis: " + wr.StatusDescription);
                    return;
                }
            } catch (WebException e) {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error running analysis: " + e.Message);
                return;
            }

            // Show the results
            ps.Progressor.Status = "Processing the results";

            using (StreamReader sread = new StreamReader(wr.GetResponseStream()))
                sResp = sread.ReadToEnd();

            JObject respAnalysis = JObject.Parse(sResp);

            JArray feats = respAnalysis["results"][0]["value"]["features"] as JArray;

            // Rectify results and order so that largest polygon can be added to the map first
            List <JToken> aryResFeats = RectifyResults(feats, orderedVehicles);

            int iSR             = respAnalysis["results"][0]["value"]["spatialReference"]["wkid"].ToObject <Int32>();
            SpatialReference sr = await QueuedTask.Run <SpatialReference>(() => {
                SpatialReference srTemp = SpatialReferenceBuilder.CreateSpatialReference(iSR);
                return(srTemp);
            });

            /*lock (_lockResults)*/
            Results.ClearResults();

            // Iterate backwards to add larger polygons behind smaller ones

            for (int iVeh = orderedVehicles.Count() - 1; iVeh >= 0; iVeh--)
            {
                Result      result  = new Result(orderedVehicles[iVeh]);
                Polygon     poly    = null;
                IDisposable graphic = null;

                // Compute color for this result
                float multiplier = aryResFeats.Count > 1 ? ((float)iVeh) / ((float)(aryResFeats.Count - 1)) : 0;
                byte  red        = (byte)(255 - (255 * multiplier));
                byte  green      = (byte)(255 * multiplier);
                Color color      = Color.FromRgb(red, green, 0);
                result.Color = color.ToString();

                result.PaddZone         = SelectedPADDZone;
                result.DollarsPerGallon = nFuelCost;

                string sGeom = aryResFeats[iVeh]["geometry"].ToString();
                poly = await QueuedTask.Run(() => {
                    Polygon polyNoSR = PolygonBuilder.FromJson(sGeom);
                    return(PolygonBuilder.CreatePolygon(polyNoSR, sr));
                });

                CIMStroke        outline = SymbolFactory.ConstructStroke(ColorFactory.BlackRGB, 1.0, SimpleLineStyle.Solid);
                CIMPolygonSymbol symPoly = SymbolFactory.ConstructPolygonSymbol(
                    ColorFactory.CreateRGBColor(color.R, color.G, color.B, RESULT_OPACITY_PCT),
                    SimpleFillStyle.Solid, outline);
                CIMSymbolReference sym    = symPoly.MakeSymbolReference();
                CIMSymbolReference symDef = SymbolFactory.DefaultPolygonSymbol.MakeSymbolReference();
                graphic = await QueuedTask.Run(() => {
                    return(mapView.AddOverlay(poly, sym));
                });

                result.DriveServiceArea        = poly;
                result.DriveServiceAreaGraphic = graphic;
                result.DriveDistM = aryResFeats[iVeh]["attributes"]["ToBreak"].Value <double>();
                /*lock (_lockResults)*/
                Results.Add(result);
            }
        }
Example #5
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)
        {
            RowBuffer rowBuffer = null;

            try
            {
                await QueuedTask.Run(() =>
                {
                    var layer = MapView.Active.GetSelectedLayers()[0];
                    if (layer is FeatureLayer)
                    {
                        var featureLayer = layer as FeatureLayer;

                        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();
                                }

                                Row row = table.CreateRow(rowBuffer);
                            }
                        }

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

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

                        featureLayer.SetRenderer(currentRenderer);
                    }
                });
            }
            catch (GeodatabaseException exObj)
            {
                Console.WriteLine(exObj);
                throw;
            }
            finally
            {
                if (rowBuffer != null)
                {
                    rowBuffer.Dispose();
                }
            }
        }
Example #6
0
        /// <summary>
        /// Warning! You must call this method on the MCT!
        /// </summary>
        /// <returns></returns>
        private CIMRenderer CreateUniqueValueRendererForUSStates()
        {
            //All of these methods have to be called on the MCT
            if (Module1.OnUIThread)
            {
                throw new CalledOnWrongThreadException();
            }

            //Create the Unique Value Renderer
            CIMUniqueValueRenderer uniqueValueRenderer = new CIMUniqueValueRenderer();

            // set the value field
            uniqueValueRenderer.Fields = new string[] { "STATE_NAME" };

            //Construct the list of UniqueValueClasses
            List <CIMUniqueValueClass> classes = new List <CIMUniqueValueClass>();

            // Alabama
            List <CIMUniqueValue> alabamaValues = new List <CIMUniqueValue>();
            CIMUniqueValue        alabamaValue  = new CIMUniqueValue();

            alabamaValue.FieldValues = new string[] { "Alabama" };
            alabamaValues.Add(alabamaValue);

            var alabamaColor = CIMColor.CreateRGBColor(255, 170, 0);

            var alabama = new CIMUniqueValueClass()
            {
                Values   = alabamaValues.ToArray(),
                Label    = "Alabama",
                Visible  = true,
                Editable = true,
                Symbol   = new CIMSymbolReference()
                {
                    Symbol = SymbolFactory.ConstructPolygonSymbol(alabamaColor)
                }
            };

            classes.Add(alabama);

            // Alaska
            List <CIMUniqueValue> alaskaValues = new List <CIMUniqueValue>();
            CIMUniqueValue        alaskaValue  = new CIMUniqueValue();

            alaskaValue.FieldValues = new string[] { "Alaska" };
            alaskaValues.Add(alaskaValue);

            var alaskaColor = CIMColor.CreateRGBColor(255, 0, 0);

            var alaska = new CIMUniqueValueClass()
            {
                Values   = alaskaValues.ToArray(),
                Label    = "Alaska",
                Visible  = true,
                Editable = true,
                Symbol   = new CIMSymbolReference()
                {
                    Symbol = SymbolFactory.ConstructPolygonSymbol(alaskaColor)
                }
            };

            classes.Add(alaska);

            // California
            List <CIMUniqueValue> californiaValues = new List <CIMUniqueValue>();
            CIMUniqueValue        californiaValue  = new CIMUniqueValue();

            californiaValue.FieldValues = new string[] { "California" };
            californiaValues.Add(californiaValue);

            var californiaColor = CIMColor.CreateRGBColor(85, 255, 0);

            var california = new CIMUniqueValueClass()
            {
                Values   = californiaValues.ToArray(),
                Label    = "California",
                Visible  = true,
                Editable = true,
                Symbol   = new CIMSymbolReference()
                {
                    Symbol = SymbolFactory.ConstructPolygonSymbol(californiaColor)
                }
            };

            classes.Add(california);

            // Colorado
            List <CIMUniqueValue> coloradoValues = new List <CIMUniqueValue>();
            CIMUniqueValue        coloradoValue  = new CIMUniqueValue();

            coloradoValue.FieldValues = new string[] { "Colorado" };
            coloradoValues.Add(coloradoValue);

            var coloradoColor = CIMColor.CreateRGBColor(0, 92, 230);

            var colorado = new CIMUniqueValueClass()
            {
                Values   = coloradoValues.ToArray(),
                Label    = "Colorado",
                Visible  = true,
                Editable = true,
                Symbol   = new CIMSymbolReference()
                {
                    Symbol = SymbolFactory.ConstructPolygonSymbol(coloradoColor)
                }
            };

            classes.Add(colorado);

            // so on and so forth for all the 51.
            //....

            //Add the classes to a group (by default there is only one group or "symbol level")
            // Unique value groups
            CIMUniqueValueGroup groupOne = new CIMUniqueValueGroup();

            groupOne.Heading = "State Names";
            groupOne.Classes = classes.ToArray();

            uniqueValueRenderer.Groups = new CIMUniqueValueGroup[] { groupOne };

            //Draw the rest with the default symbol
            uniqueValueRenderer.UseDefaultSymbol = true;
            uniqueValueRenderer.DefaultLabel     = "All other values";

            var defaultColor = CIMColor.CreateRGBColor(215, 215, 215);

            uniqueValueRenderer.DefaultSymbol = new CIMSymbolReference()
            {
                Symbol = SymbolFactory.ConstructPolygonSymbol(defaultColor)
            };

            return(uniqueValueRenderer as CIMRenderer);
        }