Skip to content

Instantly share code, notes, and snippets.

View prakharcode's full-sized avatar
💲
git status

Prakhar Srivastava prakharcode

💲
git status
View GitHub Profile
def calc_poi_opr_in_radius(poi, entity, radius, **kwargs):
entity = entity.copy()
KDT = KDTree(poi[['lat', 'long']])
deg_to_m = 1/108000.0
query = entity.progress_apply(lambda g: KDT.query_radius([[g.lat, g.long1]], r= deg_to_m * radius), axis=1)
name = kwargs['name'] if kwargs['name'] else 'default'
pos_item = list(poi.columns).index(kwargs['avg_by'])
col = kwargs['avg_by']
entity.loc[:, kwargs['opr'] + "_" + name] = [ eval("poi.iloc[ x[0], pos_item].{0}()".format(kwargs['opr']), {'poi': poi, 'x':x,'pos_item': pos_item, 'col':col }) if len(x[0]) > 0 else 0 for x in tqdm(query)]
return entity
def calc_poi_avg_in_r(poi, entity, radius, **kwargs):
entity = entity.copy()
KDT = KDTree(poi[['lat', 'long']])
deg_to_m = 1/108000.0
query = entity.progress_apply(lambda g: KDT.query_radius([[g.lat, g.long1]], r= deg_to_m * radius), axis=1)
name = kwargs['name'] if kwargs['name'] else 'default'
entity.loc[:, f'{name}'] = [ len(x[0]) for x in tqdm(query)]
return entity
@prakharcode
prakharcode / resample_rasterio.py
Last active September 18, 2020 02:43
Resample using rasterio
import rasterio
from rasterio import Affine
from rasterio.warp import reproject, Resampling
with rasterio.open('path/to/band') as src:
scale = 2 # scaling amount of data so a scale of 2 would double the pixel size
aff = src.transform
# adjust the new affine transform to new scale
@prakharcode
prakharcode / resample.py
Last active September 1, 2021 04:42
Resample, reprojection and stacking of bands using rasterio
band_dict = {
""" dictonary containing all the bands that are to be stacked
in the following format:
band_index : "path/to/band"
"""
}
dst_projection = 'EPSG:4326' # the final projection
ref_band = "path/to/ref_band/" # the band that you want as a reference
@prakharcode
prakharcode / QGIS-install.md
Last active January 10, 2024 06:10
Install QGIS 3
cd /etc/apt/
sudo vim sources.list



# paste the following

# QGIS 3 install
deb https://qgis.org/ubuntu-ltr/ bionic main
@prakharcode
prakharcode / conversion.py
Created February 12, 2019 05:34
Poly Z to Poly
import geopandas as gpd
from shapely.geometry import Polygon
df = gpd.read_file('/path/to/file')
df.geometry = df.geometry.apply(lambda x: Polygon([[i[0], i[1]] for i in x.exterior.coords]))

Keybase proof

I hereby claim:

  • I am prakharcode on github.
  • I am prakharcode (https://keybase.io/prakharcode) on keybase.
  • I have a public key ASCrc_Og_FiOO4Itmc2IFtGDs_5eS4LIQk5zg4TTuRnBTgo

To claim this, I am signing this object: