shp数据入库、出库、可视化

今天给npy写了次作业,由于各种原因,不能用我用了很久的SSM或者SpringBoot框架,只用了最原始的servlet+jsp,然后我发现…自己已经不太会用了,写这个博客记录一下整套流程~

首先,作业的大致要求是将几何数据导入数据库,然后进行查询,使用地图可视化库进行可视化。因此,本次作业决定使用中国地图shp数据,导入PostgreSQL数据库,接着查询数据,最后使用Openlayers对查询到的数据进行可视化。

技术选型

PostgreSQL + Servlet + jsp + Openlayers

一 shp数据入库

首先使用命令行将shp数据转化为sql语句:

shp2pgsql "shp路径" "数据库名"> "sql路径"

如:

shp2pgsql F:/BoundaryChn2_4p.shp boundary> F:/boundary.sql

然后在pgadmin中执行该sql文件即可。

二 搭建servlet程序

本次使用maven搭建web程序,文件结构如下:

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.tm</groupId><artifactId>webgis</artifactId><version>1.0-SNAPSHOT</version><packaging>war</packaging><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13</version><scope>test</scope></dependency><dependency><groupId>org.postgresql</groupId><artifactId>postgresql</artifactId><version>42.2.12</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>4.0.1</version><scope>provided</scope></dependency><dependency><groupId>jstl</groupId><artifactId>jstl</artifactId><version>1.2</version></dependency><!--Tomcat引用--><dependency><groupId>org.apache.tomcat.embed</groupId><artifactId>tomcat-embed-core</artifactId><version>[9.0.20,)</version><scope>provided</scope></dependency></dependencies><build><finalName>MWebgis</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>7</source><target>7</target></configuration></plugin></plugins><resources><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>true</filtering></resource><resource><directory>src/main/resources</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>true</filtering></resource></resources></build>
</project>

不赘述,文末有github链接,可自行查看。

三 数据库查询

1 数据库配置:

useSSL=false
verifyServerCertificate=false
url=jdbc:postgresql://ip:port/database
driver=org.postgresql.Driver
user=**** # 改成自己的
password=**** # 改成自己的

2 数据库链接类:

public class DBHelper {static String url;static Properties pro = new Properties();static{InputStream in = DBHelper.class.getClassLoader().getResourceAsStream("config.properties");try {pro.load(in);url = pro.getProperty("url");String driver = pro.getProperty("driver");Class.forName(driver);System.out.println("驱动器加载成功");} catch (IOException e) {System.out.println("驱动器加载失败");} catch (ClassNotFoundException e) {System.out.println("驱动器加载失败");}}public static Connection getConnection() throws SQLException{//创建数据库连接Connection con = DriverManager.getConnection(url, pro);return con;}
}

3 数据库查询方法,返回为geojson:

public String getBoundaryChn2PShp() {String result ="";String sql = "SELECT row_to_json(fc) FROM ( SELECT 'FeatureCollection' As type,array_to_json(array_agg(f)) As features FROM (SELECT 'Feature' As type, ST_AsGeoJSON(lg.geom)::json As geometry ,gid As properties FROM boundarychn2_4p As lg ) As f )  As fc";try (Connection conn = DBHelper.getConnection();PreparedStatement pstmt = conn.prepareStatement(sql);ResultSet rs = pstmt.executeQuery();) {if (rs.next()) {result = rs.getString(1);}} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}return result;}

四 Openlayers数据可视化

1 index.js

var image = new ol.style.Circle({radius: 5,fill: null,stroke: new ol.style.Stroke({color: 'red', width: 1})
});var styles = {'Point': new ol.style.Style({image: image}),'LineString': new ol.style.Style({stroke: new ol.style.Stroke({color: 'green',width: 1})}),'MultiLineString': new ol.style.Style({stroke: new ol.style.Stroke({color: 'green',width: 1})}),'MultiPoint': new ol.style.Style({image: image}),'MultiPolygon': new ol.style.Style({stroke: new ol.style.Stroke({color: 'yellow',width: 1}),fill: new ol.style.Fill({color: 'rgba(255, 255, 0, 0.1)'})}),'Polygon': new ol.style.Style({stroke: new ol.style.Stroke({color: 'blue',lineDash: [4],width: 3}),fill: new ol.style.Fill({color: 'rgba(0, 0, 255, 0.1)'})}),'GeometryCollection': new ol.style.Style({stroke: new ol.style.Stroke({color: 'magenta',width: 2}),fill: new ol.style.Fill({color: 'magenta'}),image: new ol.style.Circle({radius: 10,fill: null,stroke: new ol.style.Stroke({color: 'magenta'})})}),'Circle': new ol.style.Style({stroke: new ol.style.Stroke({color: 'red',width: 2}),fill: new ol.style.Fill({color: 'rgba(255,0,0,0.2)'})})
};var styleFunction = function(feature) {return styles[feature.getGeometry().getType()];
};var geojsonObject = {};
$.ajax({type : 'post', //传输类型async : false, //同步执行url : 'shp', //web.xml中注册的Servlet的url-patterndataType : 'json', //返回数据形式为jsonsuccess : function(result) {geojsonObject = resultvar vectorSource = new ol.source.Vector({features: (new ol.format.GeoJSON()).readFeatures(geojsonObject,{featureProjection: 'EPSG:3857'})});var vectorLayer = new ol.layer.Vector({source: vectorSource,style: styleFunction});var map = new ol.Map({layers: [new ol.layer.Tile({source: new ol.source.OSM()}),vectorLayer],target: 'map',view: new ol.View({center: [116, 39],zoom: 4})});},error : function(errorMsg) {alert("加载数据失败");}
});

2 index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<c:set var="path" value="${pageContext.request.contextPath }"/>
<head><title>index</title><script>var path = "${path}";</script><style>*{margin: 0;padding: 0;}.map {width: 100vw;height: 100vh;}</style>
</head>
<body>
<div id="map" class="map"></div>
<script src="${path}/lib/jquery-3.4.1.js"></script>
<script src="${path}/ol/ol.js"></script>
<link rel="stylesheet" href="${path}/ol/ol.css">
<script src="${path}/js/index.js"></script>
</body>
</html>

五 效果

六 github

github

shp数据入库、出库、可视化相关推荐

  1. mysql入库出库触发器_入库出库后库存自动更新的SQL触发器语句是什么?

    tb1(产品表)cpidcpnamecpcolorkucun1xxxxxx82xxxxxx7=================================tb2(入库表)riqirukucpid2 ...

  2. 家电空调手机行业序列号追溯溯源管理,汉码PDA扫码入库出库

    家电空调手机行业序列号追溯溯源管理,PDA扫码入库出库,销售售后跟踪,酒水序列号条码一物一码防伪防串货,PDA扫码入库出库仓库条码管理 在家电行业,空调行业,手机行业等,经常需要进行序列号管理,进行序 ...

  3. python出入库_练习1:python设计停车入库出库系统

    前言: 最近在某个测试群看到有人抛出了一个面试题.为了提升自己的编程能力,我也尝试的用python去写了一下. 语言:python,数据库:sqlite  .菜鸟来袭,只是基本实现功能,可能没有考虑太 ...

  4. Springboot毕设项目药库药品智能入库出库及流转管理系统e46hijava+VUE+Mybatis+Maven+Mysql+sprnig)

    Springboot毕设项目药库药品智能入库出库及流转管理系统e46hijava+VUE+Mybatis+Maven+Mysql+sprnig) 项目运行 环境配置: Jdk1.8 + Tomcat8 ...

  5. python出入库管理_练习1:python设计停车入库出库系统

    前言: 最近在某个测试群看到有人抛出了一个面试题.为了提升自己的编程能力,我也尝试的用python去写了一下. 语言:python,数据库:sqlite  .菜鸟来袭,只是基本实现功能,可能没有考虑太 ...

  6. 毕设 电脑维修_入库出库结算论文

    备注原文来源于:六月雪计算机毕业设计 摘  要 在进入信息时代以来,随网络技术与电脑的日逐发达,电子商务的空前发展,企业之间的竞争已经逐渐地从有形的市场转向了网络化.而相对应的企业售后管理也逐步进入了 ...

  7. 自动化立体仓库使用流程!海格里斯自动化立体库流程:入库——出库——拣选

    随着现代物流行业的不断进步,我们可以发现自动化立体仓库已成为现代物流系统中重要的一个组成部分,它不但可以减轻人工劳动强度,还可以节省地面面积,可以很轻松的避免一些不必要的故障出现,同时还可以提高仓库的 ...

  8. mysql入库出库触发器_oracle 触发器 实现出入库

    用语言实现 好处: 1.可以减少对数据库的访问. 2.可移植性好. 坏处: 1.操作起来考虑的东西较多,修改一处就要修改别一处.也就是说是相互关联的.如果少改了某一处,很可能使数据不一致. 用触发器实 ...

  9. postgresql 创建gis空间数据库,shp数据入库

    目录 1.postgresql创建空间数据库总共分为两步: 1.1 创建普通数据库 2.1 给数据库添加空间扩展 2.shp入库步骤: 2.1  shp数据准备 2.2 打开PostGIS 2.0 S ...

最新文章

  1. mysql数据库增删改实例_Mysql1:数据库表操作,增删改查举例
  2. c3p0连接池配置_Maven+JSP+Servlet+C3P0+Mysql实现的音乐库管理系统
  3. Python 图形界面框架 PyQt5 使用指南!
  4. 锁定计算机好在下游戏吗,巧用win7锁定计算机 防止孩子沉迷游戏
  5. Java实现Runnable接口创建多线程
  6. 生日快乐程序_别@官方了!云开发教你制作个性头像小程序,以后过节想加啥就加啥!...
  7. Matlab矩阵填充--Matlab interp2
  8. 形容PHP程序员的语句,形容程序员的句子
  9. Elastic Stack 安装
  10. 模板模式(Template)
  11. 如何使用Magit管理Git项目
  12. [转]MIDI常识20条
  13. 学习网页前的网页知识储备
  14. 《SQL Server 2005开发技术大全》分享一本书
  15. MySQL:设置字段默认为当前时间
  16. C# installshield2020项目部署打包详细教程
  17. 软考中级-软件设计师涉及的知识点和笔记
  18. 二元隐函数求二阶偏导_隐函数求二阶偏导
  19. pcr mix试剂选购相关问题
  20. 【电信学】【2011.06】​基于空时空频编码的MIMO-OFDM通信信道估计与性能分析

热门文章

  1. 重新认识莫比乌斯函数
  2. python基础之Requests库
  3. 2020.11.03 底层相关,汇编
  4. Ajax基础配置 — XMLHttpRequest
  5. 不会吧不会吧?价值“百万”的社招面试题惨遭泄露:猛补了这个,真香...
  6. 常见命令之 head与tail
  7. mysql学生成绩视图_MySql学习12---视图
  8. 如何把文档转成html格式转换,文档格式转换工具Print2Flash使用教程:如何将文档转换为Print2Flash格式件或HTML5文件?...
  9. 凯撒密码加密解密C语言详细代码
  10. JBPM的一些基本概念