Created
April 4, 2024 04:51
-
-
Save krishnaglodha/f30d8cc193c50845f58aaf8a3f7b2bbd to your computer and use it in GitHub Desktop.
Find all features in each files based on lat , long
This file contains hidden or 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
### This file will require you to give path of folder in which all GeoJSONs are present | |
## Author : [email protected] | |
## !pip install geopandas | |
### | |
import os | |
import geopandas as gpd | |
from shapely.geometry import Point | |
import json | |
def get_data(lon, lat ,folder_path = 'data'): | |
containing_polygons = [] | |
poi = Point(lon,lat) | |
for filename in os.listdir(folder_path): | |
if filename.endswith('.json'): | |
a = gpd.read_file(f"{folder_path}/{filename}") | |
contains_point = a[a.geometry.contains(poi)] | |
if len(contains_point) > 0: | |
containing_polygons.append({ | |
"file" : filename, | |
"feature":json.loads(contains_point.to_json())}) | |
return containing_polygons | |
get_data(90.29543506414096,23.755479239902694) | |
## Result will give a list of multiple dictionaries with following schema | |
''' | |
Result = [ | |
{ | |
'file': filename in which we found result, | |
'feature' : GeoJSON of the polygon | |
}, | |
{ | |
'file': filename in which we found result, | |
'feature' : GeoJSON of the polygon | |
}, | |
.. | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment