public static string GetMapPointAsDisplayString(MapPoint mp) { if (mp == null) return "NA"; var result = string.Format("{0:0.0} {1:0.0}", mp.Y, mp.X); // .ToGeoCoordinate function calls will fail if there is no Spatial Reference if (mp.SpatialReference == null) return result; ToGeoCoordinateParameter tgparam = null; try { switch (VisibilityConfig.AddInConfig.DisplayCoordinateType) { case CoordinateTypes.DD: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); tgparam.NumDigits = 6; result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DDM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DDM); tgparam.NumDigits = 4; result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DMS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DMS); tgparam.NumDigits = 2; result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.GARS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.GARS); result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.MGRS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.MGRS); result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.USNG: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.USNG); tgparam.NumDigits = 5; result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.UTM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.UTM); tgparam.GeoCoordMode = ToGeoCoordinateMode.UtmNorthSouth; result = mp.ToGeoCoordinateString(tgparam); break; default: break; } } catch(Exception ex) { // do nothing } return result; }
public override bool CanGetGARS(int srFacotryCode, out string coord) { coord = string.Empty; if (Point != null) { try { var tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.GARS); coord = Point.ToGeoCoordinateString(tgparam); return(true); } catch { } } return(false); }
public override bool CanGetDMS(int srFactoryCode, out string coord) { coord = string.Empty; if (Point != null) { try { var tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DMS); coord = Point.ToGeoCoordinateString(tgparam); return(true); } catch { /* Conversion Failed */ } } return(false); }
public override bool CanGetUSNG(int srFactoryCode, out string coord) { coord = string.Empty; if (Point != null) { try { var tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.USNG); tgparam.NumDigits = 5; coord = Point.ToGeoCoordinateString(tgparam); return(true); } catch { } } return(false); }
public override bool CanGetMGRS(int srFactoryCode, out string coord) { coord = string.Empty; if (Point != null) { try { // 5 numeric units in MGRS is 1m resolution var tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.MGRS); coord = Point.ToGeoCoordinateString(tgparam); return(true); } catch { } } return(false); }
public override bool CanGetUTM(int srFactoryCode, out string coord) { coord = string.Empty; if (Point != null) { try { var tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.UTM); tgparam.GeoCoordMode = ToGeoCoordinateMode.Default; coord = Point.ToGeoCoordinateString(tgparam); return(true); } catch { } } return(false); }
/// <summary> /// Helper method to get a string value of a MapPoint based on display configuration /// </summary> /// <param name="mp"></param> /// <returns></returns> public static string GetMapPointAsDisplayString(MapPoint mp) { if (mp == null) { return("NA"); } var result = string.Format("{0:0.0#####} {1:0.0#####}", mp.Y, mp.X); // .ToGeoCoordinate function calls will fail if there is no Spatial Reference if (mp.SpatialReference == null) { return(result); } ToGeoCoordinateParameter tgparam = null; try { switch (CoordinateConversionLibraryConfig.AddInConfig.DisplayCoordinateType) { case CoordinateTypes.DD: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); tgparam.NumDigits = 6; result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DDM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DDM); tgparam.NumDigits = 4; result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DMS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DMS); tgparam.NumDigits = 2; result = mp.ToGeoCoordinateString(tgparam); break; //case CoordinateTypes.GARS: // tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.GARS); // result = mp.ToGeoCoordinateString(tgparam); // break; case CoordinateTypes.MGRS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.MGRS); tgparam.Round = false; result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.USNG: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.USNG); tgparam.NumDigits = 5; result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.UTM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.UTM); tgparam.GeoCoordMode = ToGeoCoordinateMode.UtmNorthSouth; result = mp.ToGeoCoordinateString(tgparam); break; default: break; } } catch (Exception ex) { // do nothing System.Diagnostics.Debug.WriteLine(ex.Message); } if (CoordinateConversionLibraryConfig.AddInConfig.IsCustomFormat) { InputFormatHelper inputFormatHelper = new InputFormatHelper(); result = inputFormatHelper.ProcessInput(result); } return(result); }
protected async override void OnClick() { if (MapView.Active == null || MapView.Active.Map == null) return; // get screen point var temp = (System.Windows.Point)ArcGIS.Desktop.Framework.FrameworkApplication.ContextMenuDataContext; MapPoint mp = null; if (temp != null) { mp = QueuedTask.Run(() => { MapPoint tmp = null; tmp = MapView.Active.ScreenToMap(temp); return tmp; }).Result as MapPoint; } if (mp == null) return; string coord = String.Empty; ToGeoCoordinateParameter tgparam; try { switch (cType) { case CoordinateType.DD: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.DDM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DDM); coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.DMS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DMS); coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.GARS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.GARS); coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.MGRS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.MGRS); coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.USNG: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.USNG); tgparam.NumDigits = 5; coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.UTM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.UTM); tgparam.GeoCoordMode = ToGeoCoordinateMode.UtmNorthSouth; coord = mp.ToGeoCoordinateString(tgparam); break; default: break; } var vm = FrameworkApplication.DockPaneManager.Find("ProAppCoordConversionModule_CoordinateConversionDockpane") as CoordinateConversionDockpaneViewModel; if (vm != null) { coord = vm.GetFormattedCoordinate(coord, cType); } System.Windows.Clipboard.SetText(coord); } catch {} }
/// <summary> /// Method will return a formatted point as a string based on the configuration settings for display coordinate type /// </summary> /// <param name="point">IPoint that is to be formatted</param> /// <returns>String that is formatted based on addin config display coordinate type</returns> private string GetFormattedPoint(MapPoint point) { if (point == null) return "NA"; var result = string.Format("{0:0.0} {1:0.0}", point.Y, point.X); // .ToGeoCoordinate function calls will fail if there is no Spatial Reference if (point.SpatialReference == null) return result; ToGeoCoordinateParameter tgparam = null; try { switch (DistanceAndDirectionConfig.AddInConfig.DisplayCoordinateType) { case CoordinateTypes.DD: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); tgparam.NumDigits = 6; result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DDM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DDM); tgparam.NumDigits = 4; result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DMS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DMS); tgparam.NumDigits = 2; result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.GARS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.GARS); result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.MGRS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.MGRS); result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.USNG: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.USNG); tgparam.NumDigits = 5; result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.UTM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.UTM); tgparam.GeoCoordMode = ToGeoCoordinateMode.UtmNorthSouth; result = point.ToGeoCoordinateString(tgparam); break; default: break; } } catch(Exception ex) { // do nothing } return result; }
public override bool CanGetGARS(int srFacotryCode, out string coord) { coord = string.Empty; if (Point != null) { try { var tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.GARS); coord = Point.ToGeoCoordinateString(tgparam); return true; } catch { } } return false; }
/// <summary> /// Called when the sketch finishes. This is where we will create the sketch operation and then execute it. /// The sketch geometry will be turned into an envelope and used to query the Planet api for the relevant quads /// The FolderSelector view and various models will then be presented allowing the user to choose a save location /// Finally, after the .tif files have been downloaded a raster mosic will be created in the project default FGDB and /// the downloaded .tif files added. /// </summary> /// <param name="geometry">The geometry created by the sketch.</param> /// <returns>A Task returning a Boolean indicating if the sketch complete event was successfully handled.</returns> protected override Task <bool> OnSketchCompleteAsync(Geometry geometry) { string rasterseriesname = ""; string rasterseriesid = ""; bool _isPlanetRaster = false; if (geometry == null) { return(Task.FromResult(false)); } //Make sure a valid Planet layer is selected. IReadOnlyList <Layer> ts = MapView.Active.GetSelectedLayers(); if (ts.Count > 1) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("More than one layer selected \n Please only choose a single Planet Imagery layer", "More than one layer selected", MessageBoxButton.OK, MessageBoxImage.Warning); return(Task.FromResult(false)); } foreach (Layer item in ts) { if (item is TiledServiceLayer tiledService) { if (!tiledService.URL.Contains("https://api.planet.com/basemaps/v1/mosaics")) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("The selected layer is not a Planet Image layer", "Wrong Layer type", MessageBoxButton.OK, MessageBoxImage.Warning); return(Task.FromResult(false)); } else { rasterseriesname = tiledService.Name; rasterseriesid = tiledService.URL.Substring(tiledService.URL.IndexOf("mosaics") + 8, 36); _isPlanetRaster = true; } } } if (!_isPlanetRaster) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("The selected layer is not a Planet Image layer", "Wrong Layer type", MessageBoxButton.OK, MessageBoxImage.Warning); return(Task.FromResult(false)); } //Create min max points from the envelope and get the coords in Decimal Degrees MapPoint point0 = MapPointBuilder.CreateMapPoint(geometry.Extent.XMin, geometry.Extent.YMin, MapView.Active.Extent.SpatialReference); MapPoint point1 = MapPointBuilder.CreateMapPoint(geometry.Extent.XMax, geometry.Extent.YMax, MapView.Active.Extent.SpatialReference); ToGeoCoordinateParameter ddParam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); string geoCoordString = geometry.Extent.Center.ToGeoCoordinateString(ddParam); string[] lowP = point0.ToGeoCoordinateString(ddParam).Split(' '); string[] highP = point1.ToGeoCoordinateString(ddParam).Split(' '); IEnumerable <string> union = lowP.Union(highP); string quadparm = ""; //need to change the formatting of the coords. for (int i = 0; i < union.Count(); i++) { string crr = union.ElementAt(i); if (crr.Contains("W") || crr.Contains("S")) { crr = "-" + crr.Substring(0, crr.Length - 1); } else { crr = crr.Substring(0, crr.Length - 1); } quadparm = quadparm + "," + crr; } string[] ff = quadparm.Trim(',').Split(','); var result = getQuadsAsync(geometry, ff, rasterseriesname, rasterseriesid); //result.Wait(); if (result.IsFaulted) { MessageBox.Show(result.Exception.Message, "An error Occured", MessageBoxButton.OK, MessageBoxImage.Error); return(Task.FromResult(false)); } //result.Wait(); return(Task.FromResult(true)); }
/// <summary> /// Helper method to get a string value of a MapPoint based on display configuration /// </summary> /// <param name="mp"></param> /// <returns></returns> public static string GetMapPointAsDisplayString(MapPoint mp) { if (mp == null) { return("NA"); } var result = string.Format("{0:0.0} {1:0.0}", mp.Y, mp.X); // .ToGeoCoordinate function calls will fail if there is no Spatial Reference if (mp.SpatialReference == null) { return(result); } ToGeoCoordinateParameter tgparam = null; try { switch (VisibilityConfig.AddInConfig.DisplayCoordinateType) { case CoordinateTypes.DD: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); tgparam.NumDigits = 6; result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DDM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DDM); tgparam.NumDigits = 4; result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DMS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DMS); tgparam.NumDigits = 2; result = mp.ToGeoCoordinateString(tgparam); break; //case CoordinateTypes.GARS: // tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.GARS); // result = mp.ToGeoCoordinateString(tgparam); // break; case CoordinateTypes.MGRS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.MGRS); result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.USNG: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.USNG); tgparam.NumDigits = 5; result = mp.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.UTM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.UTM); tgparam.GeoCoordMode = ToGeoCoordinateMode.UtmNorthSouth; result = mp.ToGeoCoordinateString(tgparam); break; default: break; } } catch (Exception ex) { // do nothing } return(result); }
public string GetInputDisplayString() { if (Point == null) return "NA"; var result = string.Format("{0:0.0} {1:0.0}", Point.Y, Point.X); if (Point.SpatialReference == null) return result; ToGeoCoordinateParameter tgparam = null; try { switch (CoordinateConversionViewModel.AddInConfig.DisplayCoordinateType) { case CoordinateTypes.DD: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); tgparam.NumDigits = 6; result = Point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DDM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DDM); tgparam.NumDigits = 4; result = Point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DMS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DMS); tgparam.NumDigits = 2; result = Point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.GARS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.GARS); result = Point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.MGRS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.MGRS); result = Point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.USNG: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.USNG); tgparam.NumDigits = 5; result = Point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.UTM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.UTM); tgparam.GeoCoordMode = ToGeoCoordinateMode.UtmNorthSouth; result = Point.ToGeoCoordinateString(tgparam); break; default: break; } } catch(Exception ex) { // do nothing } return result; }
protected override async Task <bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry) { try { if (_graphic != null) { _graphic.Dispose(); } //Polygon polygon; //await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => //{ // List<Coordinate2D> coordinates2 = new List<Coordinate2D>() //{ // //new Coordinate2D(-159.20168702818188, 21.876487211082708), // //new Coordinate2D(-159.42653907783114, 21.838951660451173), // //new Coordinate2D(-159.44077880308507, 21.94718691051718), // //new Coordinate2D(-159.21630329750306, 21.94718691051718), // //new Coordinate2D(-159.21413990271841, 21.9365008022738), // //new Coordinate2D(-159.21383956606297, 21.93655454291286), // //new Coordinate2D(-159.20168702818188, 21.876487211082708), // new Coordinate2D(-17773406.8675, 2478583.7239999995), // new Coordinate2D(-17773406.8675, 2578583.7239999995), // new Coordinate2D(-16773406.8675, 2578583.7239999995), // new Coordinate2D(-17773406.8675, 2478583.7239999995) //}; // CIMPolygonSymbol _polygonSymbol = null; // _polygonSymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Null, SymbolFactory.Instance.ConstructStroke(ColorFactory.Instance.BlackRGB, 2.0, SimpleLineStyle.Solid)); // using (PolygonBuilder polygonBuilder = new PolygonBuilder(coordinates2, MapView.Active.Extent.SpatialReference)) // { // polygonBuilder.SpatialReference = MapView.Active.Extent.SpatialReference; // polygon = polygonBuilder.ToGeometry(); // geometry = polygonBuilder.ToGeometry(); // //Geometry geometry2 = GeometryEngine.Instance.ProjectEx(geometry, projTransFromSRs); // _graphic = MapView.Active.AddOverlayAsync(geometry, _polygonSymbol.MakeSymbolReference()); // } //}); //return true; //DockPane pane = FrameworkApplication.DockPaneManager.Find("test_docing_Panel_PlanetDocPane"); DockPane pane = FrameworkApplication.DockPaneManager.Find("test_docing_Panel_Demo"); //PlanetDocPaneViewModel planetDocPaneViewModel = (PlanetDocPaneViewModel)pane; //planetDocPaneViewModel.Users = "New collection" pane.Enabled = true; //Add an overlay graphic to the map view _graphic = await this.AddOverlayAsync(geometry, _lineSymbol.MakeSymbolReference()); //define the text symbol var textSymbol = new CIMTextSymbol(); //define the text graphic var textGraphic = new CIMTextGraphic(); //await QueuedTask.Run(() => //{ // //Create a simple text symbol // textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular"); // //Sets the geometry of the text graphic // textGraphic.Shape = geometry; // //Sets the text string to use in the text graphic // //textGraphic.Text = "This is my line"; // //Sets symbol to use to draw the text graphic // textGraphic.Symbol = textSymbol.MakeSymbolReference(); // //Draw the overlay text graphic // _graphic = this.ActiveMapView.AddOverlay(textGraphic); //}); string ejson = geometry.ToJson(); Polygon poly = (Polygon)geometry; IReadOnlyList <Coordinate2D> coordinates = poly.Copy2DCoordinatesToList(); ToGeoCoordinateParameter ddParam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); List <string> geocoords = new List <string>(); List <Tuple <double, double> > AllPts = new List <Tuple <double, double> >(); double x; double y; foreach (Coordinate2D item in coordinates) { MapPoint mapPoint = MapPointBuilder.CreateMapPoint(item, MapView.Active.Extent.SpatialReference); List <Tuple <string, string> > pts = new List <Tuple <string, string> >(); string dd1 = mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[0]; pts.Add(new Tuple <string, string>(mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[1], mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[0])); if (pts[0].Item1.Contains("W")) { x = double.Parse("-" + pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse("-" + pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length -1)))); } else if (pts[1].Item2.Contains("S")) { x = double.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse("-" + pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse("-" + pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)))); } else { x = double.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse(pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)))); } AllPts.Add(new Tuple <double, double>(x, y)); geocoords.Add(mapPoint.ToGeoCoordinateString(ddParam)); } double[,] sd = new double[AllPts.Count, 2]; for (int i = 0; i < AllPts.Count; i++) { sd[i, 0] = AllPts[i].Item1; //+ "," + AllPts[i].Item2; sd[i, 1] = AllPts[i].Item2; } List <double[, ]> ss = new List <double[, ]>(); ss.Add(sd); Config configPoints = new Config { type = "Polygon", coordinates = ss.ToArray() }; Config configGeom = new Config { type = "GeometryFilter", field_name = "geometry", config = configPoints }; //DateFilter Config dateconfigconfig2 = new Config { gte = "2019-05-19T16:51:19.926Z", lte = "2019-08-19T16:51:19.926Z" }; Config dateconfigconfig = new Config { type = "DateRangeFilter", field_name = "acquired", config = dateconfigconfig2 }; Config dateconfig = new Config { type = "OrFilter", config = new[] { dateconfigconfig } }; SearchFilter searchFilter = new SearchFilter(); List <string> typoes = new List <string>(); typoes.Add("PSScene4Band"); typoes.Add("SkySatCollect"); typoes.Add("REOrthoTile"); List <Config> mainconfigs = new List <Config>(); mainconfigs.Add(dateconfig); mainconfigs.Add(configGeom); searchFilter.item_types = typoes.ToArray(); Filter topfilter = new Filter(); topfilter.type = "AndFilter"; searchFilter.filter = topfilter; Config mainConfig = new Config(); searchFilter.filter.config = mainconfigs.ToArray(); //string json = JsonConvert.SerializeObject(searchFilter); string json = JsonConvert.SerializeObject(searchFilter, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); string asas = "{\"filter\":{\"type\":\"AndFilter\",\"config\":[{\"type\":\"GeometryFilter\",\"field_name\":\"geometry\",\"config\":{\"type\":\"Polygon\",\"coordinates\":[[[-159.44149017333984,21.877787931279187],[-159.44998741149902,21.87679231243837],[-159.45372104644778,21.872769941600623],[-159.45217609405518,21.866835742000745],[-159.44372177124023,21.864207091531895],[-159.43561077117923,21.86930503623256],[-159.44149017333984,21.877787931279187]]]}},{\"type\":\"OrFilter\",\"config\":[{\"type\":\"DateRangeFilter\",\"field_name\":\"acquired\",\"config\":{\"gte\":\"2019-05-22T16:36:32.254Z\",\"lte\":\"2019-08-22T16:36:32.254Z\"}}]}]},\"item_types\":[\"PSScene4Band\",\"REOrthoTile\",\"SkySatCollect\"]}"; //var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.somewhere.com/v2/cases"); HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; HttpClient client = new HttpClient(handler) { BaseAddress = new Uri("https://api.planet.com") }; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "data/v1/quick-search"); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.CacheControl = new CacheControlHeaderValue(); request.Headers.CacheControl.NoCache = true; request.Headers.Host = "api.planet.com"; request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); //request.Headers.Remove("Content-Type"); //request.Headers.Add("Content-Type", "application/json"); var content = new StringContent(json, Encoding.UTF8, "application/json"); request.Content = content; var byteArray = Encoding.ASCII.GetBytes("1fe575980e78467f9c28b552294ea410:hgvhgv"); client.DefaultRequestHeaders.Host = "api.planet.com"; //_client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); content.Headers.Remove("Content-Type"); content.Headers.Add("Content-Type", "application/json"); //client.DefaultRequestHeaders.AcceptEncoding.Add(StringWithQualityHeaderValue.Parse("gzip")); client.DefaultRequestHeaders.Add("Connection", "keep-alive"); client.DefaultRequestHeaders.Add("User-Agent", "ArcGISProC#"); //content.Headers.TryAddWithoutValidation("Authorization", "Basic " + Convert.ToBase64String(byteArray)); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "MWZlNTc1OTgwZTc4NDY3ZjljMjhiNTUyMjk0ZWE0MTA6");//Convert.ToBase64String(byteArray)); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); using (HttpResponseMessage httpResponse = client.SendAsync(request).Result) { using (HttpContent content2 = httpResponse.Content) { var json2 = content2.ReadAsStringAsync().Result; QuickSearchResult quickSearchResult = JsonConvert.DeserializeObject <QuickSearchResult>(json2); //Geometry geometry2 = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, JsonConvert.SerializeObject( quickSearchResult.features[5].geometry)); } } pane.Activate(); return(true); } catch (Exception exe) { if (_graphic != null) { _graphic.Dispose(); } return(false); } }
/// <summary> /// Do a Quick search against the Planet Data api /// The results of the search update the QuickSearchResults Collection /// </summary> private void DoSearch() { ShowCircularAnimation = Visibility.Visible; TreeEnabled = false; Polygon poly = (Polygon)AOIGeometry; IReadOnlyList <Coordinate2D> coordinates = poly.Copy2DCoordinatesToList(); ToGeoCoordinateParameter ddParam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); List <string> geocoords = new List <string>(); List <Tuple <double, double> > AllPts = new List <Tuple <double, double> >(); double x; double y; foreach (Coordinate2D item in coordinates) { MapPoint mapPoint = MapPointBuilder.CreateMapPoint(item, MapView.Active.Extent.SpatialReference); List <Tuple <string, string> > pts = new List <Tuple <string, string> >(); string dd1 = mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[0]; pts.Add(new Tuple <string, string>(mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[1], mapPoint.ToGeoCoordinateString(ddParam).Split(' ')[0])); if (pts[0].Item1.Contains("W")) { x = double.Parse("-" + pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse("-" + pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length -1)))); } else if (pts[1].Item2.Contains("S")) { x = double.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse("-" + pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse("-" + pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)))); } else { x = double.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)); y = double.Parse(pts[0].Item2.Substring(0, pts[0].Item2.Length - 1)); //AllPts.Add(new Tuple<int, int>(int.Parse(pts[0].Item1.Substring(0, pts[0].Item1.Length - 1)), int.Parse(pts[0].Item2.Substring(0, pts[1].Item2.Length - 1)))); } AllPts.Add(new Tuple <double, double>(x, y)); geocoords.Add(mapPoint.ToGeoCoordinateString(ddParam)); } double[,] sd = new double[AllPts.Count, 2]; for (int i = 0; i < AllPts.Count; i++) { sd[i, 0] = AllPts[i].Item1; //+ "," + AllPts[i].Item2; sd[i, 1] = AllPts[i].Item2; } List <double[, ]> ss = new List <double[, ]>(); ss.Add(sd); Config configPoints = new Config { type = "Polygon", coordinates = ss.ToArray() }; Config configGeom = new Config { type = "GeometryFilter", field_name = "geometry", config = configPoints }; //cloudcoverfiler RangeFilterConfig cloudconfig = new RangeFilterConfig { gte = _CloudcoverLow / 100, lte = _CloudcoverHigh / 100 }; Config cloudCoverFilter = new Config { type = "RangeFilter", field_name = "cloud_cover", config = cloudconfig }; //DateFilter Config dateconfigconfig2 = new Config { gte = _DateFrom.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo), //"2019-05-19T16:51:19.926Z", lte = _DateTo.ToString("yyyy-MM-dd'T'HH:mm:ss.fffzzz", DateTimeFormatInfo.InvariantInfo) //"2019-08-19T16:51:19.926Z" }; Config dateconfigconfig = new Config { type = "DateRangeFilter", field_name = "acquired", config = dateconfigconfig2 }; Config dateconfig = new Config { type = "OrFilter", config = new[] { dateconfigconfig } }; SearchFilter searchFilter = new SearchFilter(); List <string> types = new List <string>(); //typoes.Add("PSScene4Band"); //typoes.Add("SkySatCollect"); //typoes.Add("REOrthoTile"); foreach (var prop in this.GetType().GetProperties()) { if (prop.PropertyType.Name == "Boolean") { if (((bool)prop.GetValue(this, null)) && (prop.Name.StartsWith("Product"))) { types.Add(prop.Name.Substring(7)); } //Console.WriteLine(prop.MemberType.ToString()); } } List <Config> mainconfigs = new List <Config> { dateconfig, cloudCoverFilter, configGeom }; searchFilter.item_types = types.ToArray(); Filter topfilter = new Filter(); topfilter.type = "AndFilter"; searchFilter.filter = topfilter; Config mainConfig = new Config(); searchFilter.filter.config = mainconfigs.ToArray(); //string json = JsonConvert.SerializeObject(searchFilter); string json = JsonConvert.SerializeObject(searchFilter, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); //string asas = "{\"filter\":{\"type\":\"AndFilter\",\"config\":[{\"type\":\"GeometryFilter\",\"field_name\":\"geometry\",\"config\":{\"type\":\"Polygon\",\"coordinates\":[[[-159.44149017333984,21.877787931279187],[-159.44998741149902,21.87679231243837],[-159.45372104644778,21.872769941600623],[-159.45217609405518,21.866835742000745],[-159.44372177124023,21.864207091531895],[-159.43561077117923,21.86930503623256],[-159.44149017333984,21.877787931279187]]]}},{\"type\":\"OrFilter\",\"config\":[{\"type\":\"DateRangeFilter\",\"field_name\":\"acquired\",\"config\":{\"gte\":\"2019-05-22T16:36:32.254Z\",\"lte\":\"2019-08-22T16:36:32.254Z\"}}]}]},\"item_types\":[\"PSScene4Band\",\"REOrthoTile\",\"SkySatCollect\"]}"; //var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://api.somewhere.com/v2/cases"); HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; HttpClient client = new HttpClient(handler) { BaseAddress = new Uri("https://api.planet.com") }; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "data/v1/quick-search"); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); request.Headers.CacheControl = new CacheControlHeaderValue(); request.Headers.CacheControl.NoCache = true; request.Headers.Host = "api.planet.com"; request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); //request.Headers.Remove("Content-Type"); //request.Headers.Add("Content-Type", "application/json"); var content = new StringContent(json, Encoding.UTF8, "application/json"); request.Content = content; var byteArray = Encoding.ASCII.GetBytes("1fe575980e78467f9c28b552294ea410:hgvhgv"); client.DefaultRequestHeaders.Host = "api.planet.com"; //_client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); content.Headers.Remove("Content-Type"); content.Headers.Add("Content-Type", "application/json"); //client.DefaultRequestHeaders.AcceptEncoding.Add(StringWithQualityHeaderValue.Parse("gzip")); client.DefaultRequestHeaders.Add("Connection", "keep-alive"); client.DefaultRequestHeaders.Add("User-Agent", "ArcGISProC#"); //content.Headers.TryAddWithoutValidation("Authorization", "Basic " + Convert.ToBase64String(byteArray)); //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "MWZlNTc1OTgwZTc4NDY3ZjljMjhiNTUyMjk0ZWE0MTA6");//Convert.ToBase64String(byteArray)); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); try { using (HttpResponseMessage httpResponse = client.SendAsync(request).Result) { using (HttpContent content2 = httpResponse.Content) { var json2 = content2.ReadAsStringAsync().Result; QuickSearchResult quickSearchResult = JsonConvert.DeserializeObject <QuickSearchResult>(json2); //if (_quickSearchResults is null ) //{ _quickSearchResults = new ObservableCollection <QuickSearchResult>(); Items = new ObservableCollection <AcquiredDateGroup>(); Pages = new List <Model.Page>(); //} _quickSearchResults.Add(quickSearchResult); Model.Page page = new Model.Page { QuickSearchResult = quickSearchResult }; List <AcquiredDateGroup> groupedItems = Model.Page.ProcessQuickSearchResults(quickSearchResult); page.Items = new ObservableCollection <Model.AcquiredDateGroup>(groupedItems); Pages.Add(page); CurrentPage = page; Items = new ObservableCollection <Model.AcquiredDateGroup>(groupedItems); //ProcessQuickSearchResults(quickSearchResult, page); HasPages = true; HasNextPage = quickSearchResult._links._next != null; IsNotFirstPage = false; PageNumber = 1; PageTotal = HasNextPage ? "many" : "1"; PaginatorVisibility = Visibility.Visible; //Pages.AddRange(await Model.Page.GetAllPages(quickSearchResult)); } } } catch (Exception e) { ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace); } ShowCircularAnimation = Visibility.Hidden; TreeEnabled = true; }
public string GetInputDisplayString() { if (Point == null) { return("NA"); } var result = string.Format("{0:0.0#####} {1:0.0#####}", Point.Y, Point.X); if (Point.SpatialReference == null) { return(result); } ToGeoCoordinateParameter tgparam = null; try { switch (CoordinateConversionLibraryConfig.AddInConfig.DisplayCoordinateType) { case CoordinateTypes.DD: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); tgparam.NumDigits = 6; result = Point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DDM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DDM); tgparam.NumDigits = 4; result = Point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DMS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DMS); tgparam.NumDigits = 2; result = Point.ToGeoCoordinateString(tgparam); break; //case CoordinateTypes.GARS: // tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.GARS); // result = Point.ToGeoCoordinateString(tgparam); // break; case CoordinateTypes.MGRS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.MGRS); tgparam.Round = false; result = Point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.USNG: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.USNG); tgparam.NumDigits = 5; result = Point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.UTM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.UTM); tgparam.GeoCoordMode = ToGeoCoordinateMode.UtmNorthSouth; result = Point.ToGeoCoordinateString(tgparam); break; default: break; } } catch (Exception ex) { // do nothing } return(result); }
public override bool CanGetMGRS(int srFactoryCode, out string coord) { coord = string.Empty; if (Point != null) { try { // 5 numeric units in MGRS is 1m resolution var tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.MGRS); coord = Point.ToGeoCoordinateString(tgparam); return true; } catch { } } return false; }
/// <summary> /// Method will return a formatted point as a string based on the configuration settings for display coordinate type /// </summary> /// <param name="point">IPoint that is to be formatted</param> /// <returns>String that is formatted based on addin config display coordinate type</returns> private string GetFormattedPoint(MapPoint point) { if (point == null) { return("NA"); } var result = string.Format("{0:0.0} {1:0.0}", point.Y, point.X); // .ToGeoCoordinate function calls will fail if there is no Spatial Reference if (point.SpatialReference == null) { return(result); } ToGeoCoordinateParameter tgparam = null; try { switch (DistanceAndDirectionConfig.AddInConfig.DisplayCoordinateType) { case CoordinateTypes.DD: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); tgparam.NumDigits = 6; result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DDM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DDM); tgparam.NumDigits = 4; result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.DMS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DMS); tgparam.NumDigits = 2; result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.GARS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.GARS); result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.MGRS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.MGRS); result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.USNG: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.USNG); tgparam.NumDigits = 5; result = point.ToGeoCoordinateString(tgparam); break; case CoordinateTypes.UTM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.UTM); tgparam.GeoCoordMode = ToGeoCoordinateMode.UtmNorthSouth; result = point.ToGeoCoordinateString(tgparam); break; default: break; } } catch (Exception ex) { // do nothing } return(result); }
public override bool CanGetUSNG(int srFactoryCode, out string coord) { coord = string.Empty; if (Point != null) { try { var tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.USNG); tgparam.NumDigits = 5; coord = Point.ToGeoCoordinateString(tgparam); return true; } catch { } } return false; }
protected async override void OnClick() { if (MapView.Active == null || MapView.Active.Map == null) { return; } // get screen point var temp = (System.Windows.Point)ArcGIS.Desktop.Framework.FrameworkApplication.ContextMenuDataContext; MapPoint mp = null; if (temp != null) { mp = QueuedTask.Run(() => { MapPoint tmp = null; tmp = MapView.Active.ScreenToMap(temp); return(tmp); }).Result as MapPoint; } if (mp == null) { return; } string coord = String.Empty; ToGeoCoordinateParameter tgparam; try { switch (cType) { case CoordinateType.DD: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DD); coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.DDM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DDM); coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.DMS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.DMS); coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.GARS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.GARS); coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.MGRS: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.MGRS); coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.USNG: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.USNG); tgparam.NumDigits = 5; coord = mp.ToGeoCoordinateString(tgparam); break; case CoordinateType.UTM: tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.UTM); tgparam.GeoCoordMode = ToGeoCoordinateMode.UtmNorthSouth; coord = mp.ToGeoCoordinateString(tgparam); break; default: break; } var vm = FrameworkApplication.DockPaneManager.Find("ProAppCoordConversionModule_CoordinateConversionDockpane") as CoordinateConversionDockpaneViewModel; if (vm != null) { coord = vm.GetFormattedCoordinate(coord, cType); } System.Windows.Clipboard.SetText(coord); } catch {} }
public override bool CanGetUTM(int srFactoryCode, out string coord) { coord = string.Empty; if (Point != null) { try { var tgparam = new ToGeoCoordinateParameter(GeoCoordinateType.UTM); tgparam.GeoCoordMode = ToGeoCoordinateMode.UtmNorthSouth; coord = Point.ToGeoCoordinateString(tgparam); return true; } catch { } } return false; }