public async Task <List <MapPoint> > ToPointCollectionAsync(Geometry geometry) { List <MapPoint> result = null; PointNr = 0; if (geometry != null) { result = new List <MapPoint>(); GeometryType geometryType = geometry.GeometryType; switch (geometryType) { case GeometryType.Point: if ((!geometry.IsEmpty) && IsPointMeasurement) { if (geometry is MapPoint mapPoint) { result.Add(await AddZOffsetAsync(mapPoint)); } } break; case GeometryType.Polygon: case GeometryType.Polyline: if (geometry is Multipart multipart) { ReadOnlyPointCollection points = multipart.Points; IEnumerator <MapPoint> enumPoints = points.GetEnumerator(); while (enumPoints.MoveNext()) { MapPoint mapPointPart = enumPoints.Current; result.Add(await AddZOffsetAsync(mapPointPart)); } } break; } PointNr = result.Count; if ((PointNr >= 2) && (geometryType == GeometryType.Polygon)) { MapPoint point1 = result[0]; MapPoint point2 = result[PointNr - 1]; PointNr = point1.IsEqual(point2) ? (PointNr - 1) : PointNr; } if ((PointNr >= 2) && (geometryType == GeometryType.Polyline)) { MapPoint point1 = result[0]; MapPoint point2 = result[PointNr - 1]; if (point1.IsEqual(point2)) { PointNr = PointNr - 1; result.RemoveAt(result.Count - 1); } } } return(result); }
/// <summary> /// テキスト ボックスに格納される /// </summary> private void ManipulateGeometry(FeatureLayer manipulatedlayer) { QueuedTask.Run(() => { var fileGDBpath = new FileGeodatabaseConnectionPath(new Uri(_gdbPath)); using (Geodatabase geodatabase = new Geodatabase(fileGDBpath)) { // フィーチャクラスを取得する using (FeatureClass featureClass = geodatabase.OpenDataset <FeatureClass>(_featureClassName)) { using (var rowCursor = manipulatedlayer.Search(null)) { var editOperation = new EditOperation(); if (manipulatedlayer.GetFeatureClass().GetDefinition().GetShapeType().ToString() == "Polygon") { while (rowCursor.MoveNext()) { using (var row = rowCursor.Current) { Feature feature = row as Feature; Geometry shape = feature.GetShape(); MapPoint mapPoint = GeometryEngine.Instance.Centroid(shape); //レイヤーのフィーチャクラスの Shape フィールドを取得 string shapeField = featureClass.GetDefinition().GetShapeField(); var attributes = new Dictionary <string, object>(); attributes.Add(shapeField, mapPoint); //ジオメトリの属性値設定 foreach (var fld in row.GetFields().Where(fld => fld.FieldType != FieldType.Geometry && fld.FieldType != FieldType.OID && fld.Name != "Shape_Length" && fld.Name != "Shape_Area")) { attributes.Add(fld.Name, row[fld.Name]); } //フィーチャの作成と編集実行 editOperation.Create(featureClass, attributes); } } } else if (manipulatedlayer.GetFeatureClass().GetDefinition().GetShapeType().ToString() == "Polyline") { while (rowCursor.MoveNext()) { using (var row = rowCursor.Current) { Feature feature = row as Feature; Polyline polyline = feature.GetShape() as Polyline; ReadOnlyPointCollection pts = polyline.Points; var mapPointBuilder = new MapPointBuilder(manipulatedlayer.GetSpatialReference()); mapPointBuilder.X = pts.First().X; mapPointBuilder.Y = pts.First().Y; MapPoint firstMapPoint = mapPointBuilder.ToGeometry(); mapPointBuilder.X = pts.Last().X; mapPointBuilder.Y = pts.Last().Y; MapPoint lastMapPoint = mapPointBuilder.ToGeometry(); //レイヤーのフィーチャクラスの Shape フィールドを取得 string shapeField = featureClass.GetDefinition().GetShapeField(); var firstAttributes = new Dictionary <string, object>(); firstAttributes.Add(shapeField, firstMapPoint); var lastAttributes = new Dictionary <string, object>(); lastAttributes.Add(shapeField, lastMapPoint); //ジオメトリの属性値設定 foreach (var fld in row.GetFields().Where(fld => fld.FieldType != FieldType.Geometry && fld.FieldType != FieldType.OID && fld.Name != "Shape_Length" && fld.Name != "Shape_Area")) { firstAttributes.Add(fld.Name, row[fld.Name]); lastAttributes.Add(fld.Name, row[fld.Name]); } editOperation.Create(featureClass, firstAttributes); editOperation.Create(featureClass, lastAttributes); } } } editOperation.Execute(); } } } }); }