Tagged: , ,

Viewing 0 reply threads
  • Author
    Posts
    • #9270
      leo
      Keymaster

      Often we’re asked how to cast a field as a string, integer or float using the rawdata API

       

      The first step is to transform the data field that you want to request data for.
      This is done inside the fields param, by writing the new value, followed by :@ and the field to transform, finally to cast it as a separate type you can do __str, __int, __float for string, integer, and float casting respectively.
      Thus for casting the latitude as a string it would be:

      &fields=latitude_string:@lat__str
      
      results in: "latitude_string": "4.696300000000001",
      

      To get the value as an integer you’ll need to also multiply it by 100000 first,

      &fields=latitude_float:(@lat__float*100000)
      
      results in: "latitude_float": 469630.0000000001,
      

      Finally to get rid of any decimals you can round the value.

      &fields=latitude_integer_rounded:(@lat__float*100000).round(0),
      
      results in: "latitude_integer_rounded": 469630,
      

      Full example

      api/rawdata?vehicles=2600&fields=lon,lon_1e7:(@lon__float*100000).round(0),lat,lat_1e7:(@lat__float*100000),speed&speed=kph&duration=P1D&filter=speed>0

Viewing 0 reply threads
  • The topic ‘How to cast fields as strings, integers, or floats in rawdata API’ is closed to new replies.