Search in sources :

Example 6 with IllegalValueException

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

the class IndexVectorMapCreator 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 7 with IllegalValueException

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

the class IndexVectorMapCreator method insertBinaryMapRenderObjectIndex.

private void insertBinaryMapRenderObjectIndex(RTree mapTree, Collection<Node> nodes, List<List<Node>> innerWays, Map<MapRulType, String> names, long id, boolean area, TIntArrayList types, TIntArrayList addTypes, boolean commit) 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 binnercoord = new ByteArrayOutputStream();
    ByteArrayOutputStream btypes = new ByteArrayOutputStream();
    ByteArrayOutputStream badditionalTypes = new ByteArrayOutputStream();
    try {
        for (int j = 0; j < types.size(); j++) {
            Algorithms.writeSmallInt(btypes, types.get(j));
        }
        for (int j = 0; j < addTypes.size(); j++) {
            Algorithms.writeSmallInt(badditionalTypes, addTypes.get(j));
        }
        for (Node n : nodes) {
            if (n != null) {
                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);
            }
        }
        if (innerWays != null) {
            for (List<Node> ws : innerWays) {
                boolean exist = false;
                if (ws != null) {
                    for (Node n : ws) {
                        if (n != null) {
                            exist = true;
                            int y = MapUtils.get31TileNumberY(n.getLatitude());
                            int x = MapUtils.get31TileNumberX(n.getLongitude());
                            Algorithms.writeInt(binnercoord, x);
                            Algorithms.writeInt(binnercoord, y);
                        }
                    }
                }
                if (exist) {
                    Algorithms.writeInt(binnercoord, 0);
                    Algorithms.writeInt(binnercoord, 0);
                }
            }
        }
    } catch (IOException es) {
        throw new IllegalStateException(es);
    }
    if (init) {
        // conn.prepareStatement("insert into binary_map_objects(id, area, coordinates, innerPolygons, types, additionalTypes, name) values(?, ?, ?, ?, ?, ?, ?)");
        mapBinaryStat.setLong(1, id);
        mapBinaryStat.setBoolean(2, area);
        mapBinaryStat.setBytes(3, bcoordinates.toByteArray());
        mapBinaryStat.setBytes(4, binnercoord.toByteArray());
        mapBinaryStat.setBytes(5, btypes.toByteArray());
        mapBinaryStat.setBytes(6, badditionalTypes.toByteArray());
        mapBinaryStat.setString(7, encodeNames(names));
        addBatch(mapBinaryStat, commit);
        try {
            mapTree.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 : RTreeInsertException(rtree.RTreeInsertException) Rect(rtree.Rect) Node(net.osmand.osm.edit.Node) IllegalValueException(rtree.IllegalValueException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) LeafElement(rtree.LeafElement)

Example 8 with IllegalValueException

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

the class IndexUploader method calcBounds.

public static Rect calcBounds(rtree.Node n) {
    Rect r = null;
    rtree.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) LeafElement(rtree.LeafElement) Element(org.w3c.dom.Element) 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