/** * 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.geom.Geometry; import org.gvsig.tools.ToolsLocator; import org.gvsig.tools.dynobject.DynObject; import org.gvsig.tools.i18n.I18nManager; import org.gvsig.tools.task.SimpleTaskStatus; import org.gvsig.topology.lib.api.ExecuteTopologyRuleActionException; import org.gvsig.topology.lib.api.TopologyDataSet; import org.gvsig.topology.lib.api.TopologyReport; import org.gvsig.topology.lib.api.TopologyReportLine; import org.gvsig.topology.lib.api.TopologyRule; import org.gvsig.topology.lib.api.TopologyRuleFactory; import org.gvsig.topology.lib.spi.AbstractTopologyRule; import org.gvsig.topology.lib.spi.AbstractTopologyRuleAction; /** * * @author jjdelcerro */ @SuppressWarnings("UseSpecificCatch") public class LineMustBeLargerThanToleranceRule extends AbstractTopologyRule { private class DeleteAction extends AbstractTopologyRuleAction { public DeleteAction() { super( LineMustBeLargerThanToleranceRuleFactory.NAME, "delete", "Delete", "Removes line features that would collapse during the validate process based on the topology's tolerance." ); } @Override public int execute(TopologyRule rule, TopologyReportLine line, DynObject parameters) { try { TopologyDataSet dataset = line.getDataSet1(); dataset.delete(line.getFeature1()); return EXECUTE_OK; } catch (Exception ex) { throw new ExecuteTopologyRuleActionException(ex); } } } public LineMustBeLargerThanToleranceRule() { // for persistence only } public LineMustBeLargerThanToleranceRule( TopologyRuleFactory factory, double tolerance, String dataSet1, String dataSet2 ) { super(factory, tolerance, dataSet1, dataSet2); this.addAction(new DeleteAction()); } @Override public void check(SimpleTaskStatus taskStatus, TopologyReport report, Feature feature) throws Exception { Geometry geom = feature.getDefaultGeometry(); if( geom.perimeter()