/** * gvSIG. Desktop Geographic Information System. * * Copyright (C) 2007-2021 gvSIG Association. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * For any additional information, do not hesitate to contact us * at info AT gvsig.com, or visit our website www.gvsig.com. */ package org.gvsig.topology.rule; import org.gvsig.fmap.dal.feature.Feature; import org.gvsig.fmap.dal.feature.FeatureSet; import org.gvsig.fmap.geom.Geometry; import org.gvsig.tools.ToolsLocator; import org.gvsig.tools.i18n.I18nManager; import org.gvsig.tools.task.SimpleTaskStatus; import org.gvsig.topology.lib.api.TopologyReport; import org.gvsig.topology.lib.api.TopologyRuleFactory; import org.gvsig.topology.lib.spi.AbstractTopologyRule; /** * * @author jjdelcerro */ @SuppressWarnings("UseSpecificCatch") public class GeometryIsValidRule extends AbstractTopologyRule { public GeometryIsValidRule() { // for persistence only } public GeometryIsValidRule( TopologyRuleFactory factory, double tolerance, String dataSet1, String dataSet2 ) { super(factory, tolerance, dataSet1, dataSet2); } @Override protected void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature1) throws Exception { FeatureSet set = null; try { Geometry geom = feature1.getDefaultGeometry(); Geometry.ValidationStatus status = geom.getValidationStatus(); if ( !status.isValid() ) { I18nManager i18n = ToolsLocator.getI18nManager(); report.addLine(this, this.getDataSet1(), this.getDataSet2(), feature1.getDefaultGeometry(), status.getProblemLocation(), feature1.getReference(), null, false, i18n.getTranslation("_The_geometry_is_not_valid")+". "+status.getMessage() ); } } catch(Exception ex) { LOGGER.warn("Can't check feature.", ex); addCodeException(report, feature1, ex); } finally { if( set!=null ) { set.dispose(); } } } }