Select to view content in your preferred language

Clip token protected WCS layer

579
1
01-07-2019 06:01 AM
GiacomoFavaron
Occasional Contributor

I am trying to create a geoprocessing service that let you created a buffer and use that buffer to clip a WMS service I published on my Portal.

 

The WMS service is protected and I managed to get to the service using a token but I cannot find a way to download the data.

 

This is my code, what am I doing wrong?

 

 

 

import arcpy
from arcpy import env
import requests
import json
from json import loads, dumps

 

env.outputCoordinateSystem = arcpy.SpatialReference(4326)

 

#Buffer
Point = arcpy.GetParameterAsText(0)
Buffer ="in_memory/Buffer"
Dist = 100
Distance = str(Dist) + " Meters"

outBuffer = arcpy.Buffer_analysis(Point, Buffer, Distance)

arcpy.SetParameter(1, outBuffer)

 

for row in arcpy.da.SearchCursor(outBuffer, ["SHAPE@"]):
   extent = row[0].extent
   XMin = str(extent.XMin)
   YMin = str(extent.YMin)
   XMax = str(extent.XMax)
   YMax = str(extent.YMax)

   coordinates = XMin + "," + YMin + "," + XMax + "," + YMax
   arcpy.AddMessage(coordinates)

 

resp = requests.post("https://xyzxyzxy.com/arcgis/sharing/rest/generateToken?f=json",
   data={"username":"xyzxy", "password":"xyzxy",
      "referer":"https://xyzxyzxy.com"})

 

tokenCode = str(json.dumps(resp.json()["token"]))
arcpy.AddMessage(tokenCode)


mapService = "https://xyzxyzxy.com/arcgis/services/MapServices/NameofLayer/MapServer/WCSServer?SERVICE=WCS&VERSION..." + coordinates + "&FORMAT=GTiff" + "?f=json&token=" + tokenCode
arcpy.AddMessage(mapService)

arcpy.SetParameter(2, mapService)

0 Kudos
1 Reply
GiacomoFavaron
Occasional Contributor

I think I have problems building the request. After looking at the results I received back from the server I changed the request to:

 

https://xyzxyzxy.com/arcgis/services/MapServices/NameofLayer/MapServer/WCSServer?SERVICE=WCS&VERSION... 

 

However I get the error message that " parameter COVERAGE is invalid" even if passed the name of the layer.

0 Kudos