├── .classpath
├── .gitignore
├── .project
├── .settings
├── org.eclipse.core.resources.prefs
└── org.eclipse.jdt.core.prefs
├── README.md
├── SQL部分.sql
├── pom.xml
├── src
├── main
│ ├── java
│ │ ├── entity
│ │ │ ├── GdNavLinkNJ.java
│ │ │ └── GdNavLink_hibernate.java
│ │ ├── gaode
│ │ │ ├── GetNav.java
│ │ │ ├── GetNavNJ.java
│ │ │ └── response_example.json
│ │ └── utils
│ │ │ ├── HibernateUtils.java
│ │ │ ├── HttpClientResult.java
│ │ │ ├── HttpClientUtils.java
│ │ │ └── JPAUtil.java
│ └── resources
│ │ └── META-INF
│ │ └── persistence.xml
└── test
│ └── java
│ └── gaode
│ └── TestClass.java
└── target
└── classes
└── META-INF
└── MANIFEST.MF
/.classpath:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | gaode2
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | encoding//src/main/java=UTF-8
3 | encoding//src/test/java=UTF-8
4 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
3 | org.eclipse.jdt.core.compiler.compliance=1.8
4 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7 | org.eclipse.jdt.core.compiler.release=disabled
8 | org.eclipse.jdt.core.compiler.source=1.8
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | --------------------- 2020年12月更新-------------------------
2 | 功能一:
3 | 南京市东南大学至新街口区域,道路车速获取的代码.
4 | 核心代码:
5 | src/main/entity/GdNavLinkNJ.java
6 | src/main/gaode/GetNavNJ.java
7 | --------------------- end -------------------------
8 |
9 |
10 | --------------------- 2020年1月更新-------------------------
11 | 功能二:
12 | 利用高德路径规划接口获取路网
13 | 核心代码:
14 | src/main/entity/GdNavLink_hibernate.java
15 | src/main/gaode/GetNav.java
16 | "SQL部分.sql"
17 | ------------------------ end -------------------------
18 |
19 |
20 | 概述----------
21 | 语言: JAVA
22 | 项目管理方式: maven
23 | 数据库: ORACLE
24 | 持久化框架: hibernate. 使用该持久化框架的目的是方便大家切换数据库为自己的偏好(如postSQL/MySQL等)
25 |
26 |
27 |
28 | 如何使用----------
29 | 1. 构建maven工程
30 | 2. maven无法自动添加oracle数据库的jdbc驱动,需要手动安装该驱动(ojdbc6-11.2.0.1.0.jar),oracle版权原因, 我就不上传这个jar包了, 需要请自行百度,联系我也行.
31 | 3. 在main/resources/META-INF/persistence.xml中修改数据库连接参数
32 | 4. 在getHttpReq方法中填入你自己申请的KEY
33 | 5. SQL部分。仅功能二用到,功能一不用。在数据库中新建表GD_NAV_POINT和GD_NAV_TRAFFIC,详见“SQL部分.sql”,可以用你自己的方法构造OD点对,也可以参照公众号教程中的操作实例
34 | 6. 运行: 功能一: 运行src/main/java/gaode/GetNavNJ.java 中的main方法; 功能二: 运行src/main/java/gaode/GetNavTrafficHibernate.java中的main方法.
35 | 7. SQL部分(仅功能二需要运行)。回到“SQL部分.sql”, 进行连通性和拓扑性的批量处理。
36 | 8. 最后在数据库中导出表GD_NAV_TRAFFIC_2, 即为最终路网。
37 |
38 |
39 | 建议:
40 | 1. 建议先学习功能二, 再学习功能一. 不然你很难理解功能一每个步骤的意图(尽管有注释).
41 | 2. 看代码时一定要结合着公众号文章教程, 原因同上.
42 |
43 |
44 | 作者公众号: 数牍小点子
45 | 微信: xuxinkun0591
46 |
--------------------------------------------------------------------------------
/SQL部分.sql:
--------------------------------------------------------------------------------
1 | /* 规律总结:
2 | 1.在信号灯左转处,没有左转弧线,道路会缺失;在非信号灯双向路左转处,有时候会断开,有时候不会
3 | 2.在部分掉头处,导航路径(道路)会缺失
4 | 3.连续间隔15分钟访问某tmc,获得step的速度,速度会一直变.
5 | 4.最靠近交叉口的tmc速度一天到晚都很低,应该是考虑了信号灯等待时间.
6 | 5.有一些小路高德路况为"未知",在官方地图上也未显示,这些小路的速度(路程/时间)会给出一个相对固定的值(比如9km/h)
7 | */
8 |
9 | /* 第一步 */
10 | --1.1 创建OD点对表, 用于设置导航起终点, 该表可直接在ArcMap中编辑
11 | -- DROP TABLE "XXK"."GD_NAV_POINT" ;
12 | CREATE TABLE "XXK"."GD_NAV_POINT"
13 | ( "OBJECTID" NUMBER(*,0) NOT NULL ENABLE,
14 | "PROJECT" NVARCHAR2(50),
15 | "SHAPE" "MDSYS"."SDO_GEOMETRY" ,
16 | "SE_ANNO_CAD_DATA" BLOB
17 | );
18 | --1.2 生成表GD_NAV_POINT的视图V_GD_NAV_POINT, 按高德接口要求构造起终点坐标, java将直接访问该视图
19 | CREATE OR REPLACE VIEW v_gd_nav_point as
20 | select TO_CHAR(ROUND(a.shape.sdo_point.x,6))||','||TO_CHAR(ROUND(a.shape.sdo_point.y,6)) S, --起点
21 | TO_CHAR(ROUND(b.shape.sdo_point.x,6))||','||TO_CHAR(ROUND(b.shape.sdo_point.y,6)) E, --终点
22 | from GD_NAV_POINT a,GD_NAV_POINT b
23 | where a.objectid <> b.objectid
24 | ;
25 | SELECT * FROM v_gd_nav_point;
26 |
27 |
28 |
29 |
30 | /* 第二步 */
31 | --2 创建路段表, 用于保存API路段数据
32 | -- drop table GD_NAV_TRAFFIC;
33 | create table GD_NAV_TRAFFIC(
34 | seq number(8) ,
35 | dept varchar2(32), -- step/tmc
36 | tmcid number(8), -- 第几个tmc
37 | action varchar2(32),
38 | distance number(8),
39 | duration number(8),
40 | speed number(4),
41 | orientation varchar2(64),
42 | road varchar2(128),
43 | status varchar2(32),
44 | insert_time date,
45 | polyline sdo_geometry
46 | );
47 | -- 创建空间索引
48 | CALL SDOINDEX('GD_NAV_TRAFFIC','polyline',4326);
49 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
4 | 4.0.0
5 | jtxx
6 | gaode
7 | v1
8 | gaode_name
9 | gaode_desc
10 |
11 |
12 |
13 |
14 |
15 | org.apache.maven.plugins
16 | maven-compiler-plugin
17 | 3.5.1
18 |
19 | 1.8
20 | 1.8
21 | UTF-8
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | junit
31 | junit
32 | 4.9
33 |
34 |
35 |
36 |
37 | org.apache.httpcomponents
38 | httpclient
39 | 4.5.5
40 |
41 |
42 |
43 | com.google.code.gson
44 | gson
45 | 2.8.0
46 |
47 |
48 |
49 | org.hibernate
50 | hibernate-core
51 | 5.0.7.Final
52 |
53 |
54 | org.hibernate
55 | hibernate-spatial
56 | 5.0.7.Final
57 |
58 |
59 | org.hibernate
60 | hibernate-entitymanager
61 | 5.0.7.Final
62 |
63 |
64 |
65 |
66 | com.oracle
67 | ojdbc6
68 | 11.2.0.1.0
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/src/main/java/entity/GdNavLinkNJ.java:
--------------------------------------------------------------------------------
1 | package entity;
2 |
3 |
4 | import javax.persistence.Column;
5 | import javax.persistence.Entity;
6 | import javax.persistence.GeneratedValue;
7 | import javax.persistence.GenerationType;
8 | import javax.persistence.Id;
9 | import javax.persistence.Table;
10 |
11 | import com.vividsolutions.jts.geom.Geometry;
12 |
13 | @Entity
14 | @Table(name = "GD_NAV_TRAFFIC_NJ")
15 | public class GdNavLinkNJ {
16 | @Id
17 | @GeneratedValue(strategy = GenerationType.AUTO)
18 | private Long seq;
19 | private Long batch;
20 | private Long linkid;
21 | private String dept;
22 | private Long tmcid;
23 | private String action;
24 | private Long distance;
25 | private Long duration;
26 | private Long speed;
27 | private String orientation;
28 | private String road;
29 | private String status;
30 | //@Temporal(TemporalType.TIMESTAMP) //指定时间格式
31 | @Column(name="insert_time") //指定特定的列名
32 | private java.sql.Timestamp insertTime;
33 | private Geometry polyline;
34 |
35 | public GdNavLinkNJ() {
36 | super();
37 | }
38 |
39 | public GdNavLinkNJ(Long batch,Long linkid,String dept, Long tmcid, String action, Long distance,
40 | Long duration, Long speed,String orientation, String road, String status, java.sql.Timestamp insertTime, Geometry polyline) {
41 | super();
42 | this.batch=batch;
43 | this.linkid=linkid;
44 | this.dept = dept;
45 | this.tmcid = tmcid;
46 | this.action = action;
47 | this.distance = distance;
48 | this.duration = duration;
49 | this.speed = speed;
50 | this.orientation = orientation;
51 | this.road = road;
52 | this.status = status;
53 | this.insertTime = insertTime;
54 | this.polyline = polyline;
55 | }
56 |
57 | public Long getBatch() {
58 | return batch;
59 | }
60 |
61 | public void setBatch(Long batch) {
62 | this.batch = batch;
63 | }
64 |
65 | public Long getLinkid() {
66 | return linkid;
67 | }
68 |
69 | public void setLinkid(Long linkid) {
70 | this.linkid = linkid;
71 | }
72 |
73 | public Long getSeq() {
74 | return seq;
75 | }
76 |
77 | public void setSeq(Long seq) {
78 | this.seq = seq;
79 | }
80 |
81 | public String getDept() {
82 | return dept;
83 | }
84 |
85 | public void setDept(String dept) {
86 | this.dept = dept;
87 | }
88 |
89 | public Long getTmcid() {
90 | return tmcid;
91 | }
92 |
93 | public void setTmcid(Long tmcid) {
94 | this.tmcid = tmcid;
95 | }
96 |
97 | public String getAction() {
98 | return action;
99 | }
100 |
101 | public void setAction(String action) {
102 | this.action = action;
103 | }
104 |
105 | public Long getDistance() {
106 | return distance;
107 | }
108 |
109 | public void setDistance(Long distance) {
110 | this.distance = distance;
111 | }
112 |
113 | public Long getDuration() {
114 | return duration;
115 | }
116 |
117 | public void setDuration(Long duration) {
118 | this.duration = duration;
119 | }
120 |
121 | public Long getSpeed() {
122 | return speed;
123 | }
124 |
125 | public void setSpeed(Long speed) {
126 | this.speed = speed;
127 | }
128 |
129 | public String getOrientation() {
130 | return orientation;
131 | }
132 |
133 | public void setOrientation(String orientation) {
134 | this.orientation = orientation;
135 | }
136 |
137 | public String getRoad() {
138 | return road;
139 | }
140 |
141 | public void setRoad(String road) {
142 | this.road = road;
143 | }
144 |
145 | public String getStatus() {
146 | return status;
147 | }
148 |
149 | public void setStatus(String status) {
150 | this.status = status;
151 | }
152 |
153 | public java.sql.Timestamp getInsertTime() {
154 | return insertTime;
155 | }
156 |
157 | public void setInsertTime(java.sql.Timestamp insertTime) {
158 | this.insertTime = insertTime;
159 | }
160 |
161 | public Geometry getPolyline() {
162 | return polyline;
163 | }
164 |
165 | public void setPolyline(Geometry polyline) {
166 | this.polyline = polyline;
167 | }
168 |
169 | @Override
170 | public int hashCode() {
171 | return polyline.toText().toString().hashCode();
172 | }
173 | @Override
174 | public boolean equals(Object o) {
175 | GdNavLinkNJ p2 = (GdNavLinkNJ)o;
176 | // 判定条件: 1.geom满足equals关系;2.方向相同
177 | boolean if_equal = polyline.toText().equals(p2.getPolyline().toText()) &&
178 | orientation.equals(p2.getOrientation());
179 | return if_equal;
180 | }
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/src/main/java/entity/GdNavLink_hibernate.java:
--------------------------------------------------------------------------------
1 | package entity;
2 |
3 |
4 | import javax.persistence.Column;
5 | import javax.persistence.Entity;
6 | import javax.persistence.GeneratedValue;
7 | import javax.persistence.GenerationType;
8 | import javax.persistence.Id;
9 | import javax.persistence.Table;
10 |
11 | import com.vividsolutions.jts.geom.Geometry;
12 |
13 | /*
14 | create table gd_nav_traffic(
15 | seq number(8) ,
16 | dept varchar2(32), -- step/tmc
17 | tmcid number(8), -- 第几个tmc
18 | action varchar2(32),
19 | distance number(8),
20 | duration number(8),
21 | speed number(4),
22 | orientation varchar2(64),
23 | road varchar2(128),
24 | status varchar2(32),
25 | insert_time date,
26 | polyline sdo_geometry
27 | );
28 | */
29 | @Entity
30 | @Table(name = "GD_NAV_TRAFFIC")
31 | public class GdNavLink_hibernate {
32 | @Id
33 | @GeneratedValue(strategy = GenerationType.AUTO)
34 | private Long seq;
35 | private String dept;
36 | private Long tmcid;
37 | private String action;
38 | private Long distance;
39 | private Long duration;
40 | private Long speed;
41 | private String orientation;
42 | private String road;
43 | private String status;
44 | //@Temporal(TemporalType.TIMESTAMP) //指定时间格式
45 | @Column(name="insert_time") //指定特定的列名
46 | private java.sql.Timestamp insertTime;
47 | private Geometry polyline;
48 |
49 | public GdNavLink_hibernate() {
50 | super();
51 | }
52 |
53 | public GdNavLink_hibernate(String dept, Long tmcid, String action, Long distance,
54 | Long duration, Long speed,String orientation, String road, String status, java.sql.Timestamp insertTime, Geometry polyline) {
55 | super();
56 | this.dept = dept;
57 | this.tmcid = tmcid;
58 | this.action = action;
59 | this.distance = distance;
60 | this.duration = duration;
61 | this.speed = speed;
62 | this.orientation = orientation;
63 | this.road = road;
64 | this.status = status;
65 | this.insertTime = insertTime;
66 | this.polyline = polyline;
67 | }
68 |
69 |
70 |
71 | public Long getSeq() {
72 | return seq;
73 | }
74 |
75 | public void setSeq(Long seq) {
76 | this.seq = seq;
77 | }
78 |
79 | public String getDept() {
80 | return dept;
81 | }
82 |
83 | public void setDept(String dept) {
84 | this.dept = dept;
85 | }
86 |
87 | public Long getTmcid() {
88 | return tmcid;
89 | }
90 |
91 | public void setTmcid(Long tmcid) {
92 | this.tmcid = tmcid;
93 | }
94 |
95 | public String getAction() {
96 | return action;
97 | }
98 |
99 | public void setAction(String action) {
100 | this.action = action;
101 | }
102 |
103 | public Long getDistance() {
104 | return distance;
105 | }
106 |
107 | public void setDistance(Long distance) {
108 | this.distance = distance;
109 | }
110 |
111 | public Long getDuration() {
112 | return duration;
113 | }
114 |
115 | public void setDuration(Long duration) {
116 | this.duration = duration;
117 | }
118 |
119 | public Long getSpeed() {
120 | return speed;
121 | }
122 |
123 | public void setSpeed(Long speed) {
124 | this.speed = speed;
125 | }
126 |
127 | public String getOrientation() {
128 | return orientation;
129 | }
130 |
131 | public void setOrientation(String orientation) {
132 | this.orientation = orientation;
133 | }
134 |
135 | public String getRoad() {
136 | return road;
137 | }
138 |
139 | public void setRoad(String road) {
140 | this.road = road;
141 | }
142 |
143 | public String getStatus() {
144 | return status;
145 | }
146 |
147 | public void setStatus(String status) {
148 | this.status = status;
149 | }
150 |
151 | public java.sql.Timestamp getInsertTime() {
152 | return insertTime;
153 | }
154 |
155 | public void setInsertTime(java.sql.Timestamp insertTime) {
156 | this.insertTime = insertTime;
157 | }
158 |
159 | public Geometry getPolyline() {
160 | return polyline;
161 | }
162 |
163 | public void setPolyline(Geometry polyline) {
164 | this.polyline = polyline;
165 | }
166 |
167 | @Override
168 | public int hashCode() {
169 | return polyline.toText().toString().hashCode();
170 | }
171 | @Override
172 | public boolean equals(Object o) {
173 | GdNavLink_hibernate p2 = (GdNavLink_hibernate)o;
174 | // 判定条件: 1.geom满足equals关系;2.方向相同
175 | boolean if_equal = polyline.toText().equals(p2.getPolyline().toText()) &&
176 | orientation.equals(p2.getOrientation());
177 | return if_equal;
178 | }
179 |
180 | }
181 |
--------------------------------------------------------------------------------
/src/main/java/gaode/GetNav.java:
--------------------------------------------------------------------------------
1 | /* 高德导航,获取路况
2 | * hibernate版本
3 | * 请求示例:
4 | https://restapi.amap.com/v3/direction/driving?
5 | origin=119.363306,26.048199
6 | &destination=119.364579,26.041252
7 | &waypoints=119.2299,26.088477;119.236967,26.091547;119.240965,26.093188
8 | &strategy=10
9 | &extensions=all
10 | &key=你的key
11 | */
12 |
13 | package gaode;
14 |
15 | import java.util.ArrayList;
16 | import java.util.HashMap;
17 | import java.util.List;
18 | import java.util.Map;
19 |
20 | import org.hibernate.Session;
21 | import org.hibernate.Transaction;
22 |
23 | import com.google.gson.JsonArray;
24 | import com.google.gson.JsonObject;
25 | import com.google.gson.JsonParser;
26 | import com.vividsolutions.jts.geom.Coordinate;
27 | import com.vividsolutions.jts.geom.Geometry;
28 | import com.vividsolutions.jts.io.ParseException;
29 | import com.vividsolutions.jts.io.WKTReader;
30 |
31 | import entity.GdNavLink_hibernate;
32 | import utils.HttpClientResult;
33 | import utils.HttpClientUtils;
34 | import utils.JPAUtil;
35 |
36 | public class GetNav implements Runnable{
37 | private java.sql.Timestamp insert_time;
38 | private static List