How to detect Tiled Package conflict, compatibility issue ?

4219
8
Jump to solution
04-08-2013 05:13 AM
JeremieJoalland1
Occasional Contributor II
Take a disconnected application (no internet) with ArcGIS Runtime 10.1.1, where the user can load data by selecting source file.
In my application, user can select these file formats : .tif, .jp2, .shp, .mpk and .tpk.
- The rasters and shapefile are loaded through a blank mpk in WGS 84 coordinate system and will reproject correctly on another basemap if necessary,
- same thing with mpk which will reproject correctly if necessary,
- but I have issues on TPK loading (Tiled Packages) !

I have created some simple TPK from shapefile data to test the load of multiple tiled packages. the TPK can differs from Map coordinates system and from Tiling Scheme.

My Tiled Packages :

- Canada.tpk : WGS_1984_Web_Mercator_Auxiliary_Sphere & ArcGIS Online tiling scheme
- Canada_cities.tpk : WGS_1984_Web_Mercator_Auxiliary_Sphere & ArcGIS Online tiling scheme
- Canada_myScheme.tpk : GCS_North_American_1983 & my tiling scheme (6 scales - xml created by "Generate Map Server Chache Tiling Scheme" tool.
- Canada_myScheme_cities.tpk : GCS_North_American_1983 & my tiling scheme

(when creating TPK, it seems that ArcGIS Online tiling scheme change the coordinate system from "GCS_North_American_1983" to "WGS_1984_Web_Mercator_Auxiliary_Sphere")

Here are my results when I load (using one button for each tpk) :
- Canada.tpk + Canada_cities.tpk : display is correct,
- Canada_myScheme.tpk + Canada_myScheme_cities.tpk : display is correct,
- Canada_myScheme.tpk (WGS84) + Canada_cities.tpk (NAD83) : the 2nd TPK is not display at all. I can understand that coordinates system is different, but the 2nd tpk is initialized correctly (from Listener). Also strange, the fullExtent was limited at Canada_myScheme.tpk extent and when I added the 2nd tpk, I could zoom out according to full extent of 2nd tpk, even if nothing is displayed. So it seems that JMap managed the 2 TPK, but can't display the tiles of 2nd tpk.

but how can I manage this uncompatibility ?... catch it in order to inform the user ?

Layer status is "INITIALIZED", so I can't catch issue there... I also can't get the spatial reference from tiled package before adding it to the map... and once it's added, the getSpatialReference() is the same than map's spatial reference...

I attach my test application source code with zipped tpk files.
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: mbaird

You can detect the spatial reference before you add the tpk to the map. 

Take a look at the following code:

        //final ArcGISLocalTiledLayer tl = new ArcGISLocalTiledLayer("C:\\Data\\forum\\Canada.tpk");
        //final ArcGISLocalTiledLayer tl = new ArcGISLocalTiledLayer("C:\\Data\\forum\\Canada.tpk");
        final ArcGISLocalTiledLayer tl = new ArcGISLocalTiledLayer("C:\\Data\\forum\\Canada_myScheme.tpk");

       
        tl.initializeAsync();
       
        tl.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {
  
   @Override
   public void layerInitializeComplete(LayerInitializeCompleteEvent e) {
    // TODO Auto-generated method stub
  
    System.out.println("init" + tl.getDefaultSpatialReference().getText());
   
   
    //add it to the map if you are happy with the spatial reference
    map.getLayers().add(tl);
   }
  });


Does this help?

Mark

View solution in original post

0 Kudos
8 Replies
by Anonymous User
Not applicable
Original User: mbaird

You can detect the spatial reference before you add the tpk to the map. 

Take a look at the following code:

        //final ArcGISLocalTiledLayer tl = new ArcGISLocalTiledLayer("C:\\Data\\forum\\Canada.tpk");
        //final ArcGISLocalTiledLayer tl = new ArcGISLocalTiledLayer("C:\\Data\\forum\\Canada.tpk");
        final ArcGISLocalTiledLayer tl = new ArcGISLocalTiledLayer("C:\\Data\\forum\\Canada_myScheme.tpk");

       
        tl.initializeAsync();
       
        tl.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() {
  
   @Override
   public void layerInitializeComplete(LayerInitializeCompleteEvent e) {
    // TODO Auto-generated method stub
  
    System.out.println("init" + tl.getDefaultSpatialReference().getText());
   
   
    //add it to the map if you are happy with the spatial reference
    map.getLayers().add(tl);
   }
  });


Does this help?

Mark
0 Kudos
MarkBaird
Esri Regular Contributor
It's also worth noting that there is a cost (sometimes quite significant) to reprojecting spatial data on the fly.  It will always take longer to render data which is not in the same spatial reference.

I do however think that it's acceptable to have a web Mercator basemap and project data in a wgs84 spatial reference.  This is not a costly process.

Mark
0 Kudos
by Anonymous User
Not applicable
Original User: jjoalland13

You can detect the spatial reference before you add the tpk to the map. 

final ArcGISLocalTiledLayer tl = new ArcGISLocalTiledLayer("C:\\Data\\forum\\Canada_myScheme.tpk"); 
tl.initializeAsync(); 
tl.addLayerInitializeCompleteListener(new LayerInitializeCompleteListener() { 
@Override 
public void layerInitializeComplete(LayerInitializeCompleteEvent e) { 
System.out.println("init" + tl.getDefaultSpatialReference().getText()); 
  
//add it to the map if you are happy with the spatial reference 
map.getLayers().add(tl); 

});


When I try your solution with asynchronous initialize, I still can't get the Spatial Reference of the TPK before adding it to the map... tl.getDefaultSpatialReference is always Null !

for exemple, my following code (using tl.initializeAsync(); ) :
@Override
public void layerInitializeComplete(LayerInitializeCompleteEvent e) {
 count++;
 ArcGISLocalTiledLayer layer = (ArcGISLocalTiledLayer) e.getLayer();
 if (layer.getStatus() == LayerStatus.INITIALIZED) {
  System.out.println(String.format(count + "-LayerInitializeCompleteEvent- Layer '%s' is initialized !", layer.getName()));
  
  if (layer.getSpatialReference() != null) {
   System.out.println(count + "   layer spatial ref : " + layer.getSpatialReference().getText());
  }
  else {
   System.out.println(count + "   layer spatial ref IS NULL !!!");
  }
  
  //add it to the map if you are happy with the spatial reference
  map.getLayers().add(layer);
 } else {
  System.out.println(String.format(count + "-LayerInitializeCompleteEvent- ERROR: Layer '%s' has status : '%s'", layer.getName(), layer.getStatus()));   }
}


produce following output result when I click load 2 TPK from same spatial ref :
Java version : 1.7.0_07 (Oracle Corporation) x86
Rendering engine : DirectX
1-LayerInitializeCompleteEvent- Layer 'C:\temp\Canada.tpk' is initialized !
1   layer spatial ref IS NULL !!!
-MapEventListenerAdapter- Map is ready !
2-LayerInitializeCompleteEvent- Layer 'C:\temp\Canada_cities.tpk' is initialized !
2   layer spatial ref IS NULL !!!
0 Kudos
JeremieJoalland1
Occasional Contributor II
It's also worth noting that there is a cost (sometimes quite significant) to reprojecting spatial data on the fly.  It will always take longer to render data which is not in the same spatial reference.

I do however think that it's acceptable to have a web Mercator basemap and project data in a wgs84 spatial reference.  This is not a costly process.


I agree with on this point, and reprojecting on the fly is working fine on my application with Shapefile and rasters for exemple.

My question was more about multiple Tiled Package which are composed of tiled/images :
  - Is it possible to overlap 2 Tiled Packages which are in different Spatial Reference ?

When I try it, the 2nd Tiled Pacakge seems to be added (no exception/error), but it's not displayed on the map !
0 Kudos
by Anonymous User
Not applicable
Original User: eacheson

Is it possible to overlap 2 Tiled Packages which are in different Spatial Reference ?


Hi,

It's not possible, no. You can't stack tiled layers with a difference spatial reference.

The first layer added to the map will define the map's spatial reference. Subsequent layers, except for tiled layers, will be re-projected to this spatial reference. Tiled layers won't be displayed if the tiled layer's spatial reference doesn't match the map's spatial reference (and hence the first layer's spatial reference).

~elise
0 Kudos
JeremieJoalland1
Occasional Contributor II
It's not possible, no. You can't stack tiled layers with a difference spatial reference.

The first layer added to the map will define the map's spatial reference. Subsequent layers, except for tiled layers, will be re-projected to this spatial reference. Tiled layers won't be displayed if the tiled layer's spatial reference doesn't match the map's spatial reference (and hence the first layer's spatial reference).


my last issue is now to find a way to catch this difference... Once the user has selected a TPK file to load it, how can I check its spatial reference is not compatible with the current map ?

for now, there is no error, no exception... ArcGIS Runtime behave like it can manage this new TPK (with different spatial reference) but without displaying it !! and this it not acceptable for us... we need to be able to catch the issue and inform the user with proper message.
0 Kudos
by Anonymous User
Not applicable
Original User: mbaird

The code you posted earlier showed you were using the getSpatialReference method.

I suggusted trying the getDefaultSpatialReference method.  Is this not working for you?

Mark
0 Kudos
JeremieJoalland1
Occasional Contributor II
The code you posted earlier showed you were using the getSpatialReference method.
I suggusted trying the getDefaultSpatialReference method.  Is this not working for you?


sorry Mark, it's my mistake... I read to fast and was using getSpatialReference instead of getDefaultSpatialReference as suggested.

so it's working fine now ! thanks.
0 Kudos