⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vectormap.java

📁 Java source code for the Ant Colony Optimization Problem.
💻 JAVA
字号:
package jwo.jpss.spatial;       // Part of the spatial modelling package.

import java.util.*;             // For the Java collection framework.
import jwo.jpss.spatial.gui.*;  // For GUI representation.
import javax.swing.JPanel;			

//  **************************************************************
/** A collection of GIS vectors that model object boundaries.
  * @author Jo Wood
  * @version 2.5, 23rd October, 2001
  */
//  **************************************************************

public class VectorMap extends SpatialObject
{   
    // -------------------- Object variables ---------------------
    
    private Vector gisVectors;     // Collection of GIS vectors.
      
    // --------------------- Constructors ------------------------
    
    /** Creates an empty vector map with default characteristics.
      */
    public VectorMap()
    {
    	gisVectors = new Vector();
        setBounds(new Footprint(0,0,1,1));
        setHeader(new Header("Default vector map"));
    }

    /** Creates a vector map from the given GIS vector.
      * @param gisVector GIS vector object from which to create map.
      * @param header Header associated with the vector map.
      */
    public VectorMap(GISVector gisVector, Header header)
    {
        // Add vector object to map.
        gisVectors = new Vector();
        add(gisVector);
        setHeader(header);

        // Store its bounding rectangle.
        updateBounds();
    }

    // ----------------------- Methods ---------------------------
    
    /** Adds the given GIS vector object to the map.
      * @param gisVector GIS vector object to add.
      */
    public void add(GISVector gisVector)
    {
        gisVectors.add(gisVector);
        updateBounds();
    }

    /** Removes the given GIS vector object from the map. If the
      * map does not contain the object, it is unchanged.
      * @param gisVector GIS Vector object to remove.
      * @return True if vector object removed.
      */
    public boolean remove(GISVector gisVector)
    { 
        return gisVectors.remove(gisVector);
    }

    /** Returns a collection of GIS vectors stored in this map.
      * @return Collection of GIS vectors.
      */
    public Vector getGISVectors()
    {
        return gisVectors;
    }

    /** Reports the details of this vector map.
      * @return Summary of this vector map.
      */
    public String toString()
    {
        return "Vector map with "+gisVectors.size()+" objects and " +
               getBounds().toString();
    } 
    
    /** Creates a panel onto which this vector map may be drawn.
      * @return Panel onto which this vector map may be drawn.
      */
    public SpatialPanel createPanel()
    {
        return new VectorPanel(this);
    }
    
    // ------------------ Implemented Methods --------------------
     
    /** Reports the type of spatial model.
      * @return Type of spatial model (VECTOR_2D, VECTOR_3D etc). 
      */
    public int getType()
    {
        return VECTOR_2D;
    }

    /** Reports the attribute at the given point location.
      * @param fp Location to query.
      * @return Attribute associated with the GIS vector if given
      * location intersects with object, otherwise NO_VALUE or OUT_OF_BOUNDS.
      */
    public float getAttribute(Footprint fp)
    {
        if (compare(new SpatialObject(fp)) == SEPARATE)
            return OUT_OF_BOUNDS;
        else
        {
            // Check each object in map.
            Iterator i = gisVectors.iterator();
            while (i.hasNext())
            {
                GISVector gisVector = (GISVector)i.next();
                float attrib = gisVector.getAttribute(fp);
                if (attrib != OUT_OF_BOUNDS)
                    return attrib;
            }
        }   
        // Nothing found.
        return NO_VALUE;
    }

    // --------------------- Private Methods ---------------------

    /** Updates the minimum enclosing rectangle as that enclosing
      * all GIS Vectors within this map.
      */
    private void updateBounds()
    {
        // Check there are some GIS vectors to examine.
        if (gisVectors.size() == 0)
            return;

        // Initialise map bounds with those of the first GIS vector.
        Iterator i = gisVectors.iterator();
        GISVector gisVector = (GISVector)i.next();
        setBounds(gisVector.getBounds());

        // Search through remaining objects updating bounds if necessary.
        while (i.hasNext())
        {
            gisVector = (GISVector)i.next();
            setBounds(getUnionMER(gisVector.getBounds()));
        }  
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -