2

I'm trying to visualize some geometries in OpenLayers using a north polar projection.

The data comes from the GeoServer and I have defined my projection in

949918=PROJCS["Mars_North_Pole_Stereographic",GEOGCS["Mars 2000",DATUM["D_Mars_2000",SPHEROID["Mars_2000_IAU_IAG",3396190.0,169.89444722361179]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Stereographic"],PARAMETER["False_Easting",0],PARAMETER["False_Northing",0],PARAMETER["Central_Meridian",0],PARAMETER["Scale_Factor",1],PARAMETER["Latitude_Of_Origin",90],UNIT["Meter",1]]

Then a simple viewer with OpenLayers.

// North Polar stereographic
// for Mars polar, from: https://astrowebmaps.wr.usgs.gov/webmapatlas/Layers/maps.html

proj4.defs(
  "EPSG:949918",
  "+proj=stere +lat_0=90 +lon_0=0 +k=1 +x_0=0 +y_0=0 +a=3396190 +b=3376200 +units=m +no_defs"
);

var north_stereo = ol.proj.get("EPSG:949918"); // not null now
var north_stereo_code = north_stereo.getCode();
var mdim_extent = [-1512512, -1512512, 1512512, 1512512];
var mdim_world_extent = [-180, 65, 180, 89];
north_stereo.setExtent(mdim_extent);
north_stereo.setWorldExtent(mdim_world_extent);

// Geoserver Base Map
var wmsBaseMap = new ol.layer.Tile({
  source: new ol.source.TileWMS({
    wrapX: false,
    noWrap: true,
    url: "http://localhost:8070/geoserver/OL/wms",
    serverType: "geoserver",
    params: {
      LAYERS: "OL:mola064_clon0_gray-hillshade_14400x7200",
      TILED: true
    }
  })
});

// Geoserver Footprints
var vector = new ol.layer.Vector({
  source: new ol.source.Vector({
    wrapX: false,
    noWrap: true,
    format: new ol.format.GeoJSON(),
    url: function(extent) {
      return (
        "http://localhost:8070/geoserver/OL/ows?service=WFS&" +
        "srsName=EPSG:949918&version=1.0.0&request=GetFeature&" +
        "typeName=LAYER&" +
        "&maxFeatures=1000&outputFormat=application%2Fjson"
      );
    }
  })
});

// OL Map
let map = new ol.Map({
  layers: [wmsBaseMap, vector],
  target: "map",

  view: new ol.View({
    projection: "EPSG:949918",
    center: [0, 0],
    zoom: 4
  })
});

var graticule = new ol.Graticule({
  strokeStyle: new ol.style.Stroke({
    color: "rgba(0,0,0,0.8)",
    width: 1
  }),
  maxLines: 1000 // bad for performance but necessary for rare cases
});

graticule.setMap(map);

The result I get is this.

enter image description here

As we can see, some footprints look out of the base map.

Maybe basemap is wrong? Why do some footprints look outside the basemap? Aren't geometries reprojecting well? Could it be that I have the wrong projections? Should I discriminate and only visualize those who cross the North Pole?

Any idea what might be going on?

I'm using OL 6.3.1 ,proj4 2.6.2 and Geoserver 2.17 and I'm also testing with OL 4.6.5 and proj4 2.4.4, in case the error is due to the version of the libraries.

UPDATE

I finally found a solution. I'll have to try it out more but it works for now.

The projection I'm using is restricting the latitude to over 65, but by returning the geometries I'm not doing that.

If I add a filter, restricting the latitude, everything works correctly.

CQL_FILTER=BBOX(the_geom,-180,65,180,89)
AND
other='whatever'

I'll try a projection without latitude restriction with North Polar ortographic for example, I think I'll have no problem there

enter image description here

  • 1
    Try specifying the data projection format: new ol.format.GeoJSON({dataProjection: "EPSG:949918"}) (that is for versions 5 and 6, use defaultDataProjection in OpenLayers 3 and 4) – Mike Jun 14 at 13:20
  • Thanks,But it doesn't work, they keep showing up outside the basemap.Maybe it's the basemap that should cover more area. Could it be? – Fran Raga Jun 14 at 16:30
  • Is the base data in the correct projection in the layer preview? – Ian Turton Jun 14 at 18:04
  • 1
    I would try to open both the basemap and vector map in QGIS using your custom projection (with the raw data not through WMS) to try to understand the case: the issue is due to webmap itself (server or client error/misconfiguration) or the data behind the scene? – ThomasG77 Jun 14 at 18:22
  • The data on the geoserver are in the projection EPSG:949900 (Mars 2000), basemap and gootprints.I've tried it with QGIS but the results are wrong too. I'll try it again. – Fran Raga Jun 14 at 18:36