Skip to content
mtehver edited this page Jun 5, 2014 · 4 revisions

Nutiteq SDK allows to use different map projections for your data, e.g. local projections.

General rules

  • MapView will be in the projection of your defined baseLayer
  • Overlay layers are adjusted to it as much as possible.
  • We do not suggest to mix raster base map and raster overlay with different projections, the results could be inaccurate.
  • Vector overlay with different projection works just fine.
  • Spherical view (globe) does not support local projections, there you must use EPSG:4326 (WGS84) or EPSG:3857 (Google Spherical Mercator - leaves poles uncovered) as base map projection.
  • Some native datasources (e.g. Spatialite and OGR vector files) can detect and reproject data automatically to the layer's projection, as they have Proj.4 built into. Then you do not need to define custom projections, just use usual base ones.

Built-in projections and interface

Nutiteq SDK has built-in definitions for the most common EPSG:4326 (WGS84) and EPSG:3857 (Google Spherical Mercator), in com.nutiteq.projections package. Most raster background maps use EPSG:3857. There is no need to use any external library for these projections.

For customization com.nutiteq.projections package is abstract class Projection (javadoc). This is the one you need to extend to use different projections, though this is highly technical and it is better to use JavaProj or Proj.4 based wrappers from AdvancedLayers project.

Projection engines in AdvancedLayers project

Our http://nutiteq.github.io/advancedlayers/ project has pre-integrated two open source geographical projection libraries: older JavaProj and more recent Proj4j. They are both Java ports of the popular Proj.4 engine, the Proj4j seems to be a bit nicer and supports more projections. Usage:

  1. include a projection library to your project. You can get Proj4j from here https://github.com/nutiteq/advancedlayers/blob/master/extlibs/proj4j-0.1.0.jar . This library can define projections using Proj.4 string.

  2. find Proj.4 definition string for your projection. One example: http://spatialreference.org/ref/epsg/26986/, see Proj4 link in the page.

  3. Define Projection object. You can create own class using one from AdvancedLayers com.nutiteq.projection package (see files) as sample, or use just with in-line definition:

        Projection proj = new com.nutiteq.projections.Proj4jProjection(
                "+proj=lcc +lat_1=42.68333333333333 +lat_2=41.71666666666667 +lat_0=41 +lon_0=-71.5 +x_0=200000 +y_0=750000 +ellps=GRS80 +datum=NAD83 +units=m +no_defs".split(" "),
                new Bounds(-20037508.34f, 20037508.34f, 20037508.34f, -20037508.34f)) {

            @Override
            public String name() {
                return "EPSG:26986";
            }
        };
  1. Test it. The same web page at spatialreference.org has test locations, e.g. "Input Coordinates: -71.685, 42.12 Output Coordinates: 184701.979362, 874414.376528". So I try same conversion:
    Log.debug("output coordinates "+proj.fromWgs84(-71.685, 42.12));

and it prints to logcat:

    output coordinates MapPos [x=184701.97936194774, y=874414.3765282441, z=0.0]

Which is same as the test location, with sub-mm accuracy.

  1. Use it. Usage depends for what exactly do you want to use it: is it raster or vector layer, is it base or overlay and what is datasource. Some datasources (e.g. Spatialite and vector files) can for same data files detect and reproject data automatically to the layer's projection. For others you need to define data projection, and you can give the proj object as defined above.

For some internally most complicated cases, like using custom projection as base raster layer with tiles you may need to adjust projection bounds (to fit with your real tiling bounds), otherwise it may give problems. See Custom Tilesets page how to define and calibrate bounds.

Clone this wiki locally