python data maps SDK results in corrupt PNG output

Richard Kooijman 0 Reputation points
2023-08-01T15:29:04.4433333+00:00

I run the attached simple Python test to generate a PNG file from Azure Data Maps API.

In some cases I get a blue picture with a signature, but most of the time I get a corrupt PNG that does not reflect what I am looking for: partial image, or macOS Preview won't even show something.

Does anybody see what's wrong?

I also tried a Java version of this functionality and works as expected.

Same subscription, same data maps account, etc, just in another language and a different SDK from Azure (python vs Java).

regards, Richard.test copy.py.txt

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
561 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 12,276 Reputation points
    2023-08-01T22:36:09.44+00:00

    Hi @Richard Kooijman Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    I am just wondering if you have tried the async approach to get the static image. Please find the implementation for this through the link sample_get_map_static_image_async.py. Here is the code sample for your reference.

    
    """
    FILE: sample_get_map_static_image_async.py
    DESCRIPTION:
        This sample demonstrates how to the static image service renders a user-defined, rectangular image containing a map section using a zoom level from 0 to 20. The static image service renders a user-defined, rectangular image containing a map section using a zoom level from 0 to 20.
    USAGE:
        python sample_get_map_static_image_async.py
        Set the environment variables with your own values before running the sample:
        - AZURE_SUBSCRIPTION_KEY - your subscription key
    """
    import asyncio
    import os
    
    subscription_key = os.getenv("AZURE_SUBSCRIPTION_KEY")
    
    async def get_map_static_image_async():
        # [START get_map_static_image_async]
        from azure.core.credentials import AzureKeyCredential
        from azure.maps.render.aio import MapsRenderClient
    
        maps_render_client = MapsRenderClient(credential=AzureKeyCredential(subscription_key))
    
        async with maps_render_client:
            result = await maps_render_client.get_map_static_image(img_format="png", center=(52.41064,4.84228))
        # [END get_map_static_image_async]
    
    if __name__ == '__main__':
       asyncio.run(get_map_static_image_async())
    

    Please give it a try and let us know if this helps.



    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.

    1 person found this answer helpful.
    0 comments No comments