Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Temperaturverteilung
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s39174
Temperaturverteilung
Commits
7d90010a
Commit
7d90010a
authored
3 years ago
by
Clemens Berteld
Browse files
Options
Downloads
Patches
Plain Diff
Added attribute "transparent" in db
parent
b5df86ac
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dataacquisition/ExportToDatabase.py
+7
-6
7 additions, 6 deletions
dataacquisition/ExportToDatabase.py
dataacquisition/sandbox_rasterize.py
+14
-0
14 additions, 0 deletions
dataacquisition/sandbox_rasterize.py
dataacquisition/vectorlayer.qgz
+0
-0
0 additions, 0 deletions
dataacquisition/vectorlayer.qgz
with
21 additions
and
6 deletions
dataacquisition/ExportToDatabase.py
+
7
−
6
View file @
7d90010a
...
...
@@ -73,7 +73,7 @@ def check_for_db_existence(cursor):
def
create_table
(
station_list
,
cursor
):
print
(
'
Creating table stations
'
)
df_columns
=
list
(
station_list
)
columns
=
[
'
station_id INTEGER
'
,
'
lon NUMERIC
'
,
'
lat NUMERIC
'
,
'
country TEXT
'
,
'
file TEXT
'
]
columns
=
[
'
station_id INTEGER
'
,
'
lon NUMERIC
'
,
'
lat NUMERIC
'
,
'
country TEXT
'
,
'
file TEXT
'
,
'
transparent BOOL
'
]
for
column
in
df_columns
:
if
str
(
column
).
startswith
(
'
19
'
)
or
str
(
column
).
startswith
(
'
20
'
):
columns
.
append
(
'"
{}
"
NUMERIC
'
.
format
(
column
))
...
...
@@ -91,7 +91,7 @@ def insert_empty_matrix_into_db(cursor):
print
(
'
Inserting empty matrix into database
'
)
matrix_density
=
param_interpol
[
'
matrix_density
'
]
with
open
(
'
clipped_
matrix_{}x{}.csv
'
.
format
(
matrix_density
,
matrix_density
),
'
r
'
)
as
matrix
:
with
open
(
'
matrix_{}x{}
_4326_with_transparency
.csv
'
.
format
(
matrix_density
,
matrix_density
),
'
r
'
)
as
matrix
:
matrix_data
=
matrix
.
readlines
()
matrix_points
=
0
for
line
in
matrix_data
[
1
:]:
...
...
@@ -99,13 +99,14 @@ def insert_empty_matrix_into_db(cursor):
values
=
''
# Used in second parameter of cursor.execute() (Avoids SQL injection)
data
=
line
.
split
(
'
;
'
)
id
=
int
(
"
9999
"
+
data
[
0
].
replace
(
'"'
,
''
))
lon
=
float
(
data
[
1
])
transparent
=
data
[
1
]
lon
=
float
(
data
[
3
])
lat
=
float
(
data
[
2
].
replace
(
'
\n
'
,
''
))
for
n
in
[
id
,
lon
,
lat
]:
for
n
in
[
id
,
transparent
,
lon
,
lat
]:
values
=
(
*
values
,
n
)
# adding n to existing tuple
query
=
sql
.
SQL
(
"
INSERT INTO STATIONS (station_id, lon, lat, country)
"
"
VALUES ({id}, {lon}, {lat},
'
Germany
'
);
"
).
format
(
id
=
sql
.
Placeholder
(),
lon
=
sql
.
Placeholder
(),
lat
=
sql
.
Placeholder
())
query
=
sql
.
SQL
(
"
INSERT INTO STATIONS (station_id,
transparent,
lon, lat, country)
"
"
VALUES ({id},
{transparent},
{lon}, {lat},
'
Germany
'
);
"
).
format
(
id
=
sql
.
Placeholder
(),
transparent
=
sql
.
Placeholder
(),
lon
=
sql
.
Placeholder
(),
lat
=
sql
.
Placeholder
())
# print(query.as_string(cursor))
# print(values)
cursor
.
execute
(
query
,
values
)
...
...
This diff is collapsed.
Click to expand it.
dataacquisition/sandbox_rasterize.py
0 → 100644
+
14
−
0
View file @
7d90010a
import
configparser
import
psycopg2
cfg
=
configparser
.
ConfigParser
()
cfg
.
read
(
'
../config.ini
'
)
assert
"
POSTGRES
"
in
cfg
,
"
missing POSTGRES in config.ini
"
param_postgres
=
cfg
[
"
POSTGRES
"
]
with
psycopg2
.
connect
(
database
=
param_postgres
[
"
dbName
"
],
user
=
param_postgres
[
"
user
"
],
password
=
param_postgres
[
"
password
"
],
host
=
param_postgres
[
"
host
"
],
port
=
param_postgres
[
"
port
"
])
as
connection
:
with
connection
.
cursor
()
as
cursor
:
cursor
.
execute
(
'
select st_astext(square) from stations where file is null
'
)
results
=
cursor
.
fetchall
()
for
result
in
results
:
print
(
result
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
dataacquisition/vectorlayer.qgz
+
0
−
0
View file @
7d90010a
No preview for this file type
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment