MCPcopy
hub / github.com/django/django / test_raster_warp

Method test_raster_warp

tests/gis_tests/gdal_tests/test_raster.py:466–538  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

464 self.assertIn("Block=40x23", compressed.info)
465
466 def test_raster_warp(self):
467 # Create in memory raster
468 source = GDALRaster(
469 {
470 "datatype": 1,
471 "driver": "MEM",
472 "name": "sourceraster",
473 "width": 4,
474 "height": 4,
475 "nr_of_bands": 1,
476 "srid": 3086,
477 "origin": (500000, 400000),
478 "scale": (100, -100),
479 "skew": (0, 0),
480 "bands": [
481 {
482 "data": range(16),
483 "nodata_value": 255,
484 }
485 ],
486 }
487 )
488
489 # Test altering the scale, width, and height of a raster
490 data = {
491 "scale": [200, -200],
492 "width": 2,
493 "height": 2,
494 }
495 target = source.warp(data)
496 self.assertEqual(target.width, data["width"])
497 self.assertEqual(target.height, data["height"])
498 self.assertEqual(target.scale, data["scale"])
499 self.assertEqual(target.bands[0].datatype(), source.bands[0].datatype())
500 self.assertEqual(target.name, "sourceraster_copy.MEM")
501 result = target.bands[0].data()
502 if numpy:
503 result = result.flatten().tolist()
504 self.assertEqual(result, [5, 7, 13, 15])
505
506 # Test altering the name and datatype (to float)
507 data = {
508 "name": "/path/to/targetraster.tif",
509 "datatype": 6,
510 }
511 target = source.warp(data)
512 self.assertEqual(target.bands[0].datatype(), 6)
513 self.assertEqual(target.name, "/path/to/targetraster.tif")
514 self.assertEqual(target.driver.name, "MEM")
515 result = target.bands[0].data()
516 if numpy:
517 result = result.flatten().tolist()
518 self.assertEqual(
519 result,
520 [
521 0.0,
522 1.0,
523 2.0,

Callers

nothing calls this directly

Calls 5

warpMethod · 0.95
GDALRasterClass · 0.90
datatypeMethod · 0.80
dataMethod · 0.45
flattenMethod · 0.45

Tested by

no test coverage detected