Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@

__pycache__
.vscode
.vscode

*.tif
*.geojson
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,46 @@ poetry shell
## Install the dependencies
```sh
poetry install
```
## Usage

### Python APIs

```python

#Python API to access resources

from pyGDI import createAuth
from pyGDI import ResourceFetchcer

client_id="your client id"
client_secret="your client secret"
role="consumer"

#authenticate first
auth= createAuth(client_id=client_id, client_secret=client_secret, role=role)

resource_id="413872b1-84f3-4ca8-ad07-05c6cbb3ecf5" #sample is given
fetch_resource_data(auth= auth, resource_id=resource_id, save_object=True, config_path=None, file_path="download.geojson")

```

```python

#Python API to access STAC items

from pyGDI import createSTACAuth
from pyGDI import get_assets

client_id="your client id"
client_secret="your client secret"
role="consumer"
collection_ids="f6443e79-0594-4d65-bb0d-d025893c99fe"

#authenticate first
stac_auth= createSTACAuth(client_id=client_id, client_secret=client_secret, role=role, collection_id=collection_ids)
get_assets(auth=stac_auth, config="config.json")

```

## Fetching Resources (Vector Resources)
Expand Down
96 changes: 0 additions & 96 deletions features/vector_features/get_re.py

This file was deleted.

51 changes: 23 additions & 28 deletions gdi_cli.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import click
from auth.token_gen import TokenGenerator

from features.vector_features.get_re import ResourceFetcher
from features.vector_features.count_features import count_features
from features.vector_features.download_features import download_features
from features.vector_features.buffer import make_buffer
from features.vector_features.intersection import make_intersection
from features.vector_features.gcode import list_features
from features.vector_features.compute_geo import compute_geometry_measures
from features.vector_features.ReduceToImage import reduce_to_image
from features.vector_features.optimalRoute import compute_optimal_route
from features.vector_features.voronoi_diagram import create_voronoi_diagram
from features.vector_features.clip_data import make_clip
from features.vector_features.delaunay_triangles import make_delaunay_triangles

from features.raster_features.search_cat import search_stac
from features.raster_features.get_data import get_assets

from common.minio_ops import get_ls

def gen_token(client_id, client_secret, role):
token_generator = TokenGenerator(client_id, client_secret, role)
auth_token = token_generator.generate_token()
return auth_token
from pyGDI import createAuth, createSTACAuth
from pyGDI import fetch_resource_data
from pyGDI import count_features
from pyGDI import download_features
from pyGDI import make_buffer
from pyGDI import make_intersection
from pyGDI import list_features
from pyGDI import compute_geometry_measures
from pyGDI import reduce_to_image
from pyGDI import compute_optimal_route
from pyGDI import create_voronoi_diagram
from pyGDI import make_clip
from pyGDI import make_delaunay_triangles

from pyGDI import search_stac
from pyGDI import get_assets

from pyGDI import get_ls


def get_resource(client_id, client_secret, role, resource_id, save_object, config_path, file_path):
Expand All @@ -40,8 +34,8 @@ def get_resource(client_id, client_secret, role, resource_id, save_object, confi
file_path : str (Node red will ignore this parameter)

"""
fetcher = ResourceFetcher(client_id, client_secret, role)
resource_data = fetcher.fetch_resource_data(resource_id, save_object, config_path, file_path)
auth = createAuth(client_id=client_id, client_secret=client_secret, role=role)
resource_data = fetch_resource_data(auth,resource_id, save_object, config_path, file_path)
return resource_data


Expand All @@ -53,7 +47,7 @@ def get_resource(client_id, client_secret, role, resource_id, save_object, confi
@click.option('--role', required=True, help="Role for the token.", default = "consumer")
def generate_token(client_id, client_secret, role):
"""Generate an authentication token."""
token = gen_token(client_id, client_secret, role)
token = createAuth(client_id, client_secret, role)
click.echo(f"Generated Token: {token}")


Expand Down Expand Up @@ -238,7 +232,8 @@ def search_cat(collection_ids):
@click.option('--config', required=True, help="Path to the config file.")
def get_stac_assets(client_id, client_secret, role, collection_ids, config):
'''Download Cartosat images from the STAC browser and stream to minio'''
get_assets(client_id, client_secret, role, collection_ids, config)
stac_auth=createSTACAuth(client_id, client_secret, role, collection_ids)
get_assets(stac_auth,config)



Expand Down
21 changes: 21 additions & 0 deletions pyGDI/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from .auth.token_gen import TokenGenerator, createAuth
from .auth.stac_token_gen import StacTokenGenerator, createSTACAuth

from .features.vector_features.get_re import fetch_resource_data
from .features.vector_features.count_features import count_features
from .features.vector_features.download_features import download_features
from .features.vector_features.buffer import make_buffer
from .features.vector_features.intersection import make_intersection
from .features.vector_features.gcode import list_features
from .features.vector_features.compute_geo import compute_geometry_measures
from .features.vector_features.ReduceToImage import reduce_to_image
from .features.vector_features.optimalRoute import compute_optimal_route
from .features.vector_features.voronoi_diagram import create_voronoi_diagram
from .features.vector_features.clip_data import make_clip
from .features.vector_features.delaunay_triangles import make_delaunay_triangles

from .features.raster_features.search_cat import search_stac
from .features.raster_features.get_data import get_assets

from .common.minio_ops import get_ls

52 changes: 38 additions & 14 deletions auth/stac_token_gen.py → pyGDI/auth/stac_token_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,32 @@ class StacTokenGenerator:
role (str): The role for the request payload.
"""

def __init__(self, client_id: str, client_secret: str, role: str, collection_id:list):
self.client_id = client_id
self.client_secret = client_secret
self.token_url = "https://dx.geospatial.org.in/auth/v1/token"
self.item_id = collection_id
self.item_type = "resource"
self.role = role
def __init__(self, client_id: str, client_secret: str, role: str, collection_id:str):
self._client_id = client_id
self._client_secret = client_secret
self._token_url = "https://dx.geospatial.org.in/auth/v1/token"
self._item_id = collection_id
self._item_type = "resource"
self._role = role

def generate_token(self) -> str:
@property
def client_id(self) -> str:
return self._client_id

@property
def client_secret(self) -> str:
return self._client_secret

@property
def role(self):
return self._role

@property
def collection_id(self):
return self._item_id

@property
def get_stac_token(self) -> str:
"""
Generate an authentication token.

Expand All @@ -30,16 +47,16 @@ def generate_token(self) -> str:
"""
try:
response = requests.post(
self.token_url,
self._token_url,
headers={
"clientId": self.client_id,
"clientSecret": self.client_secret,
"clientId": self._client_id,
"clientSecret": self._client_secret,
"Content-Type": "application/json"
},
json={
"itemId": self.item_id,
"itemType": self.item_type,
"role": self.role
"itemId": self._item_id,
"itemType": self._item_type,
"role": self._role
}
)

Expand All @@ -54,6 +71,13 @@ def generate_token(self) -> str:
except requests.RequestException as e:
# print(response.json())
raise Exception(f"Error generating auth token: {e}")


def createSTACAuth(client_id: str, client_secret: str, role: str, collection_id:str) -> StacTokenGenerator:

tokengenerator= StacTokenGenerator(client_id=client_id, client_secret=client_secret, role=role, collection_id=collection_id)
return tokengenerator



# Example usage
Expand Down
Loading