Clip token protected WCS layer

438
1
01-07-2019 06:01 AM
GiacomoFavaron
New Contributor III

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://xxxxxxxx.com/arcgis/sharing/rest/generateToken?f=json",
   data={"username":"xxxxx", "password":"xxxxx",
      "referer":"https://xxxxxxxx.com"})

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


mapService = "https://xxxxxxxx.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
New Contributor III

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://xxxxxxxx.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