# Rasteric: A Comprehensive Geospatial Library
**Rasteric** is a comprehensive library for geospatial data preprocessing, analysis, and modeling. It provides a variety of functions for transforming and manipulating geospatial data, including:
- Data normalization with `norm()`
- Resampling using `resample()`
- Feature extraction through `extract()`
It also offers analytical techniques such as:
- `zonalstats()` for spatial analysis
- `ndvi()` for vegetation index calculation
- `haversine()` for distance calculations
## Supported Data Formats
Rasteric is designed to work with multiple geospatial data formats, including:
- Shapefiles
- GeoJSON
- Raster data
## Key Functions
### Data Handling
- `convpath()` for file path handling
- `stack_rasters()` for combining multiple rasters
- `convras()` for converting rasters to vector format
### Visualization
- `plot()` for displaying raster data
- `contour()` for creating contour plots
- `hist()` for histogram generation
### Data Manipulation
- `clipraster()` for cropping rasters
- `reproject_raster()` for coordinate system transformations
- `bandnames()` for managing raster band information
### Utilities
- `mergecsv()` for combining data files
- `savetif()` for saving processed data
## Integration and Applications
Rasteric integrates seamlessly with popular geospatial tools and platforms, enhancing its functionality with features like:
- `getFeatures()` for working with vector data
- `stats()` for quick raster statistics
Widely used in the geospatial industry, research, and open-source communities, Rasteric facilitates:
- Development of geospatial applications
- Performance of spatial analysis
- Modeling of complex geospatial phenomena
Its diverse set of functions, including `zonalstats()`, `ndvi()`, and `resample()`, make it a versatile tool for a wide range of geospatial tasks.
## Example:
```python
from rasteric import raster
from matplotlib import pyplot
fig, (axr, axg, axb) = pyplot.subplots(1, 3, figsize=(21, 7))
fig, (axr, axg, axb) = pyplot.subplots(1, 3, figsize=(21, 7))
raster.plot('T60GVV.tif', bands=[3], ax=axr, title="Red", brightness_factor=5)
raster.plot('IMG_001_clip.tif', bands=[4,2,1], ax=axg, title="Green", brightness_factor=5)
raster.plot('IMG_001_clip.tif', bands=[4], ax=axb, title="Red")
```
![Example Image](https://github.com/tnmthai/geotran/blob/main/image.png)
```python
clip(raster_file, shapefile, output_file)
```
---
## Function Descriptions
### convpath(file_path)
Converts a Windows-style file path to a Unix-style path for cross-platform compatibility.
**Parameters:**
- `file_path` (str): The input file path to be converted.
---
### norm(array)
Applies min-max normalization to a raster array, adjusting pixel values between 0 and 1.
**Parameters:**
- `array` (numpy array): The input raster array to be normalized.
---
### plot(file, bands=(3, 2, 1), cmap='viridis', title='Raster photo', ax=None)
Displays a raster image using specified bands, allowing visualization of multi-band or single-band images.
**Parameters:**
- `file` (str): Path to the raster file.
- `bands` (tuple): Bands to be displayed (default is (3, 2, 1) for RGB).
- `cmap` (str): Colormap to be used (default is 'viridis').
- `title` (str): Title for the plot (default is 'Raster photo').
- `ax` (matplotlib.axes.Axes): Optional axes object to plot on.
---
### contour(file)
Plots a raster image with overlaid contours to visualize elevation changes or continuous data variations.
**Parameters:**
- `file` (str): Path to the raster file.
---
### hist(file, bin=50, title="Histogram")
Plots a histogram of raster values to display the distribution of pixel intensities.
**Parameters:**
- `file` (str): Path to the raster file.
- `bin` (int): Number of bins for the histogram (default is 50).
- `title` (str): Title for the histogram plot (default is "Histogram").
---
### haversine(lon1: float, lat1: float, lon2: float, lat2: float) -> float
Calculates the great-circle distance between two geographical points using latitude and longitude.
**Parameters:**
- `lon1` (float): Longitude of the first point.
- `lat1` (float): Latitude of the first point.
- `lon2` (float): Longitude of the second point.
- `lat2` (float): Latitude of the second point.
**Returns:**
- float: The distance between the two points in kilometers.
---
### stack(input_files, output_file, band_names=None)
Stacks multiple raster files into a single multi-band raster file.
**Parameters:**
- `input_files` (list): List of paths to input raster files.
- `output_file` (str): Path to the output stacked raster file.
- `band_names` (list): Optional list of names for the output bands.
---
### bandnames(input_raster, band_names)
Updates the names of bands in a raster file to provide meaningful descriptions.
**Parameters:**
- `input_raster` (str): Path to the input raster file.
- `band_names` (list): List of new names for the raster bands.
---
### getFeatures(geo)
Retrieves geometric features from a given geographical input.
**Parameters:**
- `geo` (GeoDataFrame): Input GeoDataFrame containing the geometries.
---
### clip(raster_file, shapefile, output_file, epsg_code=4326)
Clips a raster file using a shapefile polygon and exports the result to a new raster file.
**Parameters:**
- `raster_file` (str): Path to the input raster file.
- `shapefile` (str): Path to the shapefile used for clipping.
- `output_file` (str): Path to the output clipped raster file.
- `epsg_code` (int): EPSG code for the output raster (default is 4326).
---
### extract(rf, shp, all_touched=False)
Extracts pixel values from a raster based on geometries in a shapefile, storing results in a GeoDataFrame.
**Parameters:**
- `rf` (str): Path to the raster file.
- `shp` (str): Path to the shapefile.
- `all_touched` (bool): If True, include all pixels touched by geometries (default is False).
---
### savetif(output, gdf, colname='FVC', input_raster=None, resolution=10, dtype=rasterio.float32)
Converts vector data into a raster file and burns values from a GeoDataFrame column into the raster.
**Parameters:**
- `output` (str): Path to the output raster file.
- `gdf` (GeoDataFrame): Input GeoDataFrame containing geometries and values.
- `colname` (str): Column name in the GeoDataFrame to use for raster values (default is 'FVC').
- `input_raster` (str): Optional path to an input raster for reference.
- `resolution` (int): Desired resolution for the output raster (default is 10).
- `dtype`: Data type for the output raster (default is rasterio.float32).
---
### mergecsv(path, outfile='combined_all.csv')
Combines multiple CSV files from a specified directory into a single CSV file.
**Parameters:**
- `path` (str): Path to the directory containing CSV files.
- `outfile` (str): Name of the output merged CSV file (default is 'combined_all.csv').
---
### reproject(input_raster, output_raster, target_crs)
Reprojects a raster to a different coordinate reference system (CRS).
**Parameters:**
- `input_raster` (str): Path to the input raster file.
- `output_raster` (str): Path to the output reprojected raster file.
- `target_crs`: Target coordinate reference system.
---
### ndvi(red_band, nir_band)
Calculates the Normalized Difference Vegetation Index (NDVI) from red and near-infrared bands.
**Parameters:**
- `red_band` (numpy array): The red band values.
- `nir_band` (numpy array): The NIR band values.
---
### zonalstats(raster_file, vector_file, stats=['mean', 'max', 'min', 'std'])
Calculates zonal statistics for each polygon in a vector file based on underlying raster values.
**Parameters:**
- `raster_file` (str): Path to the input raster file.
- `vector_file` (str): Path to the input vector file.
- `stats` (list): List of statistics to calculate (default is ['mean', 'max', 'min', 'std']).
---
### convras(raster_file, output_shapefile, field_name='value')
Converts a raster to a vector format (polygons).
**Parameters:**
- `raster_file` (str): Path to the input raster file.
- `output_shapefile` (str): Path to the output shapefile.
- `field_name` (str): Name of the field to store raster values (default is 'value').
---
### resample(input_raster, output_raster, scale_factor=2, resampling_method='bilinear')
Resamples a raster to a different resolution using a specified scale factor and resampling method.
**Parameters:**
- `input_raster` (str): Path to the input raster file.
- `output_raster` (str): Path to the output resampled raster file.
- `scale_factor` (float): Scale factor for resampling (default is 2).
- `resampling_method` (str): Resampling method to use (default is 'bilinear').
---
### stats(raster_file)
Calculates basic statistics (min, max, mean, std) for a raster file.
**Parameters:**
- `raster_file` (str): Path to the input raster file.
---
Raw data
{
"_id": null,
"home_page": "https://github.com/tnmthai/rasteric",
"name": "rasteric",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Thai Tran",
"author_email": "me@tnmthai.com",
"download_url": "https://files.pythonhosted.org/packages/43/71/018404652ee958d91f6609130b998a4048e71e390a635b0e8c09ab986871/rasteric-1.0.0.tar.gz",
"platform": null,
"description": "\n# Rasteric: A Comprehensive Geospatial Library\n\n**Rasteric** is a comprehensive library for geospatial data preprocessing, analysis, and modeling. It provides a variety of functions for transforming and manipulating geospatial data, including:\n\n- Data normalization with `norm()`\n- Resampling using `resample()`\n- Feature extraction through `extract()`\n\nIt also offers analytical techniques such as:\n\n- `zonalstats()` for spatial analysis\n- `ndvi()` for vegetation index calculation\n- `haversine()` for distance calculations\n\n## Supported Data Formats\n\nRasteric is designed to work with multiple geospatial data formats, including:\n\n- Shapefiles\n- GeoJSON\n- Raster data\n\n## Key Functions\n\n### Data Handling\n- `convpath()` for file path handling\n- `stack_rasters()` for combining multiple rasters\n- `convras()` for converting rasters to vector format\n\n### Visualization\n- `plot()` for displaying raster data\n- `contour()` for creating contour plots\n- `hist()` for histogram generation\n\n### Data Manipulation\n- `clipraster()` for cropping rasters\n- `reproject_raster()` for coordinate system transformations\n- `bandnames()` for managing raster band information\n\n### Utilities\n- `mergecsv()` for combining data files\n- `savetif()` for saving processed data\n\n## Integration and Applications\n\nRasteric integrates seamlessly with popular geospatial tools and platforms, enhancing its functionality with features like:\n\n- `getFeatures()` for working with vector data\n- `stats()` for quick raster statistics\n\nWidely used in the geospatial industry, research, and open-source communities, Rasteric facilitates:\n\n- Development of geospatial applications\n- Performance of spatial analysis\n- Modeling of complex geospatial phenomena\n\nIts diverse set of functions, including `zonalstats()`, `ndvi()`, and `resample()`, make it a versatile tool for a wide range of geospatial tasks.\n\n## Example:\n\n```python\nfrom rasteric import raster\nfrom matplotlib import pyplot\n\nfig, (axr, axg, axb) = pyplot.subplots(1, 3, figsize=(21, 7))\n\nfig, (axr, axg, axb) = pyplot.subplots(1, 3, figsize=(21, 7))\n\nraster.plot('T60GVV.tif', bands=[3], ax=axr, title=\"Red\", brightness_factor=5)\nraster.plot('IMG_001_clip.tif', bands=[4,2,1], ax=axg, title=\"Green\", brightness_factor=5)\nraster.plot('IMG_001_clip.tif', bands=[4], ax=axb, title=\"Red\")\n\n```\n\n![Example Image](https://github.com/tnmthai/geotran/blob/main/image.png)\n```python\nclip(raster_file, shapefile, output_file)\n```\n\n---\n\n## Function Descriptions\n### convpath(file_path)\nConverts a Windows-style file path to a Unix-style path for cross-platform compatibility.\n\n**Parameters:**\n- `file_path` (str): The input file path to be converted.\n\n---\n\n### norm(array)\nApplies min-max normalization to a raster array, adjusting pixel values between 0 and 1.\n\n**Parameters:**\n- `array` (numpy array): The input raster array to be normalized.\n\n---\n\n### plot(file, bands=(3, 2, 1), cmap='viridis', title='Raster photo', ax=None)\nDisplays a raster image using specified bands, allowing visualization of multi-band or single-band images.\n\n**Parameters:**\n- `file` (str): Path to the raster file.\n- `bands` (tuple): Bands to be displayed (default is (3, 2, 1) for RGB).\n- `cmap` (str): Colormap to be used (default is 'viridis').\n- `title` (str): Title for the plot (default is 'Raster photo').\n- `ax` (matplotlib.axes.Axes): Optional axes object to plot on.\n\n---\n\n### contour(file)\nPlots a raster image with overlaid contours to visualize elevation changes or continuous data variations.\n\n**Parameters:**\n- `file` (str): Path to the raster file.\n\n---\n\n### hist(file, bin=50, title=\"Histogram\")\nPlots a histogram of raster values to display the distribution of pixel intensities.\n\n**Parameters:**\n- `file` (str): Path to the raster file.\n- `bin` (int): Number of bins for the histogram (default is 50).\n- `title` (str): Title for the histogram plot (default is \"Histogram\").\n\n---\n\n### haversine(lon1: float, lat1: float, lon2: float, lat2: float) -> float\nCalculates the great-circle distance between two geographical points using latitude and longitude.\n\n**Parameters:**\n- `lon1` (float): Longitude of the first point.\n- `lat1` (float): Latitude of the first point.\n- `lon2` (float): Longitude of the second point.\n- `lat2` (float): Latitude of the second point.\n\n**Returns:**\n- float: The distance between the two points in kilometers.\n\n---\n\n### stack(input_files, output_file, band_names=None)\nStacks multiple raster files into a single multi-band raster file.\n\n**Parameters:**\n- `input_files` (list): List of paths to input raster files.\n- `output_file` (str): Path to the output stacked raster file.\n- `band_names` (list): Optional list of names for the output bands.\n\n---\n\n### bandnames(input_raster, band_names)\nUpdates the names of bands in a raster file to provide meaningful descriptions.\n\n**Parameters:**\n- `input_raster` (str): Path to the input raster file.\n- `band_names` (list): List of new names for the raster bands.\n\n---\n\n### getFeatures(geo)\nRetrieves geometric features from a given geographical input.\n\n**Parameters:**\n- `geo` (GeoDataFrame): Input GeoDataFrame containing the geometries.\n\n---\n\n### clip(raster_file, shapefile, output_file, epsg_code=4326)\nClips a raster file using a shapefile polygon and exports the result to a new raster file.\n\n**Parameters:**\n- `raster_file` (str): Path to the input raster file.\n- `shapefile` (str): Path to the shapefile used for clipping.\n- `output_file` (str): Path to the output clipped raster file.\n- `epsg_code` (int): EPSG code for the output raster (default is 4326).\n\n---\n\n### extract(rf, shp, all_touched=False)\nExtracts pixel values from a raster based on geometries in a shapefile, storing results in a GeoDataFrame.\n\n**Parameters:**\n- `rf` (str): Path to the raster file.\n- `shp` (str): Path to the shapefile.\n- `all_touched` (bool): If True, include all pixels touched by geometries (default is False).\n\n---\n\n### savetif(output, gdf, colname='FVC', input_raster=None, resolution=10, dtype=rasterio.float32)\nConverts vector data into a raster file and burns values from a GeoDataFrame column into the raster.\n\n**Parameters:**\n- `output` (str): Path to the output raster file.\n- `gdf` (GeoDataFrame): Input GeoDataFrame containing geometries and values.\n- `colname` (str): Column name in the GeoDataFrame to use for raster values (default is 'FVC').\n- `input_raster` (str): Optional path to an input raster for reference.\n- `resolution` (int): Desired resolution for the output raster (default is 10).\n- `dtype`: Data type for the output raster (default is rasterio.float32).\n\n---\n\n### mergecsv(path, outfile='combined_all.csv')\nCombines multiple CSV files from a specified directory into a single CSV file.\n\n**Parameters:**\n- `path` (str): Path to the directory containing CSV files.\n- `outfile` (str): Name of the output merged CSV file (default is 'combined_all.csv').\n\n---\n\n### reproject(input_raster, output_raster, target_crs)\nReprojects a raster to a different coordinate reference system (CRS).\n\n**Parameters:**\n- `input_raster` (str): Path to the input raster file.\n- `output_raster` (str): Path to the output reprojected raster file.\n- `target_crs`: Target coordinate reference system.\n\n---\n\n### ndvi(red_band, nir_band)\nCalculates the Normalized Difference Vegetation Index (NDVI) from red and near-infrared bands.\n\n**Parameters:**\n- `red_band` (numpy array): The red band values.\n- `nir_band` (numpy array): The NIR band values.\n\n---\n\n### zonalstats(raster_file, vector_file, stats=['mean', 'max', 'min', 'std'])\nCalculates zonal statistics for each polygon in a vector file based on underlying raster values.\n\n**Parameters:**\n- `raster_file` (str): Path to the input raster file.\n- `vector_file` (str): Path to the input vector file.\n- `stats` (list): List of statistics to calculate (default is ['mean', 'max', 'min', 'std']).\n\n---\n\n### convras(raster_file, output_shapefile, field_name='value')\nConverts a raster to a vector format (polygons).\n\n**Parameters:**\n- `raster_file` (str): Path to the input raster file.\n- `output_shapefile` (str): Path to the output shapefile.\n- `field_name` (str): Name of the field to store raster values (default is 'value').\n\n---\n\n### resample(input_raster, output_raster, scale_factor=2, resampling_method='bilinear')\nResamples a raster to a different resolution using a specified scale factor and resampling method.\n\n**Parameters:**\n- `input_raster` (str): Path to the input raster file.\n- `output_raster` (str): Path to the output resampled raster file.\n- `scale_factor` (float): Scale factor for resampling (default is 2).\n- `resampling_method` (str): Resampling method to use (default is 'bilinear').\n\n---\n\n### stats(raster_file)\nCalculates basic statistics (min, max, mean, std) for a raster file.\n\n**Parameters:**\n- `raster_file` (str): Path to the input raster file.\n\n---\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Comprehensive Geospatial Library",
"version": "1.0.0",
"project_urls": {
"Bug Tracker": "https://github.com/tnmthai/rasteric/issues",
"Homepage": "https://github.com/tnmthai/rasteric",
"repository": "https://github.com/tnmthai/rasteric"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8fe080ddbe792617b60b5bfed7c656320d5a5ad959bec3ac24c6e8cca22624d1",
"md5": "6fd7b04575c7871ee4c5a1cb84bfeb0e",
"sha256": "705f81a92dd3ad84de4b0cb9076abd9f9d7bef72979b81d11b652331c112c1ff"
},
"downloads": -1,
"filename": "rasteric-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6fd7b04575c7871ee4c5a1cb84bfeb0e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 18482,
"upload_time": "2024-10-15T22:14:16",
"upload_time_iso_8601": "2024-10-15T22:14:16.435891Z",
"url": "https://files.pythonhosted.org/packages/8f/e0/80ddbe792617b60b5bfed7c656320d5a5ad959bec3ac24c6e8cca22624d1/rasteric-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4371018404652ee958d91f6609130b998a4048e71e390a635b0e8c09ab986871",
"md5": "a021091a746b1d3a9edab00dfa477221",
"sha256": "fec4cd6e4f2ceab2f75cede9a852c923fced09fa26852d5527473e95445a924c"
},
"downloads": -1,
"filename": "rasteric-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "a021091a746b1d3a9edab00dfa477221",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 18233,
"upload_time": "2024-10-15T22:14:17",
"upload_time_iso_8601": "2024-10-15T22:14:17.769731Z",
"url": "https://files.pythonhosted.org/packages/43/71/018404652ee958d91f6609130b998a4048e71e390a635b0e8c09ab986871/rasteric-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-15 22:14:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tnmthai",
"github_project": "rasteric",
"github_not_found": true,
"lcname": "rasteric"
}