private async void SelectTagByTypoAsync(FeatureLayer featureLayer, string tipo, QueryParameters queryParams) { try { FeatureQueryResult result = await featureLayer.SelectFeaturesAsync(queryParams, SelectionMode.New); if (null != result) { IEnumerator <Feature> enumerator = result.GetEnumerator(); if (null != enumerator) { while (enumerator.MoveNext()) { Feature item = enumerator.Current; MapPoint projectedLocation = (MapPoint)item.Geometry; var tag = item.Attributes["TAG"]; var intent = new Intent(this, typeof(ConsultarTap)); intent.PutExtra("codigoTag", tag.ToString()); intent.PutExtra("x", projectedLocation.X); intent.PutExtra("y", projectedLocation.Y); intent.PutExtra("reference", projectedLocation.SpatialReference.Wkid); intent.PutExtra("tipo", tipo); StartActivity(intent); } } } } catch (Exception ex) { Log.Info("Error", ex.Message); GenerateAlertError("No tiene Tag"); } }
private async void myTestBtn3_Click(object sender, RoutedEventArgs e) { FeatureLayer a = (FeatureLayer)myMapView.Map.OperationalLayers[0]; FeatureQueryResult r = await a.GetSelectedFeaturesAsync(); IEnumerator <Feature> resultFeatures = r.GetEnumerator(); List <Feature> features = new List <Feature>(); while (resultFeatures.MoveNext()) { features.Add(resultFeatures.Current); } myTest.Text = features.Count + " 个"; Esri.ArcGISRuntime.Geometry.Geometry resultGeometry = GeometryEngine.Union(features[0].Geometry, features[1].Geometry); myTest.Text = resultGeometry.IsEmpty + ""; // 渲染 SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol() { Style = SimpleLineSymbolStyle.Solid, Width = 4, Color = System.Drawing.Color.Green }; Graphic graphic = new Graphic(resultGeometry, simpleLineSymbol); graphicsOverlay.Graphics.Add(graphic); }
// 添加要素 private async void add2SHP_Click(object sender, RoutedEventArgs e) { if (table.CanAdd() && layersComboBox.Items.Count >= 1 && curSelGraphic != null && layersComboBox.SelectedIndex >= 0) { // 图层 featureLayer = (FeatureLayer)(myMapView.Map.OperationalLayers[layersComboBox.SelectedIndex]); // 属性表 table = featureLayer.FeatureTable; QueryParameters query = new QueryParameters(); query.WhereClause = string.Format("upper(FID) = \"0\""); FeatureQueryResult queryResult = await table.QueryFeaturesAsync(query); IEnumerator <Feature> resultFeatures = queryResult.GetEnumerator(); List <Feature> features = new List <Feature>(); while (resultFeatures.MoveNext()) { features.Add(resultFeatures.Current); } Feature tempGeoElement = features[0]; Feature addFeature = table.CreateFeature(features[0].Attributes, curSelGraphic.Geometry); await table.AddFeatureAsync(addFeature); t1.Text = "要素保存成功!"; } }
// 点选 private async void myMapViewGetAttributeValue(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { StackPanel stackPanel = (StackPanel)w.FindName("cykGeometryCalcuEdit"); if (layersComboBox.SelectedIndex >= 0 && stackPanel.Visibility == Visibility.Visible) { myShapeFileResult = await myMapView.IdentifyLayerAsync(featureLayer, e.Position, 15, false); //if(myShapeFileResult != null) MessageBox.Show("" + 12 + " " + myShapeFileResult); // 要素选择高亮 try { string numberFID = ((Feature)(myShapeFileResult.GeoElements[0])).GetAttributeValue("FID") + ""; QueryParameters queryParams = new QueryParameters { //WhereClause = "upper(FID) = " + numberFID Geometry = e.Location }; FeatureQueryResult queryResult = await featureLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New); IEnumerator <Feature> resultFeatures = queryResult.GetEnumerator(); List <Feature> features = new List <Feature>(); while (resultFeatures.MoveNext()) { features.Add(resultFeatures.Current); } // 每一次"选择"都需要点击一次"选择"按钮 myMapView.GeoViewTapped -= myMapViewGetAttributeValue; //t1.Text = numberFID + " ID;" + features.Count + "个; " + e.Location.X + ", " + e.Location.Y + " // 投影" + myMapView.Map.SpatialReference + "," + myMapView.UnitsPerPixel; } catch (Exception ex) { } //t1.Text += featureLayer.Description + table.DisplayName + "..."; } }
private async void unionBtn_Click(object sender, RoutedEventArgs e) { FeatureQueryResult r = await layer.GetSelectedFeaturesAsync(); IEnumerator <Feature> resultFeatures = r.GetEnumerator(); List <Feature> features = new List <Feature>(); while (resultFeatures.MoveNext()) { features.Add(resultFeatures.Current); } for (int i = 0; i < features.Count - 1; i++) { resultGeometry = GeometryEngine.Union(features[i].Geometry, features[i + 1].Geometry.Extent); } try { if (featureStyle == 1) { graphic = new Graphic(resultGeometry, simplePointSymbol); } else if (featureStyle == 2) { graphic = new Graphic(resultGeometry, simpleLineSymbol); } else if (featureStyle == 3) { graphic = new Graphic(resultGeometry, simpleFillSymbol); } MainWindow.graphicsOverlay.Graphics.Add(graphic); } catch { } }
/// <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); }
private async void MainWindow_Click(object sender, Esri.ArcGISRuntime.UI.Controls.GeoViewInputEventArgs e) { if (count == 0) { count = 1; _downPoint = e.Location; //_downPointP = e.Position; //dragSelectRectangle.Margin = new Thickness(0, 0, 0, 0); //dragSelectRectangle.Width = 0; //dragSelectRectangle.Height = 0; } else { count = 0; var _endpoint = e.Location; try { double tolerance = 0.0001; double mapTolerance = tolerance /** myMapView.UnitsPerPixel*/; MapPoint geometry = new MapPoint((_downPoint.X + _endpoint.X) / 2, (_downPoint.Y + _endpoint.Y) / 2, myMapView.SpatialReference); if (myMapView.IsWrapAroundEnabled) { geometry = (MapPoint)GeometryEngine.NormalizeCentralMeridian(geometry); } Envelope selectionEnvelope = new Envelope(geometry, Math.Abs(_downPoint.X - _endpoint.X), Math.Abs(_downPoint.Y - _endpoint.Y) /*geometry.X - mapTolerance, geometry.Y - mapTolerance, geometry.X + mapTolerance, geometry.Y + mapTolerance,*/ /*myMapView.Map.SpatialReference*/); QueryParameters queryParams = new QueryParameters() { Geometry = selectionEnvelope }; FeatureLayer tempLayer = (FeatureLayer)(myMapView.Map.OperationalLayers[0]); FeatureQueryResult fr = await tempLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New); IEnumerator <Feature> frr = fr.GetEnumerator(); List <Feature> features = new List <Feature>(); while (frr.MoveNext()) { features.Add(frr.Current); } // 查看属性 Esri.ArcGISRuntime.Data.FeatureTable tempTable = (Esri.ArcGISRuntime.Data.FeatureTable)tempLayer.FeatureTable; long row = tempTable.NumberOfFeatures; int col = tempTable.Fields.Count; List <String> fieldNames = new List <string>(); for (int i = 0; i < col; i++) { fieldNames.Add(tempTable.Fields[i] + ""); } StackPanel stackPanel = new StackPanel(); WrapPanel[] wrapPanels = new WrapPanel[row]; // 字段名 WrapPanel wrapPanelField = new WrapPanel() { Margin = new Thickness() { Left = 10, Top = 1, Right = 10, Bottom = 1 } }; for (int i = 0; i < col; i++) { Button button = new Button() { Content = fieldNames[i], ToolTip = fieldNames[i], Width = 60, Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 100, 183, 134)) }; wrapPanelField.Children.Add(button); } stackPanel.Children.Add(wrapPanelField); // 记录 for (int i = 0; i < row; i++) { wrapPanels[i] = new WrapPanel() { Margin = new Thickness() { Left = 10, Top = 1, Right = 10, Bottom = 1 } }; for (int j = 0; j < col; j++) { Button button = new Button() { Width = 60, Content = features[i].GetAttributeValue(fieldNames[j]), ToolTip = features[i].GetAttributeValue(fieldNames[j]) }; wrapPanels[i].Children.Add(button); } stackPanel.Children.Add(wrapPanels[i]); } ScrollViewer scrollViewer = new ScrollViewer(); scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Visible; scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; scrollViewer.Content = stackPanel; var window = new Window(); window.Content = scrollViewer; window.SizeToContent = SizeToContent.WidthAndHeight; window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.MaxHeight = 700; window.MaxWidth = 1000; window.Title = "要素多选属性表"; window.Show(); } catch { t1.Text = "要素多选发生错误"; } } }
// 打开属性表 private async void OpenFeatureTableWindow_Layers_CheckBox(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; ContextMenu cm = menuItem.Parent as ContextMenu; int index = int.Parse(cm.Name.Substring(16)); FeatureLayer tempLayer = (FeatureLayer)myMapView.Map.OperationalLayers[index]; Esri.ArcGISRuntime.Data.FeatureTable tempTable = tempLayer.FeatureTable; QueryParameters query = new QueryParameters(); query.WhereClause = string.Format("upper(FID) >= 0"); FeatureQueryResult queryResult = await tempTable.QueryFeaturesAsync(query); IEnumerator <Feature> resultFeatures = queryResult.GetEnumerator(); List <Feature> features = new List <Feature>(); while (resultFeatures.MoveNext()) { features.Add(resultFeatures.Current); } long row = tempTable.NumberOfFeatures; int col = tempTable.Fields.Count; List <String> fieldNames = new List <string>(); for (int i = 0; i < col; i++) { fieldNames.Add(tempTable.Fields[i] + ""); } StackPanel stackPanel = new StackPanel(); WrapPanel[] wrapPanels = new WrapPanel[row]; // 字段名 WrapPanel wrapPanelField = new WrapPanel() { Margin = new Thickness() { Left = 10, Top = 1, Right = 10, Bottom = 1 } }; for (int i = 0; i < col; i++) { Button button = new Button() { Content = fieldNames[i], ToolTip = fieldNames[i], Width = 60, Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 100, 183, 134)) }; wrapPanelField.Children.Add(button); } stackPanel.Children.Add(wrapPanelField); // 记录 for (int i = 0; i < row; i++) { wrapPanels[i] = new WrapPanel() { Margin = new Thickness() { Left = 10, Top = 1, Right = 10, Bottom = 1 } }; for (int j = 0; j < col; j++) { Button button = new Button() { Width = 60, Content = features[i].GetAttributeValue(fieldNames[j]), ToolTip = features[i].GetAttributeValue(fieldNames[j]) }; wrapPanels[i].Children.Add(button); } stackPanel.Children.Add(wrapPanels[i]); } ScrollViewer scrollViewer = new ScrollViewer(); scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Visible; scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; scrollViewer.Content = stackPanel; var window = new Window(); window.Content = scrollViewer; window.SizeToContent = SizeToContent.WidthAndHeight; window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.MaxHeight = 700; window.MaxWidth = 1000; window.Title = check[index].Content + "属性表"; window.Show(); }
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; }
/// <summary> /// Creates a frequency analysis file for the specified table. /// </summary> /// <param name="outputFile">the file to which to write the analysis</param> /// <param name="table">the table to analyse</param> /// <returns>did things go well?</returns> public async Task <bool> RunFrequencyAnalysis(string outputFile, GeodatabaseFeatureTable table) { bool allGood = true; long totalRecs = table.NumberOfFeatures; Dictionary <string, Dictionary <string, uint> > freqs = new Dictionary <string, Dictionary <string, uint> >(); string whereClause = "1=1"; string orderingName = null; long lastOID = 0; int lastBatchCount = -1; long totalRecordsProcessed = 0; int recordsPerBatch = 10000; foreach (Field aField in table.Fields) { if (aField.FieldType == FieldType.OID) { orderingName = aField.Name; whereClause = aField.Name + " > " + lastOID + " order by " + aField.Name; break; } } try { while (lastBatchCount != 0) { QueryParameters queryParams = new QueryParameters(); queryParams.ReturnGeometry = true; lastBatchCount = 0; if (orderingName == null) { queryParams.WhereClause = "1=1"; } else { queryParams.WhereClause = orderingName + " > " + lastOID + " order by " + orderingName; } FeatureQueryResult result = await table.QueryFeaturesAsync(queryParams); IEnumerator <Feature> features = result.GetEnumerator(); object attValue = null; string attStringValue = null; // // Collect the frequencies. // while (features.MoveNext()) { Feature aFeature = features.Current; totalRecordsProcessed++; lastBatchCount++; foreach (string attName in aFeature.Attributes.Keys) { attValue = aFeature.Attributes[attName]; if (attValue == null) { attStringValue = ""; } else { attStringValue = attValue.ToString(); } this.StoreFrequency(attName, attStringValue, freqs); if (orderingName.Equals(attName)) { lastOID = (long)attValue; } } if (totalRecordsProcessed % 2500 == 0) { Trace.WriteLine("Processed " + totalRecordsProcessed + " out of " + table.NumberOfFeatures); } if (lastBatchCount == recordsPerBatch) { features.Dispose(); break; } } } // // Write out the frequencies. // using (StreamWriter writer = new StreamWriter(outputFile)) { foreach (string attributeName in freqs.Keys) { Dictionary <string, uint> attributeFreqs = freqs[attributeName]; if (attributeFreqs.Count > 200) { writer.Write("\""); writer.Write(attributeName); writer.Write("\""); writer.Write(","); writer.Write("\""); writer.Write("<MANY VALUES>"); writer.Write("\""); writer.Write(","); writer.Write(table.NumberOfFeatures); writer.Write("\n"); } else { foreach (string attributeValue in attributeFreqs.Keys) { uint numVals = attributeFreqs[attributeValue]; writer.Write("\""); writer.Write(attributeName); writer.Write("\""); writer.Write(","); writer.Write("\""); writer.Write(attributeValue); writer.Write("\""); writer.Write(","); writer.Write(numVals); writer.Write("\n"); } } } } } catch (Exception e) { allGood = false; string excString = "=====================\n"; excString = excString + e.Message + "\n"; excString = excString + e.StackTrace + "\n"; this.LoggingText = excString; } return(allGood); }
private async void sureBtn_Click(object sender, RoutedEventArgs e) { try { FeatureLayer tempLayer = (FeatureLayer)myMapView.Map.OperationalLayers[index]; Esri.ArcGISRuntime.Data.FeatureTable tempTable = tempLayer.FeatureTable; // 语句 QueryParameters query = new QueryParameters(); query.WhereClause = string.Format(inTxt.Text); FeatureQueryResult queryResult = await tempTable.QueryFeaturesAsync(query); IEnumerator <Feature> resultFeatures = queryResult.GetEnumerator(); List <Feature> features = new List <Feature>(); while (resultFeatures.MoveNext()) { features.Add(resultFeatures.Current); } MessageBox.Show(inTxt.Text + "\n" + features.Count + "\n" + query.WhereClause); //long row = tempTable.NumberOfFeatures; long row = features.Count; int col = tempTable.Fields.Count; List <String> fieldNames = new List <string>(); for (int i = 0; i < col; i++) { fieldNames.Add(tempTable.Fields[i] + ""); } StackPanel stackPanel = new StackPanel(); WrapPanel[] wrapPanels = new WrapPanel[row]; // 字段名 WrapPanel wrapPanelField = new WrapPanel() { Margin = new Thickness() { Left = 10, Top = 1, Right = 10, Bottom = 1 } }; for (int i = 0; i < col; i++) { Button button = new Button() { Content = fieldNames[i], ToolTip = fieldNames[i], Width = 60, Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(255, 100, 183, 134)) }; wrapPanelField.Children.Add(button); } stackPanel.Children.Add(wrapPanelField); // 记录 for (int i = 0; i < row; i++) { wrapPanels[i] = new WrapPanel() { Margin = new Thickness() { Left = 10, Top = 1, Right = 10, Bottom = 1 } }; for (int j = 0; j < col; j++) { Button button = new Button() { Width = 60, Content = features[i].GetAttributeValue(fieldNames[j]), ToolTip = features[i].GetAttributeValue(fieldNames[j]) }; wrapPanels[i].Children.Add(button); } stackPanel.Children.Add(wrapPanels[i]); } var window = new Window(); window.Content = stackPanel; window.SizeToContent = SizeToContent.WidthAndHeight; window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.Title = "属性查询结果"; window.Show(); } catch (Exception ex2) { MessageBox.Show("查询错误!\n" + ex2.Message + "\n"); } }