Search in sources :

Example 91 with Point

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;
}
Also used : GeometryFactory(com.revolsys.geometry.model.GeometryFactory) Point(com.revolsys.geometry.model.Point) TreeMap(java.util.TreeMap)

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

Example 93 with Point

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

Example 94 with Point

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

Example 95 with Point

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);
    }
}
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)

Aggregations

Point (com.revolsys.geometry.model.Point)669 LineString (com.revolsys.geometry.model.LineString)130 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)103 Geometry (com.revolsys.geometry.model.Geometry)95 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)90 ArrayList (java.util.ArrayList)79 BoundingBox (com.revolsys.geometry.model.BoundingBox)51 Polygon (com.revolsys.geometry.model.Polygon)42 LineSegment (com.revolsys.geometry.model.segment.LineSegment)34 List (java.util.List)28 LinearRing (com.revolsys.geometry.model.LinearRing)26 PointDouble (com.revolsys.geometry.model.impl.PointDouble)22 PointDoubleXYZ (com.revolsys.geometry.model.impl.PointDoubleXYZ)19 Edge (com.revolsys.geometry.graph.Edge)18 Test (org.junit.Test)17 Punctual (com.revolsys.geometry.model.Punctual)16 Segment (com.revolsys.geometry.model.segment.Segment)15 Vertex (com.revolsys.geometry.model.vertex.Vertex)15 Record (com.revolsys.record.Record)15 Lineal (com.revolsys.geometry.model.Lineal)14