Return a copy of this raster reprojected into the given spatial reference system.
(
self, srs, driver=None, name=None, resampling="NearestNeighbour", max_error=0.0
)
| 482 | ) |
| 483 | |
| 484 | def transform( |
| 485 | self, srs, driver=None, name=None, resampling="NearestNeighbour", max_error=0.0 |
| 486 | ): |
| 487 | """ |
| 488 | Return a copy of this raster reprojected into the given spatial |
| 489 | reference system. |
| 490 | """ |
| 491 | # Convert the resampling algorithm name into an algorithm id |
| 492 | algorithm = GDAL_RESAMPLE_ALGORITHMS[resampling] |
| 493 | |
| 494 | if isinstance(srs, SpatialReference): |
| 495 | target_srs = srs |
| 496 | elif isinstance(srs, (int, str)): |
| 497 | target_srs = SpatialReference(srs) |
| 498 | else: |
| 499 | raise TypeError( |
| 500 | "Transform only accepts SpatialReference, string, and integer " |
| 501 | "objects." |
| 502 | ) |
| 503 | |
| 504 | if target_srs.srid == self.srid and (not driver or driver == self.driver.name): |
| 505 | return self.clone(name) |
| 506 | # Create warped virtual dataset in the target reference system |
| 507 | target = capi.auto_create_warped_vrt( |
| 508 | self._ptr, |
| 509 | self.srs.wkt.encode(), |
| 510 | target_srs.wkt.encode(), |
| 511 | algorithm, |
| 512 | max_error, |
| 513 | c_void_p(), |
| 514 | ) |
| 515 | target = GDALRaster(target) |
| 516 | |
| 517 | # Construct the target warp dictionary from the virtual raster |
| 518 | data = { |
| 519 | "srid": target_srs.srid, |
| 520 | "width": target.width, |
| 521 | "height": target.height, |
| 522 | "origin": [target.origin.x, target.origin.y], |
| 523 | "scale": [target.scale.x, target.scale.y], |
| 524 | "skew": [target.skew.x, target.skew.y], |
| 525 | } |
| 526 | |
| 527 | # Set the driver and filepath if provided |
| 528 | if driver: |
| 529 | data["driver"] = driver |
| 530 | |
| 531 | if name: |
| 532 | data["name"] = name |
| 533 | |
| 534 | # Warp the raster into new srid |
| 535 | return self.warp(data, resampling=resampling, max_error=max_error) |
| 536 | |
| 537 | @property |
| 538 | def info(self): |