ncols 1926 nrows 2752 xllcenter 533993.691804 yllcenter 3247644.275250 cellsize 15.000000 NODATA_value -9999 -9999 -9999 -9999 -9999 -9999 ... -9999 -9999 -9999 0.0 0.0 ... -9999 -9999 -9999 0.0 0.0 ... -9999 -9999 -9999 123.4 123.4 ... ...
Solved! Go to Solution.
file = open(r"C:\WorkSpace\Grid.asc") nCols = file.readline() nRows = file.readline() xllCenter = file.readline() yllCenter = file.readline() cellSize = file.readline() file.close() nCols = re.sub('ncols', '', re.sub('\s','',nCols)) nRows = re.sub('nrows', '', re.sub('\s','',nRows)) xllCenter = float(re.sub('xllcenter', '', re.sub('\s','',xllCenter))) yllCenter = float(re.sub('yllcenter', '', re.sub('\s','',yllCenter))) cellSize = float(re.sub('cellsize', '', re.sub('\s','',cellSize))) # subtract half the cell size to get the coordinates at the lower left corner of the cell, not the exact center xllCenterAdjust = xllCenter - 7.5 yllCenterAdjust = yllCenter - 7.5 pointX = 534557.7644 pointY = 3248152.003 xColumn = ((pointX - xllCenterAdjust)/cellSize) yColumn = ((pointY - yllCenterAdjust)/cellSize) print xColumn print yColumn
file = open(r"C:\WorkSpace\Grid.asc") nCols = file.readline() nRows = file.readline() xllCenter = file.readline() yllCenter = file.readline() cellSize = file.readline() file.close() nCols = re.sub('ncols', '', re.sub('\s','',nCols)) nRows = re.sub('nrows', '', re.sub('\s','',nRows)) xllCenter = float(re.sub('xllcenter', '', re.sub('\s','',xllCenter))) yllCenter = float(re.sub('yllcenter', '', re.sub('\s','',yllCenter))) cellSize = float(re.sub('cellsize', '', re.sub('\s','',cellSize))) # subtract half the cell size to get the coordinates at the lower left corner of the cell, not the exact center xllCenterAdjust = xllCenter - 7.5 yllCenterAdjust = yllCenter - 7.5 pointX = 534557.7644 pointY = 3248152.003 xColumn = ((pointX - xllCenterAdjust)/cellSize) yColumn = ((pointY - yllCenterAdjust)/cellSize) print xColumn print yColumn
Column = (CurrentXcoordinate - XLLcenter) / Cellsize
Row = (nrows -1) - (CurrentYcoordinate - YLLcenter) / Cellsize
Why did you include "(nrows-1) -" to calculate the row?