Hi Claudio,
a long ago I made myself a sub to import an ascii raster.
Here is the code
Oscar
a long ago I made myself a sub to import an ascii raster.
Here is the code
Public Sub ImportAsciiRaster()
Dim linein As String
Dim slin() As String
Dim ncols, nrows As Integer
Dim xll, yll, nodata As Double
Dim cell As Double
'ask the user to specify the file to import
Dim openfiledialog1 As New OpenFileDialog
openfiledialog1.ShowDialog()
Dim frasinput As String
frasinput = openfiledialog1.FileName
'Create a BGD imported raster
Dim frasout As String = System.IO.Path.ChangeExtension(frasinput, "BGD")
'Read the ascii raster file
FileOpen(64, frasinput, OpenMode.Input)
'Header
linein = LineInput(64).Trim()
slin = Regex.Split(linein, "\s+")
If (slin(0).Trim().ToUpper().Contains("NCOLS") = False) Then
MsgBox("Error import. Not a ESRI ascii raster")
Exit Sub
End If
Integer.TryParse(slin(1).Trim(), ncols)
linein = LineInput(64).Trim()
slin = Regex.Split(linein, "\s+")
Integer.TryParse(slin(1).Trim(), nrows)
linein = LineInput(64).Trim()
slin = Regex.Split(linein, "\s+")
Double.TryParse(slin(1).Trim(), xll)
linein = LineInput(64).Trim()
slin = Regex.Split(linein, "\s+")
Double.TryParse(slin(1).Trim(), yll)
linein = LineInput(64).Trim()
slin = Regex.Split(linein, "\s+")
Double.TryParse(slin(1).Trim(), cell) 'you may duplicate this and read a "cellx" and "celly" dimensions
linein = LineInput(64).Trim()
slin = Regex.Split(linein, "\s+")
Double.TryParse(slin(1).Trim(), nodata)
Dim rasopt() As String
ReDim rasopt(1)
rasopt(0) = ""
Dim datatype As System.Type
datatype = GetType(Double)
Dim rasinput As DotSpatial.Data.Raster
rasinput = DotSpatial.Data.Raster.CreateRaster(frasout, Nothing, ncols, nrows, 1, datatype, rasopt)
rasinput.Xllcenter = xll
rasinput.Yllcenter = yll
rasinput.NoDataValue = nodata
rasinput.CellHeight = cell 'Here you may put "celly" read from your ascii file
rasinput.CellWidth = cell 'Here you may put "cellx" read from your ascii file
Dim value As Double
'Reading raster cell values and insert them into rasinput
For i As Integer = 0 To nrows - 1
linein = LineInput(64)
slin = Regex.Split(linein.Trim(), "\s+")
For j As Integer = 0 To ncols - 1
Double.TryParse(slin(j), value)
rasinput.Value(i, j) = value
Next
Next
FileClose(64)
'save results
rasinput.SaveAs(frasout)
Return
End Sub
See if you can get through it Oscar