cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
BBIUser Member
Member

Shape Map in Power BI: Can I use Shapefile (TopoJSON) file as my data source?

Hi,

 

I am aware how the maps are built using shape maps but my question here is -

 

For example: I use a Shapefile to create maps and I have converted that Shapefile to TopoJSON file using mapshaper.org, Is it possible to use this TopoJSON file as a source in Power BI Desktop? Is this possible in Power BI? Is it the correct way to do it?

 

Why do we need a source file (such as Excel, CSV, SQL, etc..) on top of the TopoJSON file since the TopoJSON file itself has data in it?

 

Please apologize me if the questions are not sensible, I am trying to understand how this process works?

 

Thanks in advance.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
deldersveld
Advisor

Re: Shape Map in Power BI: Can I use Shapefile (TopoJSON) file as my data source?

The TopoJSON used for the Shape Map visual is not part of the data model. It's unique to the visual and meant to map data in the data model to shapes on the map. *Why* the product team chose to do it that way is not something I can answer. 

 

You can grab the data from the TopoJSON file using the JSON connector in Power BI Desktop, then expand through a series of columns to get the data. I have a sample M script from another post where I answered a similar question: 

let
    Source = Json.Document(File.Contents("C:\[...]\icitw_wgs84.json")),
    objects = Source[objects],
    icitw_wgs1 = objects[icitw_wgs84],
    geometries = icitw_wgs1[geometries],
    #"Converted to Table" = Table.FromList(geometries, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"arcs", "type", "properties"}, {"Column1.arcs", "Column1.type", "Column1.properties"}),
    #"Expanded Column1.properties" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1.properties", {"GEO_ID", "CREATE_ID", "NAME", "SCODE_NAME", "LCODE_NAME", "TYPE_DESC", "TYPE_CODE", "OBJECTID", "SHAPE_AREA", "SHAPE_LEN"}, {"Column1.properties.GEO_ID", "Column1.properties.CREATE_ID", "Column1.properties.NAME", "Column1.properties.SCODE_NAME", "Column1.properties.LCODE_NAME", "Column1.properties.TYPE_DESC", "Column1.properties.TYPE_CODE", "Column1.properties.OBJECTID", "Column1.properties.SHAPE_AREA", "Column1.properties.SHAPE_LEN"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Column1.properties",{"Column1.arcs", "Column1.type", "Column1.properties.GEO_ID", "Column1.properties.CREATE_ID"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Column1.properties.NAME", "Ward Name"}, {"Column1.properties.SCODE_NAME", "SCODE NAME"}, {"Column1.properties.LCODE_NAME", "LCODE NAME"}, {"Column1.properties.TYPE_DESC", "TYPE CODE"}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Renamed Columns",{"TYPE CODE", "Column1.properties.TYPE_CODE", "Column1.properties.SHAPE_AREA", "Column1.properties.SHAPE_LEN"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns1",{{"Column1.properties.OBJECTID", "Object ID"}})
in
    #"Renamed Columns1 

 

2 REPLIES 2
deldersveld
Advisor

Re: Shape Map in Power BI: Can I use Shapefile (TopoJSON) file as my data source?

The TopoJSON used for the Shape Map visual is not part of the data model. It's unique to the visual and meant to map data in the data model to shapes on the map. *Why* the product team chose to do it that way is not something I can answer. 

 

You can grab the data from the TopoJSON file using the JSON connector in Power BI Desktop, then expand through a series of columns to get the data. I have a sample M script from another post where I answered a similar question: 

let
    Source = Json.Document(File.Contents("C:\[...]\icitw_wgs84.json")),
    objects = Source[objects],
    icitw_wgs1 = objects[icitw_wgs84],
    geometries = icitw_wgs1[geometries],
    #"Converted to Table" = Table.FromList(geometries, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"arcs", "type", "properties"}, {"Column1.arcs", "Column1.type", "Column1.properties"}),
    #"Expanded Column1.properties" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1.properties", {"GEO_ID", "CREATE_ID", "NAME", "SCODE_NAME", "LCODE_NAME", "TYPE_DESC", "TYPE_CODE", "OBJECTID", "SHAPE_AREA", "SHAPE_LEN"}, {"Column1.properties.GEO_ID", "Column1.properties.CREATE_ID", "Column1.properties.NAME", "Column1.properties.SCODE_NAME", "Column1.properties.LCODE_NAME", "Column1.properties.TYPE_DESC", "Column1.properties.TYPE_CODE", "Column1.properties.OBJECTID", "Column1.properties.SHAPE_AREA", "Column1.properties.SHAPE_LEN"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Column1.properties",{"Column1.arcs", "Column1.type", "Column1.properties.GEO_ID", "Column1.properties.CREATE_ID"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Column1.properties.NAME", "Ward Name"}, {"Column1.properties.SCODE_NAME", "SCODE NAME"}, {"Column1.properties.LCODE_NAME", "LCODE NAME"}, {"Column1.properties.TYPE_DESC", "TYPE CODE"}}),
    #"Removed Columns1" = Table.RemoveColumns(#"Renamed Columns",{"TYPE CODE", "Column1.properties.TYPE_CODE", "Column1.properties.SHAPE_AREA", "Column1.properties.SHAPE_LEN"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns1",{{"Column1.properties.OBJECTID", "Object ID"}})
in
    #"Renamed Columns1 

 

BBIUser Member
Member

Re: Shape Map in Power BI: Can I use Shapefile (TopoJSON) file as my data source?

Thank You. Much appreciate your response.

Helpful resources

Announcements
Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Power BI Helps Homeless and Trouble Youth

Power BI Helps Homeless and Trouble Youth

We spoke with Power BI Super User, Greg Deckler, about his charity work

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Kudoed Authors
Users Online
Currently online: 272 members 3,220 guests
Please welcome our newest community members: