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

📄 awmlreader.java

📁 linux下用于移动节点的移动活动生成工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package de.uni_stuttgart.informatik.canu.awmlreader;

/**
 * <p>Title: AWML Reader</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: University of Stuttgart</p>
 * @author Illya Stepanov
 * @version 1.1
 */

import javax.xml.parsers.*;
import geotransform.coords.*;
import geotransform.transforms.*;
import de.uni_stuttgart.informatik.canu.mobisim.core.*;
import de.uni_stuttgart.informatik.canu.mobisim.notifications.*;
import de.uni_stuttgart.informatik.canu.spatialmodel.core.*;
import de.uni_stuttgart.informatik.canu.spatialmodel.geometry.*;

/**
 * This class reads geographic data in AWML format. <br>
 * <br>
  * @author Illya Stepanov
 */
public class AWMLReader extends ExtensionModule
{
    /**
     * Source stream
     */
    protected String fileSource;

    /**
     * Spatial Model
     */
    protected SpatialModel spatialModel;

    /**
     * Spatial Model elements loaded 
     */
    protected java.util.ArrayList elements = new java.util.ArrayList();

    /**
     * Min x-coordinate value
     */
    protected double min_x = Double.MAX_VALUE;

    /**
     * Min y-coordinate value 
     */
    protected double min_y = Double.MAX_VALUE;

    /**
     * Max x-coordinate value
     */
    protected double max_x = Double.MIN_VALUE;
    
    /**
     * Max y-coordinate value 
     */
    protected double max_y = Double.MIN_VALUE;

    /**
     * Min lat-coordinate value
     */
    protected double min_lat = Double.MAX_VALUE;

    /**
     * Min lon-coordinate value
     */
    protected double min_lon = Double.MAX_VALUE;

    /**
     * Max lat-coordinate value
     */
    protected double max_lat = Double.MIN_VALUE;

    /**
     * Max lon-coordinate value
     */
    protected double max_lon = Double.MIN_VALUE;

    /**
     * Clipping Region
     */
    protected Polygon clipArea;

    /**
     * Constructor
     */
    public AWMLReader()
    {
      super("AWMLReader");
    }

    /**
     * Returns the module's description. <br>
     * <br>
     * @return extension module's description
     */
    public String getDescription()
    {
      return "AWML Reader module";
    }

    /**
     * Executes the extension. <br>
     * <br>
     * The method is called on every simulation timestep.
     * @return 0 - the module should be executed on next timesteps,
     *        -1 - the module should not be executed on further timesteps and should be removed from the extensions' list
     */
    public int act()
    {
        return -1;
    }

    /**
     * Creates geometry elements from GML-based textual description. <br>
     * <br>
     * @return array of geometry elements
     */
    protected java.util.ArrayList processGeometry(String nexusGmlString) throws Exception
    {
        java.util.ArrayList res = new java.util.ArrayList();

        Class class_instance = null;
        if (nexusGmlString.startsWith("LINESTRING"))
          class_instance = Class.forName(Polyline.class.getName());
        else
        if (nexusGmlString.startsWith("MULTIPOLYGON"))        
          class_instance = Class.forName(Polygon.class.getName());
        
        if (class_instance!=null)
        {
          int i1, i2=0;
          
          for (;;)
          {
            Polyline shape = (Polyline)class_instance.newInstance();

            i1 = nexusGmlString.indexOf('(', i2);
            if (i1==-1)
            {
              if (i2==0)
                // exception
                throw new Exception("Error processing geometry: "+nexusGmlString);
              else
                break;
            }   
        
            // skip redundant '('
            while ( (i1<nexusGmlString.length()) && ((nexusGmlString.charAt(i1)=='(')||(nexusGmlString.charAt(i1)==' ')) )
              i1++;
            if (i1==nexusGmlString.length())
              break;
            
            // search for next matching ')'
            i2 = i1+1;
            while ( (i2<nexusGmlString.length()) && (nexusGmlString.charAt(i2)!=')') )
              i2++;
            if (i2==nexusGmlString.length())
              // exception
              throw new Exception("Error processing geometry: "+nexusGmlString);              

            String substr = nexusGmlString.substring(i1, i2).replace(',', '.');

            boolean bLat = false;             
            double lon = 0;
            java.util.StringTokenizer st = new java.util.StringTokenizer(substr);
            while (st.hasMoreTokens())
            {
              String t = st.nextToken();
              
              // remove trailing ','
              if (t.endsWith("."))
                t = t.substring(0, t.length()-1);
                
              double lat = Double.parseDouble(t);
              
              if (bLat)
              {
                Utm_Coord_3d utm = new Utm_Coord_3d();
                Gdc_To_Utm_Converter.Convert(new Gdc_Coord_3d(lat, lon, 0), utm);
                
                Point pc = new Point(utm.x, utm.y);
                shape.getPoints().add(pc);
                
                // update min and max values
                if (pc.getX()<min_x)
                  min_x = pc.getX();
                if (pc.getY()<min_y)
                  min_y = pc.getY();
                if (pc.getX()>max_x)
                  max_x = pc.getX();
                if (pc.getY()>max_y)
                  max_y = pc.getY();

                if (lat<min_lat)
                  min_lat = lat;
                if (lon<min_lon)
                  min_lon = lon;
                if (lat>max_lat)
                  max_lat = lat;
                if (lon>max_lon)
                  max_lon = lon;
              }
              else
                lon = lat;
                
              bLat ^= true;
            }
            
            res.add(shape);
          }
        }
        else
          throw new Exception("Error processing geometry: "+nexusGmlString);        
        
        return res;
    }

    /**
     * Processes the "Building" element. <br>
     * <br>
     * @param e element
     */
    protected void processBuilding(org.w3c.dom.Element e) throws Exception
    {
        String id = e.getAttribute("NOL");
        
        // process geometry        
        java.util.ArrayList shapes = null;
        org.w3c.dom.Element extent_node = (org.w3c.dom.Element)e.getElementsByTagName("extent").item(0);
        if (extent_node!=null)
        {
            org.w3c.dom.Node n = extent_node.getFirstChild();
            if (n!=null)
            {
                String s = n.getNodeValue();
                shapes = processGeometry(s);
            }
        }

        // create elements
        if ((shapes!=null)&&(shapes.size()>0))
        {
          for (int i=0; i<shapes.size(); i++)
          {
            SpatialModelElement element = new SpatialModelElement(id+'.'+i, "71", "10", (GeometryElement)shapes.get(i));
            elements.add(element);

          }
        }
        else
        {
          SpatialModelElement element = new SpatialModelElement(id, "71", "10", null);
          elements.add(element);          
        }
    }

    /**
     * Processes the "Road" element. <br>
     * <br>
     * @param e element
     */
    protected void processRoad(org.w3c.dom.Element e) throws Exception
    {
        String id = e.getAttribute("NOL");

        // process geometry
        java.util.ArrayList shapes = null;
        org.w3c.dom.Element roadRun_node = (org.w3c.dom.Element)e.getElementsByTagName("roadRun").item(0);
        if (roadRun_node!=null)
        {

⌨️ 快捷键说明

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