Skip to content

Instantly share code, notes, and snippets.

View asinghvi17's full-sized avatar
🔍

Anshul Singhvi asinghvi17

🔍
  • Columbia University
  • New York, NY
View GitHub Profile
@asinghvi17
asinghvi17 / tiles_as_raster.jl
Created July 6, 2024 18:27
Getting a tile image in your desired dimensions from MapTiles.jl and TileProviders.jl
#=
# Getting (noninteractive) raster images from the MapTiles/TileProviders ecosystem
=#
import HTTP # to run the actual request and fetch the tiles
import ImageMagick # to read returned images, since they may be any bitmap format
using MapTiles, TileProviders # Julia map-tile infrastructure
# Julia geographic infrastructure
using Extents
import GeoInterface as GI
@asinghvi17
asinghvi17 / svg_colormap.jl
Created June 25, 2024 21:42
Implementing colormaps in SVG via passing colors as grays (allowing value based interpolation)
using Colors
function cgrad2svgf(cgrad)
stops = LinRange(0, 1, 256)
colors = cgrad[stops]
# no Alpha support yet
# but soon!
# <feFuncA type="table" tableValues="$(join(alpha.(colors), ","))"></feFuncA>
return """
<filter id="table" x="0" y="0" width="100%" height="100%">
using GLMakie
using Meshing, GeometryBasics
isoval = 100
algo = MarchingCubes(iso=isoval, insidepositive=false)
struct CameraRotationMove{T} <: FlyThroughPaths.PathChange{T}
duration::T
@asinghvi17
asinghvi17 / r_sf_integration.jl
Last active May 9, 2024 13:52
Hook into RCall.jl to convert SF geometries to GeoInterface wrappers
#=
This file provides integration for R's SF objects
which are essentially geo-dataframes,
into Julia DataFrames with GeoInterface wrapper
geometries.
This requires https://github.com/JuliaInterop/RCall.jl/pull/528,
so run `Pkg.add((; url = "https://github.com/asinghvi17/RCall.jl", rev = "patch-1"))` to get that.
TODO:
@asinghvi17
asinghvi17 / update_archive_sources.jl
Created May 3, 2024 14:27
A simple utility to update all archivesources (with some manual editing)
using SHA
function archive_source_string(prefix_name, prefix, suffix, oldhash::String; joinchar = "", unpack_target = nothing)
url = join((prefix, suffix,), joinchar)
hash = bytes2hex(get_hash(url))
print("ArchiveSource(\"\$($(prefix_name))$(joinchar)$(suffix)\", \"$(hash)\"")
if !isnothing(unpack_target)
print("; unpack_target = \"$(unpack_target)\")")
else
print(")")
@asinghvi17
asinghvi17 / proj_trans_generic.jl
Created April 14, 2024 14:18
How to use `proj_trans_generic`
using Proj, BenchmarkTools
import GeometryOps as GO
# using proj_trans_generic on a vector of tuples - or could be GB.Point or SVector or GI.Point with arbitrary metadata, doesn't matter!
points = tuple.(rand(10000), rand(10000))
t = Proj.Transformation("+proj=longlat", "+proj=natearth"; always_xy = true)
function batch_project_numsfirst!(points, projection)
# GC.@preserve points begin # not technically necessary
@asinghvi17
asinghvi17 / makie_tex_font.jl
Created May 26, 2023 19:22
Replacing the Makie latex rendering font
_stix_fonts = Dict(:regular => "/System/Library/Fonts/Supplemental/STIXTwoMath.otf",#joinpath("NewComputerModern", "NewCMMath-Regular.otf"),
:italic => "/System/Library/Fonts/Supplemental/STIXTwoMath.otf",#joinpath("NewComputerModern", "NewCM10-Italic.otf"),
:bold => "/System/Library/Fonts/Supplemental/STIXTwoMath.otf",#joinpath("NewComputerModern", "NewCM10-Bold.otf"),
:bolditalic => "/System/Library/Fonts/Supplemental/STIXTwoMath.otf",#joinpath("NewComputerModern", "NewCM10-BoldItalic.otf"),
:math => "/System/Library/Fonts/Supplemental/STIXTwoMath.otf"
)
Makie.MathTeXEngine.default_font_families["STIX"] = Makie.MathTeXEngine.FontFamily(
_stix_fonts,
@asinghvi17
asinghvi17 / metal_try.jl
Created May 26, 2023 19:21
A try at using Metal for recurrence analysis on MacOS
using BenchmarkTools, Metal
using Makie, CairoMakie
using RecurrenceAnalysis
function recurrence_kernel!(output_matrix, x1, x2)
x, y = Metal.thread_range()
end
@asinghvi17
asinghvi17 / tyler_ui.jl
Created May 25, 2023 16:19
Computing attractiveness metrics on streets
# # A GUI to display location "attractiveness"
# The following code creates a GUI which allows you to inspect
# a map of Toronto, and see the attractiveness of different locations
# based on different nearness measures.
# First, we load the necessary packages.
# We will build our GUI with the `Makie` toolchain, consisting of `Makie`, `[W]GLMakie`, and `Tyler` for map tile visualization.
# Data is from OpenStreetMap and is parsed using `OpenStreetMapX`. Attractiveness scores are obtained using `OSMToolset`.
@asinghvi17
asinghvi17 / meshimage.jl
Created March 14, 2023 16:47
A way to display images on meshes which are pretransformed in Makie.jl
using Makie: GeometryBasics
using Makie.GeometryBasics: StructArrays
@recipe(MeshImage) do scene
Attributes(
npoints = 100,
space = :data,
)
end