⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jtsalgorithms.java

📁 用于GIS(全球地理系统)的分析和处理的代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * 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.util.algo;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.CoordinateFilter;
import com.vividsolutions.jts.geom.Geometry;

import fr.ign.cogit.geoxygene.spatial.geomroot.GM_Object;
import fr.ign.cogit.geoxygene.util.conversion.JtsGeOxygene;

/**
  * Appel des methodes JTS sur des GM_Object.
  * cf. http://www.vividsolutions.com/jts/jtshome.htm
  *
  * @author Thierry Badard, Arnaud Braun & Christophe Pele 
  * @version 1.0
  * 
  */

public class JtsAlgorithms implements GeomAlgorithms {    
    
    
    public JtsAlgorithms() {
    }


    public GM_Object centroid(GM_Object geom) {
        try {
            Geometry jtsGeom=JtsGeOxygene.makeJtsGeom(geom);
            Geometry jtsCentroid=jtsGeom.getCentroid();
            return (JtsGeOxygene.makeGeOxygeneGeom(jtsCentroid));
        } catch (Exception e) {
            System.out.println("## CALCUL DE CENTROIDE AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
            e.printStackTrace();
            return null;
        }
    }

    public GM_Object convexHull(GM_Object geom)  {  
        try { 
            Geometry jtsGeom=JtsGeOxygene.makeJtsGeom(geom);           
            Geometry jtsHull=jtsGeom.convexHull();               
            GM_Object result=JtsGeOxygene.makeGeOxygeneGeom(jtsHull);
            return result;
        } catch (Exception e) {
            System.out.println("## CALCUL D'ENVELOPPE CONVEXE AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
            e.printStackTrace();
            return null;
        }
    }
    
     public GM_Object buffer (GM_Object geom, double distance) {
         try {            
             Geometry jtsGeom=JtsGeOxygene.makeJtsGeom(geom);             
             Geometry jtsBuffer=jtsGeom.buffer(distance);
             return JtsGeOxygene.makeGeOxygeneGeom(jtsBuffer);
         } catch (Exception e) {
             System.out.println("## CALCUL DE BUFFER AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
             e.printStackTrace();
             return null;
         }
     }
     
	public GM_Object buffer (GM_Object geom, double distance, int nSegments) {
		try {            
			Geometry jtsGeom=JtsGeOxygene.makeJtsGeom(geom);             
			Geometry jtsBuffer=jtsGeom.buffer(distance,nSegments);
			return JtsGeOxygene.makeGeOxygeneGeom(jtsBuffer);
		} catch (Exception e) {
			System.out.println("## CALCUL DE BUFFER AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
			e.printStackTrace();
			return null;
		}
	}
          
    public GM_Object buffer10 (GM_Object geom) {
        return buffer(geom,10);
    }
 
     public GM_Object boundary(GM_Object geom) {
         try {
             Geometry jtsGeom1=JtsGeOxygene.makeJtsGeom(geom);             
             Geometry jtsResult=jtsGeom1.getBoundary();
             return JtsGeOxygene.makeGeOxygeneGeom(jtsResult);       
         } catch (Exception e) {
             System.out.println("## CALCUL DE FRONTIERE AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
             e.printStackTrace();
             return null;
         }             
     }

    public GM_Object union(GM_Object g1, GM_Object g2)  {
        try {
            Geometry jtsGeom1=JtsGeOxygene.makeJtsGeom(g1);
            Geometry jtsGeom2=JtsGeOxygene.makeJtsGeom(g2);
            Geometry jtsUnion=jtsGeom1.union(jtsGeom2);
            return JtsGeOxygene.makeGeOxygeneGeom(jtsUnion);
        } catch (Exception e) {
            System.out.println("## CALCUL D'UNION AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
            e.printStackTrace();
            return null;
        }                        
    }   
    
    public GM_Object intersection(GM_Object g1, GM_Object g2) {
        try {
            Geometry jtsGeom1=JtsGeOxygene.makeJtsGeom(g1);
            Geometry jtsGeom2=JtsGeOxygene.makeJtsGeom(g2);
            Geometry jtsInter=jtsGeom1.intersection(jtsGeom2);
            return JtsGeOxygene.makeGeOxygeneGeom(jtsInter);
        } catch (Exception e) {
            System.out.println("## CALCUL D'INTERSECTION AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
            e.printStackTrace();
            return null;
        }            
    }    

    public GM_Object difference(GM_Object g1, GM_Object g2)   {
        try {
            Geometry jtsGeom1=JtsGeOxygene.makeJtsGeom(g1);             
            Geometry jtsGeom2=JtsGeOxygene.makeJtsGeom(g2);             
            Geometry jtsResult=jtsGeom1.difference(jtsGeom2);       
            return JtsGeOxygene.makeGeOxygeneGeom(jtsResult);
        } catch (Exception e) {
            System.out.println("## CALCUL DE DIFFERENCE AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
            e.printStackTrace();
            return null;
        }            
    }    

    public GM_Object symDifference(GM_Object g1, GM_Object g2) {
        try {
            Geometry jtsGeom1=JtsGeOxygene.makeJtsGeom(g1);
            Geometry jtsGeom2=JtsGeOxygene.makeJtsGeom(g2);
            Geometry jtsSymDiff=jtsGeom1.symDifference(jtsGeom2);
            return JtsGeOxygene.makeGeOxygeneGeom(jtsSymDiff);
        } catch (Exception e) {
            System.out.println("## CALCUL DE DIFFERENCE SYMETRIQUE AVEC JTS : PROBLEME (le resultat renvoie NULL) ##");
            e.printStackTrace();
            return null;
        }                        
    }    
    
    public boolean equals(GM_Object g1, GM_Object g2) {
        try {
            Geometry jtsGeom1=JtsGeOxygene.makeJtsGeom(g1);             
            Geometry jtsGeom2=JtsGeOxygene.makeJtsGeom(g2);             
            return jtsGeom1.equals(jtsGeom2);    
        } catch (Exception e) {
            System.out.println("## PREDICAT EQUALS AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
            e.printStackTrace();
            return false;
        }                                       
    }    

    public boolean equalsExact(GM_Object g1, GM_Object g2) {
        try {
            Geometry jtsGeom1=JtsGeOxygene.makeJtsGeom(g1);             
            Geometry jtsGeom2=JtsGeOxygene.makeJtsGeom(g2);             
            return jtsGeom1.equalsExact(jtsGeom2); 
        } catch (Exception e) {
            System.out.println("## PREDICAT EQUALSEXACT AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
            e.printStackTrace();
            return false;
        }                                                    
    }    
    
	public boolean equalsExact(GM_Object g1, GM_Object g2, double tol) {
		try {
			Geometry jtsGeom1=JtsGeOxygene.makeJtsGeom(g1);             
			Geometry jtsGeom2=JtsGeOxygene.makeJtsGeom(g2);             
			return jtsGeom1.equalsExact(jtsGeom2,tol); 
		} catch (Exception e) {
			System.out.println("## PREDICAT EQUALSEXACT AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
			e.printStackTrace();
			return false;
		}                                                    
	}        

    public boolean contains(GM_Object g1, GM_Object g2) {
        try {
            Geometry jtsGeom1=JtsGeOxygene.makeJtsGeom(g1);             
            Geometry jtsGeom2=JtsGeOxygene.makeJtsGeom(g2);             
            return jtsGeom1.contains(jtsGeom2);       
        } catch (Exception e) {
            System.out.println("## PREDICAT CONTAINS AVEC JTS : PROBLEME (le resultat renvoie FALSE) ##");
            e.printStackTrace();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -