import rastereasy
Save an image
General note
For almost all functions (reprojection, resampling, etc.), there is a dest_name
parameter where you can specify a destination to save the image (in .tif
or .jp2
format). Otherwise, you can use the .save()
function at any time.
name_im = './data/demo/sentinel.tif'
image=rastereasy.Geoimage(name_im)
help(image.save)
Help on method save in module rastereasy.rastereasy:
save(dest_name) method of rastereasy.rastereasy.Geoimage instance
Save the image to a GeoTIFF or JPEG2000 file.
This method writes the image data and all its metadata (projection, transform,
etc.) to a georeferenced file that can be read by most geospatial software.
Parameters
----------
dest_name : str
Path to save the image. File format is determined by the extension:
- .tif or .tiff: GeoTIFF format
- .jp2: JPEG2000 format
Returns
-------
None
Examples
--------
>>> # Save as GeoTIFF
>>> image.save("output.tif")
>>>
>>> # Save as JPEG2000
>>> image.save("output.jp2")
Notes
-----
- GeoTIFF (.tif) is the most widely supported format
- JPEG2000 (.jp2) offers compression and is good for large images
- The saved file will include all metadata (projection, transform, etc.)
- To save a subset of bands, first use select_bands() to create a new image with only the desired bands, then save that image
Example for modifying the image and save it
image_crop = image.crop(50,100,50,100,dest_name='image_crop1.tif')
# equivalent to
image_crop.save('image_crop2.tif')
# save to jp2
image_crop.save('image_crop2.jp2')
# Check that the driver is tif
rastereasy.Geoimage('image_crop2.tif').info()
- Size of the image:
- Rows (height): 50
- Cols (width): 50
- Bands: 12
- Spatial resolution: 10.0 meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.07938967, 38.35205966)
- Driver: GTiff
- Data type: int16
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands:
{'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}
# Check that the driver is jp2
rastereasy.Geoimage('image_crop2.jp2').info()
- Size of the image:
- Rows (height): 50
- Cols (width): 50
- Bands: 12
- Spatial resolution: 10.0 meters / degree (depending on projection system)
- Central point latitude - longitude coordinates: (7.07938967, 38.35205966)
- Driver: JP2OpenJPEG
- Data type: int16
- Projection system: EPSG:32637
- Nodata: -32768.0
- Given names for spectral bands:
{'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, '10': 10, '11': 11, '12': 12}