Package org.geotools.caching.spatialindex

Examples of org.geotools.caching.spatialindex.Region


    TestNode n;
    RegionNodeIdentifier id;
    GridSpatialIndex grid;

    protected void setUp() {
        grid = new GridSpatialIndex(new Region(new double[] { 0, 0 }, new double[] { 1, 1 }), 10,
                MemoryStorage.createInstance(), 200);
        n = new TestNode(grid, new Region(new double[] { 0, 0 }, new double[] { 1, 1 }));
        id = new RegionNodeIdentifier(n);
        store = createStorage();
    }
View Full Code Here


        int gridcapacity = Integer.parseInt(pset.getProperty(GRID_CAPACITY_PROPERTY));
        double minx = Double.parseDouble(pset.getProperty(ROOT_MBR_MINX_PROPERTY));
        double miny = Double.parseDouble(pset.getProperty(ROOT_MBR_MINY_PROPERTY));
        double maxx = Double.parseDouble(pset.getProperty(ROOT_MBR_MAXX_PROPERTY));
        double maxy = Double.parseDouble(pset.getProperty(ROOT_MBR_MAXY_PROPERTY));
        Region mbr = new Region(new double[] { minx, miny }, new double[] { maxx, maxy });
       
        GridSpatialIndex instance = new GridSpatialIndex(mbr, gridsize, storage, gridcapacity);
        return instance;
    }
View Full Code Here

        //find the root node an initialize it here
        ReferencedEnvelope bounds = store.getBounds();
        if(bounds == null){
            return;             //cannot do anything because we need to know the bounds of the data.
        }
        this.mbr = new Region(new double[] { bounds.getMinX(), bounds.getMinY() }, new double[] { bounds.getMaxX(), bounds.getMaxY() });
        this.dimension = this.mbr.getDimension();
        NodeIdentifier id = findUniqueInstance(new RegionNodeIdentifier(this.mbr));
        //GridRootNode tmpRootNode = new GridRootNode(gridsize, (RegionNodeIdentifier)id);
       
        this.rootNode = null;
View Full Code Here

     * @return if there are more than 10 missing tiles than a single envelope is returned that
     * encompasses all missing tiles; otherwise only the envelopes for the tiles
     * that are missing are returned.
     */
    public List<Envelope> match(Envelope e) {
        Region search = CacheUtil.convert(e);
        ArrayList<Envelope> missing = new ArrayList<Envelope>();

        if (!this.tracker.getRootNode().getShape().intersects(search)){
            //this request is outside of the cached area so nothing to be found
            return new ArrayList<Envelope>();
        }
        if (!this.tracker.getRootNode().getShape().contains(search)) {
            // query is partially outside of root mbr;  we limit our search to the inside of the root mbr
            Envelope r = CacheUtil.convert((Region) this.tracker.getRootNode().getShape());
            r = r.intersection(e);
            search = CacheUtil.convert(r);
        }

        List<NodeIdentifier>[] tiles = tracker.findMissingTiles(search);
        List<NodeIdentifier> missing_tiles = tiles[0];
       
        if (missing_tiles.size() > max_tiles) {
          Envelope env = new Envelope(e);
          for (Iterator<NodeIdentifier> it = missing_tiles.iterator(); it.hasNext();) {
            NodeIdentifier id = it.next();
                Envelope nextenv = CacheUtil.convert((Region) (id.getShape()));
                env.expandToInclude(nextenv);
          }
            missing.add(env);
        } else {
            for (Iterator<NodeIdentifier> it = missing_tiles.iterator(); it.hasNext();) {
              NodeIdentifier id = it.next();
                Region next = (Region) (id.getShape());
                missing.add(CacheUtil.convert(next));
            }
        }

        return missing;
View Full Code Here

     * @param e envelope to search
     *
     * @return list of two arrays {missing nodes, present nodes}
     */
    public List<NodeIdentifier>[] matchNodeIds(Envelope e) {
        Region search = CacheUtil.convert(e);

        if (!this.tracker.getRootNode().getShape().intersects(search)){
            //this request is outside of the cached area so nothing to be found or missing
            return new List[]{Collections.emptyList(), Collections.emptyList()};
        }
View Full Code Here

    /**
     * Registers a given envelope in the cache.  All nodes within this envelope
     * are flagged as valid.
     */
    protected void register(Envelope e) {
        Region r = CacheUtil.convert(e);
        ValidatingVisitor v = new ValidatingVisitor(r);

        lock.writeLock().lock();
        try {
            //we don't want to track access while we register; this will ensure that just because a node touches another node it
View Full Code Here

   
    /**
     * Unregisters all nodes in a given envelope.
     */
    protected void unregister(Envelope e){
        Region r = CacheUtil.convert(e);
        GridInvalidatingVisitor v = new GridInvalidatingVisitor(this.tracker, r);
       
        lock.writeLock().lock();
        try {
            this.tracker.containmentQuery(r, v);
View Full Code Here

        findMatchingTiles(s, cursor, mins, maxs);
        hasNext = true;
    }
   
    private void findMatchingTiles(Shape shape, int[] cursor, final int[] mins, final int[] maxs) {
        Region shapembr = shape.getMBR();
        for (int i = 0; i < this.dimension; i++) {
            mins[i] = (int) ((shapembr.getLow(i) - this.root.getShape().getMBR().getLow(i)) / ((GridRootNode)this.root).tiles_size);
            cursor[i] = mins[i];
            maxs[i] = (int) ((shapembr.getHigh(i) - this.root.getShape().getMBR().getLow(i)) / ((GridRootNode)this.root).tiles_size);
            int maxcnt = ((GridRootNode)this.root).getMaximumTileCount(i);
            if (maxs[i] >= maxcnt){
                //max tile count is 2 then we was the maximum index to be 1
                maxs[i] = maxcnt-1;
            }
View Full Code Here

    init(gridsize);
  }

  private void init(int gridsize) {
    int dims = getShape().getDimension();
    Region mbr = (Region) getShape();
    tiles_number = new int[dims];

    double area = 1;

    for (int i = 0; i < dims; i++) {
      area *= (mbr.getHigh(i) - mbr.getLow(i));
    }

    tiles_size = Math.pow(area / gridsize, 1d / dims);
    int newcapacity = 1;

    for (int i = 0; i < dims; i++) {
      int tmp;
      double dtmp = (mbr.getHigh(i) - mbr.getLow(i)) / tiles_size;
      tmp = (int) dtmp;

      if (tmp < dtmp) {
        tmp += 1;
      }
View Full Code Here

   */
  protected void split(GridSpatialIndex index) {
    int dims = tiles_number.length;
    double[] pos = new double[dims];
    double[] nextpos = new double[dims];
    Region mbr = (Region) getShape();
    // int id = 0;

    for (int i = 0; i < dims; i++) {
      pos[i] = mbr.getLow(i);
      nextpos[i] = pos[i] + tiles_size;
    }

    do {
      Region reg = new Region(pos, nextpos);
      RegionNodeIdentifier id = (RegionNodeIdentifier) index
          .findUniqueInstance(new RegionNodeIdentifier(reg));
      GridNode child = createNode(id);
      index.writeNode(child);
      this.children.add(child.getIdentifier());
View Full Code Here

TOP

Related Classes of org.geotools.caching.spatialindex.Region

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.