FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MapServer/src/mapscript/python/examples/project_csv.py at main · jbfrd/MapServer · GitHub
jbfrd
/
MapServer
Public
forked from
MapServer/MapServer
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
MapServer
/
src
/
mapscript
/
python
/
examples
/
project_csv.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
72 lines (48 loc) · 1.56 KB
Breadcrumbs
MapServer
/
src
/
mapscript
/
python
/
examples
/
project_csv.py
Copy path
File metadata and controls
executable file
·
72 lines (48 loc) · 1.56 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
"""
Simple example to read a csv file and reproject point x/y data
Usage:
project_csv.py cities.csv 2 1 EPSG:4326 EPSG:3857
"""
import
sys
import
csv
from
io
import
open
import
mapscript
def
main
(
input_file
,
x_field_idx
,
y_field_idx
,
input_proj
,
output_proj
):
# set input and output projections
proj_in
=
mapscript
.
projectionObj
(
input_proj
)
proj_out
=
mapscript
.
projectionObj
(
output_proj
)
# open file
with
open
(
input_file
,
encoding
=
'utf-8'
)
as
f
:
# read csv
csv_in
=
csv
.
reader
(
f
)
headers
=
next
(
csv_in
)
# setup output
csv_out
=
csv
.
writer
(
sys
.
stdout
)
csv_out
.
writerow
(
headers
)
for
row
in
csv_in
:
# set pointObj
point
=
mapscript
.
pointObj
(
float
(
row
[
x_field_idx
]),
float
(
row
[
y_field_idx
]))
# project
point
.
project
(
proj_in
,
proj_out
)
# update with reprojected coordinates
row
[
x_field_idx
]
=
point
.
x
row
[
y_field_idx
]
=
point
.
y
csv_out
.
writerow
(
row
)
def
usage
():
"""
Display usage if program is used incorrectly
"""
print
(
"Syntax: %s <csvfile> <x_col> <y_col> <epsg_code_in> <epsg_code_out>"
%
sys
.
argv
[
0
])
sys
.
exit
(
2
)
# check input parameters
if
(
len
(
sys
.
argv
)
!=
6
):
usage
()
input_file
=
sys
.
argv
[
1
]
# set x and y indices
x_field_idx
=
int
(
sys
.
argv
[
2
])
y_field_idx
=
int
(
sys
.
argv
[
3
])
# get projection codes
input_proj
=
"init="
+
sys
.
argv
[
4
].
lower
()
output_proj
=
"init="
+
sys
.
argv
[
5
].
lower
()
main
(
input_file
,
x_field_idx
,
y_field_idx
,
input_proj
,
output_proj
)
Back
|
FazBrowse Home
|
New Git URL