/// <summary> /// Projects the input geometry to WGS 84 /// </summary> private void ProjectGeometry(Geometry geometry) { // Geometry requires reprojection. Ensure geometry service is specified. if (string.IsNullOrEmpty(GeometryServiceUrl)) { throw new Exception(Strings.GeometryServiceNotSpecified); } // Initialize geometry service object if necessary if (_geometryService == null) { _geometryService = new GeometryService(GeometryServiceUrl); _geometryService.ProjectCompleted += GeometryService_ProjectCompleted; _geometryService.Failed += GeometryService_Failed; _outSpatialRef = new SpatialReference(4326); } // Project the geometry using the geometry service Graphic g = new Graphic() { Geometry = geometry }; // if a previous projection is still executing, cancel it if (_geometryService.IsBusy) { _geometryService.CancelAsync(); } _geometryService.ProjectAsync(new Graphic[] { g }, _outSpatialRef); }
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { _geometryService.CancelAsync(); _queryTask.CancelAsync(); Graphic clickGraphic = new Graphic(); clickGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; clickGraphic.Geometry = e.MapPoint; // Input spatial reference for buffer operation defined by first feature of input geometry array clickGraphic.Geometry.SpatialReference = MyMap.SpatialReference; _pointAndBufferGraphicsLayer.ClearGraphics(); _resultsGraphicsLayer.ClearGraphics(); clickGraphic.SetZIndex(2); _pointAndBufferGraphicsLayer.Graphics.Add(clickGraphic); // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters() { BufferSpatialReference = new SpatialReference(4326), OutSpatialReference = MyMap.SpatialReference, Unit = LinearUnit.Meter, }; bufferParams.Distances.Add(100); bufferParams.Features.Add(clickGraphic); _geometryService.BufferAsync(bufferParams); }
public void ProcessBuffer() // 传入空间对象进行buffer计算, { try { _geometryService.CancelAsync(); Graphic TempGraphic = new Graphic(); TempGraphic.Geometry = bgeom; TempGraphic.Geometry.SpatialReference = new SpatialReference(4326); BufferParameters bufferParams = new BufferParameters() { BufferSpatialReference = new SpatialReference(102113), OutSpatialReference = new SpatialReference(4326), Unit = LinearUnit.Meter }; // double degree = Distance / (106 * 1000); // bufferParams.Distances.AddRange(new double[] { degree , degree }); bufferParams.Distances.Add(Distance); bufferParams.Features.Add(TempGraphic); _geometryService.BufferAsync(bufferParams); } catch (Exception e) { MessageBox.Show(e.ToString()); } }
private void CacheSnapObjects(ESRI.ArcGIS.Client.Geometry.Geometry geometryObject, double snapDistance) { // For the given geometry (line or circle), find all the features that fall within the snapDistance. // First we need to issue a buffer in this method. GeometryService_LineBufferCompleted will // do the feature query. _snapObjects.Clear(); GeometryService geometryServiceScaleRotate = new GeometryService(_xmlConfiguation.GeometryServerUrl); if (geometryServiceScaleRotate == null) return; geometryServiceScaleRotate.BufferCompleted += GeometryService_LineBufferCompleted; geometryServiceScaleRotate.Failed += GeometryService_Failed; geometryServiceScaleRotate.CancelAsync(); Graphic clickGraphic = new Graphic(); clickGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; clickGraphic.Geometry = geometryObject; // Input spatial reference for buffer operation defined by first feature of input geometry array clickGraphic.Geometry.SpatialReference = ParcelMap.SpatialReference; // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters() { BufferSpatialReference = ParcelMap.SpatialReference, OutSpatialReference = ParcelMap.SpatialReference, }; bufferParams.Distances.Add(snapDistance); bufferParams.Features.Add(clickGraphic); System.Diagnostics.Debug.WriteLine("Async: Buffering potential candidates for snapping."); geometryServiceScaleRotate.BufferAsync(bufferParams, snapDistance); }
protected override void Invoke(object parameter) { // Reset error Error = null; try { if (Target != null && OutputSpatialReference != null) { if (Target.SpatialReference == OutputSpatialReference || (Target.SpatialReference.IsWebMercator() && OutputSpatialReference.IsWebMercator())) { // Input geometry and output spatial reference define the // same projection. Assign input to output and complete. OutputGeometry = Target; OnCompleted(); } else if (Target.SpatialReference.IsWebMercator() && OutputSpatialReference.WKID == 4326) { // Web Mercator to WGS 84 can be done client-side OutputGeometry = new WebMercator().ToGeographic(Target); OnCompleted(); } else if (Target.SpatialReference.WKID == 4326 && OutputSpatialReference.IsWebMercator()) { // WGS 84 to Web Mercator can be done client-side OutputGeometry = new WebMercator().FromGeographic(Target); OnCompleted(); } else if (!string.IsNullOrEmpty(GeometryServiceUrl)) // Need to use geometry service { Graphic g = new Graphic() { Geometry = Target }; // if a previous project operation is still running, cancel it if (_geometryService.IsBusy) { _geometryService.CancelAsync(); } _geometryService.ProjectAsync(new Graphic[] { g }, OutputSpatialReference); } else // input not valid { OnFailed(new Exception(Strings.ProjectInputsNotValid)); } } } catch (Exception ex) { OnFailed(ex); } }
protected override void Invoke(object parameter) { // Clear error Error = null; try { if (Target != null && !string.IsNullOrEmpty(GeometryServiceUrl)) { if (Target is Polyline || Target is Polygon) // Only these types need simplification { Graphic g = new Graphic() { Geometry = Target }; // If a previous simplify operation is still executing, cancel it if (_geometryService.IsBusy) { _geometryService.CancelAsync(); } _geometryService.SimplifyAsync(new Graphic[] { g }); } else { // No simplification required - just complete OutputGeometry = Target; OnCompleted(); } } else { OnFailed(new Exception(Strings.SimplifyInputsNotValid)); } } catch (Exception ex) { OnFailed(ex); } }
private void CacheSnapObjects(ESRI.ArcGIS.Client.Geometry.Geometry geometryObject, double snapDistance) { // For the given geometry (line or circle), find all the features that fall within the snapDistance. // First we need to issue a buffer in this method. GeometryService_LineBufferCompleted will // do the feature query. _snapObjects.Clear(); GeometryService geometryServiceScaleRotate = new GeometryService(_xmlConfiguation.GeometryServerUrl); if (geometryServiceScaleRotate == null) { return; } geometryServiceScaleRotate.BufferCompleted += GeometryService_LineBufferCompleted; geometryServiceScaleRotate.Failed += GeometryService_Failed; geometryServiceScaleRotate.CancelAsync(); Graphic clickGraphic = new Graphic(); clickGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; clickGraphic.Geometry = geometryObject; // Input spatial reference for buffer operation defined by first feature of input geometry array clickGraphic.Geometry.SpatialReference = ParcelMap.SpatialReference; // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters() { BufferSpatialReference = ParcelMap.SpatialReference, OutSpatialReference = ParcelMap.SpatialReference, }; bufferParams.Distances.Add(snapDistance); bufferParams.Features.Add(clickGraphic); System.Diagnostics.Debug.WriteLine("Async: Buffering potential candidates for snapping."); geometryServiceScaleRotate.BufferAsync(bufferParams, snapDistance); }
private void CalculateDistance(MapPoint mapPoint) { double dDistance = 0; if (Double.TryParse(tbDistanceValue.Text, out dDistance) == false) { return; } if (dDistance <= 0) { return; } LinearUnit unit = EncodeLinearUnit(comboDistanceUnit.SelectionBoxItem.ToString()); _geometryService.CancelAsync(); Graphic clickGraphic = new Graphic(); //clickGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; clickGraphic.Geometry = mapPoint; // Input spatial reference for buffer operation defined by first feature of input geometry array clickGraphic.Geometry.SpatialReference = Map.SpatialReference; // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters() { BufferSpatialReference = new SpatialReference(4326), OutSpatialReference = Map.SpatialReference, Unit = unit, }; bufferParams.Distances.Add(dDistance); bufferParams.Features.Add(clickGraphic); _geometryService.BufferAsync(bufferParams); }
public void IdentifyPoint(Map ParcelMap, ref Configuration config, ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint) { if (config.IdentifyURL == "") { return; } if (config.IdentifyLayerCount == 0) { return; } if (config.UseQueryIdentify) { _dataItems = new List <DataItem>(); GeometryService geometryServicePointSnap = new GeometryService(config.GeometryServerUrl); if (geometryServicePointSnap == null) { return; } QueryItem queryItem = new QueryItem(ParcelMap, ref config, clickPoint, 0); geometryServicePointSnap.BufferCompleted += GeometryService_IdentifyPointBufferCompleted; geometryServicePointSnap.Failed += GeometryService_Failed; geometryServicePointSnap.CancelAsync(); SimpleMarkerSymbol defaultSymbolMarker = new SimpleMarkerSymbol() { Color = System.Windows.Media.Brushes.Black, Size = 8, Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle }; Graphic clickGraphic = new Graphic(); clickGraphic.Symbol = defaultSymbolMarker as ESRI.ArcGIS.Client.Symbols.Symbol; clickGraphic.Geometry = clickPoint; // Input spatial reference for buffer operation defined by first feature of input geometry array clickGraphic.Geometry.SpatialReference = ParcelMap.SpatialReference; // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters() { BufferSpatialReference = ParcelMap.SpatialReference, OutSpatialReference = ParcelMap.SpatialReference, Unit = LinearUnit.Meter, }; bufferParams.Distances.Add(config.SnapTolerance * config.SpatialReferenceUnitsPerMeter); bufferParams.Features.Add(clickGraphic); geometryServicePointSnap.BufferAsync(bufferParams, queryItem); } else { ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters() { Geometry = clickPoint, MapExtent = ParcelMap.Extent, Width = (int)ParcelMap.ActualWidth, Height = (int)ParcelMap.ActualHeight, LayerOption = LayerOption.visible, SpatialReference = ParcelMap.SpatialReference }; // For performance, we allow certain layers to be only identified. if (config.IdentifyLayerIDs != null) { foreach (int id in config.IdentifyLayerIDs) { identifyParams.LayerIds.Add(id); } } IdentifyTask identifyTask = new IdentifyTask(config.IdentifyURL); identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted; identifyTask.Failed += IdentifyTask_Failed; QueryItem queryItem = new QueryItem(ParcelMap, ref config, clickPoint, 0); identifyTask.ExecuteAsync(identifyParams, queryItem); } }
public void IdentifyPoint(Map ParcelMap, ref Configuration config, ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint) { if (config.IdentifyURL == "") return; if (config.IdentifyLayerCount == 0) return; if (config.UseQueryIdentify) { _dataItems = new List<DataItem>(); GeometryService geometryServicePointSnap = new GeometryService(config.GeometryServerUrl); if (geometryServicePointSnap == null) return; QueryItem queryItem = new QueryItem(ParcelMap, ref config, clickPoint, 0); geometryServicePointSnap.BufferCompleted += GeometryService_IdentifyPointBufferCompleted; geometryServicePointSnap.Failed += GeometryService_Failed; geometryServicePointSnap.CancelAsync(); SimpleMarkerSymbol defaultSymbolMarker = new SimpleMarkerSymbol() { Color = System.Windows.Media.Brushes.Black, Size = 8, Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle }; Graphic clickGraphic = new Graphic(); clickGraphic.Symbol = defaultSymbolMarker as ESRI.ArcGIS.Client.Symbols.Symbol; clickGraphic.Geometry = clickPoint; // Input spatial reference for buffer operation defined by first feature of input geometry array clickGraphic.Geometry.SpatialReference = ParcelMap.SpatialReference; // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters() { BufferSpatialReference = ParcelMap.SpatialReference, OutSpatialReference = ParcelMap.SpatialReference, Unit = LinearUnit.Meter, }; bufferParams.Distances.Add(config.SnapTolerance * config.SpatialReferenceUnitsPerMeter); bufferParams.Features.Add(clickGraphic); geometryServicePointSnap.BufferAsync(bufferParams, queryItem); } else { ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters() { Geometry = clickPoint, MapExtent = ParcelMap.Extent, Width = (int)ParcelMap.ActualWidth, Height = (int)ParcelMap.ActualHeight, LayerOption = LayerOption.visible, SpatialReference = ParcelMap.SpatialReference }; // For performance, we allow certain layers to be only identified. if (config.IdentifyLayerIDs != null) foreach (int id in config.IdentifyLayerIDs) identifyParams.LayerIds.Add(id); IdentifyTask identifyTask = new IdentifyTask(config.IdentifyURL); identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted; identifyTask.Failed += IdentifyTask_Failed; QueryItem queryItem = new QueryItem(ParcelMap, ref config, clickPoint, 0); identifyTask.ExecuteAsync(identifyParams, queryItem); } }
private void ShowProjectedExtent(Map thisMap) { if (thisMap != null) { System.Console.WriteLine("Current extent {0}", thisMap.Extent); } if (_xmlConfiguation.OutputSpatialReference == null || thisMap == null) { return; } // if we are in Web Mercator, project the extent back into the output spatial reference. // // This is for debugging only. GeometryService geometryServiceProject = new GeometryService(_xmlConfiguation.GeometryServerUrl); if (geometryServiceProject == null) { return; } geometryServiceProject.ProjectCompleted += GeometryService_CalculateOutputCoords; geometryServiceProject.Failed += GeometryService_FailedWebMercatorScale; geometryServiceProject.CancelAsync(); var graphicList = new List <Graphic>(); double x = thisMap.Extent.XMin; double y = thisMap.Extent.YMin; MapPoint minPoint = new MapPoint(x, y, ParcelMap.SpatialReference); Graphic minGraphic = new Graphic(); minGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; minGraphic.Geometry = minPoint; graphicList.Add(minGraphic); x = thisMap.Extent.XMax; y = thisMap.Extent.YMax; MapPoint maxPoint = new MapPoint(x, y, ParcelMap.SpatialReference); Graphic maxGraphic = new Graphic(); maxGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; maxGraphic.Geometry = maxPoint; graphicList.Add(maxGraphic); if (_xmlConfiguation.HasDatumTransformation) { DatumTransform transformation = new DatumTransform(); if (_xmlConfiguation.DatumTransformationWKID > 0) { transformation.WKID = _xmlConfiguation.DatumTransformationWKID; } else { transformation.WKT = _xmlConfiguation.DatumTransformationWKT; } geometryServiceProject.ProjectAsync(graphicList, _xmlConfiguation.OutputSpatialReference, transformation, _xmlConfiguation.DatumTransformationForward); } else { geometryServiceProject.ProjectAsync(graphicList, _xmlConfiguation.OutputSpatialReference); } }
private void ShowProjectedExtent(Map thisMap) { if (thisMap != null) System.Console.WriteLine("Current extent {0}", thisMap.Extent); if (_xmlConfiguation.OutputSpatialReference == null || thisMap == null) return; // if we are in Web Mercator, project the extent back into the output spatial reference. // // This is for debugging only. GeometryService geometryServiceProject = new GeometryService(_xmlConfiguation.GeometryServerUrl); if (geometryServiceProject == null) return; geometryServiceProject.ProjectCompleted += GeometryService_CalculateOutputCoords; geometryServiceProject.Failed += GeometryService_FailedWebMercatorScale; geometryServiceProject.CancelAsync(); var graphicList = new List<Graphic>(); double x = thisMap.Extent.XMin; double y = thisMap.Extent.YMin; MapPoint minPoint = new MapPoint(x, y, ParcelMap.SpatialReference); Graphic minGraphic = new Graphic(); minGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; minGraphic.Geometry = minPoint; graphicList.Add(minGraphic); x = thisMap.Extent.XMax; y = thisMap.Extent.YMax; MapPoint maxPoint = new MapPoint(x, y, ParcelMap.SpatialReference); Graphic maxGraphic = new Graphic(); maxGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; maxGraphic.Geometry = maxPoint; graphicList.Add(maxGraphic); if (_xmlConfiguation.HasDatumTransformation) { DatumTransform transformation = new DatumTransform(); if (_xmlConfiguation.DatumTransformationWKID > 0) transformation.WKID = _xmlConfiguation.DatumTransformationWKID; else transformation.WKT = _xmlConfiguation.DatumTransformationWKT; geometryServiceProject.ProjectAsync(graphicList, _xmlConfiguation.OutputSpatialReference, transformation, _xmlConfiguation.DatumTransformationForward); } else geometryServiceProject.ProjectAsync(graphicList, _xmlConfiguation.OutputSpatialReference); }