use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class StyleTester method readWayTags.
/**
* You can have a number of ways defined in the file. If you give a
* number after 'way' that is used as the way id so that you can identify
* it in the results.
*
* A list of tags are read and added to the way up until a blank line.
*
* @param br Read from here.
* @param waydef This will contain the way-id if one was given. Otherwise
* the way id will be 1.
* @throws IOException If the file cannot be read.
*/
private static Way readWayTags(BufferedReader br, String waydef) throws IOException {
int id = 1;
String[] strings = SPACES_PATTERN.split(waydef);
if (strings.length > 1)
id = Integer.parseInt(strings[1]);
Way w = new Way(id);
w.addPoint(new Coord(1, 1));
w.addPoint(new Coord(2, 2));
String line;
while ((line = br.readLine()) != null) {
if (line.indexOf('=') < 0)
break;
String[] tagval = EQUAL_PATTERN.split(line, 2);
if (tagval.length == 2)
w.addTag(tagval[0], tagval[1]);
}
return w;
}
use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class StyleTester method readSimpleTestFile.
/**
* Read in the combined test file. This contains some ways and a style.
* The style does not need to include 'version' as this is added for you.
*/
private static List<Way> readSimpleTestFile(BufferedReader br) throws IOException {
List<Way> ways = new ArrayList<>();
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.toLowerCase(Locale.ENGLISH).startsWith("way")) {
Way w = readWayTags(br, line);
ways.add(w);
} else if (line.startsWith("<<<")) {
// read the rest of the file
readStyles(br, line);
}
/*else if ("".equals(line) || line.startsWith("#")) {
// ignore blank lines.
}*/
}
br.close();
return ways;
}
use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class LengthFunction method calcLength.
private double calcLength(Element el) {
if (el instanceof Way) {
Way w = (Way) el;
double length = 0;
Coord prevC = null;
for (Coord c : w.getPoints()) {
if (prevC != null) {
length += prevC.distance(c);
}
prevC = c;
}
return length;
} else if (el instanceof Relation) {
Relation rel = (Relation) el;
double length = 0;
for (Entry<String, Element> relElem : rel.getElements()) {
if (relElem.getValue() instanceof Way || relElem.getValue() instanceof Relation) {
if (rel == relElem.getValue()) {
// avoid recursive call
log.error("Relation " + rel.getId() + " contains itself as element. This is not supported.");
} else {
length += calcLength(relElem.getValue());
}
}
}
return length;
} else {
throw new SyntaxException("length() cannot calculate elements of type " + el.getClass().getName());
}
}
use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class HousenumberMatch method isDirectlyConnected.
public boolean isDirectlyConnected(HousenumberMatch other) {
if (getElement() instanceof Way && other.getElement() instanceof Way) {
List<Coord> s1 = ((Way) getElement()).getPoints();
List<Coord> s2 = ((Way) other.getElement()).getPoints();
for (int i = 0; i + 1 < s1.size(); i++) {
Coord co = s1.get(i);
co.setPartOfShape2(false);
}
for (int i = 0; i + 1 < s2.size(); i++) {
Coord co = s2.get(i);
co.setPartOfShape2(true);
}
for (int i = 0; i + 1 < s1.size(); i++) {
Coord co = s1.get(i);
if (co.isPartOfShape2())
return true;
}
}
return false;
}
use of uk.me.parabola.mkgmap.reader.osm.Way in project mkgmap by openstreetmap.
the class O5mBinHandler method readWay.
/**
* read a way data set
* @throws IOException
*/
private void readWay() throws IOException {
lastWayId += readSignedNum64();
if (bytesToRead == 0)
// only wayId: this is a delete action, we ignore it
return;
readVersionTsAuthor();
if (bytesToRead == 0)
// only wayId + version: this is a delete action, we ignore it
return;
Way way = startWay(lastWayId);
long refSize = readUnsignedNum32();
long stop = bytesToRead - refSize;
while (bytesToRead > stop) {
lastRef[0] += readSignedNum64();
addCoordToWay(way, lastRef[0]);
}
readTags(way);
endWay(way);
}
Aggregations