Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tesi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marco Aceti
Tesi
Commits
9190d399
Verified
Commit
9190d399
authored
2 years ago
by
Marco Aceti
Browse files
Options
Downloads
Patches
Plain Diff
Add geojson station data extractor
parent
0f9d1cdc
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2716
passed
2 years ago
Stage: test
Stage: lint
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.py
+1
-3
1 addition, 3 deletions
main.py
requirements.txt
+1
-0
1 addition, 0 deletions
requirements.txt
src/station_extractor.py
+33
-0
33 additions, 0 deletions
src/station_extractor.py
with
35 additions
and
3 deletions
main.py
+
1
−
3
View file @
9190d399
...
...
@@ -65,9 +65,7 @@ s_extractor.add_argument(
s_extractor
.
add_argument
(
"
-f
"
,
default
=
"
csv
"
,
choices
=
[
"
csv
"
,
],
choices
=
[
"
csv
"
,
"
geojson
"
],
help
=
"
output file format
"
,
dest
=
"
format
"
,
)
...
...
This diff is collapsed.
Click to expand it.
requirements.txt
+
1
−
0
View file @
9190d399
requests
==2.28.2
python-dateutil
==2.8.2
tqdm
==4.65.0
geojson
==3.0.1
This diff is collapsed.
Click to expand it.
src/station_extractor.py
+
33
−
0
View file @
9190d399
...
...
@@ -3,6 +3,8 @@ import csv
import
pickle
from
pathlib
import
Path
from
geojson
import
Feature
,
FeatureCollection
,
Point
from
src.scraper.station
import
Station
from
src.utils
import
parse_input_format_output_args
...
...
@@ -59,11 +61,42 @@ def to_csv(data: dict[str, Station], output_file: Path) -> None:
station
.
position
[
1
]
if
station
.
position
else
None
,
)
)
csvfile
.
close
()
def
to_geojson
(
data
:
dict
[
str
,
Station
],
output_file
:
Path
)
->
None
:
feature_list
:
list
[
Feature
]
=
list
()
for
station_c
in
data
:
station
:
Station
=
data
[
station_c
]
if
not
station
.
position
:
continue
feature
:
Feature
=
Feature
(
geometry
=
Point
((
station
.
position
[
1
],
station
.
position
[
0
])),
properties
=
{
"
code
"
:
station
.
code
,
"
name
"
:
station
.
name
,
"
short_name
"
:
station
.
short_name
if
hasattr
(
station
,
"
short_name
"
)
else
None
,
"
region
"
:
station
.
region_code
,
},
)
feature_list
.
append
(
feature
)
collection
:
FeatureCollection
=
FeatureCollection
(
feature_list
)
with
open
(
output_file
,
"
w+
"
)
as
f
:
f
.
write
(
str
(
collection
))
def
main
(
args
:
argparse
.
Namespace
):
input_f
,
output_f
,
format
=
parse_input_format_output_args
(
args
)
data
:
dict
[
str
,
Station
]
=
load_file
(
input_f
)
if
format
==
"
csv
"
:
to_csv
(
data
,
output_f
)
if
format
==
"
geojson
"
:
to_geojson
(
data
,
output_f
)
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