{
  "id": 182397,
  "title": "Getting Satellite map coordinates from agent centroids ",
  "url": "/competitions/lyft-motion-prediction-autonomous-vehicles/discussion/182397",
  "author_name": "",
  "post_date": "2020-09-12T15:50:31.992065500Z",
  "votes": null,
  "comment_count": 6,
  "views": 0,
  "content": "<p>I thought it would be easy to grab the centroids with their respective extents and then map them to the satellite map, however this has proven a lot more difficult than I could imagine. Has anyone been able to find a direct mapping between the agent coordinates and the maps? </p>",
  "messages": [
    {
      "id": "1007885",
      "postDate": "09/12/2020 15:50:31",
      "content": "<p>I thought it would be easy to grab the centroids with their respective extents and then map them to the satellite map, however this has proven a lot more difficult than I could imagine. Has anyone been able to find a direct mapping between the agent coordinates and the maps? </p>",
      "rawMarkdown": "I thought it would be easy to grab the centroids with their respective extents and then map them to the satellite map, however this has proven a lot more difficult than I could imagine. Has anyone been able to find a direct mapping between the agent coordinates and the maps?",
      "votes": null
    },
    {
      "id": "1008304",
      "postDate": "09/13/2020 01:29:32",
      "content": "<p>It should be in gps Lat Long * 1e5 (from 1e7 with ~1cm integer) then minus a reference location. I'm not sure of the 0,0 gps value though</p>\n<p>Add:  [37°25'45.6\"N, 122°09'15.7\"W] in Palo Alto (California, USA). from coords_systems.md</p>",
      "rawMarkdown": "It should be in gps Lat Long * 1e5 (from 1e7 with ~1cm integer) then minus a reference location. I'm not sure of the 0,0 gps value though\n\nAdd:  [37°25'45.6\"N, 122°09'15.7\"W] in Palo Alto (California, USA). from coords_systems.md",
      "votes": null
    },
    {
      "id": "1009295",
      "postDate": "09/13/2020 20:28:09",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/maxjon\" target=\"_blank\">@maxjon</a> can you give me more details on what you're trying to achieve? Are you trying to map coordinates from <code>world</code> reference system to Lat-Lng?</p>",
      "rawMarkdown": "Hi @maxjon can you give me more details on what you're trying to achieve? Are you trying to map coordinates from `world` reference system to Lat-Lng?",
      "votes": null
    },
    {
      "id": "1009700",
      "postDate": "09/14/2020 07:19:36",
      "content": "<p>Hey <a href=\"https://www.kaggle.com/lucabergamini\" target=\"_blank\">@lucabergamini</a>, this is exactly what I'm trying to do. I want to the \"raw\" coordinates from agent centroids to the satellite map. for example: </p>\n<pre><code>agents = get_agent_dictionary()\n\nmap = cv2.imread(path_to_map_image)\n\n# use unkown coord_to_map_scale, and refence_location_offsets to scale the map \n# to world reference system\nwidth = agent.extent_width * coord_to_map_scale \nheight = agent.extent_height * coord_to_map_scale \ncenter_x = (agent.centroid_x + refence_location_offset_x) * coord_to_map_scale \ncenter_y = (agent.centroid_y + refence_location_offset_y) * coord_to_map_scale \n\n# slice the satellite map\nmap_crop = crop_map(map, center_x, center_y, height=400, width=400)\n\n# draw the agent on the map without yaw\nagent_map = draw_agent(map_crop, center_x, center_y, width, height)\n\nplt.show(agent_map)\nplt.show()\n</code></pre>",
      "rawMarkdown": "Hey @lucabergamini, this is exactly what I'm trying to do. I want to the \"raw\" coordinates from agent centroids to the satellite map. for example: \n```\nagents = get_agent_dictionary()\n\nmap = cv2.imread(path_to_map_image)\n\n# use unkown coord_to_map_scale, and refence_location_offsets to scale the map \n# to world reference system\nwidth = agent.extent_width * coord_to_map_scale \nheight = agent.extent_height * coord_to_map_scale \ncenter_x = (agent.centroid_x + refence_location_offset_x) * coord_to_map_scale \ncenter_y = (agent.centroid_y + refence_location_offset_y) * coord_to_map_scale \n\n# slice the satellite map\nmap_crop = crop_map(map, center_x, center_y, height=400, width=400)\n\n# draw the agent on the map without yaw\nagent_map = draw_agent(map_crop, center_x, center_y, width, height)\n\nplt.show(agent_map)\nplt.show()\n\n```",
      "votes": null
    },
    {
      "id": "1010119",
      "postDate": "09/14/2020 14:15:30",
      "content": "<p>I'm still not 100% sure we're saying the same thing. If you're using our satellite map (in l5kit) you don't need LAT-LNG coords but ECEF (XYZ earth centred). From your snippet I think that's the case, can you confirm it? Because in that case you're trying to do something similar to what our <a href=\"https://github.com/lyft/l5kit/blob/master/l5kit/l5kit/rasterization/satellite_rasterizer.py\" target=\"_blank\">satellite rasterizer</a> already does </p>",
      "rawMarkdown": "I'm still not 100% sure we're saying the same thing. If you're using our satellite map (in l5kit) you don't need LAT-LNG coords but ECEF (XYZ earth centred). From your snippet I think that's the case, can you confirm it? Because in that case you're trying to do something similar to what our [satellite rasterizer](https://github.com/lyft/l5kit/blob/master/l5kit/l5kit/rasterization/satellite_rasterizer.py) already does",
      "votes": null
    },
    {
      "id": "1010205",
      "postDate": "09/14/2020 15:21:16",
      "content": "<p>I am trying to do what is done by the SatelliteRasterizer, but more directly without centering on EGO and all the other stuff going on here. Basically I am trying to figure out how can make this simpler or even make it work outside of the library at all. </p>\n<pre><code>world_to_ecef = np.asarray(\n        [\n            [8.46617444e-01, 3.23463078e-01, -4.22623402e-01, -2.69876744e06],\n            [-5.32201938e-01, 5.14559352e-01, -6.72301845e-01, -4.29315158e06],\n            [-3.05311332e-16, 7.94103464e-01, 6.07782600e-01, 3.85516476e06],\n            [0.00000000e00, 0.00000000e00, 0.00000000e00, 1.00000000e00],\n        ],\n        dtype=np.float64,\n    )\n\n\necef_to_aerial = np.asarray(\n        [\n            [-0.717416495, -1.14606296, -1.62854453, -572869.824],\n            [1.80065798, -1.08914046, -0.0287877303, 300171.963],\n            [0.0, 0.0, 0.0, 0.0],\n            [0.0, 0.0, 0.0, 1.0],\n        ],\n        dtype=np.float64,\n    )\n\nworld_to_aerial = np.matmul(ecef_to_aerial, world_to_ecef)\nworld_to_image_space = world_to_image_pixels_matrix(\n    self.raster_size,\n    self.pixel_size,\n    ego_translation_m=ego_translation,\n    ego_yaw_rad=ego_yaw,\n    ego_center_in_image_ratio=self.ego_center,\n)\n\n# get the center of the images in meters using the inverse of the matrix,\n# Transform it to satellite coordinates (consider also z here)\ncenter_pixel = np.asarray(self.raster_size) * (0.5, 0.5)\nworld_translation = transform_point(center_pixel, np.linalg.inv(world_to_image_space))\nsat_translation = transform_point(np.append(world_translation, ego_translation[2]), self.world_to_aerial)\n\n# Note 1: there is a negation here, unknown why this is necessary.\n# My best guess is because Y is flipped, maybe we can do this more elegantly.\nsat_im = get_sat_image_crop_scaled(\n    self.map_im,\n    self.raster_size,\n    sat_translation,\n    yaw=-ego_yaw,\n    pixel_size=self.pixel_size,\n    sat_pixel_scale=self.map_pixel_scale,\n    interpolation=self.interpolation,\n)\n</code></pre>",
      "rawMarkdown": "I am trying to do what is done by the SatelliteRasterizer, but more directly without centering on EGO and all the other stuff going on here. Basically I am trying to figure out how can make this simpler or even make it work outside of the library at all. \n\n```\nworld_to_ecef = np.asarray(\n\t\t[\n\t\t\t[8.46617444e-01, 3.23463078e-01, -4.22623402e-01, -2.69876744e06],\n\t\t\t[-5.32201938e-01, 5.14559352e-01, -6.72301845e-01, -4.29315158e06],\n\t\t\t[-3.05311332e-16, 7.94103464e-01, 6.07782600e-01, 3.85516476e06],\n\t\t\t[0.00000000e00, 0.00000000e00, 0.00000000e00, 1.00000000e00],\n\t\t],\n\t\tdtype=np.float64,\n\t)\n\n\necef_to_aerial = np.asarray(\n\t\t[\n\t\t\t[-0.717416495, -1.14606296, -1.62854453, -572869.824],\n\t\t\t[1.80065798, -1.08914046, -0.0287877303, 300171.963],\n\t\t\t[0.0, 0.0, 0.0, 0.0],\n\t\t\t[0.0, 0.0, 0.0, 1.0],\n\t\t],\n\t\tdtype=np.float64,\n\t)\n\nworld_to_aerial = np.matmul(ecef_to_aerial, world_to_ecef)\nworld_to_image_space = world_to_image_pixels_matrix(\n\tself.raster_size,\n\tself.pixel_size,\n\tego_translation_m=ego_translation,\n\tego_yaw_rad=ego_yaw,\n\tego_center_in_image_ratio=self.ego_center,\n)\n\n# get the center of the images in meters using the inverse of the matrix,\n# Transform it to satellite coordinates (consider also z here)\ncenter_pixel = np.asarray(self.raster_size) * (0.5, 0.5)\nworld_translation = transform_point(center_pixel, np.linalg.inv(world_to_image_space))\nsat_translation = transform_point(np.append(world_translation, ego_translation[2]), self.world_to_aerial)\n\n# Note 1: there is a negation here, unknown why this is necessary.\n# My best guess is because Y is flipped, maybe we can do this more elegantly.\nsat_im = get_sat_image_crop_scaled(\n\tself.map_im,\n\tself.raster_size,\n\tsat_translation,\n\tyaw=-ego_yaw,\n\tpixel_size=self.pixel_size,\n\tsat_pixel_scale=self.map_pixel_scale,\n\tinterpolation=self.interpolation,\n)\n```",
      "votes": null
    },
    {
      "id": "1014201",
      "postDate": "09/17/2020 09:05:58",
      "content": "<p>If you use <code>world_to_ecef</code> and <code>ecef_to_aerial</code> you can convert boxes world XYZ coordinates into the aerial pixel space. The issue is that the aerial map is huge, so you will still need to crop it somehow. Technically, you could stop here and plot those points on the full aerial map. This should already tell you if the process is correct.</p>",
      "rawMarkdown": "If you use `world_to_ecef` and `ecef_to_aerial` you can convert boxes world XYZ coordinates into the aerial pixel space. The issue is that the aerial map is huge, so you will still need to crop it somehow. Technically, you could stop here and plot those points on the full aerial map. This should already tell you if the process is correct.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1008304,
      "author_name": "n3n77i",
      "author_url": "",
      "post_date": "09/13/2020 01:29:32",
      "content": "<p>It should be in gps Lat Long * 1e5 (from 1e7 with ~1cm integer) then minus a reference location. I'm not sure of the 0,0 gps value though</p>\n<p>Add:  [37°25'45.6\"N, 122°09'15.7\"W] in Palo Alto (California, USA). from coords_systems.md</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1009295,
      "author_name": "lucabergamini",
      "author_url": "",
      "post_date": "09/13/2020 20:28:09",
      "content": "<p>Hi <a href=\"https://www.kaggle.com/maxjon\" target=\"_blank\">@maxjon</a> can you give me more details on what you're trying to achieve? Are you trying to map coordinates from <code>world</code> reference system to Lat-Lng?</p>",
      "votes": null,
      "replies": [
        {
          "id": 1009700,
          "author_name": "maxjon",
          "author_url": "",
          "post_date": "09/14/2020 07:19:36",
          "content": "<p>Hey <a href=\"https://www.kaggle.com/lucabergamini\" target=\"_blank\">@lucabergamini</a>, this is exactly what I'm trying to do. I want to the \"raw\" coordinates from agent centroids to the satellite map. for example: </p>\n<pre><code>agents = get_agent_dictionary()\n\nmap = cv2.imread(path_to_map_image)\n\n# use unkown coord_to_map_scale, and refence_location_offsets to scale the map \n# to world reference system\nwidth = agent.extent_width * coord_to_map_scale \nheight = agent.extent_height * coord_to_map_scale \ncenter_x = (agent.centroid_x + refence_location_offset_x) * coord_to_map_scale \ncenter_y = (agent.centroid_y + refence_location_offset_y) * coord_to_map_scale \n\n# slice the satellite map\nmap_crop = crop_map(map, center_x, center_y, height=400, width=400)\n\n# draw the agent on the map without yaw\nagent_map = draw_agent(map_crop, center_x, center_y, width, height)\n\nplt.show(agent_map)\nplt.show()\n</code></pre>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1010119,
          "author_name": "lucabergamini",
          "author_url": "",
          "post_date": "09/14/2020 14:15:30",
          "content": "<p>I'm still not 100% sure we're saying the same thing. If you're using our satellite map (in l5kit) you don't need LAT-LNG coords but ECEF (XYZ earth centred). From your snippet I think that's the case, can you confirm it? Because in that case you're trying to do something similar to what our <a href=\"https://github.com/lyft/l5kit/blob/master/l5kit/l5kit/rasterization/satellite_rasterizer.py\" target=\"_blank\">satellite rasterizer</a> already does </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1010205,
          "author_name": "maxjon",
          "author_url": "",
          "post_date": "09/14/2020 15:21:16",
          "content": "<p>I am trying to do what is done by the SatelliteRasterizer, but more directly without centering on EGO and all the other stuff going on here. Basically I am trying to figure out how can make this simpler or even make it work outside of the library at all. </p>\n<pre><code>world_to_ecef = np.asarray(\n        [\n            [8.46617444e-01, 3.23463078e-01, -4.22623402e-01, -2.69876744e06],\n            [-5.32201938e-01, 5.14559352e-01, -6.72301845e-01, -4.29315158e06],\n            [-3.05311332e-16, 7.94103464e-01, 6.07782600e-01, 3.85516476e06],\n            [0.00000000e00, 0.00000000e00, 0.00000000e00, 1.00000000e00],\n        ],\n        dtype=np.float64,\n    )\n\n\necef_to_aerial = np.asarray(\n        [\n            [-0.717416495, -1.14606296, -1.62854453, -572869.824],\n            [1.80065798, -1.08914046, -0.0287877303, 300171.963],\n            [0.0, 0.0, 0.0, 0.0],\n            [0.0, 0.0, 0.0, 1.0],\n        ],\n        dtype=np.float64,\n    )\n\nworld_to_aerial = np.matmul(ecef_to_aerial, world_to_ecef)\nworld_to_image_space = world_to_image_pixels_matrix(\n    self.raster_size,\n    self.pixel_size,\n    ego_translation_m=ego_translation,\n    ego_yaw_rad=ego_yaw,\n    ego_center_in_image_ratio=self.ego_center,\n)\n\n# get the center of the images in meters using the inverse of the matrix,\n# Transform it to satellite coordinates (consider also z here)\ncenter_pixel = np.asarray(self.raster_size) * (0.5, 0.5)\nworld_translation = transform_point(center_pixel, np.linalg.inv(world_to_image_space))\nsat_translation = transform_point(np.append(world_translation, ego_translation[2]), self.world_to_aerial)\n\n# Note 1: there is a negation here, unknown why this is necessary.\n# My best guess is because Y is flipped, maybe we can do this more elegantly.\nsat_im = get_sat_image_crop_scaled(\n    self.map_im,\n    self.raster_size,\n    sat_translation,\n    yaw=-ego_yaw,\n    pixel_size=self.pixel_size,\n    sat_pixel_scale=self.map_pixel_scale,\n    interpolation=self.interpolation,\n)\n</code></pre>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1014201,
          "author_name": "lucabergamini",
          "author_url": "",
          "post_date": "09/17/2020 09:05:58",
          "content": "<p>If you use <code>world_to_ecef</code> and <code>ecef_to_aerial</code> you can convert boxes world XYZ coordinates into the aerial pixel space. The issue is that the aerial map is huge, so you will still need to crop it somehow. Technically, you could stop here and plot those points on the full aerial map. This should already tell you if the process is correct.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1007885": "I thought it would be easy to grab the centroids with their respective extents and then map them to the satellite map, however this has proven a lot more difficult than I could imagine. Has anyone been able to find a direct mapping between the agent coordinates and the maps?",
    "1008304": "It should be in gps Lat Long * 1e5 (from 1e7 with ~1cm integer) then minus a reference location. I'm not sure of the 0,0 gps value though\n\nAdd:  [37°25'45.6\"N, 122°09'15.7\"W] in Palo Alto (California, USA). from coords_systems.md",
    "1009295": "Hi @maxjon can you give me more details on what you're trying to achieve? Are you trying to map coordinates from `world` reference system to Lat-Lng?",
    "1009700": "Hey @lucabergamini, this is exactly what I'm trying to do. I want to the \"raw\" coordinates from agent centroids to the satellite map. for example: \n```\nagents = get_agent_dictionary()\n\nmap = cv2.imread(path_to_map_image)\n\n# use unkown coord_to_map_scale, and refence_location_offsets to scale the map \n# to world reference system\nwidth = agent.extent_width * coord_to_map_scale \nheight = agent.extent_height * coord_to_map_scale \ncenter_x = (agent.centroid_x + refence_location_offset_x) * coord_to_map_scale \ncenter_y = (agent.centroid_y + refence_location_offset_y) * coord_to_map_scale \n\n# slice the satellite map\nmap_crop = crop_map(map, center_x, center_y, height=400, width=400)\n\n# draw the agent on the map without yaw\nagent_map = draw_agent(map_crop, center_x, center_y, width, height)\n\nplt.show(agent_map)\nplt.show()\n\n```",
    "1010119": "I'm still not 100% sure we're saying the same thing. If you're using our satellite map (in l5kit) you don't need LAT-LNG coords but ECEF (XYZ earth centred). From your snippet I think that's the case, can you confirm it? Because in that case you're trying to do something similar to what our [satellite rasterizer](https://github.com/lyft/l5kit/blob/master/l5kit/l5kit/rasterization/satellite_rasterizer.py) already does",
    "1010205": "I am trying to do what is done by the SatelliteRasterizer, but more directly without centering on EGO and all the other stuff going on here. Basically I am trying to figure out how can make this simpler or even make it work outside of the library at all. \n\n```\nworld_to_ecef = np.asarray(\n\t\t[\n\t\t\t[8.46617444e-01, 3.23463078e-01, -4.22623402e-01, -2.69876744e06],\n\t\t\t[-5.32201938e-01, 5.14559352e-01, -6.72301845e-01, -4.29315158e06],\n\t\t\t[-3.05311332e-16, 7.94103464e-01, 6.07782600e-01, 3.85516476e06],\n\t\t\t[0.00000000e00, 0.00000000e00, 0.00000000e00, 1.00000000e00],\n\t\t],\n\t\tdtype=np.float64,\n\t)\n\n\necef_to_aerial = np.asarray(\n\t\t[\n\t\t\t[-0.717416495, -1.14606296, -1.62854453, -572869.824],\n\t\t\t[1.80065798, -1.08914046, -0.0287877303, 300171.963],\n\t\t\t[0.0, 0.0, 0.0, 0.0],\n\t\t\t[0.0, 0.0, 0.0, 1.0],\n\t\t],\n\t\tdtype=np.float64,\n\t)\n\nworld_to_aerial = np.matmul(ecef_to_aerial, world_to_ecef)\nworld_to_image_space = world_to_image_pixels_matrix(\n\tself.raster_size,\n\tself.pixel_size,\n\tego_translation_m=ego_translation,\n\tego_yaw_rad=ego_yaw,\n\tego_center_in_image_ratio=self.ego_center,\n)\n\n# get the center of the images in meters using the inverse of the matrix,\n# Transform it to satellite coordinates (consider also z here)\ncenter_pixel = np.asarray(self.raster_size) * (0.5, 0.5)\nworld_translation = transform_point(center_pixel, np.linalg.inv(world_to_image_space))\nsat_translation = transform_point(np.append(world_translation, ego_translation[2]), self.world_to_aerial)\n\n# Note 1: there is a negation here, unknown why this is necessary.\n# My best guess is because Y is flipped, maybe we can do this more elegantly.\nsat_im = get_sat_image_crop_scaled(\n\tself.map_im,\n\tself.raster_size,\n\tsat_translation,\n\tyaw=-ego_yaw,\n\tpixel_size=self.pixel_size,\n\tsat_pixel_scale=self.map_pixel_scale,\n\tinterpolation=self.interpolation,\n)\n```",
    "1014201": "If you use `world_to_ecef` and `ecef_to_aerial` you can convert boxes world XYZ coordinates into the aerial pixel space. The issue is that the aerial map is huge, so you will still need to crop it somehow. Technically, you could stop here and plot those points on the full aerial map. This should already tell you if the process is correct."
  },
  "source": "meta"
}