Select to view content in your preferred language

Surface not created with custom DEM raster

1486
9
Jump to solution
04-23-2023 05:46 AM
maglourenco1
Occasional Contributor

Greetings everyone,

I've prepared a local raster that is a Digital Elevation Model (DEM) for a particular area of study (I will attach it).

I recreated this example using my custom raster and the Monterey raster provided in this example.

For some reason, the app loads my custom raster but does not render the 3D scene using the raster. It is quite strange because I know it loads the raster, plus, I use the raster to calculate the smartphone's view ray using the elevation data from the DEM.

It all works just fine, only the 3D surface rendering does not work for some reason...

Any idea what might be causing this? I know the Spatial References are different but it is probably not due to that because I also tried with another custom raster with the same Spatial Reference as the Monterey's raster, and the same happens.

Thank you.

Cheers

0 Kudos
1 Solution

Accepted Solutions
maglourenco1
Occasional Contributor

Greetings everyone,

I understood what happened so my raster is not rendered as a 3D Surface. Indeed the raster values were being used to calculate de view-ray. Still, the 3D Surface wasn't being rendered because the raster (ETRS89) and the SceneView (WGS84) were in different Spatial References (I didn't think so but actually they were).

I projected my raster to WGS84 and the 3D Surface was rendered.

Thus I close this topic and thanks for your attention.

View solution in original post

0 Kudos
9 Replies
KoushikHajra
Esri Contributor

Hello @maglourenco1 ,

Thank you for reaching out to us with your query. Is it possible for you to share your code with us so that we can see if there is anything obvious that stands out? 

Also, can you please wire up the layerViewState on the sceneview and see if you can see any errors? That could give you a clue as to what could be going wrong. 

Regards,

Koushik 

0 Kudos
maglourenco1
Occasional Contributor

Greetings,

Thank you very much for your help, I'm sorry I forgot to add the code.

Here is the code to load the raster from this sample:

 

public void createTerrainFromLocalRaster() {
        mSceneView = findViewById(R.id.sceneView);

        // create a scene and add a basemap to it
        ArcGISScene scene = new ArcGISScene(Basemap.createImagery());
        Log.i("SPATIAL REF", scene.getSpatialReference().getWKText());

        // add the scene to the sceneview
        mSceneView.setScene(scene);

        // specify the initial camera position
        Camera camera = new Camera(36.525, -121.80, 300.0, 180, 80.0, 0.0);
        mSceneView.setViewpointCamera(camera);

        // raster package file paths
        ArrayList<String> filePaths = new ArrayList<>();
        filePaths.add(getExternalFilesDir(null) + "/MontereyElevation.dt2");

        try {
            // add an elevation source to the scene by passing the URI of the raster package to the constructor
            RasterElevationSource rasterElevationSource = new RasterElevationSource(filePaths);

            // add a listener to perform operations when the load status of the elevation source changes
            rasterElevationSource.addLoadStatusChangedListener(loadStatusChangedEvent -> {

                // when elevation source loads
                if (loadStatusChangedEvent.getNewLoadStatus() == LoadStatus.LOADED) {
                    // add the elevation source to the elevation sources of the scene
                    mSceneView.getScene().getBaseSurface().getElevationSources().add(rasterElevationSource);
                    Log.i("RASTER", "ELEVATION SOURCES: " + mSceneView.getScene().getBaseSurface().getElevationSources().get(0).getName());

                    Log.i("RASTER", "Raster successfully loaded");
                } else if (loadStatusChangedEvent.getNewLoadStatus() == LoadStatus.FAILED_TO_LOAD) {
                    // notify user that the elevation source has failed to load
                    Log.e("ERROR", "Error loading the raster");
                }
            });

            // load the elevation source asynchronously
            rasterElevationSource.loadAsync();
        } catch (IllegalArgumentException e) {
            // catch exception thrown by RasterElevationSource when a file is invalid/not found
            Log.e("ERROR", "The elevation source has failed to load. Please ensure that the .dt2 has been pushed to the device\\'s storage.");
        }
    }

 

And here is the code to load my custom raster

 

public void addDEMToMap() {
        try {
            // create an elevation source, and add this to the base surface of the scene
            // raster package file paths
            ArrayList<String> filePaths = new ArrayList<>();
            filePaths.add(getExternalFilesDir(null) + "/dem_30m.tif");
            Log.i("DEM PATH", filePaths.toString());

            // add an elevation source to the scene by passing the URI of the raster package to the constructor
            RasterElevationSource rasterElevationSource = new RasterElevationSource(filePaths);

            // add a listener to perform operations when the load status of the elevation source changes
            rasterElevationSource.addLoadStatusChangedListener(loadStatusChangedEvent -> {
                // when elevation source loads
                if (loadStatusChangedEvent.getNewLoadStatus() == LoadStatus.LOADED) {
                    // add the elevation source to the elevation sources of the scene
                    Toast.makeText(this, "DEM did load", Toast.LENGTH_LONG).show();
                    Log.i("DEM", "DEM did load");
                    mSceneView.getScene().getBaseSurface().getElevationSources().add(rasterElevationSource);
                    Log.i("RASTER", "ELEVATION SOURCES: " + mSceneView.getScene().getBaseSurface().getElevationSources().get(0).getName());
                } else {
                    Toast.makeText(this, "DEM did NOT load", Toast.LENGTH_LONG).show();
                    Log.i("DEM", "DEM did NOT load");
                }
            });

            // load the elevation source asynchronously
            rasterElevationSource.loadAsync();
        } catch (IllegalArgumentException e) {
            // catch exception thrown by RasterElevationSource when a file is invalid/not found
            Toast.makeText(this, "DEM did NOT load", Toast.LENGTH_LONG).show();
            Log.i("DEM", "DEM did NOT load");
        }
    }

 

 

EDIT: "Also, can you please wire up the layerViewState on the sceneview and see if you can see any errors? That could give you a clue as to what could be going wrong." I didn't understand what was meant in this message

 

 

Thank you

0 Kudos
KoushikHajra
Esri Contributor

Thank you for sharing the code. I'll try it on my end to see if I can replicate with your data.

Re: layerViewStated: I wanted to see if you could wire up the listener below and see if can see any errors being emitted.

https://developers.arcgis.com/kotlin/api-reference/arcgis-maps-kotlin/com.arcgismaps.mapping.view/-g...

Hope this helps!

 

0 Kudos
maglourenco1
Occasional Contributor

Thank you very much.

I'm developing my mobile app using Java (not Kotlin).

Plus, I think that what you mentioned is appropriate when we're developing with an architecture (such as MVVM). If so, I'm not developing under any architecture.

Cheers

0 Kudos
KoushikHajra
Esri Contributor

Java also has the layerViewStateChanged. You should be able to listen to it from the sceneview. Here is the doc for it: 

https://developers.arcgis.com/java/api-reference/reference/com.esri.arcgisruntime/com/esri/arcgisrun...)

0 Kudos
maglourenco1
Occasional Contributor

Thank you very much I didn't know that.

What kind of LayerViewStateChangedEvent do you want me to publish here, the layer name?

Thank you

0 Kudos
maglourenco1
Occasional Contributor

Greetings,

I have some news regarding this issue.

So I have 2 DEMs, both of them are being used to perform the calculations but only one of them is being used to render the 3D surface.

The following one is working

yes.jpg

But his one is not.

no.jpg

What do you think might be causing this issue? Spatial Reference?

Regarding the layerViewStateChanged, it is returning the 'World Imagery' as expected (the basemap)

Thank you

0 Kudos
maglourenco1
Occasional Contributor

*forgot to attach both DEMs (zip file's names are self-explanatory)

0 Kudos
maglourenco1
Occasional Contributor

Greetings everyone,

I understood what happened so my raster is not rendered as a 3D Surface. Indeed the raster values were being used to calculate de view-ray. Still, the 3D Surface wasn't being rendered because the raster (ETRS89) and the SceneView (WGS84) were in different Spatial References (I didn't think so but actually they were).

I projected my raster to WGS84 and the 3D Surface was rendered.

Thus I close this topic and thanks for your attention.

0 Kudos