Global Positioning System Reference
In-Depth Information
The listing implies two additional conditions for the OSM delivery. For
one thing, it is important to use UTF-8 capable tools to write OSM files
in order not to break the unicodes and corrupt the file. Also, the OSM
delivery should be consistent with a well-formed XML file and every line
needs opening and closing tags.
The main method of the parser is parseOSM() . First two piped UTF-8
streams are created:
BufferedReader reader =
new BufferedReader(
new InputStreamReader(
new FileInputStream ( inFile ), "UTF8"));
BufferedWriter writer = ...
Then each line is read until the end of file is reached:
while ((line = reader.readLine()) != null)
{
// identify as element
element = createElement( elementType, line );
element = processElement( element );
// write element to output file
}
The method processElement(element) returns a (manipulated) ele-
ment or null , if the element should be removed. Different methods to
manipulate the elements are used according to the command-line switches.
These methods may serve as templates and look like:
List<String> methodName( List<String> element )
The rst method cleanAttributes(element) does exactly the data re-
duction described with the <node> element. The redundant attributes are
hard coded:
String[] attributes = {"timestamp", "visible", "user",
"action", "version", "uid", "changeset" };
The second method removeLine(element,regEx) introduces a second
parameter: a regular expression. A complete line is removed from the ele-
ment if it matches a regular expression. Additionally, the method optimizes
the element, while conserving XML validity.
The third method booleanidentifyElement(element,regEx) can be
used to check the entire element for a regular expression. The Boolean
result can be used to keep or dispose of the element according to the
command-line switch.
Reading regular expressions from the command line makes the tool very
flexible for all kinds of situations that a map engineer might encounter.
 
Search WWH ::




Custom Search