use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class PointConverter method read.
@Override
public Object read(final OsnIterator iterator) {
final Map<String, Object> values = new TreeMap<>();
values.put("type", this.geometryClass);
Point point = null;
String fieldName = iterator.nextFieldName();
while (fieldName != null) {
if (fieldName.equals("coords")) {
final String coordTypeName = iterator.nextObjectName();
if (coordTypeName.equals("/Coord3D")) {
final double x = iterator.nextDoubleAttribute("c1");
final double y = iterator.nextDoubleAttribute("c2");
double z = iterator.nextDoubleAttribute("c3");
if (z == 2147483648.0) {
z = 0;
}
final GeometryFactory geometryFactory = this.geometryFactory.convertAxisCount(3);
point = newPoint(geometryFactory, x, y, z);
} else if (coordTypeName.equals("/Coord2D")) {
final double x = iterator.nextDoubleAttribute("c1");
final double y = iterator.nextDoubleAttribute("c2");
final GeometryFactory geometryFactory = this.geometryFactory.convertAxisCount(3);
point = newPoint(geometryFactory, x, y);
} else {
iterator.throwParseError("Expecting Coord2D or Coord3D");
}
iterator.nextEndObject();
} else {
readAttribute(iterator, fieldName, values);
}
fieldName = iterator.nextFieldName();
}
Property.set(point, values);
return point;
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class PointConverter method write.
@Override
public void write(final OsnSerializer serializer, final Object object) throws IOException {
if (object instanceof Point) {
final Point point = (Point) object;
final int axisCount = point.getAxisCount();
final double x = point.getX();
final double y = point.getY();
final double z = point.getZ();
serializer.startObject(this.geometryClass);
serializer.fieldName("coords");
if (axisCount == 2) {
serializer.startObject("/Coord2D");
serializer.attribute("c1", x, true);
serializer.attribute("c2", y, false);
} else {
serializer.startObject("/Coord3D");
serializer.attribute("c1", x, true);
serializer.attribute("c2", y, true);
if (Double.isNaN(z)) {
serializer.attribute("c3", 0, false);
} else {
serializer.attribute("c3", z, false);
}
}
serializer.endObject();
serializer.endAttribute();
writeAttributes(serializer, point);
serializer.endObject();
}
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class OsmDocument method addNode.
public void addNode(final OsmNode node) {
if (node != null) {
final long id = node.getId();
final Point point = node.getGeometry();
this.nodePointMap.put(id, point);
if (node.isTagged()) {
this.nodeMap.put(id, node);
this.nodes.add(node);
this.records.add(node);
}
}
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class OsmPbfRecordIterator method parseNode.
private void parseNode(final ProtocolBufferInputStream input) throws IOException {
final OsmNode node = new OsmNode();
final List<String> keys = new ArrayList<>();
final List<String> values = new ArrayList<>();
double lat = 0;
double lon = 0;
final int inLength = input.startLengthDelimited();
boolean running = true;
while (running) {
final int tag = input.readTag();
switch(tag) {
case 0:
running = false;
break;
case 8:
final long id = input.readInt64();
node.setId(id);
break;
case 16:
readStringById(input, keys);
break;
case 18:
readStringsByIds(input, keys);
break;
case 24:
readStringById(input, values);
break;
case 26:
readStringsByIds(input, values);
break;
case 34:
parseInfo(input, node);
break;
case 64:
lat = toDegrees(input.readSInt64());
break;
case 72:
lon = toDegrees(input.readSInt64());
break;
default:
input.skipField(tag);
break;
}
}
input.endLengthDelimited(inLength);
final Point point = OsmConstants.WGS84_2D.point(lat, lon);
node.setGeometryValue(point);
addTags(node, keys, values);
this.currentRecords.add(node);
}
use of com.revolsys.geometry.model.Point in project com.revolsys.open by revolsys.
the class OsmPbfRecordIterator method parseWay.
private void parseWay(final ProtocolBufferInputStream input) throws IOException {
final OsmWay way = new OsmWay();
final List<String> keys = new ArrayList<>();
final List<String> values = new ArrayList<>();
final List<Long> nodeIds = new ArrayList<>();
final int inLength = input.startLengthDelimited();
boolean running = true;
long wayId = 0;
while (running) {
final int tag = input.readTag();
switch(tag) {
case 0:
running = false;
break;
case 8:
wayId = input.readInt64();
way.setId(wayId);
break;
case 16:
readStringById(input, keys);
break;
case 18:
readStringsByIds(input, keys);
break;
case 24:
readStringById(input, values);
break;
case 26:
readStringsByIds(input, values);
break;
case 34:
parseInfo(input, way);
break;
case 64:
input.readLong(nodeIds);
break;
case 66:
input.readLongs(nodeIds);
break;
default:
input.skipField(tag);
break;
}
}
input.endLengthDelimited(inLength);
addTags(way, keys, values);
final List<Point> points = new ArrayList<>();
long nodeId = 0;
for (final long nodeIdOffset : nodeIds) {
nodeId += nodeIdOffset;
final Point point = this.nodePoints.get(nodeId);
if (point != null) {
points.add(point);
}
}
if (nodeIds.size() == points.size()) {
Geometry geometry;
if (points.size() == 1) {
geometry = points.get(0);
} else {
geometry = OsmConstants.WGS84_2D.lineString(points);
}
way.setGeometryValue(geometry);
isPolygon(way, geometry);
if (way.hasTags()) {
this.currentRecords.add(way);
}
geometry = way.getGeometry();
this.wayGeometries.put(wayId, geometry);
} else {
this.ways.add(way);
this.wayNodeIds.add(nodeIds);
}
}
Aggregations