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
2bf1dade
Commit
2bf1dade
authored
Jul 01, 2021
by
Hoek, Steven
Browse files
Base classes Raster and GridEnvelope2D were revised.
parent
779c6d08
Changes
2
Hide whitespace changes
Inline
Side-by-side
lmgeo/formats/gridenvelope2d.py
View file @
2bf1dade
...
...
@@ -6,10 +6,10 @@ __author__ = "Steven B. Hoek"
# Helper class, to be used together with classes derived from Raster
class
GridEnvelope2D
(
object
):
# Data attributes
nrows
=
1
;
ncols
=
1
;
xll
=
0.0
;
yll
=
0.0
;
__
nrows
=
1
;
__
ncols
=
1
;
__
xll
=
0.0
;
__
yll
=
0.0
;
dx
=
2.0
;
dy
=
2.0
;
xcoords_sort
=
const
.
ASC
;
# ascending
...
...
@@ -19,10 +19,10 @@ class GridEnvelope2D(object):
# We define a grid by means of a number of rows, columns,
# a lower left corner as well as by steps in x and y direction
def
__init__
(
self
,
ncols
,
nrows
,
xll
,
yll
,
dx
,
dy
):
self
.
ncols
=
ncols
;
self
.
nrows
=
nrows
;
self
.
xll
=
xll
;
self
.
yll
=
yll
;
self
.
__
ncols
=
ncols
;
self
.
__
nrows
=
nrows
;
self
.
__
xll
=
xll
;
self
.
__
yll
=
yll
;
self
.
dx
=
dx
;
self
.
dy
=
dy
;
...
...
@@ -32,19 +32,19 @@ class GridEnvelope2D(object):
# The following 4 functions are about the extent of the envelope
def
getMinX
(
self
):
# X-coordinate of the lower left corner
return
self
.
xll
;
return
self
.
__
xll
;
def
getMinY
(
self
):
# Y-coordinate of the lower left corner
return
self
.
yll
;
return
self
.
__
yll
;
def
getMaxX
(
self
):
# X-coordinate of the upper right corner
return
self
.
xll
+
self
.
ncols
*
self
.
dx
;
return
self
.
__
xll
+
self
.
__
ncols
*
self
.
dx
;
def
getMaxY
(
self
):
# Y-coordinate of the upper right corner
return
self
.
yll
+
self
.
nrows
*
self
.
dy
;
return
self
.
__
yll
+
self
.
__
nrows
*
self
.
dy
;
def
getColAndRowIndex
(
self
,
x
,
y
):
# Return the zero-based row and column numbers of the grid cell
...
...
@@ -52,11 +52,11 @@ class GridEnvelope2D(object):
# or from the top downwards (DESC), depending on the way the coordinates are sorted
eps
=
const
.
epsilon
;
# we'll use this constant to prevent negative indices
if
self
.
xcoords_sort
==
const
.
ASC
:
k
=
int
(
round
((
x
-
self
.
xll
-
0.5
*
self
.
dx
+
eps
)
/
self
.
dx
));
k
=
int
(
round
((
x
-
self
.
__
xll
-
0.5
*
self
.
dx
+
eps
)
/
self
.
dx
));
else
:
k
=
int
(
round
((
self
.
getMaxX
()
-
x
-
0.5
*
self
.
dy
+
eps
)
/
self
.
dy
));
# TODO: check
if
self
.
ycoords_sort
==
const
.
ASC
:
i
=
int
(
round
((
y
-
self
.
yll
-
0.5
*
self
.
dy
+
eps
)
/
self
.
dy
));
i
=
int
(
round
((
y
-
self
.
__
yll
-
0.5
*
self
.
dy
+
eps
)
/
self
.
dy
));
else
:
i
=
int
(
round
((
self
.
getMaxY
()
-
y
-
0.5
*
self
.
dy
+
eps
)
/
self
.
dy
));
# TODO: check
return
k
,
i
;
...
...
@@ -75,11 +75,11 @@ class GridEnvelope2D(object):
# Rows are counted from the top downwards
k
,
i
=
self
.
getColAndRowIndex
(
x
,
y
);
if
self
.
xcoords_sort
==
const
.
ASC
:
cx
=
self
.
xll
+
(
k
+
0.5
)
*
self
.
dx
;
cx
=
self
.
__
xll
+
(
k
+
0.5
)
*
self
.
dx
;
else
:
cx
=
self
.
getMaxX
()
-
(
k
+
0.5
)
*
self
.
dx
;
if
self
.
ycoords_sort
==
const
.
ASC
:
cy
=
self
.
yll
+
(
i
+
0.5
)
*
self
.
dy
;
cy
=
self
.
__
yll
+
(
i
+
0.5
)
*
self
.
dy
;
else
:
cy
=
self
.
getMaxY
()
-
(
i
+
0.5
)
*
self
.
dy
;
return
(
cx
,
cy
);
...
...
@@ -92,17 +92,17 @@ class GridEnvelope2D(object):
return
False
;
# Now check the extent
if
self
.
ncols
!=
obj
.
ncols
:
if
self
.
__
ncols
!=
obj
.
ncols
:
return
False
;
if
self
.
nrows
!=
obj
.
nrows
:
if
self
.
__
nrows
!=
obj
.
nrows
:
return
False
;
if
abs
(
self
.
dy
-
obj
.
dy
)
>
epsilon
:
return
False
;
if
abs
(
self
.
dx
-
obj
.
dx
)
>
epsilon
:
return
False
;
if
abs
(
self
.
xll
-
obj
.
xll
)
>
epsilon
:
if
abs
(
self
.
__
xll
-
obj
.
xll
)
>
epsilon
:
return
False
;
if
abs
(
self
.
yll
-
obj
.
yll
)
>
epsilon
:
if
abs
(
self
.
__
yll
-
obj
.
yll
)
>
epsilon
:
return
False
;
else
:
return
True
;
...
...
@@ -149,5 +149,37 @@ class GridEnvelope2D(object):
return
result
def
getEnvelope
(
self
):
return
GridEnvelope2D
(
self
.
ncols
,
self
.
nrows
,
self
.
xll
,
self
.
yll
,
self
.
cellsize
,
self
.
cellsize
)
return
GridEnvelope2D
(
self
.
__ncols
,
self
.
__nrows
,
self
.
__xll
,
self
.
__yll
,
self
.
cellsize
,
self
.
cellsize
)
@
property
def
nrows
(
self
):
return
self
.
__nrows
@
nrows
.
setter
def
nrows
(
self
,
nrows
):
self
.
__nrows
=
nrows
@
property
def
ncols
(
self
):
return
self
.
__ncols
@
ncols
.
setter
def
ncols
(
self
,
ncols
):
self
.
__ncols
=
ncols
@
property
def
xll
(
self
):
return
self
.
__xll
@
xll
.
setter
def
xll
(
self
,
xll
):
self
.
__xll
=
xll
@
property
def
yll
(
self
):
return
self
.
__yll
@
yll
.
setter
def
yll
(
self
,
yll
):
self
.
__yll
=
yll
\ No newline at end of file
lmgeo/formats/raster.py
View file @
2bf1dade
...
...
@@ -13,6 +13,8 @@ class Raster(object):
nodatavalue
=
-
9999.0
;
cellsize
=
1
;
currow
=
0
roty
=
0.0
rotx
=
0.0
file_exists
=
False
def
__init__
(
self
,
filepath
):
...
...
@@ -66,7 +68,6 @@ class Raster(object):
self
.
currow
=
0
;
# TODO: Raster and GridEnvelope2D are often used together; both have dx and dy, so this causes ambiguity!
@
property
def
dx
(
self
):
return
self
.
cellsize
...
...
Write
Preview
Supports
Markdown
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