Skip to content

Commit

Permalink
Merge pull request #279 from IGNF/issue_278
Browse files Browse the repository at this point in the history
validator-core: update GeometryComplexityThresholdOption reader option
  • Loading branch information
cboucheIGN authored May 10, 2022
2 parents 4e4d410 + b8e7c8f commit fada7cd
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 328 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.commons.cli.ParseException;

import fr.ign.validator.geometry.GeometryComplexityThreshold;
import fr.ign.validator.geometry.GeometryThreshold;

/**
*
Expand All @@ -33,7 +34,7 @@ public static void buildOptions(Options options) {
{
Option option = new Option(
null, OPTION_NAME, true,
"List of threshold to survey geometry complexity : [[warningPointCount, warningRingCount, warningPartCount, warningDensity], [errorPointCount, errorRingCount, errorPartCount, errorDensity]]"
"List of threshold to survey geometry complexity : [[warnPoint, warnPart, warnRing, warnDensity, warnRingPoint], [errPoint, errRing, errPart, errDensity, errRingPoint]]"
);
option.setRequired(false);
options.addOption(option);
Expand Down Expand Up @@ -81,17 +82,23 @@ public static GeometryComplexityThreshold parseCustomOptions(CommandLine command
}

return new GeometryComplexityThreshold(
warningParameters[0].intValue(), warningParameters[1].intValue(),
warningParameters[2].intValue(), warningParameters[3],
errorParameters[0].intValue(), errorParameters[1].intValue(),
errorParameters[2].intValue(), errorParameters[3]
new GeometryThreshold(
warningParameters[0].intValue(), warningParameters[1].intValue(),
warningParameters[2].intValue(), warningParameters[3],
warningParameters[4].intValue()
),
new GeometryThreshold(
errorParameters[0].intValue(), errorParameters[1].intValue(),
errorParameters[2].intValue(), errorParameters[3],
errorParameters[4].intValue()
)
);
}

private static Double[] parseParameters(String[] params) {
Double[] parameters = new Double[4];
Double[] parameters = new Double[5];

if (params.length != 4) {
if (params.length != 5) {
return null;
}

Expand All @@ -100,6 +107,7 @@ private static Double[] parseParameters(String[] params) {
parameters[1] = Double.parseDouble(params[1].trim());
parameters[2] = Double.parseDouble(params[2].trim());
parameters[3] = Double.parseDouble(params[3].trim());
parameters[4] = Double.parseDouble(params[4].trim());
} catch (NumberFormatException e) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,104 +1,37 @@
package fr.ign.validator.geometry;

/**
* Defines treshold to determine geometry complexity - maximum point allowed -
* maximum ring (holes) allowed - maximum parts (multigeometry) allowed -
* maximum density (number of point by meters used to describe the geometry)
*
* All threshold work by couple a warning one or an error one
* A couple of warning threshold and an error one - used by geometry complexity
* validator
*
* @author cbouche
*
*/
public class GeometryComplexityThreshold {

private int warningPointCount;
private int warningRingCount;
private int warningPartCount;
private double warningDensity;

private int errorPointCount;
private int errorRingCount;
private int errorPartCount;
private double errorDensity;

public GeometryComplexityThreshold(
int warningPointCount, int warningRingCount, int warningPartCount, double warningDensity,
int errorPointCount, int errorRingCount, int errorPartCount, double errorDensity) {

this.warningPointCount = warningPointCount;
this.warningRingCount = warningRingCount;
this.warningPartCount = warningPartCount;
this.warningDensity = warningDensity;

this.errorPointCount = errorPointCount;
this.errorRingCount = errorRingCount;
this.errorPartCount = errorPartCount;
this.errorDensity = errorDensity;
}

public int getWarningPointCount() {
return warningPointCount;
}

public void setWarningPointCount(int warningPointCount) {
this.warningPointCount = warningPointCount;
}

public int getWarningRingCount() {
return warningRingCount;
}

public void setWarningRingCount(int warningRingCount) {
this.warningRingCount = warningRingCount;
}
private GeometryThreshold warningThreshold;

public int getWarningPartCount() {
return warningPartCount;
}

public void setWarningPartCount(int warningPartCount) {
this.warningPartCount = warningPartCount;
}

public double getWarningDensity() {
return warningDensity;
}

public void setWarningDensity(double warningDensity) {
this.warningDensity = warningDensity;
}

public int getErrorPointCount() {
return errorPointCount;
}

public void setErrorPointCount(int errorPointCount) {
this.errorPointCount = errorPointCount;
}

public int getErrorRingCount() {
return errorRingCount;
}
private GeometryThreshold errorThreshold;

public void setErrorRingCount(int errorRingCount) {
this.errorRingCount = errorRingCount;
public GeometryComplexityThreshold(GeometryThreshold warningThreshold, GeometryThreshold errorThreshold) {
this.warningThreshold = warningThreshold;
this.errorThreshold = errorThreshold;
}

public int getErrorPartCount() {
return errorPartCount;
public GeometryThreshold getWarningThreshold() {
return warningThreshold;
}

public void setErrorPartCount(int errorPartCount) {
this.errorPartCount = errorPartCount;
public void setWarningThreshold(GeometryThreshold warningThreshold) {
this.warningThreshold = warningThreshold;
}

public double getErrorDensity() {
return errorDensity;
public GeometryThreshold getErrorThreshold() {
return errorThreshold;
}

public void setErrorDensity(double errorDensity) {
this.errorDensity = errorDensity;
public void setErrorThreshold(GeometryThreshold errorThreshold) {
this.errorThreshold = errorThreshold;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package fr.ign.validator.geometry;

/**
* Defines treshold to determine geometry complexity - maximum point allowed -
* maximum ring (holes) allowed - maximum parts (multigeometry) allowed -
* maximum density (number of point by meters used to describe the geometry) -
* and maximum point of any ring (used in density control)
*
* @author cbouche
*
*/
public class GeometryThreshold {

private int pointCount;
private int partCount;
private int ringCount;
private double density;
private int ringPointCount;

public GeometryThreshold() {
}

public GeometryThreshold(int pointCount, int partCount, int ringCount, double density, int ringPointCount) {
this.pointCount = pointCount;
this.partCount = partCount;
this.ringCount = ringCount;
this.density = density;
this.ringPointCount = ringPointCount;
}

public int getPointCount() {
return pointCount;
}

public void setPointCount(int pointCount) {
this.pointCount = pointCount;
}

public int getPartCount() {
return partCount;
}

public void setPartCount(int partCount) {
this.partCount = partCount;
}

public int getRingCount() {
return ringCount;
}

public void setRingCount(int ringCount) {
this.ringCount = ringCount;
}

public double getDensity() {
return density;
}

public void setDensity(double density) {
this.density = density;
}

public int getRingPointCount() {
return ringPointCount;
}

public void setRingPointCount(int ringPointCount) {
this.ringPointCount = ringPointCount;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,24 @@ public void setUp() {
public void testParsingOk() throws ParseException {
String[] args = {
"--cnig-complexity-tolerance",
"[[5000, 600, 500, 0.1], [200000, 3000, 2000, 10]]"
"[[-1, 600, 500, 0.1, 50000], [200000, 3000, 2000, 10, 50005]]"
};
CommandLine commandLine = parser.parse(options, args);
GeometryComplexityThreshold result = GeometryComplexityThresholdOption.parseCustomOptions(commandLine);

assertNotNull(result);

assertEquals(5000, result.getWarningPointCount());
assertEquals(600, result.getWarningRingCount());
assertEquals(500, result.getWarningPartCount());
assertTrue(0.1 == result.getWarningDensity());

assertEquals(200000, result.getErrorPointCount());
assertEquals(3000, result.getErrorRingCount());
assertEquals(2000, result.getErrorPartCount());
assertTrue(10 == result.getErrorDensity());
assertEquals(-1, result.getWarningThreshold().getPointCount());
assertEquals(600, result.getWarningThreshold().getPartCount());
assertEquals(500, result.getWarningThreshold().getRingCount());
assertTrue(0.1 == result.getWarningThreshold().getDensity());
assertEquals(50000, result.getWarningThreshold().getRingPointCount());

assertEquals(200000, result.getErrorThreshold().getPointCount());
assertEquals(3000, result.getErrorThreshold().getPartCount());
assertEquals(2000, result.getErrorThreshold().getRingCount());
assertTrue(10 == result.getErrorThreshold().getDensity());
assertEquals(50005, result.getErrorThreshold().getRingPointCount());
}

@Test
Expand Down Expand Up @@ -96,7 +98,7 @@ public void testNotEnoughParam() throws ParseException {
public void testNotNumericParam() throws ParseException {
String[] args = {
"--cnig-complexity-tolerance",
"[[5000, 600, 500, 0.1], [ab, 3000, 2000, 10]]"
"[[5000, 600, 500, 0.1, 5000], [ab, 3000, 2000, 10, ab]]"
};
CommandLine commandLine = parser.parse(options, args);
GeometryComplexityThresholdOption.parseCustomOptions(commandLine);
Expand Down
Loading

0 comments on commit fada7cd

Please sign in to comment.