FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
geospatialpython/zipshape.py at master · GeospatialPython/geospatialpython · GitHub
GeospatialPython
/
geospatialpython
Public
Notifications
You must be signed in to change notification settings
Fork
8
Star
14
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
geospatialpython
/
zipshape.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (39 loc) · 1.08 KB
Breadcrumbs
geospatialpython
/
zipshape.py
Copy path
File metadata and controls
45 lines (39 loc) · 1.08 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
"""
Example of saving a shapefile to a file-like
object using a zip file as the target. Uses
the individual save methods for each type
of file instead of the general pyshp
save method.
"""
import
zipfile
import
StringIO
import
shapefile
# Set up buffers for saving
shp
=
StringIO
.
StringIO
()
shx
=
StringIO
.
StringIO
()
dbf
=
StringIO
.
StringIO
()
# Make a point shapefile
w
=
shapefile
.
Writer
(
shapefile
.
POINT
)
w
.
point
(
90.3
,
30
)
w
.
point
(
92
,
40
)
w
.
point
(
-
122.4
,
30
)
w
.
point
(
-
90
,
35.1
)
w
.
field
(
'FIRST_FLD'
)
w
.
field
(
'SECOND_FLD'
,
'C'
,
'40'
)
w
.
record
(
'First'
,
'Point'
)
w
.
record
(
'Second'
,
'Point'
)
w
.
record
(
'Third'
,
'Point'
)
w
.
record
(
'Fourth'
,
'Point'
)
# Save shapefile components to buffers
w
.
saveShp
(
shp
)
w
.
saveShx
(
shx
)
w
.
saveDbf
(
dbf
)
# Save shapefile buffers to zip file
# Note: zlib must be available for
# ZIP_DEFLATED to compress. Otherwise
# just use ZIP_STORED.
z
=
zipfile
.
ZipFile
(
"myshape.zip"
,
"w"
,
zipfile
.
ZIP_DEFLATED
)
z
.
writestr
(
"myshape.shp"
,
shp
.
getvalue
())
z
.
writestr
(
"myshape.shx"
,
shx
.
getvalue
())
z
.
writestr
(
"myshape.dbf"
,
dbf
.
getvalue
())
z
.
close
()
Back
|
FazBrowse Home
|
New Git URL