📄 trackscompare.java
字号:
package net.aetherial.gis.test.tools.lost.track;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.Vector;
import net.aetherial.gis.test.tools.lost.publicuse.TongtuClientException;
import net.aetherial.gis.surface.ItemValue;
/**
* <p>标题: 农村公路数据采集与核对工具</p>
*
* <p>描述: 实现<tt>TrackHypotaxis</tt>接口类中的方法</p>
*
* <p>版权: Copyright (c) 2006</p>
*
* <p>公司: 安徽省通途信息技术公司</p>
*
* @author 王爱国
* @version 1.0
*/
public class TracksCompare
implements TrackHypotaxis {
public TracksCompare() {
}
/**
* 得到航迹与比较航迹之间的关系种类
*
* 不相同 返回 0
* 相等 返回 1
* 缺少 返回 2
* 被包含 返回 3
* 被多条航迹包含 返回 4
* 部分不一致 返回 5
* 其他 返回 6
* 不存在 返回 -1
*
*/
public int getTracksCompareType(Node sourceTrack, Node compareTrack) throws
TongtuClientException {
if (this.isTrack_相等(sourceTrack, compareTrack)) {
return this.TYPE_1_相等;
}
else if (this.isTrack_缺少(sourceTrack, compareTrack)) {
return this.TYPE_2_缺少;
}
else if (this.isTrack_被包含(sourceTrack, compareTrack)) {
return this.TYPE_3_被包含;
}
else if (this.isTrack_部分不一致(sourceTrack, compareTrack)) {
return this.TYPE_5_部分不一致;
}
return TrackHypotaxis.TYPE_0_不相同;
}
/**
* 得到航迹与比较航迹之间的关系种类
*
* 不相同 返回 0
* 相等 返回 1
* 缺少 返回 2
* 被包含 返回 3
* 被多条航迹包含 返回 4
* 部分不一致 返回 5
* 其他 返回 6
* 不存在 返回 -1
*
*/
public int getTracksCompareType(Node sourceTrack, Node[] compareTracks) throws
TongtuClientException {
if (compareTracks == null) {
return TrackHypotaxis.TYPE_0_不相同;
}
if (this.isTrack_被多条航迹分割包含(sourceTrack, compareTracks)) {
return this.TYPE_4_被多条航迹包含;
}
for (int i = 0; i < compareTracks.length; i++) {
if (this.isTrack_相等(sourceTrack, compareTracks[i])) {
return this.TYPE_1_相等;
}
else if (this.isTrack_被包含(sourceTrack, compareTracks[i])) {
return this.TYPE_3_被包含;
}
else if(this.isTrack_部分不一致(sourceTrack, compareTracks[i]))
{
return this.TYPE_5_部分不一致;
}
else if(this.isTrack_缺少(sourceTrack, compareTracks[i]))
{
return this.TYPE_2_缺少;
}
}
return this.TYPE_0_不相同;
}
/**
* 判断源航迹与目标航迹是否完全相等
*/
private boolean isTrack_相等(Node sourceTrack, Node compareTrack) {
if (sourceTrack == null || compareTrack == null) {
return false;
}
else {
NodeList nl1 = ItemValue.getTracksPoint(sourceTrack);
NodeList nl2 = ItemValue.getTracksPoint(compareTrack);
if (nl1 == null || nl2 == null) {
return false;
}
else {
if (nl1.getLength() != nl2.getLength()) {
return false;
}
else {
for (int i = 0; i < nl1.getLength(); i++) {
if (!this.isTrackPointEquals( (Node) nl1.item(i), (Node) nl2.item(i))) {
return false;
}
}
return true;
}
}
}
}
/**
* 判断源航迹是否被目标航迹包含
*/
private boolean isTrack_被包含(Node sourceTrack, Node compareTrack) {
if (sourceTrack == null || compareTrack == null) {
return false;
}
else {
NodeList nl1 = ItemValue.getTracksPoint(sourceTrack);
NodeList nl2 = ItemValue.getTracksPoint(compareTrack);
if (nl1 == null || nl2 == null) {
return false;
}
else if (nl1.getLength() >= nl2.getLength()) {
return false;
}
else {
for (int i = 0; i < nl1.getLength(); i++) {
if (!this.isTrackpointInTrack(nl1.item(i), compareTrack)) {
return false;
}
}
return true;
}
}
}
/**
* 判断源航迹比目标航迹少
*/
private boolean isTrack_缺少(Node sourceTrack, Node compareTrack) {
if (this.isTrack_被包含(compareTrack, sourceTrack)) {
return true;
}
else {
return false;
}
}
/**
* 判断源航迹与目标航迹是否部分一致
*/
private boolean isTrack_部分不一致(Node sourceTrack, Node compareTrack) {
if (sourceTrack == null || compareTrack == null) {
return false;
}
else {
NodeList nl1 = ItemValue.getTracksPoint(sourceTrack);
NodeList nl2 = ItemValue.getTracksPoint(compareTrack);
if (nl1 == null || nl2 == null) {
return false;
}
else {
int equal = 0;
for (int i = 0; i < nl1.getLength(); i++) {
if (this.isTrackpointInTrack(nl1.item(i), compareTrack)) {
equal++;
}
}
if ( (equal != nl1.getLength() && equal != nl2.getLength()) &&
equal >= 2) {
return true;
}
else {
return false;
}
}
}
}
/**
*判断源航迹是否被目标内的所有航迹分割包含
*/
private boolean isTrack_被多条航迹分割包含(Node sourceTrack, Node[] compareTracks) {
if (sourceTrack == null || compareTracks == null) {
return false;
}
else {
Vector tps = new Vector();
NodeList nl = ItemValue.getTracksPoint(sourceTrack);
for (int i = 0; nl != null && i < nl.getLength(); i++) {
tps.add(nl.item(i));
}
int primalsize = tps.size();
Node tp = null;
for (int i = 0; i < compareTracks.length; i++) {
for (int j = 0; j < tps.size(); j++) {
tp = (Node) tps.elementAt(j);
if (this.isTrackpointInTrack(tp, compareTracks[i])) {
tps.removeElement(tp);
}
}
}
if ( (tps.size() < 2) && (tps.size() < primalsize - 1)) {
return true;
}
else {
return false;
}
}
}
/**
* 判断航迹点是否在目标航迹内
*/
private boolean isTrackpointInTrack(Node trackpoint, Node track) {
NodeList nl = ItemValue.getTracksPoint(track);
for (int i = 0; nl != null && i < nl.getLength(); i++) {
if (this.isTrackPointEquals(trackpoint, nl.item(i))) {
return true;
}
}
return false;
}
/**
* 判断源航迹点与目标航迹点是否完全相等
*/
private boolean isTrackPointEquals(Node sourceTrackpoint,
Node compareTrackpoint) {
if (sourceTrackpoint == null && compareTrackpoint == null) {
return true;
}
else if (sourceTrackpoint == null || compareTrackpoint == null) {
return false;
}
else {
double s_x = Double.parseDouble(ItemValue.getTracksPointX(
sourceTrackpoint));
double s_y = Double.parseDouble(ItemValue.getTracksPointY(
sourceTrackpoint));
double c_x = Double.parseDouble(ItemValue.getTracksPointX(
compareTrackpoint));
double c_y = Double.parseDouble(ItemValue.getTracksPointY(
compareTrackpoint));
/**
* 为避免Double类型数据的不准确性,Double类型的数据比较采用数值差小于0.000001 == 0.2米
*/
if (Math.abs(s_x - c_x) < 0.000001 && Math.abs(s_y - c_y) < 0.000001) {
return true;
}
else {
return false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -