Skip to content

Instantly share code, notes, and snippets.

View answerquest's full-sized avatar

Nikhil VJ answerquest

View GitHub Profile
@answerquest
answerquest / extract_vector_data.py
Last active February 7, 2024 04:58
Extract data from a vector tile layer for a given area
"""
Program by Nikhil VJ, https://nikhilvj.co.in
Based on solution worked out at https://gis.stackexchange.com/questions/475398/extract-features-in-lat-long-co-ordinates-from-vector-tile-layer-pbf-file-pytho
License: Creative Commons Zero v1.0 Universal, ref: https://choosealicense.com/licenses/cc0-1.0/
What this does:
- Given any vector tile layer in .pbf format, and a poylgon or similar shape,
- Extracts all the data from the vector tile layer falling over that shape,
- And save it to local disk as a .gpkg shapefile which you can further use
- If the vector tile layer had multiple layers, then .gpkg will have all those layers
@answerquest
answerquest / cluster1.py
Last active September 22, 2023 04:51
Grouping lat-long locations geo-spatially into N clusters
# Grouping lat-long locations geo-spatially into N clusters
from sklearn.cluster import KMeans
import pandas as pd
def clusterPoints(df1, N=10, cluster_column='cluster', lat_column='lat', lon_column='lon'):
kmeans = KMeans(n_clusters=N, random_state=None, n_init='auto')
df1[cluster_column] = kmeans.fit_predict(df1[[lat_column, lon_column]].values) + 1
# +1 so that 0,1,2,3..N-1 becomes 1,2,3..N
return
@answerquest
answerquest / google-buildings-extract-bounds.py
Last active August 20, 2023 08:19
google buildings extract for given area.
MINLAT = 21.0762
MAXLAT = 21.2057
MINLON = 78.9929
MAXLON = 79.1738
DATA_FILE = '3bd_buildings.csv'
OUTPUT_CSV = 'nagpur.csv'
import json, os
@answerquest
answerquest / emailing.py
Last active June 30, 2023 03:37
python SMTP emailing function
# by Nikhil VJ, https://nikhilvj.co.in , https://github.com/answerquest
# generic SMTP emailing function in Python, using SSL
# will take values from these env params:
# EMAIL_SERVER : SMTP server url
# EMAIL_PORT : SMTP port num (must be the SSL port)
# EMAIL_SENDER : Email account whose SMTP login you're using
# EMAIL_PW : SMTP password of the email account (likely same as regular password used to login to that account)
# tested and works well with BigRock.in hosting account's email accounts.
# ..and with Google workspace account IF you enable "allow less secure apps".
@answerquest
answerquest / India_Outline_Map.js
Last active May 15, 2024 15:50
India_Outline_Map.js Official Int'l Boundary of India as published at https://surveyofindia.gov.in/pages/outline-maps-of-india
// India_Outline_Map.js
// Official India international boundary shapefile downloaded from https://surveyofindia.gov.in/pages/outline-maps-of-india
// and converted to EPSG4326 (lat-longs), 5-decimal resolution, geojson format by https://gist.github.com/answerquest
// All copyright / ownership belongs to source Govt of India website
// NOTE: I wanted to put this in a .geojson file, but when Github shows its preview... guess what the background map is displaying! :P
// Hence, if you want to get this as a .geojson shapefile,
// please copy-paste the part from first { to last } to a text file
// and name it as India.geojson
@answerquest
answerquest / hydroSHEDS.org data vector tile layer publishing.md
Last active December 8, 2022 03:09
hydroSHEDS.org data vector tile layer publishing

hydroSHEDS.org data vector tile layer publishing

  • linux/shell commands used
  • to process data downloaded from https://www.hydrosheds.org/
  • clipping it to a rectangle around India to reduce to India data
  • converting to .geojsonl
  • creating .mbtiles using tippecanoe
  • publishing on an TileServerGL instance

clip to India rectangle and convert to .geojsonl using ogr2ogr

@answerquest
answerquest / imdblib open_data_file_year-test.ipynb
Last active October 16, 2022 06:23
imdblib new function test notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@answerquest
answerquest / _SOI Village Boundaries import
Last active October 10, 2022 12:33
SOI Village Boundaries import to PostGreSQL DB and gather in .geojsonl
SOI Village Boundaries import to PostGreSQL DB and gather in .geojsonl
@answerquest
answerquest / _SOI Toponyms import
Last active October 10, 2022 06:22
SOI Toponyms data import, csv making
SOI Toponyms data import to postgresql DB, csv making
@answerquest
answerquest / leaflet-center-location-picker.html
Created June 10, 2022 04:56
Leaflet map location picker POC with fixed center - better for mobile browsers than drag-drop
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui' />
<title>Leaflet location picker</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.3/dist/leaflet.css"
integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
crossorigin=""/>