Created
January 18, 2013 11:53
-
-
Save seumasmorrison/4564138 to your computer and use it in GitHub Desktop.
Takes a numpy array of bathymetry points from a grid ( exportable from a raster in ArcGIS using ArcPy ) and writes a tab separated xyz file, for import into gis or in this case it was written for importing bathymetry as scatter data into DHI MIKE21. Requires a hdr file for width, height, origin and cell size information.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Initial data obtained from hdr file produced with flt file when running | |
# Raster to Float in ArcToolBox and numpy file ( npy ) from RasterToNumpyArray | |
# in ArcPy | |
# Numpy uses top left as origin and geopgraphic coordinate systems treat the | |
# origin as lower left, you can either flip the incoming bathymetry maxtrix | |
# vertically or create a descending range of y_coordinates | |
import numpy as np | |
bathy = np.load('D:\\numpy_bathy.npy') | |
#bathy = np.flipud(bathy) | |
cell_size = 3 | |
no_of_columns = 18325 | |
no_of_rows = 13303 | |
lower_left_x = 607512 | |
lower_left_y = 6455598 | |
lower_right_x = lower_left_x + ( cell_size * no_of_columns ) | |
x_coordinates = np.arange(lower_left_x, lower_right_x, cell_size) | |
upper_left_y = lower_left_y + ( cell_size * no_of_rows ) | |
y_coordinates = np.arange(upper_left_y, lower_left_y, -1 * cell_size) | |
xyz_file = open('D:\\bathymetry_output2.xyz','w') | |
for index_y,y in enumerate(y_coordinates): | |
print index_y | |
for index,x in enumerate(x_coordinates): | |
depth = bathy[index_y,index] | |
if depth > -1000.0 : | |
xyz_file.write(str(x) + '\t' + str(y) + '\t' + str(depth) + '\n') | |
xyz_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment