📄 filtering.java
字号:
/*
* 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.generalisation;
import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPosition;
import fr.ign.cogit.geoxygene.spatial.coordgeom.DirectPositionList;
import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_LineString;
import fr.ign.cogit.geoxygene.spatial.coordgeom.GM_Polygon;
import fr.ign.cogit.geoxygene.spatial.geomaggr.GM_Aggregate;
import fr.ign.cogit.geoxygene.spatial.geomaggr.GM_MultiCurve;
import fr.ign.cogit.geoxygene.spatial.geomaggr.GM_MultiSurface;
import fr.ign.cogit.geoxygene.spatial.geomprim.GM_Curve;
import fr.ign.cogit.geoxygene.spatial.geomprim.GM_Ring;
import fr.ign.cogit.geoxygene.spatial.geomroot.GM_Object;
/**
* Methodes statiques de generalisation par filtrage (Douglas-Peucker).
*
* @author Thierry Badard & Arnaud Braun
* @version 1.0
*
*/
public class Filtering {
public Filtering () {
}
////////////////////////////////////////////////////////////////////////////////
///// DouglasPeucker ///////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/** Filtrage de Douglas-Peucker sur une polyligne. */
// On constitue une liste de points, et appelle la m閠hode "DouglasPeuckerListe" sur cette liste
public static GM_LineString DouglasPeuckerLineString (GM_Curve G0, double seuil) {
// lin閍rise la courbe
GM_LineString theLineString = null;
try {theLineString = G0.asLineString(0.0,0.0,0.0);}
catch (Exception e) {e.printStackTrace();}
// constitue une liste de points avec la polyligne
DirectPositionList initList = theLineString.coord();
// appelle la m閠hode qui agit sur la liste - on r閏up鑢e une liste de points
DirectPositionList resultList = DouglasPeuckerList(initList,seuil);
// cr閑 une polyligne avec cette liste de points
GM_LineString theResult = new GM_LineString(resultList);
return theResult;
}
/** Filtrage de Douglas-Peucker sur un polygone */
public static GM_Polygon DouglasPeuckerPoly (GM_Polygon P0, double seuil) {
// filtre la frontiere exterieure
GM_Curve ext = DouglasPeuckerLineString(P0.getExterior().getPrimitive(),seuil);
GM_Polygon poly = new GM_Polygon (ext);
// filtre les anneaux
if (P0.sizeInterior() != 0) {
for (int i=0; i<P0.sizeInterior(); i++) {
GM_Curve inte = DouglasPeuckerLineString(P0.getInterior(i).getPrimitive(),seuil);
poly.addInterior( new GM_Ring(inte) );
}
}
return poly;
}
/** Filtrage de DouglasPeucker sur un GM_Object.
Support閟 : Aggr間at, Courbe, Polyligne, Polygon. */
public static GM_Object DouglasPeucker (GM_Object geom, double seuil) {
if ((geom instanceof GM_Curve) || (geom instanceof GM_LineString)) return DouglasPeuckerLineString((GM_Curve)geom,seuil);
else if (geom instanceof GM_Polygon) return DouglasPeuckerPoly((GM_Polygon)geom,seuil);
else if (geom instanceof GM_MultiCurve) {
GM_MultiCurve aggr = (GM_MultiCurve)geom;
GM_MultiCurve result = new GM_MultiCurve();
for (int i=0; i<aggr.size(); i++) {
GM_Curve elt = (GM_Curve)aggr.get(i);
result.add(DouglasPeuckerLineString(elt,seuil));
}
return result;
}
else if (geom instanceof GM_MultiSurface) {
GM_MultiSurface aggr = (GM_MultiSurface)geom;
GM_MultiSurface result = new GM_MultiSurface();
for (int i=0; i<aggr.size(); i++) {
GM_Polygon elt = (GM_Polygon)aggr.get(i);
result.add(DouglasPeuckerPoly(elt,seuil));
}
return result;
}
else { //GM_Aggregat
GM_Aggregate aggr = (GM_Aggregate)geom;
GM_Aggregate result = new GM_Aggregate();
for (int i=0; i<aggr.size(); i++) {
GM_Object elt = (GM_Object)aggr.get(i);
result.add(DouglasPeucker(elt,seuil));
}
return result;
}
}
/** Douglas-Peucker sur une liste de points */
// On applique l'algo en utilisant la r閏ursivit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -