判断一个面是不是矩形在GIS中很长用的功能,那么怎么判断一个面是不是矩形呢。

  这里先要弄懂一些概念,面是什么,先看OGC标准的定义。

  

  我的英文水平有限,(有翻译更好的请留言,如果翻译的准确将被采纳)大概的意思就是一个面(Polygon 后面说的面都指的是Polygon)是平面的,是由1个外边界和0或者多个内边界组成,每个内边界是一个多边形的孔。

  这样还是抽象啊,上个图就清醒多了。

  上面三个都是面,但是有一些特殊的情况,这里就不做深入讨论了,在不同的GIS框架中也有一点点小区别。

  好了我们就判断这样的面是不是矩形。

  

//首先在这里声明一下,这里不是全都得代码,你要是copy肯能不能运行这里讲的是个思想也是个基本的思路,希望大家能根据我的思路写出自己的代码
public boolean isRectangle()
{
//首先判断外外环上是不是有5个点
if(outLine.getPointNum() != 5) return false;
     //内环的数量只能是零
if(getNumInteriorRing() != 0) return false;
     //取这个面的外包络线
Envelope envelope = getEnvelope();
     //取出外包络线的宽和高
double envelopeHeight = envelope.getHeight();
double envelopeWidth = envelope.getWidth();
     //这里为什么循环4次,因为面的定义是闭合的,闭合要求首点和末点相等,这个是GIS的知识
     //这个for循环排出了一些情况。看图一
for (int i = 0 ; i < 5; i ++)
{
Coordinate coordinate = outLine.getPoint(i);
double x = coordinate.getX();
double y = coordinate.getY(); if (!(x == envelope.getMaxX() || x == envelope.getMinX()))
{
return false;
} if(!(y == envelope.getMaxY() || y == envelope.getMinY()))
{
return false;
}
}
     //这里是本框架的特殊定义,线有外接矩形。
if (envelopeHeight == 0 || envelopeWidth == 0)
{
return true;
} Coordinate upCoor = outLine.getPoint(0);
Coordinate nextCoor = outLine.getPoint(1);
     //因为计算机计算乘法比开方快,就选择了用乘法去进行进行
double doubleEnvelopeHeight = envelopeHeight * envelopeHeight;
double doubleEnvelopWidth = envelopeWidth * envelopeWidth;
     //除了图一难道还要其他的情况
     //请看图二
for (int i = 1; i < 4; i ++)
{
       //a^2 + b^2 这里不进行开方计算,为了效率
double length = MathUtil.distanceTwoPointNoSquare(upCoor,nextCoor);
if (length > doubleEnvelopeHeight && length > doubleEnvelopWidth)
{
return false;
}
upCoor = outLine.getPoint(i);
nextCoor = outLine.getPoint(i+1);
} return true;
}

  

图一

  

 for (int i = 0 ; i < 5; i ++)
{
Coordinate coordinate = outLine.getPoint(i);
double x = coordinate.getX();
double y = coordinate.getY(); if (!(x == envelope.getMaxX() || x == envelope.getMinX()))
{
return false;
} if(!(y == envelope.getMaxY() || y == envelope.getMinY()))
{
return false;
}
}

  这个for选好排出了点不在外接矩形的顶点上的情况。

图二

 

  for (int i = 1; i < 4; i ++)
{
       //a^2 + b^2 这里不进行开方计算,为了效率
double length = MathUtil.distanceTwoPointNoSquare(upCoor,nextCoor);
if (length > doubleEnvelopeHeight && length > doubleEnvelopWidth)
{
return false;
}
upCoor = outLine.getPoint(i);
nextCoor = outLine.getPoint(i+1);
}

  这个for循环式排出图二那种情况,每个点都在外接矩形的点上,(这里要特别的说明一下,有的GIS框架中点不能定义重复的点如最后面的三角形中最后两个点相同,大家不要有什么争议)。

作者   Young-Ken(微博)

审阅者 Cindy-Leee(微博)

转载请注明 http://www.cnblogs.com/youngKen/p/4987049.html

判断一个面(Polygon)是不是矩形的更多相关文章

  1. Android判断一个点是否在矩形区域内

    个人遇到的问题判断按钮的点击事件还是滑动事件 private boolean button1Down = false; private boolean button2Down = false; pri ...

  2. js 判断一个点是否在一个多边形之内

    出处: https://github.com/substack/point-in-polygon/blob/master/index.js github: https://github.com/sub ...

  3. Mysql中判断一个点是否落在多边形内

    关于地理空间数据,经常需要处理两个空间数据的关联关系.有很多种方法可以处理,通过编写程序算法,或者是调用数据库中对应的function.在mysql数据库中,https://dev.mysql.com ...

  4. 2019-11-29-win10-uwp-如何判断一个控件在滚动条的里面是用户可见

    原文:2019-11-29-win10-uwp-如何判断一个控件在滚动条的里面是用户可见 title author date CreateTime categories win10 uwp 如何判断一 ...

  5. 2019-4-29-win10-uwp-如何判断一个控件在滚动条的里面是用户可见

    title author date CreateTime categories win10 uwp 如何判断一个控件在滚动条的里面是用户可见 lindexi 2019-04-29 10:40:33 + ...

  6. 2019-4-29-WPF-如何判断一个控件在滚动条的里面是用户可见

    title author date CreateTime categories WPF 如何判断一个控件在滚动条的里面是用户可见 lindexi 2019-4-29 9:42:2 +0800 2019 ...

  7. Android 判断一个 View 是否可见 getLocalVisibleRect(rect) 与 getGlobalVisibleRect(rect)

    Android 判断一个 View 是否可见 getLocalVisibleRect(rect) 与 getGlobalVisibleRect(rect) [TOC] 这两个方法的区别 View.ge ...

  8. excel批处理_判断一个名称是不是药品

    把药品名称导入到sheet1的A字段 # -*- coding: utf-8 -*-"""Created on Fri Dec  9 09:38:58 2016判断一个名 ...

  9. 判断一个字符串str不为空的方法

    1.str == null; 2."".equals(str); 3.str.length 4.str.isEmpty(); 注意:length是属性,一般集合类对象拥有的属性,取 ...

随机推荐

  1. Contest2037 - CSU Monthly 2013 Oct (problem A :Small change)

    [题解]:二进制拆分 任意一个整数都可以拆分成 2^0 + 2^1 + 2^2 + 2^3 + ....+ m [code]: #include <iostream> #include & ...

  2. javascript中跨源资源共享

    来自<javascript高级程序设计 第三版:作者Nicholas C. Zakas>的学习笔记(十) 通过XHR实现Ajax通信的一个主要限制,来源于跨域安全策略.默认情况下,XHR对 ...

  3. <转>struts2中Convention中的basePackage与locators配置种种

    用了Convention插件来实现所谓的0配置, 1. struts.convention.package.locators.basePackage=com.ZTest.web.action 这个属性 ...

  4. ppshu

    全部书籍已经下载完毕! http://3cvpkfx4gdnkcduj.onion/ https://3cvpkfx4gdnkcduj.onion.cab/ https://3cvpkfx4gdnkc ...

  5. python top project of 2013

    Hi Pythonistas! 测试和调试 Testing & Debugging 框架及Web Frameworks & Web 并发 Concurrency 任务调度 Job Sc ...

  6. hdu 4336 Card Collector 容斥原理

    读完题目就知道要使用容斥原理做! 下面用的是二进制实现的容斥原理,详见:http://www.cnblogs.com/xin-hua/p/3213050.html 代码如下: #include< ...

  7. pflua:用Lua编写的高性能网络包过滤工具箱

    http://www.csdn.net/article/2014-09-05/2821568-pflua

  8. SGU111 Very simple problem

    多少个平方数小于等于X,二分. PS:java BigInteger. import java.util.*; import java.math.*; public class Solution { ...

  9. centos安装异常解决方法

    VMware系统安装Centos7后,第一次启动出现以下异常信息: Initial setup of CentOS Linux (core) ) [x] Creat user ) [!] Licens ...

  10. PHP使用Mysql事务实例解析

    <?php //数据库连接 $conn = mysql_connect('localhost', 'root', ''); mysql_select_db('test', $conn); mys ...