Loading...

Getting geospatial insights from big data using SynapseML

Getting geospatial insights from big data using SynapseML

Any commercial or government organization, big or small, collects and stores a lot of data and, in general, across multiple systems. Getting insights and doing Machine Learning across all these different and distributed datasets can be a challenge. For example, an insurance company that insures houses would like to understand if an address is located in a flood zone to calculate the risks involved and estimate the risk. These types of problems need an analytics system that can combine, transform, and enrich the data to give needed  insights and useful results.

 

Getting geospatial insights from big data

Azure Synapse is a limitless analytics service that combines Enterprise data warehousing and Big Data analytics. It gives you the freedom to query data on your terms. By combining Azure Maps geospatial capabilities with Azure Synapse and SynapseML, you can enrich your data with location-aware capabilities. SynapseML geospatial services can geocode addresses, reverse-geocode coordinates, and also check if a coordinate is inside a polygon. The geocoder is very tolerant of typos and incomplete addresses. It will also handle everything from exact street addresses or street intersections and higher-level geographies such as city centers, counties, states, etc.

 

How to visualize customer addresses on a floodplain?

Before you can start using SynapseML to geocode, you need to obtain a Azure Maps key and set it in your environment. Learn here how to get a Azure Maps key.

 

 

from synapse.ml.cognitive import * from synapse.ml.geospatial import * # An Azure Maps account key azureMapsKey = os.environ["AZURE_MAPS_KEY"]

 

 

 

Load address data

King County (WA) publishes floodplain and tax parcel data. We can use the addresses in the tax parcel data and the Azure Maps geocoder to calculate coordinates. Then, using these coordinates and the floodplain data, we can enrich our dataset with a flag indicating whether the house is in a flood zone or not. The following data has been sourced from King County's Open data portal.

 

 

data = spark.read\ .option("header", "true")\ .csv("wasbs://[email protected]/maps/KingCountyAddress.csv") # Visualize incoming schema print("Schema:") data.printSchema() # Choose a subset of the data for this example subset_data = data.limit(50) display(subset_data)

 

 

 

Wire-up the Address Geocoder

We will use the address geocoder to enrich the dataset with location coordinates of the addresses.

 

 

from pyspark.sql.functions import col from synapse.ml.cognitive import * from synapse.ml.stages import FixedMiniBatchTransformer, FlattenBatch from synapse.ml.geospatial import * def extract_location_fields(df): # Use this function to select only lat/lon columns into the dataframe return df.select(col("*"), col("output.response.results").getItem(0).getField("position").getField("lat").alias("Latitude"), col("output.response.results").getItem(0).getField("position").getField("lon").alias("Longitude") ).drop("output") # Azure Maps geocoder to enhance the dataframe with location data geocoder = (AddressGeocoder() .setSubscriptionKey(azureMapsKey) .setAddressCol("FullAddress") .setOutputCol("output")) # Set up a fixed mini batch transformer to geocode addresses batched_dataframe = geocoder.transform(FixedMiniBatchTransformer().setBatchSize(10).transform(subset_data.coalesce(1))) geocoded_addresses = extract_location_fields(FlattenBatch().transform(batched_dataframe)) # Display the results display(geocoded_addresses)

 

 

 

Setup Check Point In Polygon

Now that we have geocoded the addresses, we can then use the CheckPointInPolygon function to check if a property is in a flood zone or not.

 

 

def extract_point_in_polygon_result_fields(df): # Use this function to select only lat/lon columns into the dataframe return df.select(col("*"), col("output.result.pointInPolygons").alias("In Polygon"), col("output.result.intersectingGeometries").alias("Intersecting Polygons") ).drop("output") check_point_in_polygon = (CheckPointInPolygon() .setSubscriptionKey(azureMapsKey) .setGeography(atlas_geo_prefix) .setUserDataIdentifier(user_data_id) .setLatitudeCol("Latitude") .setLongitudeCol("Longitude") .setOutputCol("output")) flood_plain_addresses = extract_point_in_polygon_result_fields(check_point_in_polygon.transform(geocoded_addresses)) # Display the results display(flood_plain_addresses)

 

 

 

Thank you for checking out our blog and you can read the complete tutorial on the SynapseML GitHub page.

Published on:

Learn more
Azure Maps articles
Azure Maps articles

Azure Maps articles

Share post:

Related posts

Introducing the Data-Bound Reference Layer in Azure Maps Visual for Power BI

Imagine managing a nationwide sales team and needing to understand how your sales align with factors like population density, competitor locat...

1 year ago

Enhance Azure Maps with Overture Maps Data using PMTiles!

  Supercharge Azure Maps with Overture Maps Data using PMTiles! We’ve got some exciting news. Azure Maps now supports PMTiles! This me...

1 year ago

Where do I go if I have questions about Azure Maps?

As you might expect, just looking around on your own, or asking Co-pilot, you can find comprehensive help like Samples.AzureMaps.com, wit...

1 year ago

Tailor your Reference Layers in Azure Maps Visual for Power BI

  We’re excited to share the latest enhancements to the Azure Maps visual in Power BI, designed to make your data visualization even mor...

2 years ago

Enhancing Logistics with Azure Maps and NVIDIA cuOpt for Multi-Itinerary Optimization

The logistics industry is always finding ways to optimize vehicle routing to enhance efficiency. The Vehicle Routing Problem (VRP) and Pickup ...

2 years ago

Introducing the Unified Azure Maps Experience

Microsoft has recently announced the unification of Bing Maps for Enterprise (BME) with Azure Maps, marking a remarkable advancement in their ...

2 years ago

Power BI Azure Maps Visual: Enhanced Reference Layer & Embedded Support

The Power BI Azure Maps visual has received a major update which includes an expansion of the reference layer and the addition of Power BI Emb...

2 years ago

Enhance your indoor maps with real-time map feature styling

The ability to dynamically update and visualize the state of rooms or areas within a building is critical to understanding the status of any b...

2 years ago

Dynamic Clustering Aggregation with Custom Styling in Bubble Layer

The Power BI Azure Maps visual allows you to create stunning geospatial visualizations with your data. Today, we are excited to announce a new...

2 years ago

HO HO HO Two Point OH!

You might notice some big changes have come to the North Pole experience at NORADSanta.ORG this year.  Developer elves have implemented a...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.