Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for reading arcinfo adf tin layers #162 #164

Merged
merged 2 commits into from
Oct 14, 2019

Conversation

vcloarec
Copy link
Collaborator

First Draft, the mesh seems to be loaded. Need tests to verify if the geometry is ok.

@saberraz
Copy link
Contributor

@vcloarec nice.
I tried it with the attached mesh.

mdalinfo tnz.adf
Mesh loaded: OK
  Driver: ESRI_TIN
  Vertex count: 13
  Face count: 19
  Projection: undefined
Datasets loaded: OK
  Groups count: 1
  Terrain Elevation

But when I try to open it in QGIS, I get core dump.
top.zip

PS: we can probably use the attached TIN for test and credit http://lab.usgin.org

@PeterPetrik PeterPetrik self-requested a review October 11, 2019 05:58
Copy link
Contributor

@PeterPetrik PeterPetrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good start. just few small notes, but in general it looks very good.

#include "mdal_esri_tin.hpp"

//from https://stackoverflow.com/questions/41012414/convert-double-value-from-little-endian-to-big-endian
template <typename T>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have a function for this in https://github.com/lutraconsulting/MDAL/blob/master/mdal/frmts/mdal_selafin.cpp#L145

maybe we can just move that function to MDAL utils and use it here too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added new function in MDAL utils, and I have changed selafin driver and esri tin driver.
Tell me what do you think about ?
But I am not sure that it is a good idea because the number of bytes read in the file depend now of the size of type. Is there a risk that this size of type is different from platform to other ? If yes, it is maybe not a good idea ...

if ( ! faceIn.is_open() )
return false;

//check if the file sizes of the nodes are coherent ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it does not need to be... what you can check is first line of some file if they have some standard header/first line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't more information that the position of the points and the indexes of the face. The unused first bytes (64 bytes for tnxy.adf, and 16 bytes for tnz.adf) are used by ArcGIS to store information about 4 virtual points created by ArcGIS for triangulation/generation (https://en.wikipedia.org/wiki/Esri_TIN, see Superpoint). Those points seem to be necessary for ArcGIS but not for MDAL.

So, for me, the only information to know if a file can be read is :

  • if it can be opened
  • if the size of the tns.adf file (Z value file) is coherent with the size of of tnxy.adf file.
    I am not sure of the relevance of checking the size file coherence.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets keep it as it is, just remove commented out code please

mdal/frmts/mdal_esri_tin.cpp Outdated Show resolved Hide resolved
mdal/frmts/mdal_esri_tin.cpp Outdated Show resolved Hide resolved
mdal/frmts/mdal_esri_tin.cpp Outdated Show resolved Hide resolved
mdal/frmts/mdal_esri_tin.hpp Show resolved Hide resolved
mdal/mdal_utils.cpp Outdated Show resolved Hide resolved
@@ -505,6 +506,12 @@ void MDAL::addBedElevationDatasetGroup( MDAL::Mesh *mesh, const Vertices &vertic
mesh->datasetGroups.push_back( group );
}

void MDAL::addBedElevationDatasetGroup( MDAL::Mesh *mesh, const Vertices &vertices )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just use Bed elevation, not Terrain elevation . It is standard

Copy link
Collaborator Author

@vcloarec vcloarec Oct 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me "Bed Elevation" is specific for river bed elevation. Terrain Elevation could be more generic. As TIN are note only for river, that's why I purpose to keep Bed Elevation for format specific to hydraulic modeling, and maybe we can purpose another name for other format not specific to river.
A more generic name could be "Elevation" or simply "Altitude" ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whatabout keeping the Bed elevation and just change the name in the TIN driver...?

tests/CMakeLists.txt Outdated Show resolved Hide resolved
tests/test_esri_tin.cpp Show resolved Hide resolved
@PeterPetrik PeterPetrik added 2D enhancement New feature or request formats formats/providers labels Oct 11, 2019
@PeterPetrik PeterPetrik added this to the MDAL 0.4.0 milestone Oct 11, 2019
@nyalldawson
Copy link
Contributor

Wow, great work.... That was super fast!!

@vcloarec
Copy link
Collaborator Author

vcloarec commented Oct 11, 2019

@saberraz
The issue is may be fix, it was bad indexes for faces
Edit :
Issue was not completely fixed. Now it is better, I can load mesh in QGIS.
Now, there are still work to do, like manage CRS, optimization and take account of comments of Peter!

@vcloarec
Copy link
Collaborator Author

@PeterPetrik , I try to look at all your comments may be later today.

@saberraz
Copy link
Contributor

Nice, my test mesh works now!
test

@vcloarec
Copy link
Collaborator Author

vcloarec commented Oct 11, 2019

Nice, my test mesh works now!

It is not the prettier TIN I've seen :) When it displayed on my screen, I believed there is a big issue in the code, but no...
The non-public TINs sent by Nyall look better!

@nyalldawson
Copy link
Contributor

I've got some nice simple reference files incoming (freely licensed). Will post a link when I receive them!

@vcloarec
Copy link
Collaborator Author

vcloarec commented Oct 12, 2019

I've got some nice simple reference files incoming (freely licensed). Will post a link when I receive them!

@nyalldawson
Is it possible to have TIN files with holes ?

@nyalldawson
Copy link
Contributor

I'll ask. Also trying to get some with tagged edges/vertices...

@vcloarec vcloarec changed the title [WIP] Add support for reading arcinfo adf tin layers #162 Add support for reading arcinfo adf tin layers #162 Oct 14, 2019
@vcloarec
Copy link
Collaborator Author

vcloarec commented Oct 14, 2019

Hello,
With this last commit, I think MDAL reads ESRI TIN as well as possible. Holes haven't been tested, but with coming Nyall files, maybe it will be done.
My comments on particular points below :

Superpoints :
If the first bytes of xy file and z file are usually used for particular points (called "superpoints" here) that are not used by MDAL, it seems it is not always the case. The file "thul.adf" contains the indexes of the superpoints that can be no the first. The code has been adapted to take into account superpoints that are not at the
beginning. But as we don't have a file with superpoints not at the beginning, it is not tested in such a situation.

Mask :
ArcGIS uses a mask to make invisible faces, those which are outside the outer boundaries, in holes or linked with superpoints. In this PR, MDAL simply used the mask file to ignore those faces.

Name of the TIN :
ESRI TINs are saved in a folder that the user gives when he creates it in ArcGis. All the different files in this folder always have the same names and have all the extension *.adf. As MDAL and QGIS used a filename to load a mesh, the trick is to retrieve the folder with any files with *.adf extension is provided to MDAL. So, in QGIS, selecting any *.adf files permits to load the TIN. The bad consequence is the name of the mesh is the name of the selected file, not the name of the folder...
I have implemented a method in the ESRI TIN driver to retrieve the name of the TIN. But now, it is not used because it seems not trivial for QGIS to obtain this name...

Endianness :
The endianness is handled by a new function in MDAL utils. This template function permits to read the value of any type in a binary file. An option provides the possibility to change the endianness of the value if needed.
Depending on the platform, if the type size is not compatible with the same type in the file, the caller keeps the responsibility to handle with this.
For Selafin driver, I have changed the read_double() method to see how this method could be improved. But, as some other methods could have to be changed too, I purpose to restore the initial code of this method. The Selafin driver could be improved in another commit/PR if the new template function is pertinent.

mdal/frmts/mdal_esri_tin.cpp Outdated Show resolved Hide resolved
@PeterPetrik
Copy link
Contributor

thanks a lot, merging!

@PeterPetrik PeterPetrik merged commit 6f9ebab into lutraconsulting:master Oct 14, 2019
@nyalldawson
Copy link
Contributor

Awesome work -- this is very exciting!

@PeterPetrik any chance of a mdal version bump prior to QGIS 3.10.0?

@nyalldawson
Copy link
Contributor

@vcloarec here's a zipped archive of a bunch of freely-usable tin reference files

tins.zip

It includes the original dems, the arcgis tins, and the results of exporting the tins to polygon layers (in the gdb file).

Hope it helps verify the holes/islands cases!

@vcloarec
Copy link
Collaborator Author

vcloarec commented Oct 14, 2019

Thanks @nyalldawson , I quickly tried to load the mesh in QGIS, and all have been loaded, with holes and islands. I will add this TIN to the test folder and add tests, but later, I don't have time anymore...
I am very happy this enhancement seems to be in the next release of QGIS!

@nyalldawson
Copy link
Contributor

@vcloarec

For completeness, the attached updates to the tins adds an example with tagged vertices. That should cover all the functionality possible in this format:

dem (2).zip

@PeterPetrik
Copy link
Contributor

@nyalldawson @vcloarec any possibility you have time to add those to test suite?

@vcloarec
Copy link
Collaborator Author

@nyalldawson @vcloarec any possibility you have time to add those to test suite?

I don't have a lot of time this week for that. I will try next week.

@vcloarec
Copy link
Collaborator Author

Hi,
I started to add the test with the TINs give by @nyalldawson.
First test, no problem, the vertices count and the faces count read by MDAL are the same than in the gdb files.
When testing the dem with hole, there is a little difference with vertices count between MDAL and the gdb file. Two of those extra vertices are in blue in the picture below (the underlayer is the raster TIN, the source ?)
image

I think, during any of the conversions, faces have gone away and the vertices stay alone... Maybe, this is due of the border of the raster TIN.

So, in the ESRI TIN files, it seems there are vertices without faces ...
I purpose to implement a process to remove those isolated vertices, but it will slow down the loading...
What do you think about ?

@nyalldawson
Copy link
Contributor

@vcloarec I can't work out quite where in the tin you are looking -- can you show the whole extent?

@nyalldawson
Copy link
Contributor

@vcloarec disregard that, sorry!

@nyalldawson
Copy link
Contributor

@vcloarec
Here's what I see in arcmap:

image

So those extra vertices are attached only to edges with a type of "Outside edge" (3). I gather you are currently stripping these away during the conversion?

@vcloarec
Copy link
Collaborator Author

@nyalldawson, yes, outside faces (so implicitly associated edges, as MDAL doesn't store directly the edges) are stripped away.
For my information, what is the relation between the raster DEM (tif) and the TIN ? If the raster DEM is a conversion from the TIN, it is weird that some pixels are outside the boundary :
Screenshot_20191025_082040

In any cases, even if there is no visual consequences to keep the isolated vertices, I think it is cleaner to strip away this vertices too when loading the mesh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2D enhancement New feature or request formats formats/providers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants