示例#1
0
        // 피처추가
        public async void handlerGeoViewTappedAddFeature(object sender, GeoViewInputEventArgs e)
        {
            try
            {
                // Get the MapPoint from the EventArgs for the tap.
                MapPoint destinationPoint = e.Location;
                // Normalize the point - needed when the tapped location is over the international date line.
                destinationPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(destinationPoint);



                // Get the path to the first layer - the local feature service url + layer ID
                //string layerUrl = _localFeatureService.Url + "/" + GetLayerId(_selectedLayer);

                // Create the ServiceFeatureTable
                //ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(new Uri(layerUrl));
                //FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);

                // Wait for the layer to load
                //await featureLayer.LoadAsync();


                FeatureTable layerTable = layers[_selectedLayerNm].FeatureTable;


                //피처추가
                Feature _addedFeature = layerTable.CreateFeature();
                _addedFeature.Geometry = destinationPoint;

                //속성추가
                //Field Field_FTR_CDE = new Field(FieldType.Text, "FTR_CDE", "시설물코드", 50);
                //Field Field_FTR_IDN = new Field(FieldType.Int32, "FTR_IDN", "관리번호", 10);
                //Field Field_SHT_NUM = new Field(FieldType.Text, "SHT_NUM", "도엽번호", 50);

                string ftr_cde = "SA118";
                try
                {
                    //ftr_cde = _selectedLayer.Split(',')[0];
                }
                catch (Exception) {}

                _addedFeature.SetAttributeValue("FTR_CDE", ftr_cde);
                _addedFeature.SetAttributeValue("FTR_IDN", 999f);
                _addedFeature.SetAttributeValue("SHT_NUM", "99999");
                _addedFeature.SetAttributeValue("SHT_NUM", "99999");
                _addedFeature.SetAttributeValue("HJD_CDE", "3171033000");
                _addedFeature.SetAttributeValue("MNG_CDE", "MNG401");



                await layerTable.AddFeatureAsync(_addedFeature);

                //추가내용 새로고침
                _addedFeature.Refresh();

                MessageBox.Show("Added feature ", "Success!");

                //이벤트핸들러원복
                mapView.GeoViewTapped -= handlerGeoViewTappedMoveFeature;
                mapView.GeoViewTapped -= handlerGeoViewTappedAddFeature;
                mapView.GeoViewTapped -= handlerGeoViewTapped;
                mapView.GeoViewTapped += handlerGeoViewTapped;
            }
            catch (Exception ex)
            {
                Messages.ShowErrMsgBox(ex.ToString());
            }
        }
示例#2
0
        /// <summary>
        /// 레이어에 Feature(MapPoint, PolyLine, Polygon)를 추가
        /// </summary>
        /// <param name="geometry"></param>
        private async void AddFeatureToLayer(Geometry geometry)
        {
            FeatureTable layerTable = layers[_selectedLayerNm].FeatureTable;

            if (layerTable is null)
            {
                layerTable = await InitLayerTable(_selectedLayerNm);
            }

            //피처추가
            Feature _addedFeature = layerTable.CreateFeature();

            _addedFeature.Geometry = geometry;

            //속성추가
            _addedFeature.SetAttributeValue("FTR_CDE", this.FTR_CDE);
            _addedFeature.SetAttributeValue("FTR_IDN", Convert.ToDouble(NEW_FTR_IDN));

            try
            {
                await layerTable.AddFeatureAsync(_addedFeature);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                //관리번호 타입이 정수이여서 에러나면 다시 시도
                _addedFeature.SetAttributeValue("FTR_IDN", Convert.ToInt32(NEW_FTR_IDN));
                try
                {
                    await layerTable.AddFeatureAsync(_addedFeature);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            finally
            {
                _addedFeature.Refresh();
            }

            //위치정보 WKT 만들기
            if (geometry is Polyline)
            {
                Polyline line = geometry as Polyline;
                GisCmm.WKT_LINE += "LINESTRING(";
                foreach (var p in line.Parts[0].Points)
                {
                    GisCmm.WKT_LINE += (p.X + " " + p.Y + ",");
                }
                GisCmm.WKT_LINE = GisCmm.WKT_LINE.Substring(0, GisCmm.WKT_LINE.Length - 1) + ")";
            }
            else if (geometry is Polygon)
            {
                Polygon gon = geometry as Polygon;
                GisCmm.WKT_POLYGON += "MULTIPOLYGON(((";
                foreach (var p in gon.Parts[0].Points)
                {
                    GisCmm.WKT_POLYGON += (p.X + " " + p.Y + ",");
                }
                //첫포인트로 폴리곤 마무리
                foreach (var p in gon.Parts[0].Points)
                {
                    GisCmm.WKT_POLYGON += (p.X + " " + p.Y + ",");
                    break;
                }

                GisCmm.WKT_POLYGON = GisCmm.WKT_POLYGON.Substring(0, GisCmm.WKT_POLYGON.Length - 1) + ")))";
            }
            else if (geometry is MapPoint)
            {
                MapPoint point = geometry as MapPoint;
                GisCmm.WKT_POINT = "POINT(" + point.X + " " + point.Y + ")";
            }


            //추가내용 새로고침
            _addedFeature.Refresh();
        }