use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class O5mBinHandler method readRel.
/**
* read a relation data set
* @throws IOException
*/
private void readRel() throws IOException {
lastRelId += readSignedNum64();
if (bytesToRead == 0)
// only relId: this is a delete action, we ignore it
return;
readVersionTsAuthor();
if (bytesToRead == 0)
// only relId + version: this is a delete action, we ignore it
return;
GeneralRelation rel = new GeneralRelation(lastRelId);
long refSize = readUnsignedNum32();
long stop = bytesToRead - refSize;
while (bytesToRead > stop) {
Element el = null;
long deltaRef = readSignedNum64();
int refType = readRelRef();
String role = stringPair[1];
lastRef[refType] += deltaRef;
long memId = lastRef[refType];
if (refType == 0) {
el = saver.getNode(memId);
if (el == null) {
// we didn't make a node for this point earlier,
// do it now (if it exists)
Coord co = saver.getCoord(memId);
if (co != null) {
el = new Node(memId, co);
saver.addNode((Node) el);
}
}
} else if (refType == 1) {
el = saver.getWay(memId);
} else if (refType == 2) {
el = saver.getRelation(memId);
if (el == null) {
saver.deferRelation(memId, rel, role);
}
} else {
assert false;
}
if (// ignore non existing ways caused by splitting files
el != null)
rel.addElement(role, el);
}
boolean tagsIncomplete = readTags(rel);
rel.setTagsIncomplete(tagsIncomplete);
saver.addRelation(rel);
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class PolishMapDataSource method coordsFromString.
private List<Coord> coordsFromString(String value) {
String[] ords = value.split("\\) *, *\\(");
List<Coord> points = new ArrayList<>();
for (String s : ords) {
Coord co = makeCoord(s);
if (log.isDebugEnabled())
log.debug(" L: ", co);
mapper.addToBounds(co);
points.add(co);
}
log.debug(points.size() + " points from " + value);
return points;
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class PolishMapDataSource method endSection.
/**
* At the end of a section, we add what ever element that we have been
* building to the map.
*/
private void endSection() {
switch(section) {
case S_IMG_ID:
break;
case S_POINT:
if (extraAttributes != null && point.hasExtendedType())
point.setExtTypeAttributes(makeExtTypeAttributes());
mapper.addToBounds(point.getLocation());
mapper.addPoint(point);
break;
case S_POLYLINE:
if (points != null) {
if (roadHelper.isRoad()) {
polyline.setPoints(points);
mapper.addRoad(roadHelper.makeRoad(polyline));
} else {
if (extraAttributes != null && polyline.hasExtendedType())
polyline.setExtTypeAttributes(makeExtTypeAttributes());
final int maxPointsInLine = LineSplitterFilter.MAX_POINTS_IN_LINE;
if (points.size() > maxPointsInLine) {
List<Coord> segPoints = new ArrayList<>(maxPointsInLine);
for (Coord p : points) {
segPoints.add(p);
if (segPoints.size() == maxPointsInLine) {
MapLine seg = polyline.copy();
seg.setPoints(segPoints);
mapper.addLine(seg);
segPoints = new ArrayList<>(maxPointsInLine);
segPoints.add(p);
}
}
if (!segPoints.isEmpty()) {
polyline.setPoints(segPoints);
mapper.addLine(polyline);
}
} else {
polyline.setPoints(points);
mapper.addLine(polyline);
}
}
}
break;
case S_POLYGON:
if (points != null) {
if (points.get(0) != points.get(points.size() - 1)) {
// not closed, close it
points.add(points.get(0));
}
shape.setPoints(points);
if (extraAttributes != null && shape.hasExtendedType())
shape.setExtTypeAttributes(makeExtTypeAttributes());
mapper.addShape(shape);
}
break;
case S_RESTRICTION:
restrictionHelper.addRestriction(restriction);
break;
case 0:
// ignored section
break;
default:
log.warn("unexpected default in switch", section);
break;
}
// Clear the section state.
section = 0;
endLevel = 0;
points = null;
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class PolishMapDataSource method makeCoord.
/**
* Create a coordinate from a string. The string will look similar:
* (2.3454,-0.23), but may not have the leading opening parenthesis.
* @param value A string representing a lat,long pair.
* @return The coordinate value.
*/
private Coord makeCoord(String value) {
String[] fields = value.split("[(,)]");
int i = 0;
if (fields[0].isEmpty())
i = 1;
Double f1 = Double.valueOf(fields[i]);
Double f2 = Double.valueOf(fields[i + 1]);
Coord co = new Coord(f1, f2);
long key = Utils.coord2Long(co);
Coord co2 = coordMap.get(key);
if (co2 != null)
return co2;
coordMap.put(key, co);
return co;
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class PolishMapDataSource method point.
/**
* This is called for every line within the POI section. The lines are
* key value pairs that have already been decoded into name and value.
* For each name we recognise we set the appropriate property on
* the <i>point</i>.
*
* @param name Parameter name.
* @param value Its value.
*/
private void point(String name, String value) {
if (name.equals("Type")) {
int type = Integer.decode(value);
point.setType(type);
} else if (name.equals("SubType")) {
int subtype = Integer.decode(value);
int type = point.getType();
if (type <= 0xff)
point.setType((type << 8) | subtype);
} else if (name.startsWith("Data") || name.startsWith("Origin")) {
Coord co = makeCoord(value);
setResolution(point, name);
point.setLocation(co);
} else {
if (extraAttributes == null)
extraAttributes = new HashMap<>();
extraAttributes.put(name, value);
}
}
Aggregations