Skip to main content
Question

Managing raster files from API request


armando_amador
Contributor
Forum|alt.badge.img+4

I have requested a raster file from an API (HERE Map Image API v3), and the response comes in the fashion of (I guess) base64 data.


I would like to have a way to transform such data and store it in proper folders.

Any idea?

 

Regards.

3 replies

hkingsbury
Celebrity
Forum|alt.badge.img+50
  • Celebrity
  • June 26, 2024

Two transformers to look at will be the TextDecoder (can decoded the base64) and the AttributeFileWriter which can write the contents of an attribute to a file


armando_amador
Contributor
Forum|alt.badge.img+4
hkingsbury wrote:

Two transformers to look at will be the TextDecoder (can decoded the base64) and the AttributeFileWriter which can write the contents of an attribute to a file

Hi @hkingsbury, thanks for your help, it helped to show the way to unlock AI capabilities in FME 2024, using PythonCaller I asked to the AI and it provided this code:

import fme
import fmeobjects


class FeatureProcessor(object):

    def __init__(self):
        pass

    def input(self, feature: fmeobjects.FMEFeature):
        # Retrieve the _response_body attribute from the feature
        response_body = feature.getAttribute('_response_body')

        # Assuming response_body contains binary data for the raster
        # Convert the binary data to a raster file
        # This example saves the raster to a temporary file. Adjust the path as necessary.
        raster_file_path = r'YOURFILEPATH\raster.tif'
        with open(raster_file_path, 'wb') as file:
            file.write(response_body)

        # Optionally, set the path of the raster file as an attribute to the feature
        feature.setAttribute('rasterFilePath', raster_file_path)

        # Output the feature
        self.pyoutput(feature)

This helped to convert my api _responsebody input data and then stored it into the specific path.

Sharing it to newbies in the future to have a nice way to solve this issue.

Regards!


hkingsbury
Celebrity
Forum|alt.badge.img+50
  • Celebrity
  • June 26, 2024

Nice job @armando_amador! Did you try the AttributeFileWriter? You’ll be able to achieve the same outcome without needing python
 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings