Exemplo n.º 1
0
        /// <summary>
        /// Get the neighborhood name for the new tree by running a spatial intersect
        /// </summary>
        internal static async Task <string> GetNeighborhoodForAddedFeature(FeatureTable neighborhoodsTable, MapPoint newTreePoint)
        {
            // if the webmap used in the app is not the tree dataset map, this method will not work
            if (WebmapURL != TreeDatasetWebmapUrl)
            {
                return(null);
            }

            // set the parameters for the query
            // we want only one neighborhood that intersects the geometry of the newly added tree
            var queryParams = new QueryParameters()
            {
                ReturnGeometry      = false,
                Geometry            = newTreePoint,
                SpatialRelationship = SpatialRelationship.Intersects,
            };

            try
            {
                await neighborhoodsTable.LoadAsync();

                var featureQueryResult = await neighborhoodsTable.QueryFeaturesAsync(queryParams);

                // get the first result and return it's name
                if (featureQueryResult.Count() > 0)
                {
                    return(featureQueryResult.First().Attributes[NeighborhoodNameField].ToString());
                }
            }
            catch { } // if unable to get the neighborhood, just don't populate it

            return(null);
        }
Exemplo n.º 2
0
        // 관리번호로 해당Feature 객체찾기
        public async void SelectFct(string _FTR_CDE, string _FTR_IDN, FeatureLayer _featureLayer)
        {
            // 0.Feature 테이블 가져오기
            //FeatureLayer __featureLayer = _featureLayer.Clone() as FeatureLayer;
            FeatureTable _featureTable = _featureLayer.FeatureTable;



            // Create a query parameters that will be used to Query the feature table.
            QueryParameters queryParams = new QueryParameters();


            // Construct and assign the where clause that will be used to query the feature table.
            queryParams.WhereClause = " FTR_CDE = '" + _FTR_CDE + "' ORDER BY FTR_IDN DESC";
            if (!FmsUtil.IsNull(_FTR_IDN))
            {
                queryParams.WhereClause = " FTR_CDE = '" + _FTR_CDE + "' AND FTR_IDN like '%' ||  " + _FTR_IDN + " || '%'";
            }


            List <Feature> features;

            try
            {
                // Query the feature table.
                FeatureQueryResult queryResult = await _featureTable.QueryFeaturesAsync(queryParams);

                // Cast the QueryResult to a List so the results can be interrogated.
                features = queryResult.ToList();
            }
            catch (Exception e)
            {
                Messages.ShowErrMsgBox(e.Message);
                return;
            }

            if (features.Any())
            {
                // Create an envelope.
                EnvelopeBuilder envBuilder = new EnvelopeBuilder(SpatialReferences.WebMercator);



                if (features.Count == 1)
                {
                    //한건인 경우 선택처리
                    ShowFctPage(features[0]);
                }
                else
                {
                    //피쳐영역 Extent 위치이동
                    foreach (Feature feature in features)
                    {
                        envBuilder.UnionOf(feature.Geometry.Extent); //복수의 피처영역 합치기
                    }
                    // Zoom to the extent of the selected feature(s).
                    await mapView.SetViewpointGeometryAsync(envBuilder.ToGeometry(), 50);
                }
            }
        }
Exemplo n.º 3
0
        private async Task <List <TrackInfo> > GetPlaylistArtists(Paging <PlaylistTrack> playlistTracks, FeatureTable artistPlaces)
        {
            List <TrackInfo> artists = new List <TrackInfo>();

            foreach (PlaylistTrack plt in playlistTracks.Items)
            {
                SimpleArtist artist = plt.Track.Artists.FirstOrDefault();

                string artistid  = artist.Id;
                string trackid   = plt.Track.Id;
                string trackname = plt.Track.Name;

                QueryParameters query = new QueryParameters
                {
                    WhereClause = "artistid = '" + artistid + "'"
                };

                FeatureQueryResult queryResult = await artistPlaces.QueryFeaturesAsync(query);

                foreach (Feature f in queryResult)
                {
                    await(f as ArcGISFeature).LoadAsync();
                    string      artistname = f.Attributes["artistname"].ToString();
                    string      hometown   = f.Attributes["placename"].ToString();
                    string      bio        = f.Attributes["bioshort"].ToString();
                    bool        isOnTour   = int.Parse(f.Attributes["isontour"].ToString()) == 1;
                    string      imgUrl     = f.Attributes["imageurl"].ToString();
                    BitmapImage src        = new BitmapImage(new Uri(imgUrl, UriKind.Absolute));

                    TrackInfo thisArtist = new TrackInfo(artistname, artistid, bio, src, hometown, trackname, trackid, f.Geometry as MapPoint, isOnTour);

                    // Add the track info to the list
                    artists.Add(thisArtist);
                }
            }

            return(artists);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Temporary method.  Just displays attributes and values from a single record in the passed table.
        /// </summary>
        /// <param name="testLayer">from which to get the single record</param>
        /// <returns>marker indicating the task is complete</returns>
        public async Task <bool> ShowSingleRecordAsync(TesterLayer testLayer)
        {
            if (testLayer.LayerLoadException != null)
            {
                this.LogLayerLoadException(testLayer);
            }
            else if (testLayer.FeatureTable != null)
            {
                FeatureTable    aTable      = testLayer.FeatureTable;
                QueryParameters queryParams = new QueryParameters();
                queryParams.MaxFeatures    = 1;
                queryParams.ReturnGeometry = true;
                queryParams.WhereClause    = "1=1";
                FeatureQueryResult fqr = await aTable.QueryFeaturesAsync(queryParams);

                IEnumerator <Feature> features = fqr.GetEnumerator();
                this.LoggingText = "=============";
                this.LoggingText = "TABLE: " + aTable.TableName;
                Feature aFeature = null;

                while (features.MoveNext())
                {
                    aFeature         = features.Current;
                    this.LoggingText = "\tShape = " + aFeature.Geometry;

                    foreach (string attName in aFeature.Attributes.Keys)
                    {
                        this.LoggingText = "\t" + attName + " = " + aFeature.Attributes[attName];
                    }
                }

                this.LoggingText = "=============";
            }

            return(true);
        }
Exemplo n.º 5
0
        // 레이에서 해당 Feature 찾기
        private async Task QueryStateFeature(string _FTR_CDE, string _FTR_IDN, FeatureLayer _featureLayer)
        {
            try
            {
                // 0.Feature 테이블 가져오기
                //FeatureLayer __featureLayer = _featureLayer.Clone() as FeatureLayer;
                FeatureTable _featureTable = _featureLayer.FeatureTable;



                // Create a query parameters that will be used to Query the feature table.
                QueryParameters queryParams = new QueryParameters();


                // Construct and assign the where clause that will be used to query the feature table.
                queryParams.WhereClause = " FTR_CDE = '" + _FTR_CDE + "' ";
                if (!FmsUtil.IsNull(_FTR_IDN))
                {
                    queryParams.WhereClause += " AND FTR_IDN = " + _FTR_IDN;
                }


                List <Feature> features;
                try
                {
                    // Query the feature table.
                    FeatureQueryResult queryResult = await _featureTable.QueryFeaturesAsync(queryParams);

                    // Cast the QueryResult to a List so the results can be interrogated.
                    features = queryResult.ToList();
                }
                catch (Exception)
                {
                    Messages.ShowErrMsgBox("보호된 메모리 접근 에러..");
                    return;
                }

                if (features.Any())
                {
                    // Create an envelope.
                    EnvelopeBuilder envBuilder = new EnvelopeBuilder(SpatialReferences.WebMercator);



                    // Loop over each feature from the query result.
                    foreach (Feature feature in features)
                    {
                        // Add the extent of each matching feature to the envelope.
                        //envBuilder.UnionOf(feature.Geometry.Extent); //복수의 피처영역 합치기

                        // Select each feature.
                        _featureLayer.SelectFeature(feature);
                        //해당피처로 이동
                        await mapView.SetViewpointCenterAsync(feature.Geometry.Extent.GetCenter(), 40000);
                    }

                    // Zoom to the extent of the selected feature(s).
                    //await mapView.SetViewpointGeometryAsync(envBuilder.ToGeometry(), 50);
                }
                else
                {
                    MessageBox.Show("해당 시설물 위치를 찾을 수 없습니다.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occurred.\n" + ex, "Sample error");
            }
        }
Exemplo n.º 6
0
        private async void CreateFeatureCollectionLayerFromNYTimesArticles()
        {
            // Read the NY Times data from the text file and get back a list of each article.
            // The format of each record/article will look like:
            // [Article summary]~[Article abstract]~[Country name]~[Url to the NY times article]~[Url to an image about the NY times article]~[Date of NY Times news article]
            // Ex:
            // Netanyahu not happy with Cohen~A spokesman for Prime Minister Benjamin Netanyahu disagrees with Roger Cohen’s “pessimism.”~Israel~https://www.nytimes.com/2018/01/02/opinion/israel-future.html~https://www.nytimes.com/images/2017/12/29/opinion/29cohenWeb/29cohenWeb-thumbLarge.jpg~20180102
            List <string> myNYTimesArticles = ReadTextFile3(_NEWSFILE);

            // Get the collection of all the layers in the map.
            var myMapAllLayers = MyMapView.Map.AllLayers;

            // Create a place holder for the world countries feature layer.
            FeatureLayer myFeatureLayer = null;

            // Loop through all of the layers.
            foreach (var myLayer in myMapAllLayers)
            {
                // Get the Id of the layer.
                string myLayerName = myLayer.Id;

                // If the layer id matches world countries set that to the feature layer.
                if (myLayerName == "WorldCountries")
                {
                    myFeatureLayer = (FeatureLayer)myLayer;
                }
            }

            // Get the feature table from the world countries shape file feature layer.
            FeatureTable myFeatureTable = myFeatureLayer.FeatureTable;

            // Create a new query parameters.
            QueryParameters myQueryParameters = new QueryParameters();

            // Define the where clause for the query parameters. It will select all the records in the world countries shape file feature table.
            myQueryParameters.WhereClause = "1 = 1";

            // Execute the feature query and get the results back. It will select all the records in the world countries shape file feature table.
            FeatureQueryResult myFeatureQueryResult = await myFeatureTable.QueryFeaturesAsync(myQueryParameters);

            // Create the schema for the polygon feature collection table.
            List <Field> myFeatureCollectionAttributeFields = new List <Field>();

            // Create a field for the feature collection layer. It will contain a text field called area name that is the county name.
            Field myAreaNameField = new Field(FieldType.Text, "AreaName", "Area Name", 50);

            // Add the country name field to the list of fields that will be added to the feature collection table.
            myFeatureCollectionAttributeFields.Add(myAreaNameField);

            // Create the feature collection table based on the list of attribute fields, a polygons feature type
            FeatureCollectionTable myFeatureCollectionTable = new FeatureCollectionTable(myFeatureCollectionAttributeFields, GeometryType.Polygon, SpatialReferences.Wgs84);

            // Create the outline symbol for the country fill symbol.
            SimpleLineSymbol mySimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.DarkBlue, 2);

            // Create the fill symbol for the country. Solid yellow, with dark blue outline.
            SimpleFillSymbol mySimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Yellow, mySimpleLineSymbol);

            // Set the renderer of the feature collection table to be the simple fill symbol.
            myFeatureCollectionTable.Renderer = new SimpleRenderer(mySimpleFillSymbol);

            // Loop through each feature in the returned feature query results of the world countries shape file
            foreach (Feature myFeature in myFeatureQueryResult)
            {
                // Get the geometry (aka shape) for one feature.
                Geometry myGeometry = myFeature.Geometry;

                // Get the value (aka. the text for the record of a specific field).
                var myValue = (string)myFeature.Attributes["NAME"];

                // Loop through each NY Times article.
                foreach (string oneNYTimesArticle in myNYTimesArticles)
                {
                    // Remove an embedded double quotes that may be in or surrounding the country name in the NY Times data base.
                    char[] charsToTrim = { '"' };
                    string country     = oneNYTimesArticle.Split('~')[2].Trim(charsToTrim);

                    // Find a match from the shape file country feature and the NY Times country name in the article.
                    if ((string)myValue == country)
                    {
                        // Create a new polygon feature, provide geometry and attribute values.
                        Feature polyFeature = myFeatureCollectionTable.CreateFeature();
                        polyFeature.SetAttributeValue(myAreaNameField, country);
                        polyFeature.Geometry = myGeometry;

                        // Add the new features to the appropriate feature collection table.
                        await myFeatureCollectionTable.AddFeatureAsync(polyFeature);

                        // Once we have found a matching country in the subset news article file that matches a shape file record
                        // there is no need to find another one since we have just created a record in the FeatureCollectionTable.
                        break;
                    }
                }
            }

            // Create a feature collection and add the feature collection tables
            FeatureCollection myFeatureCollection = new FeatureCollection();

            myFeatureCollection.Tables.Add(myFeatureCollectionTable);

            // Create a FeatureCollectionLayer
            FeatureCollectionLayer myFeatureCollectionLayer = new FeatureCollectionLayer(myFeatureCollection);

            myFeatureCollectionLayer.Id   = "Joined"; // might not be needed
            myFeatureCollectionLayer.Name = "JoinedFCL";

            // When the layer loads, zoom the map centered on the feature collection
            await myFeatureCollectionLayer.LoadAsync();

            // Add the layer to the Map's Operational Layers collection
            MyMapView.Map.OperationalLayers.Add(myFeatureCollectionLayer);
        }
Exemplo n.º 7
0
        public async void AddGeocoderDataSet(FeatureTable table, GeocoderSettings geocoder)
        {
            try
            {
                _cancel = false;
                Logging.LogMethodCall(ClassName, () => new Dictionary <String, object> {
                    { nameof(table), table }, { nameof(geocoder), geocoder }
                });
                bool blHouseNumberField = false, blLeftFromField = false, blLeftToField = false, blRightFromField = false, blRightToField = false, blPreDirField = false, blStreetNameField = false, blStreetTypeField = false, blSufDirField = false, blAptNumberField = false, blZoneField = false;
                int  flds = 0;
                if ((blHouseNumberField = !string.IsNullOrWhiteSpace(geocoder.HouseNumberField)) && table.Fields.Any(fld => fld.Name == geocoder.HouseNumberField))
                {
                    flds++;
                }
                if ((blLeftFromField = !string.IsNullOrWhiteSpace(geocoder.LeftFromField)) && table.Fields.Any(fld => fld.Name == geocoder.LeftFromField))
                {
                    flds++;
                }
                if ((blLeftToField = !string.IsNullOrWhiteSpace(geocoder.LeftToField)) && table.Fields.Any(fld => fld.Name == geocoder.LeftToField))
                {
                    flds++;
                }
                if ((blRightFromField = !string.IsNullOrWhiteSpace(geocoder.RightFromField)) && table.Fields.Any(fld => fld.Name == geocoder.RightFromField))
                {
                    flds++;
                }
                if ((blRightToField = !string.IsNullOrWhiteSpace(geocoder.RightToField)) && table.Fields.Any(fld => fld.Name == geocoder.RightToField))
                {
                    flds++;
                }
                if ((blPreDirField = !string.IsNullOrWhiteSpace(geocoder.PreDirField)) && table.Fields.Any(fld => fld.Name == geocoder.PreDirField))
                {
                    flds++;
                }
                if ((blStreetNameField = !string.IsNullOrWhiteSpace(geocoder.StreetNameField)) && table.Fields.Any(fld => fld.Name == geocoder.StreetNameField))
                {
                    flds++;
                }
                if ((blStreetTypeField = !string.IsNullOrWhiteSpace(geocoder.StreetTypeField)) && table.Fields.Any(fld => fld.Name == geocoder.StreetTypeField))
                {
                    flds++;
                }
                if ((blSufDirField = !string.IsNullOrWhiteSpace(geocoder.SufDirField)) && table.Fields.Any(fld => fld.Name == geocoder.SufDirField))
                {
                    flds++;
                }
                if ((blAptNumberField = !string.IsNullOrWhiteSpace(geocoder.AptNumberField)) && table.Fields.Any(fld => fld.Name == geocoder.AptNumberField))
                {
                    flds++;
                }
                if ((blZoneField = !string.IsNullOrWhiteSpace(geocoder.ZoneField)) && table.Fields.Any(fld => fld.Name == geocoder.ZoneField))
                {
                    flds++;
                }
                if (flds == 0)
                {
                    ErrorHelper.OnMessage("No address records available for (" + geocoder.LayerName + ").");
                }
                else
                {
                    var qf = new QueryParameters();
                    qf.WhereClause = "1=1";
                    var result = await table.QueryFeaturesAsync(qf);

                    var ds = new GeocodeDataset
                    {
                        Name          = geocoder.LayerName,
                        MinMatchScore = geocoder.MinMatchScore
                    };
                    foreach (Feature row in result)
                    {
                        String address = String.Empty;

                        switch (geocoder.Type)
                        {
                        case GeocoderTypes.SingleField:
                            address = getDictionaryValue(row.Attributes, geocoder.StreetNameField, blStreetNameField);
                            break;

                        case GeocoderTypes.SingleHouse:
                            address = String.Format("{0} {1} {2} {3} {4} {5}",
                                                    getDictionaryValue(row.Attributes, geocoder.HouseNumberField, blHouseNumberField),
                                                    getDictionaryValue(row.Attributes, geocoder.AptNumberField, blAptNumberField),
                                                    getDictionaryValue(row.Attributes, geocoder.PreDirField, blPreDirField),
                                                    getDictionaryValue(row.Attributes, geocoder.StreetNameField, blStreetNameField),
                                                    getDictionaryValue(row.Attributes, geocoder.StreetTypeField, blStreetTypeField),
                                                    getDictionaryValue(row.Attributes, geocoder.SufDirField, blSufDirField));
                            break;
                            //case GeocoderTypes.SingleRange:
                            //    continue;
                            //case GeocoderTypes.DualRange:
                            //    continue;
                        }
                        if (string.IsNullOrWhiteSpace(address))
                        {
                            continue;
                        }
                        GeocodeRecord gr = new GeocodeRecord
                        {
                            AddressStandardized = StandardizeAddress(address),
                            Location            = row.Geometry
                        };
                        gr.AddressStandardized.Zone = getDictionaryValue(row.Attributes, geocoder.ZoneField, blZoneField);

                        string soundex = gr.AddressStandardized.StreetNameSoundex;
                        if (!ds.RecordFamilies.ContainsKey(soundex))
                        {
                            ds.RecordFamilies.Add(soundex, new List <GeocodeRecord>());
                        }
                        ds.RecordFamilies[soundex].Add(gr);
                        if (_cancel)
                        {
                            return;
                        }
                    }
                    if (ds.RecordFamilies.Count > 0)
                    {
                        GeocoderDatasets.Add(ds);
                        GeocoderAvailable = true;
                    }
                    else
                    {
                        ErrorHelper.OnMessage("No address fields found for  (" + geocoder.LayerName + ").");
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHelper.OnError(MethodBase.GetCurrentMethod().DeclaringType.Name, "Error setting up geocoder", ex);
            }
        }
Exemplo n.º 8
0
        private async void renderBtn_Click(object sender, RoutedEventArgs e)
        {
            // 随机
            Random rd = new Random();

            UniqueValueRenderer regionRenderer = new UniqueValueRenderer();

            // 需要找的field的字段名
            regionRenderer.FieldNames.Add(chooseField);
            // 获取值
            QueryParameters query = new QueryParameters();

            query.WhereClause = string.Format("upper(FID) >= 0");
            FeatureQueryResult queryResult = await featureTable.QueryFeaturesAsync(query);

            IEnumerator <Feature> resultFeatures = queryResult.GetEnumerator();
            List <Object>         featureValue   = new List <Object>();

            try
            {
                while (resultFeatures.MoveNext())
                {
                    featureValue.Add((resultFeatures.Current).GetAttributeValue(chooseField));
                }
                featureValue = featureValue.Distinct().ToList();
            }
            catch
            {
                return;
            }
            // 将值分组
            int count = featureValue.Count;

            if (layer.FeatureTable.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Point)
            {
                for (int i = 0; i < count; i++)
                {
                    int num = rd.Next(0, sort);
                    System.Drawing.Color tempColor       = colorList[num];
                    SimpleMarkerSymbol   tempPointSymbol = new SimpleMarkerSymbol()
                    {
                        Color = tempColor, Size = 6, Style = SimpleMarkerSymbolStyle.Circle
                    };
                    regionRenderer.UniqueValues.Add(new UniqueValue("null", "null", tempPointSymbol, featureValue[i]));
                }
                regionRenderer.DefaultSymbol = defaultPoint;
                regionRenderer.DefaultLabel  = "zero";
            }
            else if (layer.FeatureTable.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Polyline)
            {
                for (int i = 0; i < count; i++)
                {
                    int num = rd.Next(0, sort);
                    System.Drawing.Color tempColor      = colorList[num];
                    SimpleLineSymbol     tempLineSymbol = new SimpleLineSymbol()
                    {
                        Style = SimpleLineSymbolStyle.Solid, Width = 5, Color = tempColor
                    };
                    regionRenderer.UniqueValues.Add(new UniqueValue("null", "null", tempLineSymbol, featureValue[i]));
                }
                regionRenderer.DefaultSymbol = defaultLine;
                regionRenderer.DefaultLabel  = "zero";
            }
            else if (layer.FeatureTable.GeometryType == Esri.ArcGISRuntime.Geometry.GeometryType.Polygon)
            {
                SimpleLineSymbol outLineSymbol = new SimpleLineSymbol()
                {
                    Style = SimpleLineSymbolStyle.Solid, Width = 3, Color = System.Drawing.Color.Gray
                };
                for (int i = 0; i < count; i++)
                {
                    int num = rd.Next(0, sort);
                    System.Drawing.Color tempColor      = colorList[num];
                    SimpleFillSymbol     tempFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, tempColor, outLineSymbol);
                    regionRenderer.UniqueValues.Add(new UniqueValue("null", "null", tempFillSymbol, featureValue[i]));
                }
                regionRenderer.DefaultSymbol = defaultFill;
                regionRenderer.DefaultLabel  = "zero";
            }
            layer.Renderer = regionRenderer;
        }