Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
patch read_generic to Feature collection fuction in aeronetlib.
@patch_to(ds.FeatureCollection, cls_method=True)
def read_generic(cls,
fp: str,
dst_crs: Union[str, rasterio.crs.CRS]=None,
):
'''
geojson reader and can also be used to ensure the geojson in mapped to a destined crs
'''
with open(fp, 'r', encoding='utf-8') as f:
collection = json.load(f)
features = []
src_crs = collection['crs']['properties']['name'] if isinstance(collection['crs'], dict) else collection['crs']
print(src_crs)
dst_crs = src_crs if dst_crs is None else dst_crs
for i, feature in enumerate(collection['features']):
try:
new_geometry = transform_geom(
src_crs=src_crs,
dst_crs=dst_crs,
geom=feature["geometry"],
)
feature_ = ds.Feature(
geometry=new_geometry,
properties=feature['properties'],
crs=dst_crs,
)
features.append(feature_)
except (KeyError, IndexError) as e:
message = 'Feature #{} have been removed from collection. Error: {}'.format(i, str(e))
warnings.warn(message, RuntimeWarning)
return cls(features, dst_crs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment