4

I have connected my QGIS to the Sao Paulo Hydropower potential MapServer with a WMTS connection using the following URL:

http://tps.geosur.info/arcgis/rest/services/maps/GeoSUR_SPHydropower/MapServer/WMTS/1.0.0/WMTSCapabilities.xml

Hydropower potential

Visually this is great but how can I access the data source behind this specific layer: Hydropower Potential MW (ID: 7)?. In other words, how can I click on a coloured line in QGIS to see what the potential value is?.

I noticed there is a link to a json version but not sure how to load this into QGIS (or if it is indeed the best method).

  • What happens if you identify the line? – HeikkiVesanto Oct 20 '16 at 11:15
  • @Vesanto - The Identify Features tool is not available for this layer. – Joseph Oct 20 '16 at 11:15
  • For your purpose, would it be OK if you made a local copy of the data, or does it have to be the live version from the server? – PhilippNagel Oct 20 '16 at 14:02
  • @PhilippNagel - A local copy would actually be more ideal as long as the data is available ;) – Joseph Oct 20 '16 at 14:07
2

See the capabilities of the server from http://tps.geosur.info/arcgis/rest/services/maps/GeoSUR_SPHydropower/MapServer/WMTS/1.0.0/WMTSCapabilities.xml

If WMTS server supports GetFeatureInfo request it would be included in the OperationsMetadata section. This server simply does not support GetFeatureInfo and you can't request info about from the features.

Many people understand that MapServer means the open source one http://mapserver.org/ while this server seems to be ESRI ArcGIS server. However, WMTS is the same for both.

WMTS servers which support GetFeatureInfo has something like this in the OperationsMetadata:

<ows:Operation name="GetFeatureInfo">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="http://www.maps.bob/maps.cgi?">
<ows:Constraint name="GetEncoding">
<ows:AllowedValues>
<ows:Value>KVP</ows:Value>
</ows:AllowedValues>
</ows:Constraint>
</ows:Get>
</ows:HTTP>
</ows:DCP>
</ows:Operation>
  • Thanks for your answer, this is both interesting and disappointing! Do you know anything about the json version? Otherwise I'll see using that can yield any results =) – Joseph Oct 20 '16 at 12:03
  • Sorry, I have no experience on such rest service. The document that I get from the link contains stuff like "capabilities": "Map,Query,Data"which feels promising. – user30184 Oct 20 '16 at 12:09
  • No problem, thanks for the tip. I'll take a looksie! – Joseph Oct 20 '16 at 12:17
2

There are two options to get to the underlying data on ArcGIS Server from QGIS. You indicate you would prefer a local copy, so I will cover that first, but I will briefly touch on connecting to the REST endpoint as well.

Before you do any of this, please make sure it's OK to do so. I don't see an express license statement for the data on that server. I would contact the owner and see what the license is and what you're allowed to do with their data.

Local Copy:

I would recommend that you look into the Bolton & Menk GIS Team ArcGIS REST API. It can be found on Github at https://github.com/Bolton-and-Menk-GIS/restapi There are other similar tools available, but many of them rely on ESRI software to do their work. In fact, ESRI themselves have similar tool.

This is a Python module that lets you interact with many aspects of ArcGIS Server. One example shown in the readme is how to save a copy of a Feature Service to a shapefile or KMZ. This works either with proprietery ESRI tools if they are installed and licensed, or otherwise it will use open source tools for this.

So for this purpose you would define the server url:

rest_url = 'http://tps.geosur.info/arcgis/rest/services'
ags = restapi.ArcServer(rest_url)

Then you can use the various sample script in the readme and

For example, define the MapService you want to work with:

GeoSUR_SPHydropower = ags.get_MapService('GeoSUR_SPHydropower')

and view the layers it contains:

print GeoSUR_SPHydropower.list_layers()

You can also see these listed on the MapService page: http://tps.geosur.info/arcgis/rest/services/maps/GeoSUR_SPHydropower/MapServer

To save the data locally, you would have to download each layer individually and save it to shapefile. For example:

lyr = GeoSUR_SPHydropower.layer('Regionalized Basins')
output = r'c:\path\to\shapefile.shp'
lyr.layer_to_fc(output)

As you can see, you could easily automate downloading of all the layers with the list_layers method.

Live connection in QGIS:

There is an experimental QGIS Plugin available to do just this with an ArcGIS Server REST service. To install it, go to Plugins - Manage and install plugins..., then go to Settings, and check "Show also experimental plugins". At the bottom, click "Reload repository" and go back to the "All" tab. Now search for ArcGIS REST API Connector and install it. A new icon will appear in your Manage Layers toolbar: ArcGIS REST API Connector icon Click it and paste a layer URL into the first field, Layer URL. The second field, Layer Name, should populate automatically. You need to put a layer URL here, and only certain types of layers are supported. You can't use a Group Layer (one that contains multiple other layers). If you look on the service page, the layers are shown in a nested way. Layers you can use are always the ones on the lowest respective level:

Layer list with usable layers highlighted

The ones underlined in red are ones you can probably use, although I'm not sure if the Labels ones are the image layers are supported. To add the layer, just right-click it's name in that list and copy the url, then paste it in the Layer URL field.

Populated Dialog

  • Many thanks for your answer, I will test this and let you know how I get on :) – Joseph Oct 20 '16 at 14:48
  • 1
    I would also recommend restapi :) I'm working on a new release (version 1.0) that will be out sometime in the near future. – crmackey Oct 20 '16 at 16:55
  • @crmackey - I installed your restapi package using setup.py install in the cmd prompt. But when I run import restapi from shell, I receive an error: ImportError: No module named restapi. Any ideas? I use Windows 7 and the package seems to have been successfully installed in C:\Python34\Lib\site-packages\restapi (I'm guessing this is where it's supposed to be?). – Joseph Oct 21 '16 at 10:02
  • @Joseph Do you have multiple versions of Python running by chance? If so, have you verified that restapi is in the site-packages folder in all instances (i.e. Python 2.x)? Maybe you are getting that error when running a different version. – crmackey Oct 24 '16 at 17:44
  • @crmackey - I only have Python 3.4.2 installed. I'll try reinstalling it again and play around, thanks! – Joseph Oct 25 '16 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.