RasterLayer is not showing the image at right location

1018
4
11-22-2016 02:46 AM
JoseFernandez6
New Contributor

Hello,

I'm developing an Android application and I'm trying to add a RasterLayer to may map containing a tif image. The map has web mercator 102100 as spatial reference and the spatial reference of the image is different (ED50 / UTM 30N). I have the .pfj, .tif and .tfw files in the same folder. This is my code to add the RasterLayer to my MapView:

String rasterPath = "<path to tif image>";
FileRasterSource rasterSource = null;
try {
   rasterSource = new FileRasterSource(rasterPath);
   rasterSource.project(mMapView.getSpatialReference());
   RasterLayer rasterLayer = new RasterLayer(rasterSource);
   rasterLayer.setOpacity(0.5f);
   mMapView.addLayer(rasterLayer);
} catch (IllegalArgumentException ie) {
   Log.d("IAE", "null or empty path");
} catch (FileNotFoundException fe) {
   Log.d("FNFE", "raster file doesn't exist");
} catch (RuntimeException re) {
   Log.d("RE", "raster file can't be opened");
}

When I run the application, the image is shown in a bad location. I think the problem is the API is not making the reprojection of the image. How does the API know the spatial reference of the image? Do I need to add any other file?

Thanks in advance

0 Kudos
4 Replies
NeilAyres
MVP Alum

Although I have no idea of how to program this for Android, I do not speak java or whatever this is....

But, you say your raster image is in ED50 / UTM30N. That indicates to me that you will need a suitable datum transformation between ED50 and WGS84 (on which Web Mercator is based).

0 Kudos
NeilAyres
MVP Alum

Alternatively, just reproject the image first (with a transformation) from UTM30/ED50 to WebMerc/WGS84.

0 Kudos
JoseFernandez6
New Contributor

Hi Neil,

Thank you for your response. I agree with you I need a datum transformation. And there is the real problem: I don't know how to add that transformation. In that line: 

rasterSource.project(mMapView.getSpatialReference());

I indicate the source what spatial reference I want to use in my map. Then, the API would make the projection, but: what is the spatial reference of the image? I know the spatial reference but I don't know how to say the API what spatial reference is used in the image in order to make the projection.

Thanks again for your help

0 Kudos
NeilAyres
MVP Alum

Well, there are a whole stack of ED50 to WGS84 transformations available to you. Which one depends on the location of your data and accuracy.

See pages 12 to 14 of the geographic_transformations.pdf found in the documentation folder of the ArcGIS installation.

In ArcGIS / arcpy / python world, the transformation is set in the environment variables. So, no idea how to do this in Android.

As I said before, isn't it just vest to use the normal desktop tools and reproject / transform the image up front.

0 Kudos