R: WMS map not showing up - r

I have this WMS layer:
http://apps.ecmwf.int/wms/?token=public&version=1.3.0&request=GetMap&layers=composition_bbaod550
I want to add it to a leaflet map but it is not showing up.
Here is my code:
library("leaflet")
library("sp")
leaflet() %>% addTiles() %>% setView(0, 50, zoom = 1) %>%
addWMSTiles("http://apps.ecmwf.int/wms/?token=public&version=1.3.0&request=GetMap",
layers = "composition_bbaod550",
options = WMSTileOptions(format = "image/png", transparent = TRUE))
What am I doing wrong?
EDIT #1:
Here is what the network requests look like from the developer console
EDIT #2:
Here is my code with IvanSanchez's suggestions. As you can see the proposed approach did not fix the problem
library("leaflet")
library("sp")
leaflet() %>% addTiles() %>% setView(0, 50, zoom = 1) %>%
addWMSTiles("http://apps.ecmwf.int/wms/",
layers = "composition_bbaod550",
options = WMSTileOptions(token = "public",
srs = "EPSG:4326",
format = "image/png",
transparent = TRUE))

If we make a GetCapabilities request to the WMS service as below, we can see that the highest supported WMS version is 1.1.1. So your GetMap request for a version=1.3.0 WMS service will probably error.
http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities&
When I looked at the response it appeared to have some errors and indeed when I checked in my XML editor, there are many errors (so many that the log is greater the character limit allowed in this answer).
WMS configuration errors:
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Attribute "xlink:execution" is not allowed to appear in element "OnlineResource".
Start location: 44:17
End location: 44:54
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 97:8
End location: 97:11
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 122:10
End location: 122:13
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Attribute "multipleValues" is not allowed to appear in element "Extent".
Start location: 137:60
End location: 137:78
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 273:10
End location: 273:13
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Attribute "multipleValues" is not allowed to appear in element "Extent".
Start location: 288:60
End location: 288:78
System ID: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Main validation file: http://apps.ecmwf.int/wms/?token=public&service=WMS&request=GetCapabilities
Schema: http://schemas.opengis.net/wms/1.1.1/WMS_MS_Capabilities.dtd
Engine name: Xerces
Severity: error
Description: Unexpected element "SRS". The content of the parent element type must match "(Name?,Title,Abstract?,KeywordList?,SRS*,LatLonBoundingBox?,BoundingBox*,Dimension*,Extent*,Attribution?,AuthorityURL*,Identifier*,MetadataURL*,DataURL*,FeatureListURL*,Style*,ScaleHint?,Layer*)".
Start location: 393:10
End location: 393:13
...
The SRS / LatLonBoundingBox / BoundingBox section should look something like below (structure, not content):
<SRS>CRS:84</SRS>
<SRS>EPSG:27700</SRS>
<SRS>EPSG:3034</SRS>
<SRS>EPSG:3413</SRS>
<SRS>EPSG:3857</SRS>
<SRS>EPSG:4258</SRS>
<SRS>EPSG:4326</SRS>
<SRS>EPSG:900913</SRS>
<LatLonBoundingBox minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="CRS:84"
minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="EPSG:27700"
minx="-235677" miny="-34616" maxx="827937" maxy="1.28234e+006" />
<BoundingBox SRS="EPSG:3034"
minx="2.5664e+006" miny="2.55843e+006" maxx="3.67848e+006" maxy="3.94271e+006" />
<BoundingBox SRS="EPSG:3413"
minx="1.79406e+006" miny="-3.77262e+006" maxx="3.43831e+006" maxy="-2.09742e+006" />
<BoundingBox SRS="EPSG:3857"
minx="-1.20245e+006" miny="6.37538e+006" maxx="436488" maxy="8.6571e+006" />
<BoundingBox SRS="EPSG:4258"
minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="EPSG:4326"
minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
<BoundingBox SRS="EPSG:900913"
minx="-10.8018" miny="49.5889" maxx="3.92104" maxy="61.1359" />
So the service is definitely not configured correctly, and this is probably the root cause of any problems you are having.

Do not include the version nor the request parameters in the base WMS URL. These are added internally by Leaflet. Leaflet expects a base WMS URL, as explained in http://leafletjs.com/examples/wms/wms.html.
So instead of
addWMSTiles("http://apps.ecmwf.int/wms/?token=public&version=1.3.0&request=GetMap",
Do
addWMSTiles("http://apps.ecmwf.int/wms/?token=public&",
Also, quoting from the Leaflet WMS tutorial:
L.TileLayer.WMS has extra options, which can be found in Leaflet’s API documentation. Any option not described there will be passed to the WMS server in the getImage URLs.
So you can actually do
addWMSTiles("http://apps.ecmwf.int/wms/",
layers = "composition_bbaod550",
options = WMSTileOptions(token = "public", format = "image/png", transparent = TRUE))
If this fails, use the developer console in your web browser (press F12) and see the network requests. How do the requests to the WMS look like?
Edit:
After a tiny bit of debugging, it seems that the WMS server is responding with:
<!DOCTYPE ServiceExceptionReport SYSTEM "/static/frontend/contrib/exception_1_1_1.dtd">
<ServiceExceptionReport version="1.1.1">
<ServiceException code='InvalidSRS'><![CDATA[
Unsupported projection 'EPSG:3857'
]]>
</ServiceException>
</ServiceExceptionReport>
This means that the WMS server is not capable of outputting images which fit the default map projection for Leaflet.
If you want to use this WMS server, you'll have to check the list of supported map projections from its GetCapabilities document, and use Proj4Leaflet to make the map use a projection different than the default.
Do read:
http://leafletjs.com/examples/wms/wms.html#notes-to-gis-users-of-wms-services (Leaflet using a different map proj)
http://www.qgistutorials.com/en/docs/working_with_wms.html (How to see the capabilities of a WMS using QGIS)
https://github.com/rstudio/leaflet/blob/master/inst/examples/proj4Leaflet.R (examples of Leaflet for R with custom map projs)
I'm sorry there's no straightforward answer; you'll have to do a bit of work and learning about projections.

Related

How to setup Airflow custom email template

In the airflow.cfg, I have set how I need my email to look like but when an email is sent, the settings/layout I have specified is not being applied.
subject_template = 'Airflow alert: {{ti}}'
# File that will be used as the template for Email content (which will be rendered using Jinja2).
# If not set, Airflow uses a base template.
# Example: html_content_template = /path/to/my_html_content_template_file
html_content_template = (
'Try {{try_number}} out of {{max_tries + 1}}<br>'
'Job Name: {{ti.dag_id}}<br>'
'Task Id: {{ti.task_id}}<br>'
'Exception: {{exception_html}}<br>'
'Log: Link<br>'
'Host: {{ti.hostname}}<br>'
'Log file: {{ti.log_filename}}<br>')
What I'm I missing?
From the docs of html_content_template:
File that will be used as the template for Email content (which will be rendered using Jinja2). If not set, Airflow uses a base template.
I guess the expected value would be something like:
html_content_template = /path/to/my_html_content_template_file
Try creating a file with the template and providing the path to that file in the settings.

API Platform - External values Swagger are not showing in UI Openapis

According to
https://swagger.io/docs/specification/adding-examples/#external
I have:
# config/api_platform/resources.yaml
App\Entity\Example:
...
responses:
'201':
content:
application/json:
examples:
ExampleA:
externalValue: 'https://127.0.0.1:8000/example/ExampleA.json'
ExampleB:
value:
name: Nino
ExampleB is rendered.
But ExampleA with externalValue is not generated.
Resolved. I found this, externalValue is not supported in Swagger-UI
https://github.com/swagger-api/swagger-ui/issues/5433

How to use "$ref" reference and declare components from Swagger in API platform?

We can define components in Swagger:
components:
schemas:
User:
properties:
id:
type: integer
name:
type: string
And use this component later:
responses:
'200':
description: The response
schema:
$ref: '#/components/schemas/User'
I want to use this in order to avoid duplicating content.
I try to use this syntax in API Platform:
components:
schemas:
Part:
description: Array of Part
type: array
items:
type: object
properties:
name:
type: string
App\Entity\Item:
collectionOperations:
post:
method: 'POST'
swagger_context:
parameters:
- name: body
description: Item data
in: body
schema:
type: object
properties:
name:
description: Part
type: string
required: true
part:
$ref: '#/components/schemas/Part'
It gives me an error:
Exception thrown when handling an exception (Symfony\Component\Config\Exception\FileLoaderLoadException: Resource "components" not found in . (which is being imported from "/app/config/routes/api_platform.yaml"). Make sure there is a loader supporting the "api_platform" type.)
It looks like the YAML loader doesn't recognize the components item.
How can I define and use references in API Platform? How can I define a reference and use it in several YAML files?
You cannot do that like this.
The components key belongs to the Swagger/OpenAPI format, not to the API Platform configuration (mapping) format. Both API Platform configuration files and Swagger definitions can be written in YAML, but they are not related.
So, as the error message describes, Swagger components cannot be injected in API Platform's configuration files directly, as you try to do.
API Platform's configuration does allow allows to inject some context in the generated Swagger file using the swagger_context key, but you cannot write random Swagger definitions (such as your component key) outside of this structure.
To do what you want to achieve the swagger_context key will not be enough (components must be injected at the root of the Swagger file, and it's not possible with swagger_context).
Instead of using this key, you'll have to create a decorator for the Swagger documentation generator, as explained in this documentation entry: https://api-platform.com/docs/core/swagger/#overriding-the-swagger-documentation
Decorator allows to access to the whole Swagger structure, and to modify it. So you'll be able to add your components structure.
It possible ... See How can I annotate my attribute which is Value Object in order that API Platform would generate its fields for swagger documentation?
In my exemple, I have the entity Checker, I created two groups :
* #ApiResource(
* attributes={
* "normalization_context"={"groups"={"read"}},
* "denormalization_context"={"groups"={"write"}},
* },
Then in the swagger_context responses :
* "responses" = {
* "201" = {
* "description" = "....",
* "schema" = {
* "type" = "object",
* "properties" = {
* "myresult" = {
* "$ref"="#/definitions/Checker-read"
* }

Uploading of image to WordPress through Python's requests

In order to validate the installation of WordPress instances, we are writing Python unit tests. One of the test should perform the following action: upload an image to WordPress.
In order to do that, I am using the Requests library.
When I inspect the form within /wp-admin/media-new.php page through Firebug (form information, I get the following information):
Form
Id: file-form
Name
Method: post
Action: http://localhost:8000/wp-admin/media-new.php
Elements
id: plupload-browse-button
type: button
value: Select Files
id:async-upload
name: async-upload
type: file
label: Upload
id:html-upload
name: html-upload
type: submit
value: Upload
id: post_id
name: post_id
type: hidden
value: 0
id: _wpnonce
name: _wpnonce
type: hidden
value: c0fc3b80bb
id: file-form
name: _wp_http_referer
type: hidden
value: /wp-admin/media-new.php
I believe that the _wpnonce is a unique value generated for each session. Therefore, before trying to upload the file, I get the media-new.php page and grab the _wpnonce in the form (hence the variable in my code).
My code is the following:
with open('1.jpg', 'rb') as f:
upload_data = {'post_id': '0',
'_wp_http_referer': '/wp-admin/media-new.php',
'_wpnonce': wp_nonce,
'action': 'upload_attachement',
'name': '1.jpg',
'async-upload': f,
'html-upload': 'Upload'}
upload_result = session.post('http://localhost:8000/wp-admin/media-new.php', upload_data)
The code runs fine and the upload_result.status_code equals 200.
However, the image never shows up in the media gallery of WordPress.
I believe this a simple error, but I can't figure out what I'm missing.
Thanks in advance for the help.
If you want to post files you should use the files parameter. Also the '_wpnonce' value is not enough to get authenticated, you need to have cookies.
url = 'http://localhost:8000/wp-admin/media-new.php'
data = {
'post_id': '0',
'_wp_http_referer': '/wp-admin/media-new.php',
'_wpnonce': wp_nonce,
'action': 'upload_attachement',
'html-upload': 'Upload'
}
files = {'async-upload':('1.jpg', open('1.jpg', 'rb'))}
headers = {'Cookie': my_cookies}
upload_result = session.post(url, data=data, files=files, headers=headers)
I'm assuming that you have acquired valid cookies from your browser. If you want to get authenticated with requests check my answer to this post: login-wordpress-with-requests

Extjs 4 - Retrieve data in json format and load a Store. It sends OPTION request

I'm developing an app with Spring MVC and the view in extjs 4. At this point, i have to create a Grid which shows a list of users.
In my Spring MVC controller i have a Get method which returns the list of users in a jsonformat with "items" as a root.
#RequestMapping(method=RequestMethod.GET, value="/getUsers")
public #ResponseBody Users getUsersInJSON(){
Users users = new Users();
users.setItems(userService.getUsers());
return users;
}
If i try to access it with the browser i can see the jsondata correctly.
{"items":[{"username":"name1",".....
But my problem is relative to request of the Ext.data.Store
My Script is the following:
Ext.onReady(function(){
Ext.define('UsersList', {
extend: 'Ext.data.Model',
fields: [
{name:'username', type:'string'},
{name:'firstname', type:'string'}
]
});
var store = Ext.create('Ext.data.Store', {
storeId: 'users',
model: 'UsersList',
autoLoad: 'true',
proxy: {
type: 'ajax',
url : 'http://localhost:8080/MyApp/getUsers.html',
reader: {type: 'json', root: 'items'}
}
});
Ext.create('Ext.grid.Panel',{
store :store,
id : 'user',
title: 'Users',
columns : [
{header : 'Username', dataIndex : 'username'},
{header : 'Firstname', dataIndex: 'firstname'}
],
height :300,
width: 400,
renderTo:'center'
});
});
When the store tries to retrieve the data and launchs the http request, in my firebug console appears OPTIONS getUsers.html while the request in the browser launchs GET getUsers.html
As a result, Ext.data.Store has not elements and the grid appears with the columnames but without data. Maybe i've missed something
Thank you
You can change the HTTP methods that are used by the proxy for the different CRUD operations using actionMethods.
But, as you can see in the doc (and as should obviously be the case), GET is the default for read operations. So the OPTIONS request you are observing is quite puzzling. Are you sure that there's not another part of your code that overrides the default application-wide? Maybe do a search for 'OPTIONS' in all your project's JS files, to try and find a possible suspect. Apparently there's no match in the whole Ext code, so that probably doesn't come from the framework.
Edit:
Ok, I think I've got it. If your page is not accessed from the same domain (i.e. localhost:8080, the port is taken into account), the XHR object seems to resort to an OPTIONS request.
So, to fix your problem, either omit the domain name completely, using:
url: '/MyApp/getUsers.html'
Or double check that your using the same domain and port to access the page and make the requests.

Resources