I have a script which downloads features from an ArcGIS MapServer via the REST API. Getting vector features is relatively trivial since the features can be retrieved as JSON. However, when retrieving a map as an image, I'm getting stuck at the point where I have retrieved a response.
The relevant portion of my code, which gives me a valid image URL, is this:
# Export the map to JSON.urlGetImage = '%s/export?bbox=%s&bboxSR=%s&format=png&f=json' % ( theBasicUrl, bbox, bboxSR)urlGetImageResponse = urllib2.urlopen(urlGetImage)jsonImage = json.loads(urlGetImageResponse.read())# Read the image URL from the JSON and save the image.urllib.urlretrieve(jsonImage['href'], os.path.join(tempFolder, 'test.png'))Note the parameter where I retrieve the response as JSON. This is not essential. I don't care what I retrieve it as, so long as I can retrieve the generated raster somehow.
A sample response is this:
{"width": 400, "href": "https://[SERVER NAME]:[PORT]/arcgis/rest/directories/arcgisoutput/imagery/DEM_MapServer/_ags_map26932bd6681a4546a951125dd7c60e88.png", "scale": 20326865.193372156, "extent": {"xmin": 2996004.971208999, "ymin": -3232131.5223958646, "ymax": -1080867.3202355732, "xmax": 5147269.17336929, "spatialReference": {"wkid": 102100, "latestWkid": 3857}}, "height": 400}This gives me a path to download an image from, as well as the relevant spatial reference WKID. I then save it to an image.
My question is this: how do I go from here (an image on the drive) to a (referenced) raster dataset? Or have I already gone wrong in getting to this point?
أكثر...
The relevant portion of my code, which gives me a valid image URL, is this:
# Export the map to JSON.urlGetImage = '%s/export?bbox=%s&bboxSR=%s&format=png&f=json' % ( theBasicUrl, bbox, bboxSR)urlGetImageResponse = urllib2.urlopen(urlGetImage)jsonImage = json.loads(urlGetImageResponse.read())# Read the image URL from the JSON and save the image.urllib.urlretrieve(jsonImage['href'], os.path.join(tempFolder, 'test.png'))Note the parameter where I retrieve the response as JSON. This is not essential. I don't care what I retrieve it as, so long as I can retrieve the generated raster somehow.
A sample response is this:
{"width": 400, "href": "https://[SERVER NAME]:[PORT]/arcgis/rest/directories/arcgisoutput/imagery/DEM_MapServer/_ags_map26932bd6681a4546a951125dd7c60e88.png", "scale": 20326865.193372156, "extent": {"xmin": 2996004.971208999, "ymin": -3232131.5223958646, "ymax": -1080867.3202355732, "xmax": 5147269.17336929, "spatialReference": {"wkid": 102100, "latestWkid": 3857}}, "height": 400}This gives me a path to download an image from, as well as the relevant spatial reference WKID. I then save it to an image.
My question is this: how do I go from here (an image on the drive) to a (referenced) raster dataset? Or have I already gone wrong in getting to this point?
أكثر...