web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Powerapps Geospatial M...
Power Apps
Answered

Powerapps Geospatial Map: creating polygon shapes from collection

(2) ShareShare
ReportReport
Posted on by 3
Hello Teams, thanks for reading my question.
 
I have a collection BAHRO in my canvas app:
 
Table(
   
   
 {
        Label: "Shape 1",
        Latitude: -6.8897768493196,
        Longitude: 107.57331505790732,
        Point: 0,
        RowNo: 1
    },
    {
        Label: "Shape 1",
        Latitude: -6.888393037560325,
        Longitude: 107.57359474002298,
        Point: 1,
        RowNo: 2
    },
    {
        Label: "Shape 1",
        Latitude: -6.8885049980318875,
        Longitude: 107.57422175787919,
        Point: 2,
        RowNo: 3
    },
    {
        Label: "Shape 1",
        Latitude: -6.88991567948157,
        Longitude: 107.57392403417323,
        Point: 3,
        RowNo: 4
    }
)
 
Since Map control only accepts JSON for shape items, I create a collection from my BAHRO and then use JSON function with a button.
Here is the code:
ClearCollect(ShapeNew,
    ForAll(BAHRO,
        {type: "Feature",
        properties: "",
        geometry:
            {coordinates:Longitude &", "& Latitude}
        }
    )
);
ClearCollect(GrupByLabel,GroupBy(ShapeNew,type,GrupType));
JSON(GrupByLabel,JSONFormat.IndentFour)
 
and this is the output:
  1. [
  2.     {
  3.         "GrupType": [
  4.             {
  5.                 "geometry": {
  6.                     "coordinates": "107.57331506, -6.88977685"
  7.                 },
  8.                 "properties": ""
  9.             },
  10.             {
  11.                 "geometry": {
  12.                     "coordinates": "107.57359474, -6.88839304"
  13.                 },
  14.                 "properties": ""
  15.             },
  16.             {
  17.                 "geometry": {
  18.                     "coordinates": "107.57422176, -6.888505"
  19.                 },
  20.                 "properties": ""
  21.             },
  22.             {
  23.                 "geometry": {
  24.                     "coordinates": "107.57392403, -6.88991568"
  25.                 },
  26.                 "properties": ""
  27.             },
  28.             {
  29.                 "geometry": {
  30.                     "coordinates": "107.57430903, -6.88858315"
  31.                 },
  32.                 "properties": ""
  33.             },
  34.             {
  35.                 "geometry": {
  36.                     "coordinates": "107.57435865, -6.88839809"
  37.                 },
  38.                 "properties": ""
  39.             },
  40.             {
  41.                 "geometry": {
  42.                     "coordinates": "107.57452964, -6.88844402"
  43.                 },
  44.                 "properties": ""
  45.             },
  46.             {
  47.                 "geometry": {
  48.                     "coordinates": "107.57448069, -6.88862975"
  49.                 },
  50.                 "properties": ""
  51.             },
  52.             {
  53.                 "geometry": {
  54.                     "coordinates": "107.5744264, -6.8902072"
  55.                 },
  56.                 "properties": ""
  57.             },
  58.             {
  59.                 "geometry": {
  60.                     "coordinates": "107.57455745, -6.89023212"
  61.                 },
  62.                 "properties": ""
  63.             },
  64.             {
  65.                 "geometry": {
  66.                     "coordinates": "107.57452215, -6.89038169"
  67.                 },
  68.                 "properties": ""
  69.             },
  70.             {
  71.                 "geometry": {
  72.                     "coordinates": "107.57475267, -6.89042655"
  73.                 },
  74.                 "properties": ""
  75.             },
  76.             {
  77.                 "geometry": {
  78.                     "coordinates": "107.57469942, -6.89068251"
  79.                 },
  80.                 "properties": ""
  81.             },
  82.             {
  83.                 "geometry": {
  84.                     "coordinates": "107.57453448, -6.89064971"
  85.                 },
  86.                 "properties": ""
  87.             },
  88.             {
  89.                 "geometry": {
  90.                     "coordinates": "107.57456264, -6.89052032"
  91.                 },
  92.                 "properties": ""
  93.             },
  94.             {
  95.                 "geometry": {
  96.                     "coordinates": "107.57437141, -6.89048285"
  97.                 },
  98.                 "properties": ""
  99.             }
  100.         ],
  101.         "type": "Feature"
  102.     }
  103. ]
 
I need the output to be like this:
 
{
      "type": "Feature",
      "properties": {},
      "geometry": {
        "coordinates": [
          [
            [
              107.52852120618252,
              -6.89184921745435
            ],
            [
              107.52852120618252,
              -6.892935477601725
            ],
            [
              107.52959909897777,
              -6.892935477601725
            ],
            [
              107.52959909897777,
              -6.89184921745435
            ],
            [
              107.52852120618252,
              -6.89184921745435
            ]
          ]
        ],
        "type": "Polygon"
      }
    }
 
I have been trying figuring out where I went wrong as well as searching on forums for similar topics but still no luck.
Any idea and tips will be appreciated.
Thanks
 
Categories:
I have the same question (0)
  • Verified answer
    Daniel Bocklandt Profile Picture
    5,117 Super User 2025 Season 2 on at
     
    So I think what you want to use is this: 
    ClearCollect(
        ShapeNew,
            {
                type:"Feature",
                properties:"",
                geometry:{
                    coordinates:
                        
                        ForAll(BAHRO, {long:ThisRecord.Longitude, lat:ThisRecord.Latitude}
                        )
                        
                    ,
                    type:"Polygone"
                }
            });
    ClearCollect(GrupByLabel,GroupBy(ShapeNew,type,GrupType));
    Set(varJSON,JSON(GrupByLabel,JSONFormat.Compact))
    If you don't  need to differentiate between long and Lat with columns this should work as well: 
     
    ClearCollect(
        ShapeNew,
            {
                type:"Feature",
                properties:"",
                geometry:{
                    coordinates:
                        
                        ForAll(BAHRO, ThisRecord.Longitude &", "& ThisRecord.Latitude)
                        
                    ,
                    type:"Polygone"
                }
            });
    ClearCollect(GrupByLabel,GroupBy(ShapeNew,type,GrupType));
    Set(varJSON,JSON(GrupByLabel,JSONFormat.Compact))
     

    If this solved your problem, please mark it as Solved to help others find the solution faster.
    If you found it helpful, consider giving it a Like to support each other in this community!

    Thanks, and happy building!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard