Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Prakhar Srivastava prakharcode

🎯
Focusing
Block or report user

Report or block prakharcode

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Calculate any operation on a radius of an entity and poi
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
View Calculate number of point in a radius
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 Mar 25, 2019
Resample using rasterio
View resample_rasterio.py
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 Mar 25, 2019
Resample, reprojection and stacking of bands using rasterio
View resample.py
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
View QGIS-install.md
cd /etc/apt/
sudo vim sources.list



# paste the following

# QGIS 3 install
deb https://qgis.org/ubuntu-ltr/ bionic main
View conversion.py
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]))
View keybase.md

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:

You can’t perform that action at this time.