top of page

Portugal Smart Cities 2021

You can replicate the Mapify demonstration performed in this event by following this article.



TL;DR;


In this post you will go through the process of replicating the data visualization and functionality seen in the Portugal Smart Cities Summit 2021 Mapify demo presentation.


Requirements:

  • Mapify account (you can request a trial account here)

If you want to dive right in the deep end without following this tutorial, feel free to schedule a talk with us, and start creating your location intelligence solutions today!


 

Your first step will be to create a Dataset containing Lisbon’s parishes. You can download the respective shapefile from here.


Step 1 — Create a “Lisbon — Freguesias” dataset by uploading the provided shapefile.

Step 2 — Create a “Lisbon — Freguesias” GeoJSON layer and give a simple styling, using 10% opacity level in the fill color.


You should now have something similar to the screenshot below:

Step 3— Create a “Restricted Zones” dataset by defining a new dataset schema.


Select Polygon type for the geom field, and add two more fields:


  • id as Text, non nullable, and unique

  • description as Text, nullable


It should look similar to the screenshot below:

Save the dataset. Go back to the dataset details page, and click on the “Edit data on Mapify Editor” button. A new browser tab will open with the Mapify Editor loaded for you to edit the data in the Restricted Zones dataset.


Click on the “Create Feature” button and draw a polygon over an area which is inside one of Lisbon’s parishes. You can add more features of you want, to simulate additional restricted zones.


Save your changes and once you’re done, be sure to publish the changes.


If you draw a new restricted zone over the Parque das Nações area, if could look something like the screenshot below:


Step 4— Create a “Restricted Zones” GeoJSON layer and give a simple styling, using 10% opacity level in the fill color, which you can define with a red tint.


Taking the feature created in step 3 as an example, the layer preview could look something like the screenshot below:


Step 5— Create a bike-positions Push Data Feed to handle incoming real time bike location and data.


Specify the following feed schema:

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "type": "object",
  "properties": {
    "bike_id": {
      "type": "string"
    },
    "speed": {
      "type": "integer"
    },
    "temperature": {
      "type": "integer"
    },
    "location": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string"
        },
        "coordinates": {
          "type": "array"
        }
      }
    }
  }
}

Step 6— Create an API Key which will be used by the simulator to send real time data to the previously created Data Feed. For the purpose of this demo, make sure the API Key you create has the following claims enabled:

  • Data Feeds

  • Workflows

  • Topic Messaging

  • Dictionaries

It should look something like the screenshot below:


Step 7— Create Workflow 01 and set its source to the bike-positions Data Feed.

Add a Sink Email node below the source node, and configure it as below:


Subject:

Message received from: ${bike_id}

Body:

Message received from: ${bike_id}
Temperature: ${temperature}
Speed: ${speed}

In the “To email address”, type your email address.


This first workflow is quite simple, and should look like the screenshot below:

Step 8— You can already test your workflow using the Simulator. Start the workflow you created and open a new tab of your browser and navigate to https://simulator.mapify.ai


Copy the API Key you created in step 6 and paste it in the simulator respective field. Then select the bike-positions Data Feed as the target for the simulator messages.


You should now have the message template based on the bike-positions Data Feed schema automatically filled. Create three dynamic parameters for the simulator to generate random values for:

  • bike_speed, an integer variable generated from an interval between 0 and 50

  • bike_temperature, an integer variable generated from an interval between 20 and 100

  • bike_position, a MultiPoint variable generated along a pre-defined line, with maximum step of 500m.

Select the “Restricted Zones” as the context layer, and be sure that the path drawn crosses at least one of the restricted zones you defined.

In the the message schema template, replace the values of the attributes:

  • bike_id with “Bike01”

  • bike_temperature with “${bike_temperature}”

  • bike_speed with “${bike_speed}”

  • location.type with “MultiPoint”

  • location.coordinates with “${bike_position}”

You should now have a similar simulator configuration as illustrated in the screenshot below:


Note: You can click the “Show Sample” button to preview an example of a generated message using the configured template.


To send a quick test message to the Data Feed, set the values of “New message after 1 seconds. Stop after 1 message”.


Click the “Start” button, and a generated message will be sent to the Data Feed.


Check your email inbox, you should have received the email alert sent through the Workflow.


Step 9 — The next step is to demonstrate the ability to create a workflow which includes a spatial operation . So go back to the Mapify Console browser tab, and make sure to stop the previously created workflow, then create a new “Workflow 02”, which will also have the bike-positions Data Feed as its source.


Below the Source node add a “Spatial Intersect ion— Mapify Layer” transformer node and name it “Intersect_Freguesias” (the name you give it will affect the naming of the variable used to obtain the result of the node). Select the previously created “Lisbon — Freguesias” layer as the layer to intersect. For the Geometry type select the location.type message field, and for the Coordinates value select the location.coordinates message field.


It should be similar to the example illustrated below:

Below the spatial intersection node, add an Email sink node, similar to the one created in step 7, with the added intersection result in the email body:


Subject:

Message received from: ${bike_id}

Body:

Message received from: ${bike_id}
Temperature: ${temperature}
Speed: ${speed}
Intersected Freguesia: ${intersect_freguesias_result.features[0].properties.freguesia}

In the “To email address”, type your email address.


You should have a similar workflow to the screenshot below:

Step 10 — Now go back to the Simulator tab and click the “Start” button to send another message to the Data Feed.


Check your email inbox, and you should have another email, this time with the additional information of the intersected polygon from the “Lisbon — Freguesias” layer.


Step 11— The next step is to demonstrate the ability to create a more complex workflow but adding the ability to see data updating in real time on a Map.


So before creating your final workflow, you will need:

  • A “Bike Positions” Dataset to persist the latest location received for your bike

  • A “Bike Positions” Layer to display the bike(s) location(s) in real time

  • A Map that aggregates the three layers created: “Lisboa — Freguesias”, “Restricted Zones”, and the “Bike Positions layer.

Let’s start by creating a new “Bike Positions” dataset, for which you will define its schema.


Select Point as the geom field type, and then add and configure additional fields on the dataset as illustrated in the screenshot below:


Save the dataset.


Step 12— Create a “Bike Positions” Realtime layer from the “Bike Positions” dataset. In the Style tab, select the “By Attribute” styling tab.


To style positions when they are inside a restricted zone, select the attribute “restricted” from the list, “Equal To” from the operators list, and select “true” for the value. Pick white or a light color for the outline and red (for example #ff0000) for the fill color.


For all other positions, change the styling options in the “OTHER” style tab. Pick white or a light color for the outline and a green color (for example #66c2a4) for the fill color.


The style configurations should look pretty similar to the screenshot below:

Save the layer (previewing it won’t display any bike positions since the underlying “Bike Positions” dataset doesn’t have any data yet).


Step 13 — Create a new Map named “Demo”. Navigate to the Maps option in the left hand menu, and create a new Map. Create a group of layers named “Context” for the context layers.


Add the “Lisbon — Freguesias” layer to it, and the “Restricted Zones” layers above it.


Create a group of layers named “Realtime” and add the “Bike Positions” layer to it.


It should look similar to the screenshot below:

On the Details tab, click the “Calculate Bounding Box” button. Save the new Map.


Step 15 — The final step is to create a new “Workflow 03”, which will also have the bike-positions Data Feed as its source.


Below the Source node add a “Spatial Intersect ion — Mapify Layer” transformer node just like in step 9 with the same name and configuration.


Below that node, add an additional “Spatial Intersection — Mapify Layer” transformer node.


Name it “Intersect Zones” and select the “Restricted Zones” layer as the layer to intersect. For the Geometry type select the location.type message field, and for the Coordinates value select the location.coordinates message field.


Below the spatial intersection node, add an Email sink node, similar to the one created in step 9, with the added intersection of the restricted zone result in the email body:


Subject:

Message received from: ${bike_id}

Body:

Message received from: ${bike_id} 
Temperature: ${temperature}
Speed: ${speed}
Intersected Freguesia: ${intersect_freguesias_result.features[0].properties.freguesia}
Restricted: ${intersect_zones_result!=null}
Restricted zone: ${intersect_zones_result.features[0].properties.description}

In the “To email address”, type your email address.


Below the Email sink node, add a new Dataset sink node. Select the “Bike Positions” dataset, and select the “Update” radio button so that records with the same key attribute value are updated.


For the Coordinates value, select the location.coordinates message field.


For the remaining dataset fields, select the respective workflow message mappings:

  • id: bike_id

  • speed: speed

  • freguesia: intersect_freguesias_result.features[0].properties.freguesia

  • restricted: intersect_zones_result!=null

  • temperature: temperature

  • restricted_zone: intersect_zones_result.features[0].properties.description

It will look something like the screenshot below:



Your workflow structure should look like the screenshot below:

Save the workflow.


Step 16 — Navigate to the previously created Map details page, and click on the preview tab. Toggle all layers of the map to be visible. You should see the context layers, but no bike positions yet.


Now go back to the Simulator, and change values of the message generation, to : “New message after 10 seconds. Stop after 10 messages”.


Click the “Start” button and quickly change to the Mapify Console tab where the map in being previewed. Wait 10 seconds for each message being received from the simulator, and notice how the bike position symbol will be displayed depending on it intersecting restricted zones, and how it moves across the map without requiring any kind of refresh from the user.

Also check your email inbox, and you should have as many emails as messages sent, this time with the additional information of the intersected “Restricted Zones” layer.


Congratulations, you built a great demo ! :-)

I hope you enjoyed this walkthrough and can now see how quick and easy it is to prepare spatial data, process real time data feeds and leverage location intelligence operations with Mapify!


Ready to power your solutions with Mapify ? Feel free to request a Mapify trial here, or click here to schedule a talk with us and we’ll show you what Mapify can do for you and your business.

bottom of page