Created
July 21, 2022 19:42
-
-
Save Banashek/1cc3d8435843bcff230906fb037eeefd to your computer and use it in GitHub Desktop.
Quick and dirty fable-py prettymaps. Very dynamic for proof of concept.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Fable.Core | |
open Fable.Core.PyInterop | |
open Fable.Python.Json | |
[<ImportAll("sys")>] | |
let sys: obj = nativeOnly | |
let prettymaps: obj = importAll "prettymaps" | |
let matplotlib: obj = importAll "matplotlib" | |
let address = "Praça Ferreira do Amaral, Macau" | |
let radius = 1100 | |
let perimeterSettings = {| |} | |
let streetLayerSettings = | |
{| width = | |
{| motorway = 5 | |
trunk = 5 | |
primary = 4.5 | |
secondary = 4 | |
tertiary = 3.5 | |
residential = 3 | |
service = 2 | |
unclassified = 2 | |
pedestrian = 2 | |
footway = 1 |} |} | |
let buildingLayerSettings = | |
{| tags = | |
{| building = true | |
landuse = "construction" | |
union = false |} |} | |
let waterLayerSettings = {| tags = {| natural = [| "water"; "bay" |] |} |} | |
let greenLayerSettings = | |
{| tags = | |
{| landuse = "grass" | |
natural = [| "island"; "wood" |] | |
leisure = "park" |} |} | |
let forestLayerSettings = {| tags = {| landuse = "forest" |} |} | |
type ParkingLayerTags = | |
{ amenity: string | |
highway: string | |
[<CompiledName("man_made")>] | |
manmade: string } | |
let parkingLayerTags: ParkingLayerTags = | |
{ amenity = "parking" | |
highway = "pedestrian" | |
manmade = "pier" } | |
let parkingLayerSettings = | |
{| tags = | |
{| amenity = "parking" | |
highway = "pedestrian" | |
man_made = "pier" |} |} | |
let layers = | |
{| perimeter = perimeterSettings | |
streets = streetLayerSettings | |
building = buildingLayerSettings | |
water = waterLayerSettings | |
green = greenLayerSettings | |
parking = parkingLayerSettings |} | |
let drawingKwargs = | |
{| background = | |
{| fc = "#f2f4cb" | |
ec = "#dadbc1" | |
hatch = "ooo..." | |
zorder = -1 |} | |
perimeter = | |
{| fc = "#f2f4cb" | |
ec = "#dadbc1" | |
lw = 0 | |
hatch = "ooo..." | |
zorder = 0 |} | |
green = | |
{| fc = "#d0f1bf" | |
ec = "#2f3737" | |
lw = 1 | |
zorder = 1 |} | |
forest = | |
{| fc = "#64b96a" | |
ec = "#2f3737" | |
lw = 1 | |
zorder = 1 |} | |
water = {| | |
fc = "#a1e3ff" | |
ec = "#2f3737" | |
hatch = "ooo..." | |
hatch_c = "#85c9e6" | |
lw = 1 | |
zorder = 2 |} | |
parking = | |
{| fc = "#f2f4cb" | |
ec = "#2f3737" | |
lw = 1 | |
zorder = 3 |} | |
streets = | |
{| fc = "#2f3737" | |
ec = "#475657" | |
alpha = 1 | |
lw = 0 | |
zorder = 3 |} | |
building = | |
{| palette = [| "#ffc857"; "#e9724c"; "#c5283d" |] | |
ec = "#2f3737" | |
lw = 0.5 | |
zorder = 4 |} |} | |
let figSize = (12, 12) | |
[<Emit("matplotlib.pyplot.subplots(figsize = ($0, $1), constrained_layout = $2)")>] | |
let subplots (_figX: int) (_figY: int) (_constrainedLayout: bool) : obj * obj = nativeOnly | |
[<Emit("matplotlib.pyplot.savefig($0)")>] | |
let saveFigure (_path: string) = nativeOnly | |
[<Emit("prettymaps.plot($0, radius = $1, ax = $2, layers = $3, drawing_kwargs = $4)")>] | |
let plot (_address: string) (_radius: int) (_axis: obj) (_layers: obj) (_drawing_kwargs: obj) : obj = nativeOnly | |
/// Main | |
/// | |
let (fig, ax) = subplots 12 12 true | |
let plottedLayers = plot address radius ax layers drawingKwargs | |
saveFigure "./figure.png" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
dotnet new console -lang f\#
dotnet new tool-manifest
dotnet tool install fable-py --version 4.0.0-alpha-032
dotnet add package Fable.Core.Experimental --version 4.0.0-alpha-032
dotnet add package Fable.Python
python -m venv .
chmod +x ./bin/activate
./bin/activate
python -m pip install prettymaps
python -m pip install osmnx==1.2.1
(See this issue)dotnet fable-py fablepymap.fsproj
python program.py