FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
geospatialpython/PureShp2Img.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
/
PureShp2Img.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (36 loc) · 986 Bytes
Breadcrumbs
geospatialpython
/
PureShp2Img.py
Copy path
File metadata and controls
39 lines (36 loc) · 986 Bytes
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
"""
PureShp2Img - Convert a shapefile polygon to a PNG image using pure python
Requires Rui Carmo's PNGCanvas module from http://the.taoofmac.com
"""
import
shapefile
import
pngcanvas
# Read in a shapefile and write png image
r
=
shapefile
.
Reader
(
"mississippi"
)
xdist
=
r
.
bbox
[
2
]
-
r
.
bbox
[
0
]
ydist
=
r
.
bbox
[
3
]
-
r
.
bbox
[
1
]
iwidth
=
400
iheight
=
600
xratio
=
iwidth
/
xdist
yratio
=
iheight
/
ydist
pixels
=
[]
#
# Only using the first shape record
for
x
,
y
in
r
.
shapes
()[
0
].
points
:
px
=
int
(
iwidth
-
((
r
.
bbox
[
2
]
-
x
)
*
xratio
))
py
=
int
((
r
.
bbox
[
3
]
-
y
)
*
yratio
)
pixels
.
append
([
px
,
py
])
c
=
pngcanvas
.
PNGCanvas
(
iwidth
,
iheight
)
c
.
polyline
(
pixels
)
f
=
file
(
"mississippi.png"
,
"wb"
)
f
.
write
(
c
.
dump
())
f
.
close
()
#
# Create a world file
wld
=
file
(
"mississippi.pgw"
,
"w"
)
wld
.
write
(
"%s
\n
"
%
(
xdist
/
iwidth
))
wld
.
write
(
"0.0
\n
"
)
wld
.
write
(
"0.0
\n
"
)
wld
.
write
(
"-%s
\n
"
%
(
ydist
/
iheight
))
wld
.
write
(
"%s
\n
"
%
r
.
bbox
[
0
])
wld
.
write
(
"%s
\n
"
%
r
.
bbox
[
3
])
wld
.
close
Back
|
FazBrowse Home
|
New Git URL