use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class OsmWay method setGeometry.
protected void setGeometry(final List<Point> points) {
Geometry geometry;
if (points.isEmpty()) {
geometry = OsmConstants.WGS84_2D.point();
} else if (points.size() == 1) {
geometry = points.get(0);
} else {
final LineString line = OsmConstants.WGS84_2D.lineString(points);
if (isArea() && line.isClosed()) {
geometry = OsmConstants.WGS84_2D.polygon(line);
} else {
geometry = line;
}
}
setGeometryValue(geometry);
}
use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class OsmPbfRecordIterator method parseRelation.
private void parseRelation(final ProtocolBufferInputStream input) throws IOException {
final OsmRelation relation = new OsmRelation();
final List<String> keys = new ArrayList<>();
final List<String> values = new ArrayList<>();
final List<Long> memberIds = new ArrayList<>();
final List<Integer> memberTypes = new ArrayList<>();
final List<String> memberRoles = new ArrayList<>();
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();
relation.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, relation);
break;
case 64:
readStrings(input, memberRoles);
break;
case 66:
readStringsByIds(input, memberRoles);
break;
case 72:
input.readLong(memberIds);
break;
case 74:
input.readLongs(memberIds);
break;
case 80:
input.readEnum(memberTypes);
break;
case 82:
input.readEnums(memberTypes);
break;
default:
input.skipField(tag);
break;
}
}
input.endLengthDelimited(inLength);
addTags(relation, keys, values);
final List<Geometry> parts = new ArrayList<>();
long memberId = 0;
for (int i = 0; i < memberIds.size(); i++) {
final long memberIdOffset = memberIds.get(i);
memberId += memberIdOffset;
Geometry geometry = null;
final int memberType = memberTypes.get(i);
switch(memberType) {
case 0:
geometry = this.nodePoints.get(memberId);
break;
case 1:
geometry = this.wayGeometries.get(memberId);
break;
default:
throw new RuntimeException("Unknown member type " + memberType);
}
if (geometry != null) {
parts.add(geometry);
}
}
if (memberIds.size() == parts.size()) {
final Geometry geometry = OsmConstants.WGS84_2D.geometry(parts);
if (memberTypes.get(0) == 1 && !Property.hasValue(memberRoles.get(0))) {
}
relation.setGeometryValue(geometry);
this.currentRecords.add(relation);
final long relationId = relation.getId();
this.relationGeometries.put(relationId, geometry);
} else {
this.relations.add(relation);
this.relationMemberIds.add(memberIds);
this.relationMemberRoles.add(memberRoles);
this.relationMemberTypes.add(memberTypes);
}
}
use of com.revolsys.geometry.model.Geometry 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);
}
}
use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class ContourConverter method read.
@Override
public Object read(final OsnIterator iterator) {
final Map<String, Object> values = new TreeMap<>();
values.put(SaifConstants.TYPE, GEOMETRY_CLASS);
Geometry geometry = null;
String fieldName = iterator.nextFieldName();
while (fieldName != null) {
if (fieldName.equals("arc")) {
final String objectName = iterator.nextObjectName();
final OsnConverter osnConverter = this.converters.getConverter(objectName);
if (osnConverter == null) {
iterator.throwParseError("No Geometry Converter for " + objectName);
}
geometry = (Geometry) osnConverter.read(iterator);
} else if (fieldName.equals("value")) {
final double value = iterator.nextDoubleValue();
values.put("value", new Double(value));
} else {
readAttribute(iterator, fieldName, values);
}
fieldName = iterator.nextFieldName();
}
Property.set(geometry, values);
return geometry;
}
use of com.revolsys.geometry.model.Geometry in project com.revolsys.open by revolsys.
the class WithinDistance method test.
@Override
public boolean test(final Record record) {
if (this.geometry1Value == null || this.geometry2Value == null || this.distanceValue == null) {
return false;
} else {
final Geometry geometry1 = this.geometry1Value.getValue(record);
final Geometry geometry2 = this.geometry2Value.getValue(record);
;
final Number acceptDistance = this.distanceValue.getValue(record);
if (acceptDistance == null || geometry1 == null || geometry2 == null) {
return false;
} else {
final double distance = geometry1.distance(geometry2);
return distance <= acceptDistance.doubleValue();
}
}
}
Aggregations