Search in sources :

Example 26 with Geometry

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);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) LineString(com.revolsys.geometry.model.LineString)

Example 27 with 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);
    }
}
Also used : OsmRelation(com.revolsys.record.io.format.openstreetmap.model.OsmRelation) ArrayList(java.util.ArrayList) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Geometry(com.revolsys.geometry.model.Geometry)

Example 28 with Geometry

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);
    }
}
Also used : OsmWay(com.revolsys.record.io.format.openstreetmap.model.OsmWay) Geometry(com.revolsys.geometry.model.Geometry) ArrayList(java.util.ArrayList) LineString(com.revolsys.geometry.model.LineString) Point(com.revolsys.geometry.model.Point) Point(com.revolsys.geometry.model.Point)

Example 29 with Geometry

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;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) ArcLineString(com.revolsys.record.io.format.saif.geometry.ArcLineString) ContourLineString(com.revolsys.record.io.format.saif.geometry.ContourLineString) LineString(com.revolsys.geometry.model.LineString) TreeMap(java.util.TreeMap)

Example 30 with 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();
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry)

Aggregations

Geometry (com.revolsys.geometry.model.Geometry)488 Point (com.revolsys.geometry.model.Point)140 LineString (com.revolsys.geometry.model.LineString)87 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)75 ArrayList (java.util.ArrayList)70 BoundingBox (com.revolsys.geometry.model.BoundingBox)39 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)39 Polygon (com.revolsys.geometry.model.Polygon)34 List (java.util.List)33 Record (com.revolsys.record.Record)32 Iterator (java.util.Iterator)20 RecordDefinition (com.revolsys.record.schema.RecordDefinition)18 LinearRing (com.revolsys.geometry.model.LinearRing)16 Vertex (com.revolsys.geometry.model.vertex.Vertex)16 LayerRecord (com.revolsys.swing.map.layer.record.LayerRecord)14 LineSegment (com.revolsys.geometry.model.segment.LineSegment)13 GeometricShapeFactory (com.revolsys.geometry.util.GeometricShapeFactory)13 FieldDefinition (com.revolsys.record.schema.FieldDefinition)12 DataType (com.revolsys.datatype.DataType)10 IOException (java.io.IOException)10