<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Issues Downloading WMTS Data as Raster in ArcGIS Pro in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/issues-downloading-wmts-data-as-raster-in-arcgis/m-p/1552280#M73090</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hello GIS community,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I’m trying to create a Python script to download a specific area of imagery from a WMTS service and save it as a raster image (e.g., PNG or TIFF). This script is intended to be used within an ArcGIS Pro toolbox, where the user defines the area they want to download. The downloaded image will be used for Deep Learning in ArcGIS Pro.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here’s what I’ve tried so far:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;SPAN&gt;I have used GDAL in my script to connect to the WMTS service and attempted to download the data as a raster.&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;SPAN&gt;I’m working with the following WMTS URL: &lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="https://api.dataforsyningen.dk/orto_foraar_wmts_DAF?service=WMTS&amp;amp;request=GetCapabilities&amp;amp;token=577b8b556967c27dd029d1acbd544650" target="_blank" rel="noopener"&gt;https://api.dataforsyningen.dk/orto_foraar_wmts_DAF?service=WMTS&amp;amp;request=GetCapabilities&amp;amp;token=577b8b556967c27dd029d1acbd544650&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;SPAN&gt;The process seems to complete without error, but the output image file is empty (0 KB).&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;I’m not using a &lt;/SPAN&gt;&lt;SPAN&gt;layer_name&lt;/SPAN&gt;&lt;SPAN&gt; parameter because the WMTS service should provide that based on the GetCapabilities response. The user also defines the extent within ArcGIS Pro.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Below is the script I’ve been working on:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;import os&lt;BR /&gt;import logging&lt;BR /&gt;from osgeo import gdal&lt;/P&gt;&lt;P&gt;# Set up logging&lt;BR /&gt;logging.basicConfig(filename=os.path.join(output_folder, 'wmts_download.log'), level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')&lt;BR /&gt;logging.info('Log file created.')&lt;/P&gt;&lt;P&gt;# Parameters&lt;BR /&gt;wmts_url = '&lt;A href="https://api.dataforsyningen.dk/orto_foraar_wmts_DAF?service=WMTS&amp;amp;request=GetCapabilities&amp;amp;token=577b8b556967c27dd029d1acbd544650" target="_blank" rel="noopener"&gt;https://api.dataforsyningen.dk/orto_foraar_wmts_DAF?service=WMTS&amp;amp;request=GetCapabilities&amp;amp;token=577b8b556967c27dd029d1acbd544650&lt;/A&gt;'&lt;BR /&gt;output_folder = r'D:\Ortofoto'&lt;BR /&gt;workspace = '713203,415311581 6173517,82703254 713491,018988423 6173662,51763386'&lt;BR /&gt;output_file = os.path.join(output_folder, 'geodanmark_2023_10cm.png')&lt;/P&gt;&lt;P&gt;# Log parameters&lt;BR /&gt;logging.info(f'URL: {wmts_url}')&lt;BR /&gt;logging.info(f'Output Folder: {output_folder}')&lt;/P&gt;&lt;P&gt;# Open the WMTS dataset&lt;BR /&gt;logging.info('Attempting to open WMTS dataset.')&lt;BR /&gt;ds = gdal.Open(wmts_url)&lt;BR /&gt;if ds is None:&lt;BR /&gt;logging.error('Failed to open WMTS dataset.')&lt;BR /&gt;raise RuntimeError('Failed to open WMTS dataset.')&lt;/P&gt;&lt;P&gt;# Set spatial reference&lt;BR /&gt;logging.info('Setting spatial reference.')&lt;BR /&gt;spatial_ref = gdal.osr.SpatialReference()&lt;BR /&gt;spatial_ref.ImportFromWkt(workspace)&lt;/P&gt;&lt;P&gt;# Attempt to create output file&lt;BR /&gt;logging.info(f'Attempting to create output file: {output_file}')&lt;BR /&gt;driver = gdal.GetDriverByName('PNG')&lt;BR /&gt;out_ds = driver.CreateCopy(output_file, ds)&lt;BR /&gt;if out_ds is None:&lt;BR /&gt;logging.error('Failed to create output file.')&lt;BR /&gt;raise RuntimeError('Failed to create output file.')&lt;/P&gt;&lt;P&gt;logging.info(f'Downloaded image saved as: {output_file}')&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Has anyone faced a similar issue when using a WMTS service to download data as a raster image in ArcGIS Pro?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would appreciate any advice or examples of scripts that successfully download and save WMTS data, or any alternative approaches for accomplishing this task.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance for your help!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;//Per&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Oct 2024 12:08:04 GMT</pubDate>
    <dc:creator>PerAndersen</dc:creator>
    <dc:date>2024-10-25T12:08:04Z</dc:date>
    <item>
      <title>Issues Downloading WMTS Data as Raster in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/issues-downloading-wmts-data-as-raster-in-arcgis/m-p/1552280#M73090</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello GIS community,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I’m trying to create a Python script to download a specific area of imagery from a WMTS service and save it as a raster image (e.g., PNG or TIFF). This script is intended to be used within an ArcGIS Pro toolbox, where the user defines the area they want to download. The downloaded image will be used for Deep Learning in ArcGIS Pro.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here’s what I’ve tried so far:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;&lt;SPAN&gt;I have used GDAL in my script to connect to the WMTS service and attempted to download the data as a raster.&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;SPAN&gt;I’m working with the following WMTS URL: &lt;/SPAN&gt;&lt;SPAN&gt;&lt;A href="https://api.dataforsyningen.dk/orto_foraar_wmts_DAF?service=WMTS&amp;amp;request=GetCapabilities&amp;amp;token=577b8b556967c27dd029d1acbd544650" target="_blank" rel="noopener"&gt;https://api.dataforsyningen.dk/orto_foraar_wmts_DAF?service=WMTS&amp;amp;request=GetCapabilities&amp;amp;token=577b8b556967c27dd029d1acbd544650&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;SPAN&gt;The process seems to complete without error, but the output image file is empty (0 KB).&lt;/SPAN&gt;&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;I’m not using a &lt;/SPAN&gt;&lt;SPAN&gt;layer_name&lt;/SPAN&gt;&lt;SPAN&gt; parameter because the WMTS service should provide that based on the GetCapabilities response. The user also defines the extent within ArcGIS Pro.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Below is the script I’ve been working on:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;import os&lt;BR /&gt;import logging&lt;BR /&gt;from osgeo import gdal&lt;/P&gt;&lt;P&gt;# Set up logging&lt;BR /&gt;logging.basicConfig(filename=os.path.join(output_folder, 'wmts_download.log'), level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')&lt;BR /&gt;logging.info('Log file created.')&lt;/P&gt;&lt;P&gt;# Parameters&lt;BR /&gt;wmts_url = '&lt;A href="https://api.dataforsyningen.dk/orto_foraar_wmts_DAF?service=WMTS&amp;amp;request=GetCapabilities&amp;amp;token=577b8b556967c27dd029d1acbd544650" target="_blank" rel="noopener"&gt;https://api.dataforsyningen.dk/orto_foraar_wmts_DAF?service=WMTS&amp;amp;request=GetCapabilities&amp;amp;token=577b8b556967c27dd029d1acbd544650&lt;/A&gt;'&lt;BR /&gt;output_folder = r'D:\Ortofoto'&lt;BR /&gt;workspace = '713203,415311581 6173517,82703254 713491,018988423 6173662,51763386'&lt;BR /&gt;output_file = os.path.join(output_folder, 'geodanmark_2023_10cm.png')&lt;/P&gt;&lt;P&gt;# Log parameters&lt;BR /&gt;logging.info(f'URL: {wmts_url}')&lt;BR /&gt;logging.info(f'Output Folder: {output_folder}')&lt;/P&gt;&lt;P&gt;# Open the WMTS dataset&lt;BR /&gt;logging.info('Attempting to open WMTS dataset.')&lt;BR /&gt;ds = gdal.Open(wmts_url)&lt;BR /&gt;if ds is None:&lt;BR /&gt;logging.error('Failed to open WMTS dataset.')&lt;BR /&gt;raise RuntimeError('Failed to open WMTS dataset.')&lt;/P&gt;&lt;P&gt;# Set spatial reference&lt;BR /&gt;logging.info('Setting spatial reference.')&lt;BR /&gt;spatial_ref = gdal.osr.SpatialReference()&lt;BR /&gt;spatial_ref.ImportFromWkt(workspace)&lt;/P&gt;&lt;P&gt;# Attempt to create output file&lt;BR /&gt;logging.info(f'Attempting to create output file: {output_file}')&lt;BR /&gt;driver = gdal.GetDriverByName('PNG')&lt;BR /&gt;out_ds = driver.CreateCopy(output_file, ds)&lt;BR /&gt;if out_ds is None:&lt;BR /&gt;logging.error('Failed to create output file.')&lt;BR /&gt;raise RuntimeError('Failed to create output file.')&lt;/P&gt;&lt;P&gt;logging.info(f'Downloaded image saved as: {output_file}')&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Has anyone faced a similar issue when using a WMTS service to download data as a raster image in ArcGIS Pro?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would appreciate any advice or examples of scripts that successfully download and save WMTS data, or any alternative approaches for accomplishing this task.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance for your help!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;//Per&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 12:08:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/issues-downloading-wmts-data-as-raster-in-arcgis/m-p/1552280#M73090</guid>
      <dc:creator>PerAndersen</dc:creator>
      <dc:date>2024-10-25T12:08:04Z</dc:date>
    </item>
  </channel>
</rss>

