Skip to main content
Solved

Updating geolocation on assets using Python SDK


Forum|alt.badge.img+4

Hi.

Is it possible to update the geolocatoin of assets using the Python SDK?

It seems I’m able to update the asset with a geolocation that renders the SDK unable to interact further with the asset. Example below:

 

## Create a new asset with geolocation

dsid = <data set id>

from cognite.client.data_classes import GeoLocation, Asset, Geometry

geometry1 = Geometry(
    type="Point", coordinates=[9.6573149,59.142253]
    )
asset = Asset(
    name="geotest", 
    data_set_id=dsid,
    geo_location=GeoLocation(
        type="Feature", 
        geometry=geometry1
    )
)
res = client.assets.create(asset)



## List all assets matching the name .. it works well

client.assets.list(name="geotest") 



## Update the geolocation, returns KeyError: 'type'

geometry2 = Geometry(
    type="Point", coordinates=[8.6573149,57.142253]
    )
res.geo_location = geometry2
res2 = client.assets.update([res])



## Now try to list the assets again. It fails, returning KeyError: 'type'

client.assets.list(name="geotest")

 

Best answer by Pasindu Perera

I have tried updating geolocation on assets in Python SDK. I have used following sysntax and it worked for me. Could you please try the same and let me know?

Code:

geometry_two  = Geometry(type="Point",coordinates=[8.6573149,59.142253])


my_update = AssetUpdate(id=2672701736309715).geo_location.set(GeoLocation(type="Feature",geometry=geometry_two))
result=client.assets.update(my_update)
print(result)

After made this update I am able to list my assets:

 

View original
Did this topic help you find an answer to your question?

2 replies

Pasindu Perera
Seasoned Practitioner
Forum|alt.badge.img+2
  • Seasoned Practitioner
  • 18 replies
  • Answer
  • February 8, 2024

I have tried updating geolocation on assets in Python SDK. I have used following sysntax and it worked for me. Could you please try the same and let me know?

Code:

geometry_two  = Geometry(type="Point",coordinates=[8.6573149,59.142253])


my_update = AssetUpdate(id=2672701736309715).geo_location.set(GeoLocation(type="Feature",geometry=geometry_two))
result=client.assets.update(my_update)
print(result)

After made this update I am able to list my assets:

 


Forum|alt.badge.img+4

Thanks @Pasindu Perera, I can confirm that this syntax works!


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