Skip to main content
deleted 1 character in body
Source Link
Paul H
  • 915
  • 5
  • 17

I would create a new raster dataset with the oceans masked out. Assuming any cell with an elevation less than or equal to zero, I would do:

import numpy
import rasterio
with rasterio.open('path/to/orig.tif', 'r') as orig:
    land_and_sea = orig.read(1)
    meta_data = orig.meta.copy()

nodata_value = -9999
meta_data['nodata'] = nodata_value
with rasterio.open('/path/to/masked.tif', 'w', **meta_data) as masked:
    land_only = numpy.where(land_and_sea >=> 0, land_and_sea, nodata_value)
    masked.write(land_only, 1)

Then you'd repeat the process of generating the stream network.

Alternatively, you could create a polygon from the masked raster and clip the stream to that polygon.

I would create a new raster dataset with the oceans masked out. Assuming any cell with an elevation less than or equal to zero, I would do:

import numpy
import rasterio
with rasterio.open('path/to/orig.tif', 'r') as orig:
    land_and_sea = orig.read(1)
    meta_data = orig.meta.copy()

nodata_value = -9999
meta_data['nodata'] = nodata_value
with rasterio.open('/path/to/masked.tif', 'w', **meta_data) as masked:
    land_only = numpy.where(land_and_sea >= 0, land_and_sea, nodata_value)
    masked.write(land_only, 1)

Then you'd repeat the process of generating the stream network.

Alternatively, you could create a polygon from the masked raster and clip the stream to that polygon.

I would create a new raster dataset with the oceans masked out. Assuming any cell with an elevation less than or equal to zero, I would do:

import numpy
import rasterio
with rasterio.open('path/to/orig.tif', 'r') as orig:
    land_and_sea = orig.read(1)
    meta_data = orig.meta.copy()

nodata_value = -9999
meta_data['nodata'] = nodata_value
with rasterio.open('/path/to/masked.tif', 'w', **meta_data) as masked:
    land_only = numpy.where(land_and_sea > 0, land_and_sea, nodata_value)
    masked.write(land_only, 1)

Then you'd repeat the process of generating the stream network.

Alternatively, you could create a polygon from the masked raster and clip the stream to that polygon.

added 171 characters in body
Source Link
Paul H
  • 915
  • 5
  • 17

I would create a new raster dataset with the ocean'soceans masked out. Assuming any cell with an elevation less than or equal to zero, I would do:

import numpy
import rasterio
with rasterio.open('path/to/orig.tif', 'r') as orig:
    land_and_sea = orig.read(1)
    meta_data = orig.meta.copy()

nodata_value = -9999
meta_data['nodata'] = nodata_value
with rasterio.open('/path/to/masked.tif', 'w', **meta_data) as masked:
    land_only = numpy.where(land_and_sea >= 0, land_and_sea, nodata_value)
    masked.write(land_only, 1)

Then you'd repeat the process of generating the stream network.

Alternatively, you could create a polygon from the masked raster and clip the stream to that polygon.

I would create a new raster dataset with the ocean's masked out. Assuming any cell with an elevation less than or equal to zero, I would do:

import numpy
import rasterio
with rasterio.open('path/to/orig.tif', 'r') as orig:
    land_and_sea = orig.read(1)
    meta_data = orig.meta.copy()

nodata_value = -9999
meta_data['nodata'] = nodata_value
with rasterio.open('/path/to/masked.tif', 'w', **meta_data) as masked:
    land_only = numpy.where(land_and_sea >= 0, land_and_sea, nodata_value)
    masked.write(land_only, 1)

I would create a new raster dataset with the oceans masked out. Assuming any cell with an elevation less than or equal to zero, I would do:

import numpy
import rasterio
with rasterio.open('path/to/orig.tif', 'r') as orig:
    land_and_sea = orig.read(1)
    meta_data = orig.meta.copy()

nodata_value = -9999
meta_data['nodata'] = nodata_value
with rasterio.open('/path/to/masked.tif', 'w', **meta_data) as masked:
    land_only = numpy.where(land_and_sea >= 0, land_and_sea, nodata_value)
    masked.write(land_only, 1)

Then you'd repeat the process of generating the stream network.

Alternatively, you could create a polygon from the masked raster and clip the stream to that polygon.

Source Link
Paul H
  • 915
  • 5
  • 17

I would create a new raster dataset with the ocean's masked out. Assuming any cell with an elevation less than or equal to zero, I would do:

import numpy
import rasterio
with rasterio.open('path/to/orig.tif', 'r') as orig:
    land_and_sea = orig.read(1)
    meta_data = orig.meta.copy()

nodata_value = -9999
meta_data['nodata'] = nodata_value
with rasterio.open('/path/to/masked.tif', 'w', **meta_data) as masked:
    land_only = numpy.where(land_and_sea >= 0, land_and_sea, nodata_value)
    masked.write(land_only, 1)