private async void MapView_Tapped(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Create the feature.
                ArcGISFeature feature = (ArcGISFeature)_damageFeatureTable.CreateFeature();

                // Get the normalized geometry for the tapped location and use it as the feature's geometry.
                MapPoint tappedPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(e.Location);
                feature.Geometry = tappedPoint;

                // Set feature attributes.
                feature.SetAttributeValue("typdamage", "Minor");
                feature.SetAttributeValue("primcause", "Earthquake");

                // Add the feature to the table.
                await _damageFeatureTable.AddFeatureAsync(feature);

                // Apply the edits to the service.
                await _damageFeatureTable.ApplyEditsAsync();

                // Update the feature to get the updated objectid - a temporary ID is used before the feature is added.
                feature.Refresh();

                // Confirm feature addition.
                MessageBox.Show("Created feature " + feature.Attributes["objectid"], "Success!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error adding feature");
            }
        }
Exemplo n.º 2
0
        private async void MyMapView_GeoViewTapped(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs mapClickPoint)
        {
            IdentifyLayerResult idResult = await MyMapView.IdentifyLayerAsync(serviceRequestLayer, mapClickPoint.Position, 5, false);

            ArcGISFeature serviceRequestFeature = idResult.GeoElements.FirstOrDefault() as ArcGISFeature;

            if (serviceRequestFeature == null)
            {
                return;
            }

            // Create a new feature in the comments table
            ArcGISFeature newComment = relatedTable.CreateFeature() as ArcGISFeature;


            // Add comment text to the 'comments' attribute
            newComment.Attributes["comments"] = "Please show up on time!";


            // Relate the selected service request to the new comment
            serviceRequestFeature.RelateFeature(newComment);
            await relatedTable.AddFeatureAsync(newComment);

            var results = await relatedTable.ApplyEditsAsync();
        }
Exemplo n.º 3
0
        private async Task CreateFeature(Image capturedImage, int healthValue)
        {
            _helpLabel.Text = "Adding feature...";

            try
            {
                // Get the geometry of the feature.
                MapPoint featurePoint = _graphicsOverlay.Graphics.First().Geometry as MapPoint;

                // Create attributes for the feature using the user selected health value.
                IEnumerable <KeyValuePair <string, object> > featureAttributes = new Dictionary <string, object>()
                {
                    { "Health", (short)healthValue }, { "Height", 3.2 }, { "Diameter", 1.2 }
                };

                // Ensure that the feature table is loaded.
                if (_featureTable.LoadStatus != Esri.ArcGISRuntime.LoadStatus.Loaded)
                {
                    await _featureTable.LoadAsync();
                }

                // Create the new feature
                ArcGISFeature newFeature = _featureTable.CreateFeature(featureAttributes, featurePoint) as ArcGISFeature;

                // Convert the Image from ARCore into a JPEG byte array.
                byte[] attachmentData = await ConvertImageToJPEG(capturedImage);

                // Add the attachment.
                // The contentType string is the MIME type for JPEG files, image/jpeg.
                await newFeature.AddAttachmentAsync("tree.jpg", "image/jpeg", attachmentData);

                // Add the newly created feature to the feature table.
                await _featureTable.AddFeatureAsync(newFeature);

                // Apply the edits to the service feature table.
                await _featureTable.ApplyEditsAsync();

                // Reset the user interface.
                _helpLabel.Text = "Tap to create a feature";
                _graphicsOverlay.Graphics.Clear();
                _addButton.Enabled = false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                ShowMessage("Could not create feature", "Error");
            }
        }
Exemplo n.º 4
0
        private async Task CreateFeature(int healthValue)
        {
            HelpLabel.Text = "Adding feature...";

            try
            {
                // Get the geometry of the feature.
                MapPoint featurePoint = _graphicsOverlay.Graphics.First().Geometry as MapPoint;

                // Create attributes for the feature using the user selected health value.
                IEnumerable <KeyValuePair <string, object> > featureAttributes = new Dictionary <string, object>()
                {
                    { "Health", (short)healthValue }, { "Height", 3.2 }, { "Diameter", 1.2 }
                };

                // Ensure that the feature table is loaded.
                if (_featureTable.LoadStatus != Esri.ArcGISRuntime.LoadStatus.Loaded)
                {
                    await _featureTable.LoadAsync();
                }

                // Create the new feature
                ArcGISFeature newFeature = _featureTable.CreateFeature(featureAttributes, featurePoint) as ArcGISFeature;

                // Add the newly created feature to the feature table.
                await _featureTable.AddFeatureAsync(newFeature);

                // Apply the edits to the service feature table.
                await _featureTable.ApplyEditsAsync();

                // Reset the user interface.
                HelpLabel.Text = "Tap to create a feature";
                _graphicsOverlay.Graphics.Clear();
                AddButton.IsEnabled = false;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                await Application.Current.MainPage.DisplayAlert("Error", "Could not create feature", "OK");
            }
        }
Exemplo n.º 5
0
        public static async Task <ArcCrudEnum> AddBin(BinViewModel binViewModel)
        {
            IBinstance            bin = binViewModel.Binstance;
            IEnumerable <YTYData> yTY = bin.YTYDatas;

            try
            {
                await _featureTable.LoadAsync();

                var attributes = new Dictionary <string, object>();
                attributes.Add("identifier", bin.Identifier);
                attributes.Add("created_by", bin.CreatedBy);
                attributes.Add("modified_by", bin.ModifiedBy);

                switch (bin.BinType)
                {
                case BinTypeEnum.RoundStorage:
                    attributes.Add("bin_type", "round_storage");
                    break;

                case BinTypeEnum.GravityWagon:
                    attributes.Add("bin_type", "gravity_wagon");
                    break;

                case BinTypeEnum.PolygonStructure:
                    attributes.Add("bin_type", "polygon_structure");
                    break;

                case BinTypeEnum.FlatStructure:
                    attributes.Add("bin_type", "flat_structure");
                    break;
                }

                attributes.Add("year_collected", bin.YearCollected);

                if (bin.IsLeased.HasValue)
                {
                    attributes.Add("owned_or_leased", bin.IsLeased.Value ? "leased" : "owned");
                }

                if (bin.HasDryingDevice.HasValue)
                {
                    attributes.Add("drying_device", bin.HasDryingDevice.Value ? "true" : "false");
                }

                if (bin.HasGrainHeightIndicator.HasValue)
                {
                    attributes.Add("bin_level_indicator_device", bin.HasGrainHeightIndicator.Value ? "true" : "false");
                }

                switch (bin.LadderType)
                {
                case Ladder.None:
                    attributes.Add("ladder_type", "none");
                    break;

                case Ladder.Ladder:
                    attributes.Add("ladder_type", "ladder");
                    break;

                case Ladder.Stairs:
                    attributes.Add("ladder_type", "stairs");
                    break;
                }

                attributes.Add("notes", bin.Notes);

                //bin type specific logic below
                Type t = bin.GetType();
                if (bin.BinType == BinTypeEnum.FlatStructure)
                {
                    if (t.Equals(typeof(FlatBin)))
                    {
                        FlatBin flat = (FlatBin)bin;
                        attributes.Add("crib_height", flat.CribLength);
                        attributes.Add("crib_width", flat.CribWidth);
                    }
                }
                else if (bin.BinType == BinTypeEnum.GravityWagon)
                {
                    if (t.Equals(typeof(GravityBin)))
                    {
                        GravityBin gravityBin = (GravityBin)bin;
                        attributes.Add("chute_length", gravityBin.ChuteLength);
                        attributes.Add("hopper_height", gravityBin.HopperHeight);
                        attributes.Add("rectangle_height", gravityBin.RectangleHeight);
                        attributes.Add("rectangle_length", gravityBin.RectangleLength);
                        attributes.Add("rectangle_width", gravityBin.RectangleWidth);
                    }
                }
                else if (bin.BinType == BinTypeEnum.PolygonStructure)
                {
                    if (t.Equals(typeof(PolygonBin)))
                    {
                        PolygonBin polygonBin = (PolygonBin)bin;
                        attributes.Add("side_height", polygonBin.SideHeight);
                        attributes.Add("side_width", polygonBin.SideWidth);
                        attributes.Add("number_of_sides", polygonBin.NumberOfSides);
                    }
                }
                else if (bin.BinType == BinTypeEnum.RoundStorage)
                {
                    if (t.Equals(typeof(RoundBin)))
                    {
                        RoundBin round = (RoundBin)bin;
                        if (round.HasHopper.HasValue)
                        {
                            attributes.Add("has_hopper", round.HasHopper.Value ? "true" : "false");
                        }
                        attributes.Add("radius", round.Radius);
                        attributes.Add("wall_height", round.WallHeight);
                        attributes.Add("roof_height", round.RoofHeight);
                        attributes.Add("hopper_height", round.HopperHeight);
                    }
                }

                MapPoint mp;
                double   lat = 0;
                double   lon = 0;

                try
                {
                    var locator = CrossGeolocator.Current;
                    locator.DesiredAccuracy = 1000;
                    var position = await locator.GetPositionAsync();

                    if (position == null)
                    {
                        Console.WriteLine("Location Service error");
                    }
                    lat = position.Latitude;
                    lon = position.Longitude;
                }
                catch { }

                string   lonS      = lon.ToString();
                string[] split     = lonS.Split('.');
                var      charArray = split[1].ToCharArray();
                //seperate good location, make third if necassary
                string first     = charArray[0].ToString();
                string second    = charArray[1].ToString();
                string third     = charArray[2].ToString();
                Random random    = new Random();
                int    addition  = random.Next(25, 75);
                string additionS = addition.ToString();
                string newLong   = split[0] + '.' + first + second + third + additionS;
                //latitude
                string   latS       = lat.ToString();
                string[] splitL     = latS.Split('.');
                var      charArrayL = splitL[1].ToCharArray();
                //seperate good location, make third if necassary
                string firstL             = charArrayL[0].ToString();
                string secondL            = charArrayL[1].ToString();
                string thirdL             = charArrayL[2].ToString();
                int    additionL          = random.Next(25, 75);
                string additionSL         = additionL.ToString();
                string newLat             = splitL[0] + '.' + firstL + secondL + thirdL + additionSL;
                double clusteredLongitude = double.Parse(newLong);
                double clusteredLatitude  = double.Parse(newLat);

                mp = new MapPoint(clusteredLongitude, clusteredLatitude);

                binViewModel.ArcGISFeature = (ArcGISFeature)_featureTable.CreateFeature(attributes, mp);

                await _featureTable.AddFeatureAsync(binViewModel.ArcGISFeature);

                await binViewModel.ArcGISFeature.LoadAsync();

                if (DeviceInfo.DeviceType == DeviceType.Physical)
                {
                    using (var memoryStream = new MemoryStream())
                    {
                        bin.Image.GetStream().CopyTo(memoryStream);
                        // add an attachment - pass the name, mime type, and attachment data (bytes, etc.)
                        await binViewModel.ArcGISFeature.AddAttachmentAsync("Photo.jpg", "image/jpg", memoryStream.ToArray()); //agsFeature
                    }
                }

                if (yTY == null)
                {
                    yTY = new List <YTYData>();
                }

                //create json
                string jsonString = JsonConvert.SerializeObject(yTY);
                byte[] byteArray  = Encoding.UTF8.GetBytes(jsonString);

                List <Attachment>          attachmentsToRemove = new List <Attachment>();
                IReadOnlyList <Attachment> attachments         = await binViewModel.ArcGISFeature.GetAttachmentsAsync();

                foreach (Attachment attachment in attachments)
                {
                    if (attachment.Name.Equals(YTY_FILE_NAME))
                    {
                        attachmentsToRemove.Add(attachment);
                    }
                }

                await binViewModel.ArcGISFeature.DeleteAttachmentsAsync(attachmentsToRemove);

                await binViewModel.ArcGISFeature.AddAttachmentAsync(YTY_FILE_NAME, "application/json", byteArray); //agsFeature

                await _featureTable.UpdateFeatureAsync(binViewModel.ArcGISFeature);                                //agsFeature

                // push to ArcGIS Online feature service
                IReadOnlyList <EditResult> editResults = await _featureTable.ApplyEditsAsync();

                // check results for errors
                foreach (var er in editResults)
                {
                    if (er.CompletedWithErrors)
                    {
                        return(ArcCrudEnum.Failure);
                    }
                }

                return(ArcCrudEnum.Success);
            }
            catch (ArcGISWebException)
            {
                return(ArcCrudEnum.Exception);
            }
        }
Exemplo n.º 6
0
        private async Task ScrapeArtistInfo(FullArtist artist)
        {
            string bioUrl      = $"https://open.spotify.com/artist/{artist.Id}/about";
            string pageContent = "";

            using (HttpClient client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("User-Agent", "C# console program");
                pageContent = await client.GetStringAsync(bioUrl);
            }

            var artistResults = _artistScraping.Extract(pageContent);
            var cities        = artistResults["listeners-city"];
            var listeners     = artistResults["listeners"];
            var bio           = artistResults["about"];

            // if there's no bio, we can't find locations :(
            if (bio == null)
            {
                return;
            }

            string fullBio     = bio.ToString() + artistResults["more"].ToString();
            int    shortBioEnd = System.Math.Min(fullBio.Length, 255);
            string shortBio    = fullBio.Substring(0, shortBioEnd);

            Dictionary <string, int> listenerCities = new Dictionary <string, int>();

            for (int i = 0; i < listeners.Count(); i++)
            {
                string listenersString = listeners[i].ToString().Replace("LISTENERS", "").Replace(",", "").Trim();
                int    numListeners    = int.Parse(listenersString);
                listenerCities.Add(cities[i].ToString(), numListeners);
            }

            string aboutArtistJson = JsonConvert.SerializeObject(fullBio, Newtonsoft.Json.Formatting.Indented);
            string classifiedXml   = _classifier.classifyWithInlineXML(aboutArtistJson);

            // HACK: fix "city, state" locations that are split into two:
            //       "<LOCATION>Logan</LOCATION>, <LOCATION>Utah</LOCATION>" => "<LOCATION>Logan, Utah</LOCATION>"
            classifiedXml = classifiedXml.Replace("</LOCATION>, <LOCATION>", ", ");
            MatchCollection locationMatches = _locationRx.Matches(classifiedXml);

            Dictionary <string, Graphic> artistLocations = new Dictionary <string, Graphic>();
            //UNCOMMENT
            //// Build artist locations
            //for (int i = 0; i < locationMatches.Count; i++)
            //{
            //    var m = locationMatches[i];
            //    string loc = m.Groups[1].Value;
            //    MapPoint geocodedLocation = await GeocodeArtistPlacename(loc);
            //    if (geocodedLocation == null) { continue; }

            //    // If the place name was geocoded, create a new feature to store it
            //    // (first one is considered the hometown) :\
            //    if (i == 0)
            //    {
            //        Feature newHometownFeature = _hometownTable.CreateFeature();
            //        newHometownFeature.Geometry = geocodedLocation;
            //        newHometownFeature.Attributes["placename"] = loc;
            //        newHometownFeature.Attributes["artistname"] = artist.Name;
            //        newHometownFeature.Attributes["artistid"] = artist.Id;
            //        newHometownFeature.Attributes["imageurl"] = artist.Images.Last().Url;
            //        newHometownFeature.Attributes["bioshort"] = shortBio;

            //        await _hometownTable.AddFeatureAsync(newHometownFeature);
            //    }
            //    else
            //    {
            //        if (!artistLocations.ContainsKey(loc))
            //        {
            //            Feature otherFeature = _otherPointsTable.CreateFeature();
            //            otherFeature.Geometry = geocodedLocation;
            //            otherFeature.Attributes["placename"] = loc;
            //            otherFeature.Attributes["artistname"] = artist.Name;
            //            otherFeature.Attributes["artistid"] = artist.Id;

            //            await _otherPointsTable.AddFeatureAsync(otherFeature);
            //        }
            //    }
            //}

            //// Apply edits to the hometown table (will apply other edits after adding listener cities)
            //await _hometownTable.ApplyEditsAsync();
            //**UNCOMMENT

            // Create points for the listener cities
            int r = 0;

            foreach (var lc in listenerCities)
            {
                r++;
                MapPoint geocodedLocation = await GeocodeArtistPlacename(lc.Key);

                if (geocodedLocation == null)
                {
                    continue;
                }

                Feature otherFeature = _listenerTable.CreateFeature();
                otherFeature.Geometry = geocodedLocation;
                otherFeature.Attributes["placename"]     = lc.Key;
                otherFeature.Attributes["artistname"]    = artist.Name;
                otherFeature.Attributes["artistid"]      = artist.Id;
                otherFeature.Attributes["listenercount"] = lc.Value;
                otherFeature.Attributes["listenerrank"]  = r;

                await _listenerTable.AddFeatureAsync(otherFeature);
            }

            // Apply edits to the other locations table
            await _listenerTable.ApplyEditsAsync();

            ArtistProgressList.Items.Add(artist.Name);
        }