FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
geospatialpython/changeShapeType.py at master · ucespff/geospatialpython · GitHub
ucespff
/
geospatialpython
Public
forked from
GeospatialPython/geospatialpython
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
geospatialpython
/
changeShapeType.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (46 loc) · 1.31 KB
Breadcrumbs
geospatialpython
/
changeShapeType.py
Copy path
File metadata and controls
56 lines (46 loc) · 1.31 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
"""
Convert one shapefile type to another
"""
import
shapefile
# Create a line and a multi-point
# and single point version of
# a polygon shapefile
## POLYLINE version
# The shapefile type we are converting to
newType
=
shapefile
.
POLYLINE
r
=
shapefile
.
Reader
(
"Mississippi"
)
w
=
shapefile
.
Writer
(
newType
)
w
.
_shapes
.
extend
(
r
.
shapes
())
# You must explicity set the shapeType of each record.
# Eventually the library will set them to the same
# as the file shape type automatically.
for
s
in
w
.
shapes
():
s
.
shapeType
=
newType
w
.
fields
=
list
(
r
.
fields
)
w
.
records
.
extend
(
r
.
records
())
w
.
save
(
"Miss_Line"
)
## MULTIPOINT version
newType
=
shapefile
.
MULTIPOINT
w
=
shapefile
.
Writer
(
newType
)
w
.
_shapes
.
extend
(
r
.
shapes
())
for
s
in
w
.
shapes
():
s
.
shapeType
=
newType
w
.
fields
=
list
(
r
.
fields
)
w
.
records
.
extend
(
r
.
records
())
w
.
save
(
"Miss_MPoint"
)
## POINT version
newType
=
shapefile
.
POINT
w
=
shapefile
.
Writer
(
newType
)
# For a single point shapefile
# from another type we
# "flatten" each shape
# so each point is a new record.
# This means we must also assign
# each point a record which means
# records are usually duplicated.
for
s
in
r
.
shapeRecords
():
for
p
in
s
.
shape
.
points
:
w
.
point
(
*
p
)
w
.
records
.
append
(
s
.
record
)
w
.
fields
=
list
(
r
.
fields
)
w
.
save
(
"Miss_Point"
)
Back
|
FazBrowse Home
|
New Git URL