一个用python编写的GIS程序-simpleGIS

更新时间:2023-06-23 07:52:37 阅读: 评论:0

⼀个⽤python编写的GIS程序-simpleGIS 例⼦取⾃<<Learning Geospatial Analysis with Python>>
代码由两部分组成。第⼀部分是数据模型,第⼆部分是绘制数据(地图渲染)。
⼀、数据模型:使⽤python内置的列表(list),⽤来存储空间数据。
# DATA MODEL
# All layers will have a name, 1+ points, and population count
NAME = 0
POINTS = 1
POP = 2
netware# Create the state layer
the sun
state = ["COLORADO", [[-109, 37], [-109, 41], [-102, 41], [-102, 37]], 5187582]
# Cities layer list
# city = [name, [point], population]
车在马前cities = []
# Add Denver
cities.append(["DENVER",[-104.98, 39.74], 634265])
# Add Boulderdewen
cities.append(["BOULDER",[-105.27, 40.02], 98889])
# Add Durango
cities.append(["DURANGO",[-107.88,37.28], 17069])
⼆、地图渲染
使⽤python Turtle 绘图模块来渲染地图。其中有⼀个函数⽤来将世界坐标转换为像素坐标。
1、⾸先计算地图的显⽰范围及设定屏幕的绘制范围
# MAP GRAPHICS RENDERING
map_width = 800
map_height = 500
# State Bounding Box
# U Python min/max function to get bounding box
minx = 180
maxx = -180
miny = 90
maxy = -90
for x,y in state[POINTS]:
if x < minx: minx = x
elif x > maxx: maxx = x
if y < miny: miny = y
elif y > maxy: maxy = y
# Get earth distance on each axis
dist_x = maxx - minx
dist_y = maxy - miny
# Scaling ratio each axis
# to map points from world to screen
x_ratio = map_width / dist_x
y_ratio = map_height / dist_y
美国前10大学2、世界坐标到屏幕坐标的转换幼儿启蒙英语下载
重阳节用英语怎么说
# Function to convert lat/lon to screen coordinates
def convert(point):
lon = point[0]
lat = point[1]
x = map_width - ((maxx - lon) * x_ratio)
y = map_height - ((maxy - lat) * y_ratio)
# Python turtle graphics start in the middle of the screen
# so we must offt the points so they are centered
x = x - (map_width/2)
y = y - (map_height/2)
return [x,y]
3、绘制地图:标注和要素图形
# Draw the state
t.up()
first_pixel = None
dead的英文是什么意思for point in state[POINTS]:
pixel = convert(point)
print pixel
if not first_pixel:
first_pixel = pixel
<(pixel)
t.down()
# Go back to the first point国际接吻
美少女谎言t.goto(first_pixel)
# Label the state
t.up()
<([0,0])
t.write(state[NAME], align="center", font=("Arial",16,"bold"))
# Draw the cities
for city in cities:
pixel = convert(city[POINTS])
t.up()
<(pixel)
# Place a point for the city
t.dot(10)
# Label the city
t.write(city[NAME] + ", Pop.: " + str(city[POP]), align="left")  t.up()
# Perform an attribute query
# Question: Which city has the largest population?
# Write the result but make sure it's under the map biggest_city = max(cities, key=lambda city:city[POP])
<(0, -1*((map_height/2)+20))
t.write("The biggest city is: " +  biggest_city[NAME])
# Perform a spatial query
# Question: Which is the western most city?
# Write the result but make sure it's under the other question western_city = min(cities, key=lambda city:city[POINTS])
<(0, -1*((map_height/2)+40))
t.write("The western-most city is: " + western_city[NAME])
# Hide our map pen
t.pen(shown=Fal)
t.done()
三、结果

本文发布于:2023-06-23 07:52:37,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1019578.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:地图   部分   渲染   绘制
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图