Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Hoek, Steven
lmgeo
Commits
e5aa84db
Commit
e5aa84db
authored
Apr 15, 2016
by
Hoek, Steven
Browse files
Merge branch 'master' of
https://github.com//sbhoek/lmgeo
Conflicts: .gitignore
parents
a7859ff2
7974848a
Changes
1
Show whitespace changes
Inline
Side-by-side
formats/inmemoryraster.py
0 → 100644
View file @
e5aa84db
from
gridenvelope2d
import
GridEnvelope2D
;
from
raster
import
Raster
import
numpy
as
np
import
const
class
InMemoryRaster
(
GridEnvelope2D
,
Raster
):
"A raster developed in the first place for testing purposes"
# Data attributes
data
=
None
__datatype
=
None
__open
=
False
dataformat
=
'f'
def
__init__
(
self
,
filepath
,
data
=
None
,
*
datatype
):
Raster
.
__init__
(
self
,
filepath
)
if
data
!=
None
:
self
.
data
=
data
if
len
(
datatype
)
>
0
:
if
(
datatype
[
0
]
==
const
.
INTEGER
):
self
.
__datatype
=
const
.
INTEGER
;
self
.
dataformat
=
'i'
else
:
self
.
__datatype
=
const
.
FLOAT
;
self
.
dataformat
=
'f'
def
open
(
self
,
mode
,
ncols
=
1
,
nrows
=
1
,
xll
=
0.0
,
yll
=
0.0
,
cellsize
=
1.0
,
nodatavalue
=-
9999.0
):
super
(
InMemoryRaster
,
self
).
open
(
mode
);
self
.
__open
=
True
if
self
.
__datatype
==
const
.
INTEGER
:
dtype
=
np
.
int
else
:
dtype
=
np
.
float
if
mode
[
0
]
==
'w'
:
self
.
data
=
np
.
zeros
((
nrows
*
ncols
),
dtype
=
dtype
)
else
:
if
self
.
data
==
None
:
raise
Exception
(
"Memory was not initialised!"
)
self
.
data
=
np
.
array
(
self
.
data
,
dtype
=
dtype
)
self
.
data
=
self
.
data
.
flatten
()
self
.
data
.
shape
=
(
nrows
,
ncols
)
self
.
xll
=
xll
self
.
yll
=
yll
self
.
dx
=
cellsize
self
.
dy
=
cellsize
self
.
nodatavalue
=
nodatavalue
GridEnvelope2D
.
__init__
(
self
,
ncols
,
nrows
,
self
.
xll
,
self
.
yll
,
self
.
dx
,
self
.
dy
)
return
True
;
def
next
(
self
,
parseLine
=
True
):
if
not
self
.
__open
:
raise
Exception
(
"Not yet fully initialised!"
)
self
.
currow
+=
1
;
if
(
self
.
currow
>
self
.
nrows
):
raise
StopIteration
;
if
parseLine
:
return
self
.
data
[
self
.
currow
-
1
,
:]
else
:
return
None
def
writenext
(
self
,
sequence_with_data
):
if
not
self
.
__open
:
raise
Exception
(
"Not yet fully initialised!"
)
self
.
currow
+=
1
;
if
(
self
.
currow
>
self
.
nrows
):
raise
StopIteration
;
if
len
(
sequence_with_data
)
!=
self
.
ncols
:
raise
Exception
(
"Attempt to assign line of wrong length!"
)
self
.
data
[
self
.
currow
-
1
,
:]
=
sequence_with_data
return
True
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment