Android Open Source - android_maplib Geo






From Project

Back to project page android_maplib.

License

The source code is released under:

GNU General Public License

If you think the Android project android_maplib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Project:  NextGIS Mobile/*from w w w. j  av a 2  s. com*/
 * Purpose:  Mobile GIS for Android.
 * Author:   Dmitry Baryshnikov (aka Bishop), bishop.dev@gmail.com
 * *****************************************************************************
 * Copyright (c) 2012-2015. NextGIS, info@nextgis.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.nextgis.maplib.datasource;

import com.nextgis.maplib.util.GeoConstants;


public class Geo
{

    protected final static double mEarthMajorRadius = 6378137.0;
    protected final static double mEarthMinorRadius = 6356752.3142;
    protected final static double mE                = mEarthMinorRadius / mEarthMajorRadius;
    protected final static double mES               = 1.0 - (mE * mE);
    protected final static double mEccent           = Math.sqrt(mES);
    protected final static double mCom              = 0.5 * mEccent;


    public static GeoPoint mercatorToWgs84SphereRet(final GeoPoint point)
    {
        GeoPoint retPt = new GeoPoint();
        retPt.mX = mercatorToWgs84SphereX(point.mX);
        retPt.mY = mercatorToWgs84SphereY(point.mY);
        return retPt;
    }


    public static double mercatorToWgs84SphereX(final double x)
    {
        return Math.toDegrees(x / mEarthMajorRadius);
    }


    public static double mercatorToWgs84SphereY(final double y)
    {
        return Math.toDegrees(2 * Math.atan(Math.exp(y / mEarthMajorRadius)) - Math.PI / 2);
    }


    public static void mercatorToWgs84Sphere(GeoPoint point)
    {
        point.mX = mercatorToWgs84SphereX(point.mX);
        point.mY = mercatorToWgs84SphereY(point.mY);
    }


    public static GeoPoint mercatorToWgs84EllipseRet(final GeoPoint point)
    {
        GeoPoint retPt = new GeoPoint();
        retPt.mX = mercatorToWgs84EllipseX(point.mX);
        retPt.mY = mercatorToWgs84EllipseY(point.mY);
        return retPt;
    }


    public static double mercatorToWgs84EllipseX(final double x)
    {
        return Math.toDegrees(x / mEarthMajorRadius);
    }


    public static double mercatorToWgs84EllipseY(final double y)
    {
        double phi = Math.toRadians(y);
        double sinphi = Math.sin(phi);
        double con = mEccent * sinphi;
        con = Math.pow(((1.0 - con) / (1.0 + con)), mCom);
        double ts = Math.tan(0.5 * ((Math.PI * 0.5) - phi)) / con;
        return 0 - mEarthMajorRadius * Math.log(ts);
    }


    public static void mercatorToWgs84Ellipse(GeoPoint point)
    {
        point.mX = mercatorToWgs84EllipseX(point.mX);
        point.mY = mercatorToWgs84EllipseY(point.mY);
    }


    public static GeoPoint wgs84ToMercatorSphereRet(final GeoPoint point)
    {
        GeoPoint retPt = new GeoPoint();
        retPt.mX = wgs84ToMercatorSphereX(point.mX);
        retPt.mY = wgs84ToMercatorSphereY(point.mY);
        return retPt;
    }


    public static double wgs84ToMercatorSphereX(final double x)
    {
        return mEarthMajorRadius * Math.toRadians(x);
    }


    public static double wgs84ToMercatorSphereY(final double y)
    {
        return mEarthMajorRadius * Math.log(Math.tan(Math.PI / 4 + Math.toRadians(y) / 2));
    }


    public static void wgs84ToMercatorSphere(GeoPoint point)
    {
        point.mX = wgs84ToMercatorSphereX(point.mX);
        point.mY = wgs84ToMercatorSphereY(point.mY);
    }


    public static boolean isGeometryTypeSame(
            final int type1,
            final int type2)
    {
        return type1 == type2 ||
               (type1 <= GeoConstants.GTMultiPolygon && type2 <= GeoConstants.GTMultiPolygon &&
                Math.abs(type1 - type2) == 3);
    }
}




Java Source Code List

com.nextgis.maplib.ApplicationTest.java
com.nextgis.maplib.api.GpsEventListener.java
com.nextgis.maplib.api.IGISApplication.java
com.nextgis.maplib.api.IJSONStore.java
com.nextgis.maplib.api.ILayerView.java
com.nextgis.maplib.api.ILayer.java
com.nextgis.maplib.api.IMapView.java
com.nextgis.maplib.api.INGWLayer.java
com.nextgis.maplib.api.IRenderer.java
com.nextgis.maplib.api.MapEventListener.java
com.nextgis.maplib.datasource.DatabaseHelper.java
com.nextgis.maplib.datasource.GeoEnvelope.java
com.nextgis.maplib.datasource.GeoGeometryCollection.java
com.nextgis.maplib.datasource.GeoGeometry.java
com.nextgis.maplib.datasource.GeoLineString.java
com.nextgis.maplib.datasource.GeoLinearRing.java
com.nextgis.maplib.datasource.GeoMultiLineString.java
com.nextgis.maplib.datasource.GeoMultiPoint.java
com.nextgis.maplib.datasource.GeoMultiPolygon.java
com.nextgis.maplib.datasource.GeoPoint.java
com.nextgis.maplib.datasource.GeoPolygon.java
com.nextgis.maplib.datasource.Geo.java
com.nextgis.maplib.datasource.NGWLayerContentProvider.java
com.nextgis.maplib.datasource.TileItem.java
com.nextgis.maplib.datasource.ngw.Connection.java
com.nextgis.maplib.datasource.ngw.Connections.java
com.nextgis.maplib.datasource.ngw.INGWResource.java
com.nextgis.maplib.datasource.ngw.LayerWithStyles.java
com.nextgis.maplib.datasource.ngw.ResourceGroup.java
com.nextgis.maplib.datasource.ngw.Resource.java
com.nextgis.maplib.display.GISDisplay.java
com.nextgis.maplib.display.Renderer.java
com.nextgis.maplib.display.SimpleFeatureRenderer.java
com.nextgis.maplib.display.SimpleLineStyle.java
com.nextgis.maplib.display.SimpleMarkerStyle.java
com.nextgis.maplib.display.Style.java
com.nextgis.maplib.display.TMSRenderer.java
com.nextgis.maplib.location.GpsEventSource.java
com.nextgis.maplib.map.LayerFactory.java
com.nextgis.maplib.map.LayerGroup.java
com.nextgis.maplib.map.Layer.java
com.nextgis.maplib.map.MapBase.java
com.nextgis.maplib.map.MapContentProviderHelper.java
com.nextgis.maplib.map.MapDrawable.java
com.nextgis.maplib.map.MapEventSource.java
com.nextgis.maplib.map.NGWRasterLayer.java
com.nextgis.maplib.map.NGWVectorLayer.java
com.nextgis.maplib.map.RemoteTMSLayer.java
com.nextgis.maplib.map.TMSLayer.java
com.nextgis.maplib.map.VectorLayer.java
com.nextgis.maplib.util.Constants.java
com.nextgis.maplib.util.DatabaseContext.java
com.nextgis.maplib.util.Feature.java
com.nextgis.maplib.util.FileUtil.java
com.nextgis.maplib.util.GeoConstants.java
com.nextgis.maplib.util.NetworkUtil.java
com.nextgis.maplib.util.SettingsConstants.java
com.nextgis.maplib.util.VectorCacheItem.java