Analytics
The Analytics portion of the MGP_SDK provides an interface for Raster and Vector Analytics operations in the Maxar Geospatial Platform.
Getting Started:
from MGP_SDK.interface import Interface
analytics = Interface().analytics
Package methods:
- Create Raster URL
- Raster Metadata
- Get Raster Arrays
- Download Raster
- Search Vector Layer
- Download Vector Analytics
- Download Vector Tiles
Create Raster URL / raster_url()
Formats a vsicurl URL to be utilized with further raster functions
Returns: URL formatted with desired parameters and /vsicurl/ prefix
Args:
- script_id: (str) Desired IPEScript (e.g. "ortho-image")
- function: (str) Desired function of the IPEScript (e.g. "ortho")
- collect_id: (str) Desired raster image ID
- api_token: (str) User's maxar_api_token
- crs: (str) Default="UTM". Desired projection
Kwargs:
* bands: (str) Comma separated string of desired bands (e.g. "red,green.blue")
* dra: (str) Binary of whether or not to apply dra to the raster. String of bool ("true", "false"). Defaults to false
* interpolation: (str) Desired resizing or (re)projection from one pixel grid to another
* acomp: (str) Binary of whether or not to apply atmospheric compensation to the output after hd (if applied) and before dra. String of bool ("true", "false"). Defaults to false
* hd: (str) Binary of whether or not to apply higher resolution to the output. String of bool ("true", "false"). Defaults to false
response = analytics.raster_url(script_id="ortho-image", function="ortho", collect_id="<collectID>", api_token="<yourAPIToken>", bands="red,green,blue", dra="true")
print(response)
Raster Metadata
raster_metadata()
Lists out various metadata information of a desired raster
Returns: Dictionary of various raster metadata information
Args:
- raster_url: (str) Vsicurl formatted URL of a raster object
response = analytics.raster_metadata(raster_url="<vsicurl-formatted-URL>")
print(response)
Get Raster Arrays
get_arrays()
Lists out the arrays of a raster
Returns: List of arrays of the raster's pixels
Args:
* raster_url: (str) Vsicurl formatted URL of a raster object
* xoff: (int) Number of pixels to offset on the x axis
* yoff: (int) Number of pixels to offset on the y axis
* width: (int) Number of pixels for the returned raster on the x axis
* height: (int) Number of pixels for the returned raster on the y axis
response = analytics.get_arrays(raster_url="<vsicurl-formatted-URL>", xoff=3067, yoff=2045, width=2045, height=2045)
print(response)
Download Raster
download_raster()
Download a rasterized image from a raster array
Returns: Success message of download location
Args:
* raster_array: (list(list)) Generated raster array
* outputpath: (str) Desired outputpath for the rasterized image including file extension
response = analytics.download_raster(raster_array=[<raster-array>], outputpath=r"your\output\path\image.extension")
print(response)
Search Vector Layer
search_vector_layer()
Function searches using the WFS method
Returns: Response is either a list of features or a shapefile of all features and associated metadata.
Args:
- layers: (str) String specifying the layers to search
- bbox: (str) Default=
None, Bounding box of AOI. Comma delimited set of coordinates. (miny,minx,maxy,maxx) - srsname: (str) Default="EPSG:4326", Desired projection
- filter: (str) Default=
None, CQL filter used to refine data of search. - shapefile: (bool) Default=
False, Binary of whether to return as shapefile format - csv: (bool) Default=
False, Binary of whether to return as a CSV format
Kwargs:
- featureprofile: (str) The desired stacking profile. Defaults to account Default
- typename: (str) The typename of the desired feature type. Defaults to FinishedFeature
response = analytics.search_vector_layer(layers="your_layers", bbox="miny,minx,maxy,maxx")
print(response)
Download Vector Analytics
download_vector_analytics()
Function downloads the image using the WMS method
Returns: requests response object or downloaded file path
Args:
* layers: (str) String specifying the layers to download
* bbox: (str) Default=None, Bounding box of AOI. Comma delimited set of coordinates. (miny,minx,maxy,maxx)
* srsname: (str) Default="EPSG:4326", Desired projection
* height: (int) Default=512, The vertical number of pixels to return
* width: (int) Default=512, The horizontal number of pixels to return
* format: (str) The format of the response image either jpeg, png or geotiff
* outputpath: (str) Output path must include output format. Downloaded path default is user home path
* display: (bool) Default=False, Display image in IDE (Jupyter Notebooks only)
response = analytics.download_vector_analytics(layers="VIVID_BASIC", bbox="miny,minx,maxy,maxx", height=256, width=256, format="jpeg", outputpath=r"your\output\path\image.extension")
print(response)
Download Vector Tiles
download_vector_tiles()
Function downloads vector imagery using the wmts method
Returns: Downloaded file path
Args:
- layers: (str) String specifying the layers to download
- zoom_level: (int) The desired zoom level
- bbox: (str) Bounding box of AOI. Comma delimited set of coordinates. (miny,minx,maxy,maxx)
- srsname: (str) Default="EPSG:4326", Desired projection
- outputpath: (str) Output path must include output format. Downloaded path default is user home path
- display: (bool) Default=
False, Display image in IDE (Jupyter Notebooks only)
response = analytics.download_vector_tiles(layers="VIVID_BASIC", zoom_level=15, bbox="miny,minx,maxy,maxx", outputpath=r"your\output\path\image.extension")
print(response)