Geospatial is a function of your life
Tags: fsharp, polyglotnotebooks, opendata
Published: 2022-12-06 10:40:38

In this post I present **Florence**, 
a low-code geospatial library for everyone that ranks city places with (life-inspired) functions.

Florence heavily laverages [.NET Interactive/Polyglot Notebooks](https://github.com/dotnet/interactive) runtime to hide and execute code behind the scene (including breaking some language constraints).

I use open data for Zurich from https://data.stadt-zuerich.ch/, but you can use any geojson data, including [imaginary Worlds](https://twitter.com/PlaceSharper/status/1585995193035071489).

Florence is still an experimental library, alpha release is due 24th Dec.

## Is geospatial hard and boring?
 
Geospatial isn't hard, it is rather **not accessible for a novice**.

You may think that certain tools are expensive, reserved for municipal departments, and that advanced programming is required (in languages you don't necessarily like). 

You can also treat this domain as (a little bit) boring.

Geospatial might be hard and boring 
...**unless you are not aware that you are doing geospatial**.

Surprisingly a lot of geospatial analysis boils down to the question "what is the best place for/to ... (anything)?". 

Also surprisingly to answer this very generic question, we can write a very simple function!

A function that takes place (or facility) and returns its value.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y7brto0rf8iab4w36g9b.png)



Such a function can be run against all well-known city districts, blocks, or custom areas.

How to get this data? "You said your library is for everyone but I don't have data-related digital skills...".

Correct, with Florence you don't care about data retrieval and types, you have it on hand. Just think about having fun(ction).


## Florence: take a quick look ##
Florence requires at least one data file to be located in a geojson folder of your _VS Code_ workspace. Once you load the Florence package, your files are _loaded_ and you have strongly-type access. 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/solrbdfn1r0vi4jpeoqa.png)

Notebook's author can share all geojson files along with the notebook. However I created a special _geojson.cloud_, so you can explore and download necessary files directly from the F# cell:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l5ocsue0z179k9279ol0.gif)
Under the cover it is some sort of a simplified [Azure Storage Type Provider](https://fsprojects.github.io/AzureStorageTypeProvider/) but with a capability to share cloud data without sharing the cloud access keys.

It is very handy, discoverable, and useful especially for bigger datasets, like addresses. Every dataset has necessary license data on folder or file level:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4n1w04tz0zk3yqpn2bln.png)

**The function of your life**

To do your analysis, you need to write just one function, like the function of your life. Such an activity is not just for fun, it can have many real applications. Imagine all residents are able to write it among plain data querying and joining: we can get exhaustive, the most powerful municipal platform possible. 

As everything that Florence expects is a geojson, your life also must be defined in geojson file. Don't be scared, there will be a nice, graphical way to define your life space directly in the notebook:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p8lg35kmufigxkw9q2kz.gif) 

For the time being, as most of us do not live in Zurich, we can ... rand our lifespace.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nl03qaog50rsr93egmrh.png)

Once the cell is executed, quite a lot of magic happens under the cover. You put names of all your important places in a list, their locations are randed, and the special type called MyCityLife is created. When you feed the type with some location, you will get distances to your important places via their names.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7iiqxq8kpf9nvane7mqs.png)

The clue here is that those places can be anything, any citizen can name it differently.


Having your city life space type on your disposal, you can write the proper analytical function:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1lq3afc9d9e9koq2b9l.png)

This function will be different for many people, even for the same person it can change overtime (there are times when we don't necessarily need our parents-in-law to be close, but it will dramatically change when children arrive).

You can run your function against the same or any other geospatial file containing city places:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tq0ev0x9vxm7bg624pxp.png)

**Distance Type Provider**

MyCityType used in the calculation is in fact a type created by a special F# Type Provider. It gets all geojson feature's properties and calculates the spatial distance to another provided location.

There are more applications for this than the presented function of life. You can get the distance between certain places similarly to asking plain questions (example for F1 fans, all you need is a single geojson with F1 tracks):

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jmxib3v1uc6kp3oztf5z.gif)

You can also measure a trip:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s4sp5s3w3z94wozfqms4.png)

**Other applications**

In this post, I did focus on applying the function of life for geospatial purposes. 
But this is only the tip of the iceberg of what you can do with Florence. The main capability is to include more data in the calculation. What if the best place should be determined based on route count of the 3 nearest stations ?


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/27xu3rgk18gr0sy37sj8.png)

The tricky part is to join datasets in a readable, succinct  manner. You can use the full F# power here. I'm pretty sure F# developers will have fun with it.