Skip to content

Commit

Permalink
Avoid and handle fault masking
Browse files Browse the repository at this point in the history
  • Loading branch information
jonherrmann committed Oct 30, 2018
1 parent 90f2623 commit 4ff5f4c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/Developer_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ The structure's root is the _TopologicalErrors_ element and _name_ attribute rep

Each error possesses an simple integer ID ( _i_ attribute ) and the error type ( _t_ attribute). The names and attributes are abbreviated to support faster parsing of the error file. An error code can possess various properties which will be described below.

The X and Y properties always stand for the X and Y coordinates. All other properties (IS, CW, CCW) reference a feature and its geometry in the database.
The X and Y properties always stand for the X and Y coordinates. All other properties (IS, CW, CCW) reference a feature and its geometry in the database. If an error is returned more than one time for a point, a _p_ attribute (for previous) is added to the error, which may indicate fault masking. The value of _p_ referes to the first occurance of the error (_i_ value). topological-errors() does not return repeated errors.

The feature can be queried with the `feature()`, the geometry with `geometric-object()` function:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public interface TopologyErrorCollector extends Releasable {
void init();

void collectError(final TopologyErrorType topologyErrorType, final String... parameter);

void collectError(final TopologyErrorType topologyErrorType, final double x, final double y, final String... parameter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import de.interactive_instruments.SUtils;
import de.interactive_instruments.exceptions.ExcUtils;
import gnu.trove.TLongIntHashMap;

/**
* Object for persisting topological errors in a XML file
Expand All @@ -33,10 +34,12 @@ public class TopologyErrorXmlWriter implements TopologyErrorCollector {
private final String themeName;
private final XMLStreamWriter writer;
private int counter = 0;
private final TLongIntHashMap coordinateHashToPreviousErrorId;

public TopologyErrorXmlWriter(final String themeName, final XMLStreamWriter writer) {
this.themeName = themeName;
this.writer = writer;
this.coordinateHashToPreviousErrorId = new TLongIntHashMap(128);
}

@Override
Expand All @@ -55,16 +58,51 @@ public void init() {
@Override
public void collectError(final TopologyErrorType topologyErrorType, final String... parameter) {
try {
// error element
writer.writeStartElement("e");
// id
writer.writeAttribute("i", Integer.toString(++counter));
// errorType
writer.writeAttribute("t", topologyErrorType.toString());
if (parameter != null) {
for (int i = 0; i < parameter.length; i++) {
writer.writeStartElement(parameter[i]);
writer.writeCharacters(parameter[++i]);
writer.writeEndElement();
}

collectParameters(parameter);

writer.writeEndElement();
} catch (final XMLStreamException e) {
final String message = themeName + " " +
topologyErrorType.toString() + " : " + SUtils.concatStr(" ", parameter);
throw new IllegalStateException("Error writing topological error: " + message, e);
}
}

@Override
public void collectError(final TopologyErrorType topologyErrorType, final double x, final double y, final String... parameter) {
try {
// error element
writer.writeStartElement("e");
// id
writer.writeAttribute("i", Integer.toString(++counter));
// errorType
writer.writeAttribute("t", topologyErrorType.toString());

final long coordinateHash = TopologyBuilder.calcCoordHashCode(x,y);
final int previousErrorI = coordinateHashToPreviousErrorId.get(coordinateHash);
if(previousErrorI!=0) {
// previous error
writer.writeAttribute("p", Integer.toString(previousErrorI));
}else{
coordinateHashToPreviousErrorId.put(coordinateHash, counter);
}
writer.writeStartElement("X");
writer.writeCharacters(Double.toString(x));
writer.writeEndElement();

writer.writeStartElement("Y");
writer.writeCharacters(Double.toString(y));
writer.writeEndElement();

collectParameters(parameter);

writer.writeEndElement();
} catch (final XMLStreamException e) {
final String message = themeName + " " +
Expand All @@ -73,6 +111,17 @@ public void collectError(final TopologyErrorType topologyErrorType, final String
}
}

private void collectParameters(final String... parameter) throws XMLStreamException {
if (parameter != null) {
for (int i = 0; i < parameter.length; i++) {
writer.writeStartElement(parameter[i]);
writer.writeCharacters(parameter[++i]);
writer.writeEndElement();
}
}
}


@Override
public void release() {
try {
Expand Down
12 changes: 7 additions & 5 deletions src/main/xquery/TopoX.xq
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ declare function topox:topological-errors-doc($topologyId as xs:int) as node() {
(:~
: Returns all topological error (e) elements from the error document
:
: Repeated errors are filtered (they can be retrieved with the topological-errors-doc function).
:
: Note: for performance reasons, this a deterministic function. Calling this
: function after changing the error file might not result in a changed output.
:
Expand All @@ -238,7 +240,7 @@ declare function topox:topological-errors-doc($topologyId as xs:int) as node() {
: @return zero or more topological error elements
:)
declare function topox:topological-errors($topologyId as xs:int, $errorCodes as xs:string*) as element()* {
topox:topological-errors-doc($topologyId)/e[topox:check-error-code($errorCodes) or @t = $errorCodes]
topox:topological-errors-doc($topologyId)/e[not(@p) and (topox:check-error-code($errorCodes) or @t = $errorCodes)]
};

(:~
Expand Down Expand Up @@ -270,12 +272,12 @@ declare function topox:feature($compressedValue as xs:long) as node() {
: @param $errorCodes errorCodes to filter (optional)
: @return nothing
:)
declare function topox:export-erroneous-features-to-geojson($topologyId as xs:int, $attachmentId as xs:string, $errorCodes as xs:string*) as empty-sequence() {
declare function topox:export-erroneous-features-to-geojson($topologyId as xs:int, $geoJsonAttachmentId as xs:string, $errorCodes as xs:string*) as empty-sequence() {
let $topoErrors := topox:topological-errors($topologyId, $errorCodes)[not(@t = ('EDGE_NOT_FOUND', 'INVALID_ANGLE'))]
return (
topox:export-error-points($topologyId, $topoErrors),
topox:export-features($topologyId, $topoErrors),
java:attachIssueMap($topologyId, $attachmentId)
java:attachIssueMap($topologyId, $geoJsonAttachmentId)
)
};

Expand All @@ -287,8 +289,8 @@ declare function topox:export-erroneous-features-to-geojson($topologyId as xs:in
: @param $topologyId ID of the topology
: @return nothing
:)
declare function topox:export-erroneous-features-to-geojson($topologyId as xs:int, $attachmentId as xs:string) as empty-sequence() {
topox:export-erroneous-features-to-geojson($topologyId, $attachmentId, ())
declare function topox:export-erroneous-features-to-geojson($topologyId as xs:int, $geoJsonAttachmentId as xs:string) as empty-sequence() {
topox:export-erroneous-features-to-geojson($topologyId, $geoJsonAttachmentId, ())
};


Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/ddt/queries/default.xq
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ declare namespace adv='http://www.adv-online.de/namespaces/adv/gid/6.0';
declare namespace wfsAdv='http://www.adv-online.de/namespaces/adv/gid/wfs';
declare namespace gml='http://www.opengis.net/gml/3.2';
declare namespace ete='http://www.interactive-instruments.de/etf/topology-error/1.0';
declare namespace uuid='java.util.UUID';

import module namespace topox = 'https://modules.etf-validator.net/topox/1';

Expand Down Expand Up @@ -57,7 +58,7 @@ let $dummy := topox:detect-free-standing-surfaces($topoId)
security.fileuri.strict_origin_policy to false in Firefox
:)
let $initTime := prof:current-ms()
let $dummy := topox:export-erroneous-features-to-geojson($topoId, "Map")
let $dummy := topox:export-erroneous-features-to-geojson($topoId, "Map_" || uuid:randomUUID() || ".js")
let $duration := prof:current-ms()-$initTime
let $dummy := local:log(" Results exported in " || $duration || " ms" )

Expand Down

0 comments on commit 4ff5f4c

Please sign in to comment.