Trying to load the tfw when opening a tif file

3883
24
Jump to solution
03-07-2017 08:06 AM
TorbenWiggerich
New Contributor III

Hello ,

I am trying to load a tif file (map000.tif) and also the correspondig tfw file (map000.tfw). 

What he actually does is, he loads the given map (map000.tif) and shows it. But I don't think that he loaded the tfw file correctly. (So loading two rasters they will be shown at the same position.)

There is no SpatialReference which I could set?

I tried to set the set SpatialReference of the Map (m_map) but it then shows nothing.

m_mapView = new MapGraphicsView( this );

QString dataPath = "<Path>\\map000.tif";
Esri::ArcGISRuntime::Raster * raster = new Esri::ArcGISRuntime::Raster( dataPath, this );
Esri::ArcGISRuntime::RasterLayer* rasterLayer = new Esri::ArcGISRuntime::RasterLayer( raster, this );

std::cout << "SpatialRefernce: " << rasterLayer->spatialReference().wkid() << std::endl;

mp_basemap = new Esri::ArcGISRuntime::Basemap( rasterLayer, this );
m_map = new Esri::ArcGISRuntime::Map( mp_basemap, this );
m_mapView->setMap( m_map );

What do I wrong?

A long time ago I had a similar question concering the SDK 10.2.3.

How to load the .tfw file when opening a .tif file? 

With kind regards

Torben

0 Kudos
1 Solution

Accepted Solutions
LucasDanzinger
Esri Frequent Contributor

Your 10.2.3 example uses Local Server. Have you tried 100.x with Local Server? Perhaps that'll give you the expected output - arcgis-runtime-samples-qt/DynamicWorkspaceRaster.cpp at master · Esri/arcgis-runtime-samples-qt · Gi... 

If that doesn't work, I think you might want to consider contacting Esri support to work through this issue. They will be able to help troubleshoot your issue further

View solution in original post

0 Kudos
24 Replies
LukeSmallwood
Esri Contributor

Hi Torben,

I think your code to load the RasterLayer looks correct - however, the spatialReference for this layer will not be set until it has been loaded. In your example, this happens when the map is added to the mapView, triggering a load for all of the dependant objects. You can read more about the details of our Loadable Pattern on this Guide Topic: Loadable pattern for asynchronous resources—ArcGIS Runtime SDK for Qt | ArcGIS for Developers 

If you want to log the spatialReference of your layer once it has been loaded, you can add a connection to the "doneLoading" signal of this type - for example, replace this line:

std::cout << "SpatialRefernce: " << rasterLayer->spatialReference().wkid() << std::endl;

with:

connect(rasterLayer, &RasterLayer::doneLoading, this, [rasterLayer](Error loadError)  {
   if (rasterLayer->loadStatus() == LoadStatus::Loaded)
      qDebug() << "SpatialRefernce: " << rasterLayer->spatialReference().wkid();

});

I hope that helps,

Luke

0 Kudos
TorbenWiggerich
New Contributor III

Hi Luke,

thanks for your quick response!

I replaced the code and now I get the  following line:

SpatialReference: 0

So I think the problem is that I get a SpatialReference of 0. How can I change this?

With kind regards

Torben

0 Kudos
DanPatterson_Retired
MVP Emeritus

within any of the Arc* suite of software a *.tifw doesn't not contain the spatial reference reference (ie ESPG code etc), it just contains information on how to translate the coordinate space.  For more information see this link

0 Kudos
TorbenWiggerich
New Contributor III

Hi,

ah ok that is good to know, that there is no spatial reference!

So my problem is than if I set the SpatialReference to load wgs84 and then load the given tif. 

To see the image we need to set the viewpoint correctly. What is done I hope...

But I can't see anything...

m_mapView = new MapGraphicsView(this);
m_map = new Esri::ArcGISRuntime::Map( Esri::ArcGISRuntime::SpatialReference::wgs84(), this );
QString dataPath = "<Path>\\map000.tif";
Esri::ArcGISRuntime::Raster * raster = new Esri::ArcGISRuntime::Raster( dataPath, this );
Esri::ArcGISRuntime::RasterLayer* rasterLayer = new Esri::ArcGISRuntime::RasterLayer( raster, this );
mp_basemap = new Esri::ArcGISRuntime::Basemap( rasterLayer, this );
m_map->setBasemap( mp_basemap );
m_mapView->setMap( m_map );
Esri::ArcGISRuntime::Envelope envelope( 5.520, 52.270, 5.530, 52.280, Esri::ArcGISRuntime::SpatialReference::wgs84() );
m_mapView->setViewpointGeometry( envelope );

And the map000.tfw file has the following format:

1,07020139694214E-05
0
0
-6,54231601356988E-06
5,52524901390075
52,2788632621671

With kind regards

Torben

0 Kudos
LukeSmallwood
Esri Contributor

Hi Torben,

Can you confirm that the raster you have is actually in wgs84? Rather than manually creating the envelope from the data in the .tfw file you could try setting the map view to the layers extent when it is loaded. Something like:

connect(rasterLayer, &RasterLayer::doneLoading, this, [this, rasterLayer](Error loadError)

{
      if (loadError.isEmpty())

            m_mapView->setViewpointGeometry(rasterLayer->fullExtent());

});

0 Kudos
TorbenWiggerich
New Contributor III

Hey,

so runinng the old version (10.2.3) it was ok to load it with a setting of SpatialReference 4326. Which is in my opinion the same as wgs84?

I changed my code to your above statement. 

connect(rasterLayer, &RasterLayer::doneLoading, this, [this, rasterLayer](Error loadError)
{
     if (loadError.isEmpty())
     {
          m_mapView->setViewpointGeometry(rasterLayer->fullExtent());
          std::cout << "Set map view: " << rasterLayer->fullExtent().xMin() << ", " << rasterLayer->fullExtent().yMin() << " -> " << rasterLayer->fullExtent().xMax() << ", " << rasterLayer->fullExtent().yMax() << std::endl;
     }
});

But he gives me the following output:

Set map view: -nan(ind), -nan(ind) -> -nan(ind), -nan(ind)

0 Kudos
LukeSmallwood
Esri Contributor

Hi Torben,

I've tried with a few raster data-sets here and they are all working correctly. Would it be possible for you to share the data in anyway?

Another thing you could try is to simply load a map with a basemap (not your raster) at the envelope position you use above to confirm that is correct.  When I do that, I see an area near Almere in the Netherlands - is that correct? The code I am using is:

Basemap* basemap = Basemap::imageryWithLabels(this);
Map* map = new Esri::ArcGISRuntime::Map( /*Esri::ArcGISRuntime::SpatialReference::wgs84(),*/ this );

map->setBasemap( basemap );
m_mapView->setMap(map);
Esri::ArcGISRuntime::Envelope envelope( 5.520, 52.270, 5.530, 52.280, Esri::ArcGISRuntime::SpatialReference::wgs84() );
m_mapView->setViewpointGeometry( envelope );

Notice that I have commented out the Spatial Reference in the constructor of the Map: when I uncomment this, the position is not loaded correctly (I will investigate that further).

If this loads at your desired location, you could try your raster code but creating the Map with no Spatial Reference?

0 Kudos
TorbenWiggerich
New Contributor III

Hi Luke,

I'm not sure what I should share with you? So I have just an Image (tif) and the corresponding tfw file. The tfw file I have already posted. Do you want the image?

The problem is that when I open the tif, without setting the map, it will display all loaded tifs at the same position. So they are all overlapped at the same position. It seems that in this case even the tfw file is not loaded...

Because of this I think I have to use the following line:

Map* map = new Esri::ArcGISRuntime::Map( Esri::ArcGISRuntime::SpatialReference::wgs84(), this );

Else all loaded tif are overlapping...

But then I don't see anything...

0 Kudos
TorbenWiggerich
New Contributor III

Ah sorry, yes it is the correct position  

0 Kudos