Select to view content in your preferred language

Shape in Geojson

9717
31
09-08-2022 08:32 AM
torkildv
Emerging Contributor

Hi,

maybe a stupid question, but: quoting https://doc.arcgis.com/en/power-bi/get-started/prepare-your-data.htm

"EsriJSON—If your data contains location information formatted using EsriJSON, it should appear in a Shape column. Drag the Shape field value into the Location field well to draw EsriJSON locations on the map. EsriJSON supports points, lines, and polygons." (my highlight)

Anyone who knows how to ma

0 Kudos
31 Replies
RudolfdeMunnik
Occasional Contributor

@TaylorWillow  and @TimMinter I hope i can assist with the following explanation that worked for me using the REST API to generate a EsriJSON format that works in the location fieldwell. Please find the steps below:

Step 1: Get the REST Endpoint: https://services1.arcgis.com/bKDOijB8sneN5004/arcgis/rest/services/AGRIC_GIS_DATA/FeatureServer/1/qu...

  • OBJECTIDS > 0, ALL FIELDS, FORMAT JSON
  • PUBLIC SHARED

Step 2: Add "Web" data to Power BI using the Get Data tool

Copy the REST Endpoint into the URL space

RudolfdeMunnik_0-1678225049305.png

Step 3: Open Power Query

Power Query opens, scroll to the end of the record.

RudolfdeMunnik_1-1678225290044.png

Step 4: Expand features

First expand the "features" column by clicking on the "expand" icon

2023-03-07 23_57_23-ARCGIS_POWER_AUTOMATE_01 - Power Query Editor.png

Select "Expand to New Rows"

2023-03-08 00_06_49-ARCGIS_POWER_AUTOMATE_01 - Power Query Editor.png

Step 5: Expand features

2023-03-08 00_08_29-ARCGIS_POWER_AUTOMATE_01 - Power Query Editor.png

Un-tick "Use original....."

Step 6: Expand attributes

2023-03-08 00_10_16-ARCGIS_POWER_AUTOMATE_01 - Power Query Editor.png

 Un-tick "Use original....."

After expanding - scroll to the last "geometry column"

Step 7: Add custom column to format EsriJSON geometry and add Spatial reference to each record

The critical step is to add a "Custom" column from the Power Query "Add Column" main menu

2023-03-08 00_15_07-ARCGIS_POWER_AUTOMATE_01 - Power Query Editor.png

2023-03-08 00_17_14-ARCGIS_POWER_AUTOMATE_01 - Power Query Editor.png

  • Provide a column name e.g. "shape"
  • Add the following syntax after the "=" sign Text.Replace(Text.FromBinary(Json.FromValue([geometry])), "]]]" ,"]]], ""spatialReference"":{""wkid"":102100,""latestWkid"":3857}")
  • Text.FromBinary will create a single string from the nested rings
  • Text.Replace will add the Spatial Reference after each records - Note the correct Spatial Reference

2023-03-08 00_23_25-ARCGIS_POWER_AUTOMATE_01 - Power Query Editor.png

Apply and Close the Power Query changes

Test:

  • Add the ArcGIS for Power BI visualizer
  • Move the "shape" column to the Location fieldwell
  • Check if geometries are drawn correctly

2023-03-08 00_28_38-ARCGIS_POWER_AUTOMATE_01 - Power BI Desktop.png

Step 8 (optional): Add geometry length field to view large geometries over 32 000 characters

You can add an additional "Custom Column" to count the Length of the geometry characters. This is to see which records exceed the 32 000 character limit of Power BI. You can then identify missing geometries.

2023-03-08 00_33_11-Custom Column.png

Geometries under 32 000 characters will have the "Spatial Reference" at the end - see sample below

2023-03-08 00_34_26-ARCGIS_POWER_AUTOMATE_01 - Power BI Desktop.png

Geometries above 32 000 characters will not end correctly and therefore not appear on the map.

2023-03-08 00_37_16-ARCGIS_POWER_AUTOMATE_01 - Power BI Desktop.png

Workarounds to prevent this issue:

  • Create a "Power BI" feature services where you "Generalize" the geometries in Pro and publish
  • Look for multipart polygons and convert to single part, then generalize

Hope this helps.

Acknowledgements to Derck Vonck @DerckVonck, from Esri South Africa,  who assisted me with custom column "formulas". Thanks Derck

NasreddineD
Emerging Contributor

Hi @RudolfdeMunnik ,

I was wondering if there is a way to create custom polygons (not existing boundaries like country, or region...) And add it to Power Bi? I managed to do it using the "join layer" in power bi, the issue is that is not connected to my power bi data... What I mean is I can only visualise the polygons and clic on it. But I would like to add colors on it depending on a status column I have in my data...

Here is an example of someone having the same issue.

https://community.esri.com/t5/arcgis-for-power-bi-questions/using-custom-polygon-locations-from-laye...

 

0 Kudos
RudolfdeMunnik
Occasional Contributor

Hi @NasreddineD,

Please find the links to my proposed solutions as posted previously.

- The methods does not use the existing/standard boundaries

- The methods does not use "join layer"

- It uses the true geometry of your custom geometries linked to Power BI visualisers

- You can change symbology/styling based on a field for color or size

1. Using Power Automate procedure - Basic and Advanced Method (from @SeanKMcGinnis )

https://community.esri.com/t5/arcgis-for-power-bi-questions/shape-in-geojson/m-p/1247011/highlight/t...

2. Using REST API (without Power Automate)

https://community.esri.com/t5/arcgis-for-power-bi-questions/shape-in-geojson/m-p/1265256/highlight/t...

Hope this helps.

0 Kudos
NasreddineD
Emerging Contributor

Hi @RudolfdeMunnik ,

I am trying the REST API solution, but I don't understand the step 1.

Should I take the link you shared? It doesn't work or something happened when you copied pasted it.

Or should I find my own link? If yes, where and how?

0 Kudos
RudolfdeMunnik
Occasional Contributor

@NasreddineD   Apologies for replying only now. For some reason the URL that i copied in Step 1 did not copy correctly. So i created a screenshot of the URL. See below.

RudolfdeMunnik_0-1682084419803.png

I hope this helps

TimMinter
Frequent Contributor

@RudolfdeMunnik Nice!  One quick thought on dealing with the 32k character constraint is that the REST service request can specify an appropriately lower precision.  So, going from 7 in your example to a lower precision that is appropriate for use in Power BI may be some good trickery.  I'm thinking that Power BI doesn't know or care about topology and is happiest with cartoon geometries anyway, so it kind of doesn't matter as long as the area looks ok to the eye.

0 Kudos
RudolfdeMunnik
Occasional Contributor

@TimMinterThank you for the feedback, Yes, I have tested the precision in the REST request. If you are using DD with 6 decimals it helps to "generalize" the polys, but if you use Web Mercator it does not really help because the coordinate numbers are big, even if you remove all decimals you still have 1m accuracy - maybe i am missing something with the precision parameters?

TimMinter
Frequent Contributor

@RudolfdeMunnik I just got a chance to follow your lead and got it to work with our data.  It looks to me like you've tested it thoroughly.  I'm forcing WGS84 decimal degrees (WKID 4326) in my REST request like this:

https://services1.arcgis.com/bKDOijB8sneN5004/arcgis/rest/services/AGRIC_GIS_DATA/FeatureServer/1/query?where=1=1&outFields=*&geometryPrecision=4&outSR=4326&f=json

 Then, I adjust the "Shape" custom field code like this:

Text.Replace(Text.FromBinary(Json.FromValue([geometry])), "]]]" ,"]]], ""spatialReference"":{""wkid"":4326,""latestWkid"":4326}")

Then, finally, I add your optional ShpTxtLen so I can see how things worked out and tweak the coordinate precision if needed.

Thanks again!

tim

PaddyFurlong
New Contributor

This is brilliant, you are an absolute lifesaver. 

I can also confirm that the procedure works for an Esri JSON file exported from ArcGIS Pro using the "Features to JSON" tool. Once you have exported the json file you can then import it into Power BI as a JSON source. Then continue from step 3 above.

TimMinter
Frequent Contributor

@PaddyFurlong - Nice!  Maybe we can string that up with a little ModelBuilder thing to generalize the geometry for detailed polygons, export to JSON, then use the resulting graphic art in Power BI.  Ideally, the REST service would have a generalize capability built in, but it seems a bit more complex than that.