FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
MapServer/src/mapscript/python/examples/shpdump.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
/
shpdump.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
94 lines (58 loc) · 1.93 KB
Breadcrumbs
MapServer
/
src
/
mapscript
/
python
/
examples
/
shpdump.py
Copy path
File metadata and controls
executable file
·
94 lines (58 loc) · 1.93 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
"""
Dump the contents of the passed in Shapefile
Usage:
python shpdump.py polygon.shp
"""
import
mapscript
import
sys
import
os
def
plural
(
x
):
"""
Returns an 's' if plural
Useful in print statements to avoid something like 'point(s)'
"""
if
x
>
1
:
return
's'
return
''
def
get_shapefile_object
(
sf_path
):
# make sure can access .shp file, create shapefileObj
if
os
.
access
(
sf_path
,
os
.
F_OK
):
sf_obj
=
mapscript
.
shapefileObj
(
sf_path
,
-
1
)
else
:
print
(
"Can't access {}"
.
format
(
sf_path
))
sys
.
exit
(
2
)
return
sf_obj
def
main
(
sf_path
):
if
not
sf_path
.
lower
().
endswith
(
".shp"
):
sf_path
+=
".shp"
sf_obj
=
get_shapefile_object
(
sf_path
)
# create an empty Shapefile object
s_obj
=
mapscript
.
shapeObj
()
# loop through each shape in the original Shapefile
for
i
in
range
(
sf_obj
.
numshapes
):
# get the object at index i
sf_obj
.
get
(
i
,
s_obj
)
print
(
"Shape %i has %i part%s"
%
(
i
,
s_obj
.
numlines
,
plural
(
s_obj
.
numlines
)))
print
(
"Bounds (%f, %f) (%f, %f)"
%
(
s_obj
.
bounds
.
minx
,
s_obj
.
bounds
.
miny
,
s_obj
.
bounds
.
maxx
,
s_obj
.
bounds
.
maxy
))
# loop through parts of each shape
for
j
in
range
(
s_obj
.
numlines
):
# get the jth part of the ith object
part
=
s_obj
.
get
(
j
)
print
(
"Part %i has %i point%s"
%
(
j
,
part
.
numpoints
,
plural
(
part
.
numpoints
)))
# loop through points in each part
for
k
in
range
(
part
.
numpoints
):
# get the kth point of the jth part of the ith shape
point
=
part
.
get
(
k
)
print
(
"%i: %f, %f"
%
(
k
,
point
.
x
,
point
.
y
))
def
usage
():
"""
Display usage if program is used incorrectly
"""
print
(
"Syntax: %s <shapefile_path>"
%
sys
.
argv
[
0
])
sys
.
exit
(
2
)
# make sure passing in filename argument
if
len
(
sys
.
argv
)
!=
2
:
usage
()
sf_path
=
sys
.
argv
[
1
]
main
(
sf_path
)
Back
|
FazBrowse Home
|
New Git URL