1.环境依赖

python2.7+pyshp模块
下载python2.7

2.配置环境

安装时可以直接add path。
在cmd中输入python,出现以下界面代表配置成功。
手动配置环境变量教程
网上有很多教程可以去搜搜。

环境配置好后,在cmd中输入python -m pip install pyshp -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com安装pyshp模块。
至此环境就配置好了。

3.主要代码

首先到开发目录开启服务器python -m CGIHTTPServer 8889,在浏览器中输入localhost:8889
在你的开发目录新建index.html文件

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="keywords" content="天地图"/>
<title>天地图-地图API-范例-经纬度直投地图</title>
<script type="text/javascript" src="http://api.tianditu.gov.cn/api?v=4.0&tk=您的密钥"></script>
<style type="text/css">body,html{width:100%;height:100%;margin:0;font-family:"Microsoft YaHei"}#mapDiv{width:100%;height:400px}input,b,p{margin-left:5px;font-size:14px}</style>
<script type="text/javascript" src="http://localhost:8889/cgi-bin/readShp.py"></script>
</head>
<body onLoad="onLoad()">
<div id="mapDiv"></div>
</body>
</html>

在你的开发目录新建一个文件cgi-bin,写的py文件必须放在这个目录。
readShp.py

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Author: wardseptember
print "Content-Type:text/javascript"
printimport shapefile
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
sf = shapefile.Reader("./cgi-bin/shapefile/aotao.shp")
shapes = sf.shapes()first_str = '''var map;var zoom = 9;map = new T.Map('mapDiv', {projection: 'EPSG:32650'});map.centerAndZoom(new T.LngLat(112.858577, 35.497694), zoom);'''
name_str=''''''
for num in range(len(shapes)):name_str=name_str+'''points_autao%d=[];'''% (num)first_str=first_str+name_strpolyline_str = ''''''
for shp in range(len(shapes)):shap = shapes[shp]#一个面文件,里面可能有很多ploygon,shapes[shp]就是一个,一共有len(shapes)个ploygonfor i in range(len(shap.points)):#读每个ploygon中点坐标polyline_str=polyline_str+'''points_autao%d.push(new T.LngLat(%f, %f));'''% (shp,shap.points[i][0],shap.points[i][1])finally_str=''
for num in range(len(shapes)):finally_str=finally_str+'''var polygon_autao%d = new T.Polygon(points_autao%d,{color: "blue", weight: 3, opacity: 0.5, fillColor: "red", fillOpacity: 0.5});map.addOverLay(polygon_autao%d);'''% (num,num,num)print first_str+polyline_str+finally_str
#必须要挨个读取ploygon,不能一次读取,不然画出来的图形就乱了。一次压入所有点,就依点画,明显不对。

读其他ploygon图层写法

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Author: wardseptemberprint "Content-Type:text/javascript"
printimport shapefile
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
sf = shapefile.Reader("./cgi-bin/shapefile/sandie.shp")
shapes = sf.shapes()first_str = '''
'''
name_str=''''''
for num in range(len(shapes)):name_str=name_str+'''points_sd%d=[];'''% (num)first_str=first_str+name_strpolyline_str = ''''''
for shp in range(len(shapes)):shap = shapes[shp]for i in range(len(shap.points)):polyline_str=polyline_str+'''points_sd%d.push(new T.LngLat(%f, %f));'''% (shp,shap.points[i][0],shap.points[i][1])finally_str=''
for num in range(len(shapes)):finally_str=finally_str+'''var polygon_sd%d = new T.Polygon(points_sd%d,{color: "blue", weight: 3, opacity: 0.5, fillColor: "#37FA3F", fillOpacity: 0.5});map.addOverLay(polygon_sd%d);'''% (num,num,num)print first_str+polyline_str+finally_str

读线文件

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Author: wardseptember
print "Content-Type:text/javascript"
printimport shapefile
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
sf = shapefile.Reader("./cgi-bin/shapefile/JCborder.shp")
shapes = sf.shapes()
first_str = '''points = [];'''
polyline_str = ''''''
for shp in range(len(shapes)):shap = shapes[shp]for i in range(len(shap.points)):polyline_str=polyline_str+'''points.push(new T.LngLat(%f, %f));'''% (shap.points[i][0],shap.points[i][1])
finally_str='''var line = new T.Polyline(points);map.addOverLay(line);
'''print first_str+polyline_str

可以发现读线读点读面写法类似。
下面是批量读点的代码

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Author: wardseptember
print "Content-Type:text/javascript"
printimport shapefile
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
sf = shapefile.Reader("./cgi-bin/shapefile/JCborder.shp")
shapes = sf.shapes()polyline_str = ''''''
lng_num=[0.0]
lat_num=[0.0]
total_points=1
for shp in range(len(shapes)):shap = shapes[shp]for i in range(len(shap.points)):total_points=total_points+1lng_num.append(shap.points[i][0])lat_num.append(shap.points[i][1])for j in range(total_points):polyline_str=polyline_str+'''var point_%d=new T.LngLat(%f, %f);var marker_%d = new T.Marker(point_%d);map.addOverLay(marker_%d);marker_%d.disableDragging();  '''% (j,lng_num[j],lat_num[j],j,j,j,j)polyline_str=polyline_str+'map.removeOverLay(marker_0)'
print polyline_str

将地质图(shp文件)叠加到天地图上相关推荐

  1. shp文件显示 c语言,上传并在地图中显示Shp文件

    前段时间参与了一个项目,客户有一个功能需求是上传SHP文件并在地图上显示,然后在此基础上做缓冲区处理.经过对比测试,最终选择了shapefile.js工具,在此做个记录. shapfe.js能够将Es ...

  2. shp文件纯前端的上传、解析、编辑、下载

    本文主要讲述一种体量较小的shp文件纯前端的上传.解析.编辑.下载的技术流程,适用于要素量少的shp文件修改操作. 准备工作 下载一下几个包,详细用法请见结尾参考. npm install file- ...

  3. 上传并在地图中显示Shp文件

    前段时间参与了一个项目,客户有一个功能需求是上传SHP文件并在地图上显示,然后在此基础上做缓冲区处理.经过对比测试,最终选择了shapefile.js工具,在此做个记录. shapfe.js能够将Es ...

  4. arcgis导出shp文件_RegionManager GIS导出shp文件编码说明

    在<RegionManager GIS数据如何上报到国家水土保持重点工程项目管理系统>一文介绍了RM GIS软件如何导出shp文件的相关操作,以及如何定义投影等相关操作.从RM GIS软件 ...

  5. 将shp文件转化为osm文件,并导入到sumo中建立路网

    前言 最近在做的一个课题要用到sumo仿真,正好我们手头也有arcgis的shp文件,比osm上面的要简洁准确不少,在座的过程中遇到不少问题,这里做一下记录 要注意的地方有几个: shp转osm的工具 ...

  6. osm服务器 显示乱码,怎样获得osm上的行政区划shp文件

    2018.4.18 :刚刚发现我这里的wifi(电信的宽带)打不开下面的其中几个网站,需要使用网络工具才行.  但是用手机流量(联通)是可以直接打开的. 2018.1.25 :方法二的网站又恢复了. ...

  7. 在Vs2017上集成osgearth3.2和qt5.9,并加载shp文件。

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 一.QT5.9在vs上部署 1.1 在Vs中下载插件 1.2 配置QT 二.OsgEarth3.2环境配置. 三.在Q ...

  8. 10显示不支持导入dwg文件_Global Mapper中80坐标系高程DEM与kml文件叠加实例

    概述 在GIS行业中,有很多经常用到的软件,比如CAD.ArcGIS.Erdas和ENVI等大型专业软件,也会常用到像Global Mapper这样的"迷你"软件,这里,我们以80 ...

  9. tif 高程_Global Mapper中80坐标系高程DEM与kml文件叠加实例

    概述 在GIS行业中,有很多经常用到的软件,比如CAD.ArcGIS.Erdas和ENVI等大型专业软件,也会常用到像Global Mapper这样的"迷你"软件,这里,我们以80 ...

最新文章

  1. php adodb使用,常用的php ADODB使用方法集锦
  2. Local Response Normalization作用——对局部神经元的活动创建竞争机制,使得其中响应比较大的值变得相对更大,并抑制其他反馈较小的神经元,增强了模型的泛化能力...
  3. 前端参数无法转为后端实体内部类_Java学到什么程度才能叫精通?
  4. Leet Code OJ 3. Longest Substring Without Repeating Characters
  5. JSP中文及传中文参数乱码解决方法小结
  6. Install Python 3.6 on Ubuntu 16.04, from source
  7. shell按照时间排序_【经典排序】希尔排序
  8. 计算机基础应用000018,计算机应用基础第01章计算机基础知识
  9. 【脑电信号】基于matlab小波工具箱脑电降噪【含Matlab源码 707期】
  10. 误差分析(python)
  11. Cplex求解线性规划
  12. 国产艾莫讯仿西门子S7-200PLC控制步进电机程序
  13. 文本相似度算法对比分析,短文本相似度主流算法
  14. objective-c类别catagory的作用?
  15. 户外直播信号差,老出现卡顿现象怎么办?
  16. ubuntu18.10安装网易云音乐,并解决网易云音乐图标无法启动的问题
  17. 清朝皇帝年表及1840年后清朝历史事件
  18. nginx配置禁止访问目录或禁止访问目录下的文件
  19. 失落的帝国:盛大业务大收缩
  20. 微机原理及应用->指令系统概述

热门文章

  1. 环保数采仪 有效解决数据采集、传输的问题
  2. 苹果全球销量超越小米重回第二,荣耀回归国内手机市场第一梯队
  3. 攻城狮应该明白的浏览器工作原理~
  4. WEB攻防-通用漏洞文件包含LFIRFI伪协议编码算法代码审计
  5. 用python爬虫来登录深信服ac行为控制器,涉及到js加密部分,更新url分类库(针对企业微信更新)
  6. c++实验3—定期存款利息计算器
  7. (27)STM32——光敏传感器实验笔记
  8. TiDB 在特来电的实践 1
  9. Http状态码大全(100、200、300、404、500等)
  10. Excel文件转换为txt文本第一次更新