Package org.geoforge.worldwind.layer

Source Code of org.geoforge.worldwind.layer.GfrRlrObjTloRndMltSurfacePolylineAbs

/*
*  Copyright (C) 2011-2014 GeoForge Project
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU Lesser General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU Lesser General Public License for more details.
*
*  You should have received a copy of the GNU Lesser General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.geoforge.worldwind.layer;

import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.render.SurfacePolyline;
import java.beans.PropertyChangeListener;
import java.util.Iterator;
import java.util.logging.Logger;
import org.geoforge.lang.util.geography.GfrUtilDmsOperation;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.worldwind.handler.IGfrHandlerWwdEarthObjectGeoforgeRenderableLayer;

/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/
abstract public class GfrRlrObjTloRndMltSurfacePolylineAbs extends GfrRlrObjTloRndMltAbs
{
   // ----
   // begin: instantiate logger for this class
   final private static Logger _LOGGER_ = Logger.getLogger(GfrRlrObjTloRndMltSurfacePolylineAbs.class.getName());

   static
   {
      GfrRlrObjTloRndMltSurfacePolylineAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
   }
   // end: instantiate logger for this class
   // ----

   protected GfrRlrObjTloRndMltSurfacePolylineAbs(
           PropertyChangeListener lstShouldRedraw,
           String strId)
           throws Exception
   {
      super(lstShouldRedraw, strId);
   }

   @Override
   public Position getPositionBarycentricObjectGeoforgeWwdEarth() throws Exception
   {
      double dblMinLat = 500;
      double dblMaxLat = -500;
      double dblMinLon = 500;
      double dblMaxLon = -500;

      for (int i=0; i<super._lstObject.size(); i++)
      {
         IGfrHandlerWwdEarthObjectGeoforgeRenderableLayer objCur = (IGfrHandlerWwdEarthObjectGeoforgeRenderableLayer) super._lstObject.get(i);

         Iterator<? extends LatLon> itr = ((SurfacePolyline) objCur).getLocations().iterator();

         if (!itr.hasNext())
         {
            String str = "! itr.hasNext()";
            GfrRlrObjTloRndMltSurfacePolylineAbs._LOGGER_.severe(str);
            throw new Exception(str);
         }

         while (itr.hasNext())
         {
            LatLon llnCur = itr.next();
            double[] dbls = llnCur.asDegreesArray();

            if (dbls[0] < dblMinLat)//=a
            {
               dblMinLat = dbls[0];
            }

            if (dbls[1] < dblMinLon)//=c
            {
               dblMinLon = dbls[1];
            }

            if (dbls[0] > dblMaxLat)//=b
            {
               dblMaxLat = dbls[0];
            }

            if (dbls[1] > dblMaxLon)//=d
            {
               dblMaxLon = dbls[1];
            }
         }
      }

      double dblLat = dblMinLat;
      dblLat += dblMaxLat;
      dblLat /= 2;

      double dblLon = dblMinLon;
      dblLon += dblMaxLon;
      dblLon /= 2;

      return Position.fromDegrees(dblLat, dblLon);
   }


   @Override
   public double getCharacteristicDimensionObjectGeoforgeRenderableLayer() throws Exception
   {
      double dblMinLat = 500;
      double dblMaxLat = -500;
      double dblMinLon = 500;
      double dblMaxLon = -500;

      for (int i = 0; i < super._lstObject.size(); i++)
      {
         IGfrHandlerWwdEarthObjectGeoforgeRenderableLayer objCur = (IGfrHandlerWwdEarthObjectGeoforgeRenderableLayer) super._lstObject.get(i);

         Iterator<? extends LatLon> itr = ((SurfacePolyline) objCur).getLocations().iterator();;

         if (!itr.hasNext())
         {
            String str = "! itr.hasNext()";
            GfrRlrObjTloRndMltSurfacePolylineAbs._LOGGER_.severe(str);
            throw new Exception(str);
         }

         while (itr.hasNext())
         {
            LatLon llnCur = itr.next();
            double[] dbls = llnCur.asDegreesArray();

            if (dbls[0] < dblMinLat)//=a
            {
               dblMinLat = dbls[0];
            }

            if (dbls[1] < dblMinLon)//=c
            {
               dblMinLon = dbls[1];
            }

            if (dbls[0] > dblMaxLat)//=b
            {
               dblMaxLat = dbls[0];
            }

            if (dbls[1] > dblMaxLon)//=d
            {
               dblMaxLon = dbls[1];
            }
         }
      }
      double dist = GfrUtilDmsOperation.s_getDistanceFromDeg(dblMinLat, dblMinLon, dblMaxLat, dblMaxLon);
      dist *= 2;
      return dist;  
   }
}
TOP

Related Classes of org.geoforge.worldwind.layer.GfrRlrObjTloRndMltSurfacePolylineAbs

TOP
Copyright © 2018 www.massapi.com. 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.