Exemple #1
0
 private void InitDataConnection(CIMWMTSServiceConnection connection)
 {
     WorkspacePath  = connection.ServerConnection.URL;
     DataSourceName = connection.LayerName;
     DataSetName    = DataSourceName;
     DataSetType    = "Web Tile Service";
     DataSource     = BuildFullUrl();
 }
Exemple #2
0
        public static async void AddLayer(string targets, string name)
        {
            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/layers");

            //request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
            request.Headers.Host = "tiles2.planet.com";
            request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
            var nvc = new List <KeyValuePair <string, string> >();

            //nvc.Add(new KeyValuePair<string, string>("ids", "PSScene4Band:20190603_205042_1042,PSScene4Band:20190528_205949_43_1061,PSScene4Band:20190818_205116_1009"));
            nvc.Add(new KeyValuePair <string, string>("ids", targets));
            //var content = new StringContent(json, Encoding.UTF8, "application/json");
            var content = new FormUrlEncodedContent(nvc);

            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/x-www-form-urlencoded"));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            client.DefaultRequestHeaders.Add("Connection", "keep-alive");
            client.DefaultRequestHeaders.Add("User-Agent", "ArcGISProC#");
            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;
                    customwmts customwmts = JsonConvert.DeserializeObject <customwmts>(json2);
                    customwmts.wmtsURL = new Uri("https://tiles.planet.com/data/v1/layers/wmts/" + customwmts.name + "?api_key=1fe575980e78467f9c28b552294ea410");
                    //Geometry geometry2 = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, JsonConvert.SerializeObject( quickSearchResult.features[5].geometry));
                    var serverConnection = new CIMProjectServerConnection {
                        URL = customwmts.wmtsURL.ToString()
                    };                                                                                            // "1fe575980e78467f9c28b552294ea410"
                    var connection = new CIMWMTSServiceConnection {
                        ServerConnection = serverConnection
                    };
                    await QueuedTask.Run(() =>
                    {
                        BasicRasterLayer layer2 = LayerFactory.Instance.CreateRasterLayer(connection, MapView.Active.Map, 0, name);
                    });
                }
            }
        }
 private async void addwmts(string url)
 {
     if (MapView.Active == null)
     {
         ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("A map must be added the the project and be active");
         //FrameworkApplication.State.Deactivate("planet_state_connection");
     }
     Project project          = Project.Current;
     var     serverConnection = new CIMProjectServerConnection {
         URL = "https://tiles.planet.com/data/v1/layers/wmts/-7zefdf-UmCPwvBPaBJ0EmLRwx2M33-YL0Jdww?api_key=1fe575980e78467f9c28b552294ea410"
     };                                                                                                                                                                                             // "1fe575980e78467f9c28b552294ea410"
     var connection = new CIMWMTSServiceConnection {
         ServerConnection = serverConnection
     };
     await QueuedTask.Run(() =>
     {
         BasicRasterLayer layer2 = LayerFactory.Instance.CreateRasterLayer(connection, MapView.Active.Map, 0, "test");
     });
 }
        /// <summary>
        /// Create a map raster layer using the URL of the gallery item
        /// </summary>
        /// <param name="item"></param>
        private async void OpenWebMapAsync(object item)
        {
            if (item is Mosaic mosaic)
            {
                if (MapView.Active == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("A map must be added the the project and be active");
                    //FrameworkApplication.State.Deactivate("planet_state_connection");
                    return;
                }
                Project project          = Project.Current;
                var     serverConnection = new CIMProjectServerConnection {
                    URL = mosaic._links._self.Substring(0, mosaic._links._self.IndexOf("?")) + "/wmts?REQUEST=GetCapabilities&api_key=" + Module1.Current.API_KEY.API_KEY_Value
                };
                var connection = new CIMWMTSServiceConnection {
                    ServerConnection = serverConnection
                };
                await QueuedTask.Run(() =>
                {
                    var extent            = MapView.Active.Extent;
                    string layerName      = "Planet Basemaps";
                    GroupLayer groupLayer = MapView.Active.Map.FindLayers(layerName).FirstOrDefault() as GroupLayer;
                    if (groupLayer == null)
                    {
                        int index  = MapView.Active.Map.Layers.Count;
                        groupLayer = LayerFactory.Instance.CreateGroupLayer(MapView.Active.Map, index, layerName);
                    }
                    BasicRasterLayer layer2 = LayerFactory.Instance.CreateRasterLayer(connection, groupLayer, 0, mosaic.name);
                    MapView.Active.ZoomTo(extent, TimeSpan.Zero);
                });
            }

            //Hardcoding trial to false so warning is never shown per Annies request 20190703
            Module1.Current.IsTrial = false;
            if (Module1.Current.IsTrial)
            {
                TrialWarning _trialwarning = new TrialWarning();
                _trialwarning.Owner   = FrameworkApplication.Current.MainWindow;
                _trialwarning.Closed += (o, e) => { _trialwarning = null; };
                _trialwarning.ShowDialog();
            }
        }
Exemple #5
0
        /// <summary>
        /// Create a map raster layer using the URL of the gallery item
        /// </summary>
        /// <param name="item"></param>
        private async void OpenWebMapAsync(object item)
        {
            if (item is Mosaic mosaic)
            {
                if (MapView.Active == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("A map must be added the the project and be active");
                    //FrameworkApplication.State.Deactivate("planet_state_connection");
                    return;
                }
                Project project          = Project.Current;
                var     serverConnection = new CIMProjectServerConnection {
                    URL = mosaic._links._self.Substring(0, mosaic._links._self.IndexOf("?")) + "/wmts?REQUEST=GetCapabilities&api_key=" + Module1.Current.API_KEY.API_KEY_Value
                };
                var connection = new CIMWMTSServiceConnection {
                    ServerConnection = serverConnection
                };
                await QueuedTask.Run(() =>
                {
                    var extent            = MapView.Active.Extent;
                    string layerName      = Model.Asset.BasemapsGroup;
                    GroupLayer groupLayer = MapView.Active.Map.FindLayers(layerName).FirstOrDefault() as GroupLayer;
                    if (groupLayer == null)
                    {
                        //add basemap group above any existing basemap-type layers, but below planet daily
                        //imagery group layer
                        IEnumerable <Layer> layers = MapView.Active.Map.Layers;
                        int targetIndex            = 0;
                        int lowestIndex            = MapView.Active.Map.Layers.Count;
                        if (lowestIndex > 0)
                        {
                            lowestIndex = lowestIndex - 1;
                            foreach (Layer layer in layers)
                            {
                                if (layer.Name == Model.Asset.RootGroup)
                                {
                                    targetIndex = MapView.Active.Map.Layers.IndexOf(layer) + 1;
                                    break;
                                }
                                if (layer is GroupLayer group)
                                {
                                    IEnumerable <Layer> children = group.GetLayersAsFlattenedList();
                                    foreach (Layer child in children)
                                    {
                                        string childType = child.GetType().Name;
                                        if (Model.Asset.ValidTypes.Contains(childType))
                                        {
                                            int layerIndex = MapView.Active.Map.Layers.IndexOf(group);
                                            if (layerIndex < lowestIndex)
                                            {
                                                lowestIndex = layerIndex;
                                                break;
                                            }
                                        }
                                    }
                                }
                                string type = layer.GetType().Name;
                                if (Model.Asset.ValidTypes.Contains(type))
                                {
                                    int layerIndex = MapView.Active.Map.Layers.IndexOf(layer);
                                    if (layerIndex < lowestIndex)
                                    {
                                        lowestIndex = layerIndex;
                                    }
                                }
                            }
                        }
                        if (targetIndex == 0)
                        {
                            targetIndex = lowestIndex == 0 ? lowestIndex : lowestIndex - 1;
                        }
                        groupLayer = LayerFactory.Instance.CreateGroupLayer(MapView.Active.Map, targetIndex, layerName);
                    }
                    try
                    {
                        BasicRasterLayer layer2 = LayerFactory.Instance.CreateRasterLayer(connection, groupLayer, 0, mosaic.name);
                        MapView.Active.ZoomTo(extent, TimeSpan.Zero);
                    }
                    catch (Exception)
                    {
                        ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("There is a problem loading the basemap. This is mostly likely due to a permissions issue.");
                    }
                });
            }

            //Hardcoding trial to false so warning is never shown per Annies request 20190703
            Module1.Current.IsTrial = false;
            if (Module1.Current.IsTrial)
            {
                TrialWarning _trialwarning = new TrialWarning();
                _trialwarning.Owner   = FrameworkApplication.Current.MainWindow;
                _trialwarning.Closed += (o, e) => { _trialwarning = null; };
                _trialwarning.ShowDialog();
            }
        }
        /// <summary>
        /// adds the sected  item to the map. uses the _mapLayerName prperty to know what scene to use
        /// </summary>
        public async void doAddToMap()
        {
            if (_permissions.Length == 0)
            {
                return;
            }
            //IsSelected = true;
            if (canToggleExisting())
            {
                return;
            }
            try
            {
                string            targets = properties.item_type + ":" + id.ToString();
                HttpClientHandler handler = new HttpClientHandler()
                {
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                };
                using (HttpClient client = new HttpClient(handler))
                {
                    client.BaseAddress = new Uri("https://api.planet.com");
                    targets            = targets.TrimEnd(',');
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "data/v1/layers");
                    //request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
                    request.Headers.Host = "tiles2.planet.com";
                    request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
                    var nvc = new List <KeyValuePair <string, string> >();
                    //nvc.Add(new KeyValuePair<string, string>("ids", "PSScene4Band:20190603_205042_1042,PSScene4Band:20190528_205949_43_1061,PSScene4Band:20190818_205116_1009"));
                    nvc.Add(new KeyValuePair <string, string>("ids", targets));
                    //var content = new StringContent(json, Encoding.UTF8, "application/json");
                    var content = new FormUrlEncodedContent(nvc);
                    request.Content = content;
                    var byteArray = Encoding.ASCII.GetBytes(Module1.Current.API_KEY.API_KEY_Value + ":hgvhgv");
                    client.DefaultRequestHeaders.Host = "api.planet.com";
                    //_client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
                    content.Headers.Remove("Content-Type");
                    content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                    client.DefaultRequestHeaders.Add("Connection", "keep-alive");
                    client.DefaultRequestHeaders.Add("User-Agent", "ArcGISProC#");
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
                    using (HttpResponseMessage httpResponse = client.SendAsync(request).Result)
                    {
                        if (httpResponse.IsSuccessStatusCode)
                        {
                            using (HttpContent content2 = httpResponse.Content)
                            {
                                var        json2      = content2.ReadAsStringAsync().Result;
                                customwmts customwmts = JsonConvert.DeserializeObject <customwmts>(json2);
                                customwmts.wmtsURL = new Uri("https://tiles.planet.com/data/v1/layers/wmts/" + customwmts.name + "?api_key=" + Module1.Current.API_KEY.API_KEY_Value);
                                //Geometry geometry2 = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, JsonConvert.SerializeObject( quickSearchResult.features[5].geometry));
                                var serverConnection = new CIMProjectServerConnection {
                                    URL = customwmts.wmtsURL.ToString()
                                };
                                var connection = new CIMWMTSServiceConnection {
                                    ServerConnection = serverConnection
                                };
                                string layerName = title + " (" + id + ")";
                                await QueuedTask.Run(() =>
                                {
                                    GroupLayer group        = GetGroupLayer();
                                    BasicRasterLayer layer2 = LayerFactory.Instance.CreateRasterLayer(connection, group as ILayerContainerEdit, 0, layerName);
                                });

                                mapLayerName = layerName;
                                CheckParents(true);
                                RemoveFootprints();
                            }
                        }
                        else
                        {
                            if (httpResponse.ReasonPhrase == "too many requests")
                            {
                                Thread.Sleep(1000);
                                doAddToMap();
                            }
                            else
                            {
                                MessageBox.Show("There was an problem adding the map, the server returned an error:" + Environment.NewLine + httpResponse.ReasonPhrase);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error adding strip to Map", "Add to Map");
            }
        }
Exemple #7
0
        public static async void AddLayer(string targets, string name)
        {
            try
            {
                using (HttpClientHandler handler = new HttpClientHandler())
                {
                    handler.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                    using (HttpClient client = new HttpClient(handler))
                    {
                        client.BaseAddress = new Uri("https://api.planet.com");
                        //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/layers");
                        //request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
                        request.Headers.Host = "tiles2.planet.com";
                        request.Headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
                        var nvc = new List <KeyValuePair <string, string> >();
                        //nvc.Add(new KeyValuePair<string, string>("ids", "PSScene4Band:20190603_205042_1042,PSScene4Band:20190528_205949_43_1061,PSScene4Band:20190818_205116_1009"));
                        nvc.Add(new KeyValuePair <string, string>("ids", targets));
                        //var content = new StringContent(json, Encoding.UTF8, "application/json");
                        var content = new FormUrlEncodedContent(nvc);
                        request.Content = content;
                        var byteArray = Encoding.ASCII.GetBytes(Module1.Current.API_KEY.API_KEY_Value + ":hgvhgv");
                        client.DefaultRequestHeaders.Host = "api.planet.com";
                        //_client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded"));
                        content.Headers.Remove("Content-Type");
                        content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
                        client.DefaultRequestHeaders.Add("Connection", "keep-alive");
                        client.DefaultRequestHeaders.Add("User-Agent", "ArcGISProC#");
                        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;
                                customwmts customwmts = JsonConvert.DeserializeObject <customwmts>(json2);
                                customwmts.wmtsURL = new Uri("https://tiles.planet.com/data/v1/layers/wmts/" + customwmts.name + "?api_key=" + Module1.Current.API_KEY.API_KEY_Value);
                                //Geometry geometry2 = GeometryEngine.Instance.ImportFromJSON(JSONImportFlags.jsonImportDefaults, JsonConvert.SerializeObject( quickSearchResult.features[5].geometry));
                                var serverConnection = new CIMProjectServerConnection {
                                    URL = customwmts.wmtsURL.ToString()
                                };
                                var connection = new CIMWMTSServiceConnection {
                                    ServerConnection = serverConnection
                                };
                                await QueuedTask.Run(() =>
                                {
                                    Layer group           = MapView.Active.Map.FindLayer(Asset.RootGroup);
                                    GroupLayer groupLayer = null;
                                    if (group != null)
                                    {
                                        groupLayer = group as GroupLayer;
                                    }
                                    else
                                    {
                                        int index  = Asset.FindRootIndex();
                                        groupLayer = LayerFactory.Instance.CreateGroupLayer(MapView.Active.Map, index, Asset.RootGroup);
                                    }
                                    BasicRasterLayer layer2 = LayerFactory.Instance.CreateRasterLayer(connection, groupLayer, 0, name);
                                });
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error adding to Map", "Add to Map");
            }
        }