Search in sources :

Example 1 with IllegalValueException

use of rtree.IllegalValueException in project OsmAnd-tools by osmandapp.

the class IndexRouteCreator method addWayToIndex.

private void addWayToIndex(long id, List<Node> nodes, PreparedStatement insertStat, RTree rTree, TIntArrayList outTypes, TLongObjectHashMap<TIntArrayList> pointTypes, TLongObjectHashMap<TIntObjectHashMap<String>> pointNamesRaw, Map<MapRoutingTypes.MapRouteType, String> names) throws SQLException {
    boolean init = false;
    int minX = Integer.MAX_VALUE;
    int maxX = 0;
    int minY = Integer.MAX_VALUE;
    int maxY = 0;
    ByteArrayOutputStream bcoordinates = new ByteArrayOutputStream();
    ByteArrayOutputStream bpointIds = new ByteArrayOutputStream();
    ByteArrayOutputStream bpointTypes = new ByteArrayOutputStream();
    ByteArrayOutputStream btypes = new ByteArrayOutputStream();
    List<MapPointName> pointNamesEmp = new ArrayList<MapPointName>();
    try {
        for (int j = 0; j < outTypes.size(); j++) {
            Algorithms.writeSmallInt(btypes, outTypes.get(j));
        }
        int pointIndex = 0;
        for (Node n : nodes) {
            if (n != null) {
                // write id
                Algorithms.writeLongInt(bpointIds, n.getId());
                // write point type
                TIntArrayList types = pointTypes.get(n.getId());
                if (types != null) {
                    for (int j = 0; j < types.size(); j++) {
                        Algorithms.writeSmallInt(bpointTypes, types.get(j));
                    }
                }
                TIntObjectHashMap<String> namesP = pointNamesRaw.get(n.getId());
                if (namesP != null) {
                    TIntObjectIterator<String> it = namesP.iterator();
                    while (it.hasNext()) {
                        it.advance();
                        MapPointName obj = new MapPointName(it.key(), pointIndex, it.value());
                        pointNamesEmp.add(obj);
                    }
                }
                Algorithms.writeSmallInt(bpointTypes, 0);
                // write coordinates
                int y = MapUtils.get31TileNumberY(n.getLatitude());
                int x = MapUtils.get31TileNumberX(n.getLongitude());
                minX = Math.min(minX, x);
                maxX = Math.max(maxX, x);
                minY = Math.min(minY, y);
                maxY = Math.max(maxY, y);
                init = true;
                Algorithms.writeInt(bcoordinates, x);
                Algorithms.writeInt(bcoordinates, y);
                pointIndex++;
            }
        }
    } catch (IOException est) {
        throw new IllegalStateException(est);
    }
    if (init) {
        // conn.prepareStatement("insert into route_objects(id, types, pointTypes, pointIds, pointCoordinates, name) values(?, ?, ?, ?, ?, ?, ?)");
        insertStat.setLong(1, id);
        insertStat.setBytes(2, btypes.toByteArray());
        insertStat.setBytes(3, bpointTypes.toByteArray());
        insertStat.setBytes(4, bpointIds.toByteArray());
        insertStat.setBytes(5, bcoordinates.toByteArray());
        insertStat.setString(6, encodeNames(names));
        insertStat.setString(7, encodeListNames(pointNamesEmp));
        addBatch(insertStat, false);
        try {
            rTree.insert(new LeafElement(new Rect(minX, minY, maxX, maxY), id));
        } catch (RTreeInsertException e1) {
            throw new IllegalArgumentException(e1);
        } catch (IllegalValueException e1) {
            throw new IllegalArgumentException(e1);
        }
    }
}
Also used : Rect(rtree.Rect) Node(net.osmand.osm.edit.Node) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) IllegalValueException(rtree.IllegalValueException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) TIntArrayList(gnu.trove.list.array.TIntArrayList) RTreeInsertException(rtree.RTreeInsertException) MapPointName(net.osmand.osm.MapRoutingTypes.MapPointName) LeafElement(rtree.LeafElement)

Example 2 with IllegalValueException

use of rtree.IllegalValueException in project OsmAnd-tools by osmandapp.

the class IndexRouteCreator method appendMissingRoadsForBaseMap.

private void appendMissingRoadsForBaseMap(Connection conn, BinaryMapIndexReader reader) throws IOException, SQLException {
    TLongObjectHashMap<RouteDataObject> map = new CheckRoadConnectivity().collectDisconnectedRoads(reader);
    // to add
    PreparedStatement ps = conn.prepareStatement(COPY_BASE);
    for (RouteDataObject rdo : map.valueCollection()) {
        // addWayToIndex(id, nodes, insertStat, rTree)
        int minX = Integer.MAX_VALUE;
        int maxX = 0;
        int minY = Integer.MAX_VALUE;
        int maxY = 0;
        long id = rdo.getId();
        for (int i = 0; i < rdo.getPointsLength(); i++) {
            int x = rdo.getPoint31XTile(i);
            int y = rdo.getPoint31YTile(i);
            minX = Math.min(minX, x);
            maxX = Math.max(maxX, x);
            minY = Math.min(minY, y);
            maxY = Math.max(maxY, y);
            long point = (x << 31) + y;
            registerBaseIntersectionPoint(point, false, id, i, i);
        }
        ps.setLong(1, id);
        ps.execute();
        try {
            baserouteTree.insert(new LeafElement(new Rect(minX, minY, maxX, maxY), id));
        } catch (RTreeInsertException e1) {
            throw new IllegalArgumentException(e1);
        } catch (IllegalValueException e1) {
            throw new IllegalArgumentException(e1);
        }
    }
    ps.close();
}
Also used : RTreeInsertException(rtree.RTreeInsertException) Rect(rtree.Rect) CheckRoadConnectivity(net.osmand.osm.util.CheckRoadConnectivity) IllegalValueException(rtree.IllegalValueException) RouteDataObject(net.osmand.binary.RouteDataObject) PreparedStatement(java.sql.PreparedStatement) LeafElement(rtree.LeafElement)

Example 3 with IllegalValueException

use of rtree.IllegalValueException in project OsmAnd-tools by osmandapp.

the class IndexRouteCreator method calcBounds.

public Rect calcBounds(rtree.Node n) {
    Rect r = null;
    Element[] e = n.getAllElements();
    for (int i = 0; i < n.getTotalElements(); i++) {
        Rect re = e[i].getRect();
        if (r == null) {
            try {
                r = new Rect(re.getMinX(), re.getMinY(), re.getMaxX(), re.getMaxY());
            } catch (IllegalValueException ex) {
            }
        } else {
            r.expandToInclude(re);
        }
    }
    return r;
}
Also used : Rect(rtree.Rect) Element(rtree.Element) LeafElement(rtree.LeafElement) IllegalValueException(rtree.IllegalValueException)

Example 4 with IllegalValueException

use of rtree.IllegalValueException in project OsmAnd-tools by osmandapp.

the class IndexTransportCreator method writeRouteStops.

private void writeRouteStops(TransportRoute r, List<TransportStop> stops) throws SQLException {
    int i = 0;
    for (TransportStop s : stops) {
        if (!visitedStops.contains(s.getId())) {
            transStopsStat.setLong(1, s.getId());
            transStopsStat.setDouble(2, s.getLocation().getLatitude());
            transStopsStat.setDouble(3, s.getLocation().getLongitude());
            transStopsStat.setString(4, s.getName());
            transStopsStat.setString(5, s.getEnName(false));
            int x = (int) MapUtils.getTileNumberX(24, s.getLocation().getLongitude());
            int y = (int) MapUtils.getTileNumberY(24, s.getLocation().getLatitude());
            addBatch(transStopsStat);
            try {
                transportStopsTree.insert(new LeafElement(new Rect(x, y, x, y), s.getId()));
            } catch (RTreeInsertException e) {
                throw new IllegalArgumentException(e);
            } catch (IllegalValueException e) {
                throw new IllegalArgumentException(e);
            }
            visitedStops.add(s.getId());
        }
        transRouteStopsStat.setLong(1, r.getId());
        transRouteStopsStat.setLong(2, s.getId());
        transRouteStopsStat.setInt(3, i++);
        addBatch(transRouteStopsStat);
    }
}
Also used : RTreeInsertException(rtree.RTreeInsertException) Rect(rtree.Rect) IllegalValueException(rtree.IllegalValueException) TransportStop(net.osmand.data.TransportStop) LeafElement(rtree.LeafElement)

Example 5 with IllegalValueException

use of rtree.IllegalValueException in project OsmAnd-tools by osmandapp.

the class IndexTransportCreator method calcBounds.

private Rect calcBounds(rtree.Node n) {
    Rect r = null;
    Element[] e = n.getAllElements();
    for (int i = 0; i < n.getTotalElements(); i++) {
        Rect re = e[i].getRect();
        if (r == null) {
            try {
                r = new Rect(re.getMinX(), re.getMinY(), re.getMaxX(), re.getMaxY());
            } catch (IllegalValueException ex) {
            }
        } else {
            r.expandToInclude(re);
        }
    }
    return r;
}
Also used : Rect(rtree.Rect) Element(rtree.Element) LeafElement(rtree.LeafElement) IllegalValueException(rtree.IllegalValueException)

Aggregations

IllegalValueException (rtree.IllegalValueException)8 LeafElement (rtree.LeafElement)8 Rect (rtree.Rect)8 RTreeInsertException (rtree.RTreeInsertException)4 Element (rtree.Element)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 Node (net.osmand.osm.edit.Node)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TLongArrayList (gnu.trove.list.array.TLongArrayList)1 PreparedStatement (java.sql.PreparedStatement)1 ArrayList (java.util.ArrayList)1 RouteDataObject (net.osmand.binary.RouteDataObject)1 TransportStop (net.osmand.data.TransportStop)1 MapPointName (net.osmand.osm.MapRoutingTypes.MapPointName)1 CheckRoadConnectivity (net.osmand.osm.util.CheckRoadConnectivity)1 Element (org.w3c.dom.Element)1