gm_envelope.java
来自「用于GIS(全球地理系统)的分析和处理的代码。」· Java 代码 · 共 406 行 · 第 1/2 页
JAVA
406 行
/*
* This file is part of the GeOxygene project source files.
*
* GeOxygene aims at providing an open framework which implements OGC/ISO specifications for
* the development and deployment of geographic (GIS) applications. It is a open source
* contribution of the COGIT laboratory at the Institut G閛graphique National (the French
* National Mapping Agency).
*
* See: http://oxygene-project.sourceforge.net
*
* Copyright (C) 2005 Institut G閛graphique National
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this library (see file LICENSE if present); if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package fr.ign.cogit.geoxygene.spatial.coordgeom;
/**
* Rectangle englobant minimum en 2D, ou pave englobant minimium en 3D.
* Un GM_envelope est parallele aux axes.
*
* @author Thierry Badard & Arnaud Braun
* @version 1.0
*
*/
public class GM_Envelope {
////////////////////////////////////////////////////////////////////////////////////////////////
// Attributs et accesseurs /////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
/** Coin superieur : Xmax, Ymax, (Zmax).*/
protected DirectPosition upperCorner;
/** Affecte le coin superieur. */
public void setUpperCorner (DirectPosition UpperCorner) {
upperCorner = (DirectPosition)UpperCorner.clone();
}
/** Renvoie le coin superieur. */
public DirectPosition getUpperCorner () {
return this.upperCorner;
}
/** Coin inferieur : Xmin, Ymin, (Zmin). */
protected DirectPosition lowerCorner;
/** Affecte le coin inferieur. */
public void setLowerCorner (DirectPosition LowerCorner) {
lowerCorner = (DirectPosition)LowerCorner.clone();
}
/** Renvoie le coin inferieur. */
public DirectPosition getLowerCorner () {
return this.lowerCorner;
}
////////////////////////////////////////////////////////////////////////////////////////////////
// Constructeurs ///////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
/** Constructeur par defaut (initialise des points 3D par defaut). */
public GM_Envelope() {
upperCorner = new DirectPosition();
lowerCorner = new DirectPosition();
}
/** Constructeur a partir des 2 coins. Attention a l'ordre des points.*/
public GM_Envelope (DirectPosition UpperCorner, DirectPosition LowerCorner) {
upperCorner = UpperCorner;
lowerCorner = LowerCorner;
}
/** Constructeur a partir de coordonnees (2D). */
public GM_Envelope (double Xmin, double Xmax, double Ymin, double Ymax) {
upperCorner = new DirectPosition(Xmax, Ymax);
lowerCorner = new DirectPosition(Xmin, Ymin);
}
/** Constructeur a partir de coordonnees (3D). */
public GM_Envelope (double Xmin, double Xmax, double Ymin, double Ymax, double Zmin, double Zmax) {
upperCorner = new DirectPosition(Xmax, Ymax, Zmax);
lowerCorner = new DirectPosition(Xmin, Ymin, Zmin);
}
/** Construit un carre dont P est le centre, de cote d. */
public GM_Envelope (DirectPosition P, double d) {
double c = d/2;
upperCorner = new DirectPosition( P.getX()+c, P.getY()+c, P.getZ()+c );
lowerCorner = new DirectPosition( P.getX()-c, P.getY()-c, P.getZ()-c );
}
////////////////////////////////////////////////////////////////////////////////////////////////
// Divers get //////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
/** Renvoie la dimension (3D). */
public int getDimension() {
if (upperCorner.getDimension() == lowerCorner.getDimension())
return upperCorner.getDimension();
else {
System.out.println("GM_Enveloppe::getDimension() : Les points upperCorner et lowerCorner n'ont pas la m阭e dimension.");
return 0;
}
}
/** Renvoie la difference des X. */
public double width() {
return upperCorner.getX()-lowerCorner.getX();
}
/** Renvoie la difference des Y. */
public double length() {
return upperCorner.getY()-lowerCorner.getY();
}
/** Renvoie la difference des Z. */
public double height() {
return upperCorner.getZ()-lowerCorner.getZ();
}
/** Renvoie le X max. */
public double maxX() {
return upperCorner.getX();
}
/** Renvoie le X min. */
public double minX() {
return lowerCorner.getX();
}
/** Renvoie le Y max. */
public double maxY() {
return upperCorner.getY();
}
/** Renvoie le Y min. */
public double minY() {
return lowerCorner.getY();
}
/** Renvoie le Z max. */
public double maxZ() {
return upperCorner.getZ();
}
/** Renvoie le Z min. */
public double minZ() {
return lowerCorner.getZ();
}
/** Renvoie le centre de l'enveloppe. */
public DirectPosition center() {
int n = this.getDimension();
DirectPosition result = new DirectPosition();
for (int i=0; i<n; i++) {
double theMin = lowerCorner.getCoordinate(i);
double theMax = upperCorner.getCoordinate(i);
result.setCoordinate(i,theMin+(theMax-theMin)/2);
}
return result;
}
////////////////////////////////////////////////////////////////////////////////////////////////
// Methodes contains ///////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
/** Indique si self contient le point passe en parametre, fonctionne en 2D uniquement. */
public boolean contains (DirectPosition thePoint) {
// int n = this.getDimension();
int n=2;
for (int i=0; i<n; i++) {
double theCoord = thePoint.getCoordinate(i);
double theMin = lowerCorner.getCoordinate(i);
double theMax = upperCorner.getCoordinate(i);
if (theCoord > theMax) return false;
if (theCoord < theMin) return false;
}
return true;
}
/** Indique si self contient le point de coordonnees x,y passees en parametre (2D). */
public boolean contains (double x, double y) {
double Xmin = lowerCorner.getX();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?