FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
geospatialpython/shp2img.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
/
shp2img.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (37 loc) · 1.14 KB
Breadcrumbs
geospatialpython
/
shp2img.py
Copy path
File metadata and controls
41 lines (37 loc) · 1.14 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
"""
shp2img.py - creates a png image and world file (.pgw) from a shapefile
containing a single polygon.
author: jlawhead@geospatialpyton.com
date: 20101204
This script requires the Python Imaging Library.
The sample shapefile used is available at:
http://geospatialpython.googlecode.com/files/Mississippi.zip
"""
import
shapefile
import
Image
,
ImageDraw
# Read in a shapefile
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
=
[]
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
))
img
=
Image
.
new
(
"RGB"
, (
iwidth
,
iheight
),
"white"
)
draw
=
ImageDraw
.
Draw
(
img
)
draw
.
polygon
(
pixels
,
outline
=
"rgb(203, 196, 190)"
,
fill
=
"rgb(198, 204, 189)"
)
img
.
save
(
"mississippi.png"
)
# 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